Crate axgeom [] [src]

A 2D geometry library. It provides a way to easily extract 1d ranges from a 2d Rectangle based off of the x or y axis. Also provides functions that operate on types that implement Ord, as well has hard coded ones for f32.

Example

extern crate axgeom;
use axgeom::{Rect,Range,Axis,AxisIter,XAXIS,YAXIS};
fn main(){
let rect = Rect::new(30.0,40.0,30.0,40.0);

for k in AxisIter::new(){
    let r=rect.get_range(k);
    assert!(r.len()==10.0);
}

let (r1,r2)=rect.subdivide(35.0,XAXIS);
assert!(*r1.get_range(XAXIS)==Range{start:30.0,end:35.0});
assert!(*r1.get_range(YAXIS)==Range{start:30.0,end:40.0});
          
assert!(*r2.get_range(XAXIS)==Range{start:35.0,end:40.0});
assert!(*r2.get_range(YAXIS)==Range{start:30.0,end:40.0});
}

Structs

Axis

An Axis has a value of either X or Y. It is used to look up values in 2d containers.

AxisIter

Iterator to iterate over the x and y axises.

ComputedVec2

A wrapper around a Vec2 with the f32 length and length sqr saved. Useful when you want to cache the length computation.

Range

A 1d range. Internally represented as start and end. (not start and length) This means that subdivision does not result in any floating point calculations. There is no protection against "degenerate" Ranges where start>end.

Rect

Stored as two Ranges.

Vec2

A 2d point made up of f32's with a way to get the value on a particular axis easily.

VecCont

A 2d generic container. Elements can be accessed using an Axis.

XAXIS_S

The x axis implementation of the AxisTrait

YAXIS_S

The y axis implementation of the AxisTrait

Constants

XAXIS

The x axis is internally represented as 0.

YAXIS

The y axis internally represented as 1.

Traits

AxisTrait

Axis trait can be used to extract the x or y axis out of a vector when you know the axis as compile time.