aboutsummaryrefslogtreecommitdiff
path: root/src/world/component.rs
blob: e8a8df9f9a01ef83df0897b9dfedac89d575ee3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//! The world is made up of components. Every component must implement this
//! general trait that makes it possible to argue about certain characteristics
//! and may make it possible to transform some items.

use crate::math::Rect;
use crate::transformable::NonRigidTransformable;

/// Anything that can be added to the map or world must implement this trait.
pub trait Component {
    /// Get the rectangle that contains the component in its entirety without excess.
    fn bounding_rect(&self) -> Rect<f64>;

    /// If this component can be transformed in a non-rigid way, a dynamic
    /// reference is returned, otherwise none.
    fn as_non_rigid(&self) -> Option<&dyn NonRigidTransformable> {
        None
    }

    /// The same as `as_non_rigid`, but mutably.
    fn as_non_rigid_mut(&mut self) -> Option<&mut dyn NonRigidTransformable> {
        None
    }
}