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 73 74 75
pub mod circle;
// pub mod ellipse;
pub mod line;
pub mod polygon;
pub mod rect;
pub mod triangle;
use crate::prelude::*;
/// A shape counts as contained if it is fully inside
pub trait ContainsShape {
/// Returns true if `self` contains `rect`
#[must_use]
fn contains_rect(&self, rect: &Rect) -> bool
where
Self: Shape + Sized,
{
contains_points(self, rect)
}
/// Returns true if `self` contains `circle`
#[must_use]
fn contains_circle(&self, circle: &Circle) -> bool
where
Self: Shape + Sized,
{
contains_points(self, circle)
}
/// Returns true if `self` contains `line`
#[must_use]
fn contains_line(&self, line: &Line) -> bool
where
Self: Shape + Sized,
{
contains_points(self, line)
}
/// Returns true if `self` contains `triangle`
#[must_use]
fn contains_triangle(&self, triangle: &Triangle) -> bool
where
Self: Shape + Sized,
{
contains_points(self, triangle)
}
// /// Returns true if `self` contains `ellipse`
// #[must_use]
// fn contains_ellipse(&self, ellipse: &Ellipse) -> bool
// where
// Self: Shape + Sized,
// {
// contains_points(self, ellipse)
// }
/// Returns true if `self` contains `polygon`
#[must_use]
fn contains_polygon(&self, polygon: &Polygon) -> bool
where
Self: Shape + Sized,
{
contains_points(self, polygon)
}
}
#[inline]
fn contains_points(shape: &dyn Shape, other: &dyn Shape) -> bool {
for point in other.points() {
if !shape.contains(point) {
return false;
}
}
true
}