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: PointThe upper-left corner of the region.
lower_right: PointThe lower-right corner of the region.
Implementations§
Source§impl BoundingBox
impl BoundingBox
Sourcepub fn width(&self) -> f64
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));Sourcepub fn height(&self) -> f64
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));Sourcepub fn background_box(&self, fill: &str) -> String
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
impl AlmostEq for BoundingBox
Source§impl Clone for BoundingBox
impl Clone for BoundingBox
Source§fn clone(&self) -> BoundingBox
fn clone(&self) -> BoundingBox
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BoundingBox
impl Debug for BoundingBox
Source§impl PartialEq for BoundingBox
impl PartialEq for BoundingBox
impl Copy for BoundingBox
impl StructuralPartialEq for BoundingBox
Auto Trait Implementations§
impl Freeze for BoundingBox
impl RefUnwindSafe for BoundingBox
impl Send for BoundingBox
impl Sync for BoundingBox
impl Unpin for BoundingBox
impl UnwindSafe for BoundingBox
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
Mutably borrows from an owned value. Read more