pub struct Bounds {
pub x: (isize, isize),
pub y: (isize, isize),
}
Expand description
Rectangular bounds describing the number of cells in each direction of the map.
These bounds are a half-open range, i.e. satisfied in the ranges:
- $x_0 <= x < x_1$
- $y_0 <= y < y_1$
Fields§
§x: (isize, isize)
The bounds on the x axis, in the format (min, max),
y: (isize, isize)
The bounds on the y axis, in the format (min, max),
Implementations§
Source§impl Bounds
impl Bounds
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns if the bounds are valid or not, i.e. if the minimum is larger than the maximum.
Sourcepub fn new(x: (isize, isize), y: (isize, isize)) -> Result<Self, Error>
pub fn new(x: (isize, isize), y: (isize, isize)) -> Result<Self, Error>
Creates a new bound from the given max and min cell indices in the x and y axes.
Must satisfy:
- $x_0 <= x_1$
- $y_0 <= y_1$
Examples found in repository?
15fn main() {
16 let translated = CellMap::<Layers, f64>::new(CellMapParams {
17 cell_size: Vector2::new(1.0, 1.0),
18 cell_bounds: Bounds::new((0, 10), (0, 10)).unwrap(),
19 position_in_parent: Vector2::new(5.0, 5.0),
20 ..Default::default()
21 });
22
23 let rotated = CellMap::<Layers, f64>::new(CellMapParams {
24 cell_bounds: Bounds::new((0, 10), (0, 10)).unwrap(),
25 cell_size: Vector2::new(1.0, 1.0),
26 position_in_parent: Vector2::new(5.0, 5.0),
27 rotation_in_parent_rad: std::f64::consts::FRAC_PI_4,
28 ..Default::default()
29 });
30
31 let scaled = CellMap::<Layers, f64>::new(CellMapParams {
32 cell_bounds: Bounds::new((0, 10), (0, 10)).unwrap(),
33 cell_size: Vector2::new(0.5, 0.5),
34 position_in_parent: Vector2::new(5.0, 5.0),
35 rotation_in_parent_rad: std::f64::consts::FRAC_PI_4,
36 ..Default::default()
37 });
38
39 #[cfg(all(feature = "debug_maps"))]
40 {
41 use cell_map::write_debug_map;
42
43 write_debug_map(&translated, "translated");
44 write_debug_map(&rotated, "rotated");
45 write_debug_map(&scaled, "scaled");
46 }
47}
Sourcepub fn from_corners(
bottom_left: Point2<isize>,
upper_right: Point2<isize>,
) -> Result<Self, Error>
pub fn from_corners( bottom_left: Point2<isize>, upper_right: Point2<isize>, ) -> Result<Self, Error>
Creates a new bound from the given opposing corners of the a rectangle.
If the corners do not satisfy all(bottom_left <= upper_right)
the bounds will be invalid
and an error is returned.
Sourcepub fn from_corners_unsorted(a: Point2<isize>, b: Point2<isize>) -> Self
pub fn from_corners_unsorted(a: Point2<isize>, b: Point2<isize>) -> Self
Creates a new bound from the given opposing corners of the a rectangle, but the corners do not have to be sorted in bottom_left, upper_right order.
This function will automatically decide which points are provided such that the bounds will be valid.
Sourcepub fn as_corners(&self) -> (Point2<isize>, Point2<isize>)
pub fn as_corners(&self) -> (Point2<isize>, Point2<isize>)
Converts this bounds into a pair of corners, the bottom left and upper right corners respectively.
Sourcepub fn contains(&self, point: Point2<isize>) -> bool
pub fn contains(&self, point: Point2<isize>) -> bool
Checks if the given point is inside the bounds
Sourcepub fn get_index(&self, point: Point2<isize>) -> Option<Point2<usize>>
pub fn get_index(&self, point: Point2<isize>) -> Option<Point2<usize>>
Gets the value of the point as an index into an array bounded by this Bounds
.
If the point is outside the bounds None
is returned
Sourcepub unsafe fn get_index_unchecked(&self, point: Point2<isize>) -> Point2<isize>
pub unsafe fn get_index_unchecked(&self, point: Point2<isize>) -> Point2<isize>
Gets the value of the point as an index into an array bounded by this Bounds
.
§Safety
This function will not panic if point
is outside the map, but use of the result to
index into the map is not guaranteed to be safe. It is possible for this function to return
a negative index value, which would indicate that the cell is outside the map.
Sourcepub fn get_shape(&self) -> (usize, usize)
pub fn get_shape(&self) -> (usize, usize)
Gets the shape of this rectangle in a format that ndarray
will accept.
NOTE: shape order is (y, x), not (x, y).
Sourcepub fn get_num_cells(&self) -> Vector2<usize>
pub fn get_num_cells(&self) -> Vector2<usize>
Gets the number of cells as a vector.
Sourcepub fn intersect(&self, other: &Bounds) -> Option<Bounds>
pub fn intersect(&self, other: &Bounds) -> Option<Bounds>
Gets the intersection of self with other, returning None
if the two do not intersect.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Bounds
impl<'de> Deserialize<'de> for Bounds
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Bounds
impl Eq for Bounds
impl StructuralPartialEq for Bounds
Auto Trait Implementations§
impl Freeze for Bounds
impl RefUnwindSafe for Bounds
impl Send for Bounds
impl Sync for Bounds
impl Unpin for Bounds
impl UnwindSafe for Bounds
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.