aboutsummaryrefslogtreecommitdiff
path: root/src/math/surface.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/surface.rs')
-rw-r--r--src/math/surface.rs55
1 files changed, 52 insertions, 3 deletions
diff --git a/src/math/surface.rs b/src/math/surface.rs
index ab1c703..088ac47 100644
--- a/src/math/surface.rs
+++ b/src/math/surface.rs
@@ -1,10 +1,34 @@
//! Surfaces, which are areas at a certain position in a vector space.
use super::{LineSegment, Polygon, Rect, Vec2};
-use nalgebra::Scalar;
+use float_cmp::ApproxEq;
+use nalgebra::RealField;
-/// Trait that describes an area in the vector space on the field of T
-pub trait Surface<T: Scalar + Copy> {
+/// 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<T: RealField, M>
+where
+ T: ApproxEq<Margin = M>,
+{
+ /// Checks if a point lies on this surface.
+ fn contains_point(&self, point: &Vec2<T>, margin: M) -> bool;
+
+ /// Checks if a line segment is entirely contained by this surface.
+ fn contains_line_segment(&self, line_segment: &LineSegment<T>, margin: M) -> bool;
+
+ /// Checks if a rectangle is entirely contained inside this surface.
+ fn contains_rect(&self, rect: &Rect<T>, margin: M) -> bool;
+
+ /// Checks if a polygon is contained wholly by this surface.
+ fn contains_polygon(&self, polygon: &Polygon<T>, 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<T>) -> bool;
+}
+
+/// The same as Surface, but the vector space will be assumed to be perfectly divideable or checkable.
+pub trait ExactSurface<T: RealField> {
/// Checks if a point lies on this surface.
fn contains_point(&self, point: &Vec2<T>) -> bool;
@@ -21,3 +45,28 @@ pub trait Surface<T: Scalar + Copy> {
/// operation for contains_... on a rectangle.
fn is_inside_rect(&self, rect: &Rect<T>) -> bool;
}
+
+/*
+// Every exact surface must also be an approximate surface, with margin 0 to be exact.
+impl<T, S> Surface<T> for S where S: ExactSurface<T> {
+ fn contains_point<M>(&self, point: &Vec2<T>, _margin: M) -> bool {
+ ExactSurface::contains_point(&self, point)
+ }
+
+ fn contains_line_segment<M>(&self, line_segment: &LineSegment<T>, margin: M) -> bool {
+ ExactSurface::contains_line_segment(&self, line_segment)
+ }
+
+ fn contains_rect<M>(&self, rect: &Rect<T>, margin: M) -> bool {
+ ExactSurface::contains_rect(&self, rect)
+ }
+
+ fn contains_polygon<M>(&self, polygon: &Polygon<T>, margin: M) -> bool {
+ ExactSurface::contains_polygon(&self, polygon)
+ }
+
+ fn is_inside_rect(&self, rect: &Rect<T>) -> bool {
+ ExactSurface::is_inside_rect(&self, rect)
+ }
+}
+*/