ToBoundingBox

Trait ToBoundingBox 

Source
pub trait ToBoundingBox {
    // Required method
    fn bounding_box(&self) -> BoundingBox;
}
Expand description

A trait providing an interface to derive bounding boxes from types.

This trait serves as an interface for types which know how to construct their own bounding box. See ToBoundingBox::bounding_box for an example.

Required Methods§

Source

fn bounding_box(&self) -> BoundingBox

Creates the bounding box of the type.

§Examples
use bounding_box::{BoundingBox, ToBoundingBox};

struct Circle {
    center: [f64; 2],
    radius: f64
}

impl ToBoundingBox for Circle {
    fn bounding_box(&self) -> BoundingBox {
        return BoundingBox::new(self.center[0] - self.radius,
                                self.center[0] + self.radius,
                                self.center[1] - self.radius,
                                self.center[1] + self.radius);
    }
}

let c = Circle {center: [0.0, 0.0], radius: 1.0};
assert_eq!(c.bounding_box(), BoundingBox::new(-1.0, 1.0, -1.0, 1.0));

Implementations on Foreign Types§

Source§

impl<T: ToBoundingBox + ?Sized> ToBoundingBox for &T

Implementors§