BoundingBox

Struct BoundingBox 

Source
pub struct BoundingBox {
    pub upper_left: Point,
    pub lower_right: Point,
}
Expand description

Record of the region occupied by a Path.

This will be a rectangle in which the points of a Path fit.

§Examples

use l_system_fractals::paths::{BoundingBox, Path, Point};
use l_system_fractals::num_validity::AlmostEq;

let pth = Path::from(vec![
    Point::new(1.0, 5.0),
    Point::new(3.7, 4.5),
    Point::new(2.5, 3.0)
]);

let bb = pth.bounding_box().unwrap();

assert!(bb.lower_right.almost_eq(&Point::new(3.7, 5.0), 0.001));
assert!(bb.upper_left.almost_eq(&Point::new(1.0, 3.0), 0.001));
// AlmostEq is implemented for BoundingBox

use std::f64::consts::PI;

use l_system_fractals::paths::{BoundingBox, Path, Point};
use l_system_fractals::num_validity::AlmostEq;

let pts: Vec<Point> = (0..15_839)
    .map(|x| (x as f64) * PI / 7919.0 + PI / 4.0)
    .map(
        |x| Point::new(5.0 * x.cos() + 6.0, 5.0 * x.sin() + 6.0)
    ).collect();

let pth: Path = pts.into();

let bb1: BoundingBox = pth.bounding_box().unwrap();

let bb2 = BoundingBox {
    upper_left: Point::new(1.0, 1.0),
    lower_right: Point::new(11.0, 11.0)
};

assert!(bb1.almost_eq(&bb2, 0.00001));

Fields§

§upper_left: Point

The upper-left corner of the region.

§lower_right: Point

The lower-right corner of the region.

Implementations§

Source§

impl BoundingBox

Source

pub fn width(&self) -> f64

The width of the bounding box.

§Examples
use l_system_fractals::paths::{BoundingBox, Path, Point};
use l_system_fractals::num_validity::AlmostEq;

let pth = Path::from(vec![
    Point::new(1.0, 5.0),
    Point::new(3.7, 4.5),
    Point::new(2.5, 3.0)
]);

let bb = pth.bounding_box().unwrap();

assert!(bb.width().almost_eq(&2.7, 0.001));
Source

pub fn height(&self) -> f64

The height of the bounding box.

§Examples
use l_system_fractals::paths::{BoundingBox, Path, Point};
use l_system_fractals::num_validity::AlmostEq;

let pth = Path::from(vec![
    Point::new(1.0, 5.0),
    Point::new(3.7, 4.5),
    Point::new(2.5, 3.0)
]);

let bb = pth.bounding_box().unwrap();

assert!(bb.height().almost_eq(&2.0, 0.001));
Source

pub fn background_box(&self, fill: &str) -> String

Returns an SVG rect with the coordinates of the bounding box (to be used as a background).

Trait Implementations§

Source§

impl AlmostEq for BoundingBox

Source§

fn almost_eq(&self, other: &Self, epsilon: f64) -> bool

Returns true if the distance between objects is less than epsilon.
Source§

impl Clone for BoundingBox

Source§

fn clone(&self) -> BoundingBox

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 BoundingBox

Source§

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

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

impl PartialEq for BoundingBox

Source§

fn eq(&self, other: &BoundingBox) -> 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 Copy for BoundingBox

Source§

impl StructuralPartialEq for BoundingBox

Auto Trait Implementations§

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