aboutsummaryrefslogtreecommitdiff
path: root/src/math/surface.rs
blob: 088ac471037f7f4bdaba94a048c7940bc460fb38 (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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! 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<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;

    /// Checks if a line segment is entirely contained by this surface.
    fn contains_line_segment(&self, line_segment: &LineSegment<T>) -> bool;

    /// Checks if a rectangle is entirely contained inside this surface.
    fn contains_rect(&self, rect: &Rect<T>) -> bool;

    /// Checks if a polygon is contained wholly by this surface.
    fn contains_polygon(&self, polygon: &Polygon<T>) -> 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;
}

/*
// 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)
    }
}
*/