Struct Bounds

Source
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

Source

pub fn empty() -> Self

Creates a new empty (zero sized) bound

Source

pub fn is_valid(&self) -> bool

Returns if the bounds are valid or not, i.e. if the minimum is larger than the maximum.

Source

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?
examples/map_rotations_check.rs (line 18)
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}
Source

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.

Source

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.

Source

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.

Source

pub fn contains(&self, point: Point2<isize>) -> bool

Checks if the given point is inside the bounds

Source

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

Source

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.

Source

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).

Source

pub fn get_num_cells(&self) -> Vector2<usize>

Gets the number of cells as a vector.

Source

pub fn intersect(&self, other: &Bounds) -> Option<Bounds>

Gets the intersection of self with other, returning None if the two do not intersect.

Source

pub fn union(&self, other: &Bounds) -> Bounds

Get the union of self with other, effectively this is the axis aligned bounding box of self and other.

If both bounds are empty this bound will be empty.

Source

pub fn get_slice_of_other( &self, other: &Bounds, ) -> Option<Vector2<(usize, usize)>>

Gets the slice of other within self, cropping other so it fits within self.

Note that slices are a pair of (min, max) half-open bounds that describe the slice into an array, i.e. they are indices.

Trait Implementations§

Source§

impl Clone for Bounds

Source§

fn clone(&self) -> Bounds

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bounds

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Bounds

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Bounds

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Bounds

Source§

fn eq(&self, other: &Bounds) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Bounds

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Bounds

Source§

impl Eq for Bounds

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: Copy + PartialEq + Debug + Any,

Source§

fn inlined_clone(&self) -> T

Performance hack: Clone doesn’t get inlined for Copy types in debug mode, so make it inline anyway.
Source§

fn is<T>() -> bool
where T: Scalar,

Tests if Self the same as the type T Read more
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,