//! Surfaces, which are areas at a certain position in a vector space. use super::{LineSegment, Polygon, Rect, Vec2}; use float_cmp::ApproxEq; use nalgebra::RealField; /// Trait that describes an area in the vector space on the field of T, with T unable to be /// used without rounding. pub trait Surface where T: ApproxEq, { /// Checks if a point lies on this surface. fn contains_point(&self, point: &Vec2, margin: M) -> bool; /// Checks if a line segment is entirely contained by this surface. fn contains_line_segment(&self, line_segment: &LineSegment, margin: M) -> bool; /// Checks if a rectangle is entirely contained inside this surface. fn contains_rect(&self, rect: &Rect, margin: M) -> bool; /// Checks if a polygon is contained wholly by this surface. fn contains_polygon(&self, polygon: &Polygon, margin: M) -> bool; /// Checks if this surface is contained by the rect in it's entirety. Think of it as the reverse /// operation for contains_... on a rectangle. fn is_inside_rect(&self, rect: &Rect) -> bool; } /// The same as Surface, but the vector space will be assumed to be perfectly divideable or checkable. pub trait ExactSurface { /// Checks if a point lies on this surface. fn contains_point(&self, point: &Vec2) -> bool; /// Checks if a line segment is entirely contained by this surface. fn contains_line_segment(&self, line_segment: &LineSegment) -> bool; /// Checks if a rectangle is entirely contained inside this surface. fn contains_rect(&self, rect: &Rect) -> bool; /// Checks if a polygon is contained wholly by this surface. fn contains_polygon(&self, polygon: &Polygon) -> bool; /// Checks if this surface is contained by the rect in it's entirety. Think of it as the reverse /// operation for contains_... on a rectangle. fn is_inside_rect(&self, rect: &Rect) -> bool; } /* // Every exact surface must also be an approximate surface, with margin 0 to be exact. impl Surface for S where S: ExactSurface { fn contains_point(&self, point: &Vec2, _margin: M) -> bool { ExactSurface::contains_point(&self, point) } fn contains_line_segment(&self, line_segment: &LineSegment, margin: M) -> bool { ExactSurface::contains_line_segment(&self, line_segment) } fn contains_rect(&self, rect: &Rect, margin: M) -> bool { ExactSurface::contains_rect(&self, rect) } fn contains_polygon(&self, polygon: &Polygon, margin: M) -> bool { ExactSurface::contains_polygon(&self, polygon) } fn is_inside_rect(&self, rect: &Rect) -> bool { ExactSurface::is_inside_rect(&self, rect) } } */