Struct palarust::box2d::Box2d [] [src]

pub struct Box2d {
    pub x0: i32,
    pub x1: i32,
    pub y0: i32,
    pub y1: i32,
}

Fields

Methods

impl Box2d
[src]

Surface of points in the 2d box (each point has surface 1)

Weighted surface of the Box2d (corners weight 1/4 and edges 1/2)

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)]);
}

Tests if a Box2d contains a Point2d

Arguments

  • &self - A Box2d
  • p - 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");
}

Computes the intersection of two box2d and returns an option.

Arguments

  • &self - A Box2d
  • rhs - 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]

Formats the value using the given formatter.

impl Clone for Box2d
[src]

Returns a copy of the value. Read more

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).");
}

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Add<Point2d> for Box2d
[src]

The addition of a Box2d with a Point2d (in this order)

Arguments

  • self - A Box2d
  • rhs - 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) );
}

The resulting type after applying the + operator

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 Box2d
  • rhs - 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));
}

The resulting type after applying the * operator

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 Box2d
  • rhs - 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) );
}

The resulting type after applying the - operator

The method for the - operator

impl Div<i32> for Box2d
[src]

The division of a Box2d with an i32 (in this order)

Arguments

  • self - A Box2d
  • rhs - An i32

Example

extern crate palarust;
use palarust::point2d::Point2d;
use palarust::box2d::Box2d;
fn main () {
    let b = Box2d::new(1, 4, 2, 8);
    let alpha = 2i32;
     
    assert_eq!(b/alpha, Box2d::new(0, 2, 1, 4) );
}

The resulting type after applying the / operator

The method for the / operator