3 releases
Uses old Rust 2015
0.1.2 | Dec 6, 2017 |
---|---|
0.1.1 | Dec 6, 2017 |
0.1.0 | Dec 6, 2017 |
#1589 in Math
31KB
761 lines
lib.rs
:
A collection of strongly typed planar geometry structs.
It strongly separates "length" types (distance between points) and "position" type (absolute point location). The semantics of this separation are:
length + length = length position + length = position length - length = length position - length = position position - position = length
All other operations between the two types are not allowed. Both lengths and positions can be multiplied with a scalar factor. However, they differ in behavior when multiplied by an arbitrary planar transformation. Namely, position types transform according to both translation and scale, while length types only scale but do not translate.
The types generic over the scalar type T
, and are tagged with an opaque Unit
type.
Conversions between different unit types are handled with different transforms.
Further, one-dimensional types are tagged with a dimension type D
, which prevents
from adding together widths and heights.
This works
use planar::Width;
struct cm;
let p1: Width<f64, cm> = Width::new(10.0);
let p2: Width<f64, cm> = Width::new(100.0);
let p3 = p1 + p2;
assert_eq!(p3, Width::new(110.0));
But this fails to compile
use planar::Width;
struct cm;
struct mm;
let p1: Width<f64, cm> = Width::new(10.0);
let p2: Width<f64, mm> = Width::new(100.0);
let p3 = p1 + p2;