1extern crate euclid;
2extern crate fixed;
3extern crate scaled;
4
5use scaled::{FixedSqrt, Point2d, Space2d, Vector2d};
6
7macro_rules! show {
8 ($e:expr) => { println!("{:<24}{:?}", format!("{}: ", stringify!($e)), $e); }
9}
10
11struct World;
12impl Space2d for World {
13 type Scalar = fixed::types::I16F16;
14 type Point = euclid::Point2D <Self::Scalar, Self>;
15 type Vector = euclid::Vector2D <Self::Scalar, Self>;
16}
17type Scalar = <World as Space2d>::Scalar;
18type Point = <World as Space2d>::Point;
19type Vector = <World as Space2d>::Vector;
20
21fn main() {
22 use std::mem::size_of;
23 use fixed::traits::ToFixed;
24 println!("example main...");
25
26 show!(size_of::<Scalar>());
27 show!(size_of::<Point>());
28 show!(size_of::<Vector>());
29
30 show!(Scalar::MIN);
31 show!(Scalar::MAX);
32 show!(Scalar::MAX.sqrt());
33
34 let x : Scalar = 1.to_fixed();
35 let y = Scalar::from_num (-1);
36 show!(x);
37 show!(x.to_bits());
38 show!(y);
39 show!(y.to_bits());
40 show!(y + x);
41 show!(y - x);
42 let e = euclid::Point2D::new (1.0, 2.0);
43 show!(e);
44 show!(Point::from_num (e));
45 let ppp : Point = [x, y].into();
46 show!(ppp);
47 let pp : Point = (x, y).into();
48 show!(pp);
49 let p = Point::new (x, y);
50 show!(p);
51 show!(p.to_bits());
52 show!(p.to_num::<f64>());
53 let v = Vector::new (x, y);
54 show!(v);
55 show!(v.to_bits());
56 show!(v.to_num::<f64>());
57 show!(v.square_length());
58 show!(v.magnitude2());
59 show!(v.magnitude());
60 show!(v.normalized());
61 let two = Scalar::from_num (2);
62 show!(v * two);
63 show!(p + v);
64 let o : Point = Point2d::origin();
67 show!(o);
68 show!(o - p);
69 let w = Vector::from_num ([127.0, 127.0].into());
70 show!(w);
71 show!(w.magnitude());
72 show!(w.magnitude2());
73 show!(w.normalized());
74 let w = Vector::from_num ([256.0, 256.0].into());
75 show!(w);
76 show!(w.magnitude());
77 show!(w.magnitude2());
78 show!(w.normalized());
79
80 println!("...example main");
81}