pub trait Point2d<S: FixedSqrt, U>:
Sized
+ Clone
+ Copy
+ Default {
// Required methods
fn new(x: S, y: S) -> Self;
fn map<F, T>(self, f: F) -> Point2D<T, U>
where F: FnMut(S) -> T;
// Provided methods
fn origin() -> Self { ... }
fn from_num<N: ToFixed>(num: Point2D<N, U>) -> Self { ... }
fn wrapping_from_num<N: ToFixed>(num: Point2D<N, U>) -> Self { ... }
fn from_bits(bits: Point2D<S::Bits, U>) -> Self { ... }
fn to_num<N: FromFixed>(self) -> Point2D<N, U> { ... }
fn to_bits(self) -> Point2D<S::Bits, U> { ... }
}
Required Methods§
fn new(x: S, y: S) -> Self
fn map<F, T>(self, f: F) -> Point2D<T, U>where
F: FnMut(S) -> T,
Provided Methods§
Sourcefn origin() -> Self
fn origin() -> Self
Examples found in repository?
examples/example.rs (line 66)
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 // euclid::Point2D::origin can't infer that Scalar : num_traits::Zero so we
65 // have to use Point2d::origin instead
66 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}
Sourcefn from_num<N: ToFixed>(num: Point2D<N, U>) -> Self
fn from_num<N: ToFixed>(num: Point2D<N, U>) -> Self
Examples found in repository?
examples/example.rs (line 44)
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 // euclid::Point2D::origin can't infer that Scalar : num_traits::Zero so we
65 // have to use Point2d::origin instead
66 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}
fn wrapping_from_num<N: ToFixed>(num: Point2D<N, U>) -> Self
fn from_bits(bits: Point2D<S::Bits, U>) -> Self
Sourcefn to_num<N: FromFixed>(self) -> Point2D<N, U>
fn to_num<N: FromFixed>(self) -> Point2D<N, U>
Examples found in repository?
examples/example.rs (line 52)
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 // euclid::Point2D::origin can't infer that Scalar : num_traits::Zero so we
65 // have to use Point2d::origin instead
66 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}
Sourcefn to_bits(self) -> Point2D<S::Bits, U>
fn to_bits(self) -> Point2D<S::Bits, U>
Examples found in repository?
examples/example.rs (line 51)
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 // euclid::Point2D::origin can't infer that Scalar : num_traits::Zero so we
65 // have to use Point2d::origin instead
66 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}
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.