Struct palarust::box2d::Box2d
[−]
[src]
pub struct Box2d { pub x0: i32, pub x1: i32, pub y0: i32, pub y1: i32, }
Fields
x0: i32
x1: i32
y0: i32
y1: i32
Methods
impl Box2d
[src]
fn new(x0: i32, x1: i32, y0: i32, y1: i32) -> Box2d
fn new_from_usize(x0: usize, x1: usize, y0: usize, y1: usize) -> Box2d
fn size(&self) -> usize
Surface of points in the 2d box (each point has surface 1)
fn weighted_size(&self) -> f64
Weighted surface of the Box2d (corners weight 1/4 and edges 1/2)
fn enlarge(&self, dx: i32) -> Box2d
fn translate(&self, p: Point2d) -> Box2d
fn multiply(&self, alpha: i32) -> Box2d
fn divide(&self, alpha: i32) -> Box2d
fn get_corners(&self) -> [Point2d; 4]
Returns an array containing the 4 corners of a box2d ordered in the trigonometric direction
Arguments
&self
- A Box2d
Example
extern crate palarust; use palarust::box2d::Box2d; use palarust::point2d::Point2d; fn main () { let b = Box2d::new(1, 4, 2, 8); assert_eq!(b.get_corners(), [Point2d::new(1,2), Point2d::new(4,2), Point2d::new(4,8), Point2d::new(1,8)]); }
fn contains(&self, p: Point2d) -> bool
Tests if a Box2d contains a Point2d
Arguments
&self
- A Box2dp
- A Point2d
Example
extern crate palarust; use palarust::box2d::Box2d; use palarust::point2d::Point2d; fn main () { let b = Box2d::new(1, 4, 2, 8); let p1 = Point2d::new(2, 3); let p2 = Point2d::new(-1, -1); assert!(b.contains(p1), "p1 must be contained in box"); assert!(!b.contains(p2), "p2 must not be contained in box"); }
fn intersection(&self, rhs: Box2d) -> Option<Box2d>
Computes the intersection of two box2d and returns an option.
Arguments
&self
- A Box2drhs
- A Box2d
Example
extern crate palarust; use palarust::box2d::Box2d; fn main () { let b = Box2d::new(1, 4, 2, 8); let b1 = Box2d::new(2, 3, 3, 5); let b2 = Box2d::new(-4, 2, -1, 4); let b3 = Box2d::new(-4, -2, -4, -1); let int1 = b.intersection(b1); match int1 { Some(int1) => assert_eq!(int1, Box2d::new(2, 3, 3, 5)), None => panic!("There should be an intersection between the two boxes"), } assert_eq!(int1, b1.intersection(b)); let int2 = b.intersection(b2); match int2 { Some(int2) => assert_eq!(int2, Box2d::new(1, 2, 2, 4)), None => panic!("There should be an intersection between the two boxes"), } assert_eq!(int2, b2.intersection(b)); let int3 = b.intersection(b3); match int3 { Some(int3) => panic!("There should be an intersection between the two boxes"), None => assert!(true, "There is no intersection"), } assert_eq!(int3, b3.intersection(b)); }
Trait Implementations
impl Debug for Box2d
[src]
impl Clone for Box2d
[src]
fn clone(&self) -> Box2d
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Copy for Box2d
[src]
impl PartialEq for Box2d
[src]
The equality of two Box2d
Arguments
&self
- A Box2d&other
- A Box2d
Example
extern crate palarust; use palarust::box2d::Box2d; fn main () { let b = Box2d::new(1, 4, 2, 8); assert_eq!(b, Box2d::new(1, 4, 2, 8)); assert!(b != Box2d::new(1, 4, 2, 9), "b is not equal to Box2d::new(1, 4, 2, 9)."); }
fn eq(&self, other: &Box2d) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl Add<Point2d> for Box2d
[src]
The addition of a Box2d with a Point2d (in this order)
Arguments
self
- A Box2drhs
- A Point2d
Example
extern crate palarust; use palarust::point2d::Point2d; use palarust::box2d::Box2d; fn main () { let b = Box2d::new(1, 4, 2, 8); let p = Point2d::new(-1, 4); assert_eq!(b+p, Box2d::new(0, 3, 6, 12) ); }
type Output = Box2d
The resulting type after applying the +
operator
fn add(self, rhs: Point2d) -> Box2d
The method for the +
operator
impl Mul<i32> for Box2d
[src]
The multiplication of a Box2d with a scalar (in this order)
Arguments
self
- A Box2drhs
- A i32
Example
extern crate palarust; use palarust::box2d::Box2d; fn main () { let b = Box2d::new(1, 4, 2, 8); let alpha = 2; assert_eq!(b*alpha, Box2d::new(2, 8, 4, 16)); }
type Output = Box2d
The resulting type after applying the *
operator
fn mul(self, rhs: i32) -> Box2d
The method for the *
operator
impl Sub<Point2d> for Box2d
[src]
The subtraction of a Box2d with a Point2d (in this order)
Arguments
self
- A Box2drhs
- A Point2d
Example
extern crate palarust; use palarust::point2d::Point2d; use palarust::box2d::Box2d; fn main () { let b = Box2d::new(1, 4, 2, 8); let p = Point2d::new(-1, 4); assert_eq!(b-p, Box2d::new(2, 5, -2, 4) ); }
type Output = Box2d
The resulting type after applying the -
operator
fn sub(self, rhs: Point2d) -> Box2d
The method for the -
operator