Skip to main content

Vector2d

Trait Vector2d 

Source
pub trait Vector2d<S: FixedSqrt, U>:
    Sized
    + Clone
    + Copy
    + Default {
Show 13 methods // Required methods fn new(x: S, y: S) -> Self; fn map<F, T>(self, f: F) -> Vector2D<T, U> where F: FnMut(S) -> T; fn magnitude2(self) -> Option<S>; fn norm(self) -> Norm<S> where S: FixedSigned; // Provided methods fn zero() -> Self { ... } fn from_num<N: ToFixed>(num: Vector2D<N, U>) -> Self { ... } fn wrapping_from_num<N: ToFixed>(num: Vector2D<N, U>) -> Self { ... } fn from_bits(bits: Vector2D<S::Bits, U>) -> Self { ... } fn to_num<N: FromFixed>(self) -> Vector2D<N, U> { ... } fn to_bits(self) -> Vector2D<S::Bits, U> { ... } fn scale(self, s: S) -> Self { ... } fn magnitude(self) -> Option<S> { ... } fn normalized(self) -> Self { ... }
}

Required Methods§

Source

fn new(x: S, y: S) -> Self

Source

fn map<F, T>(self, f: F) -> Vector2D<T, U>
where F: FnMut(S) -> T,

Source

fn magnitude2(self) -> Option<S>

Source

fn norm(self) -> Norm<S>
where S: FixedSigned,

Provided Methods§

Source

fn zero() -> Self

Source

fn from_num<N: ToFixed>(num: Vector2D<N, U>) -> Self

Examples found in repository?
examples/example.rs (line 69)
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}
Source

fn wrapping_from_num<N: ToFixed>(num: Vector2D<N, U>) -> Self

Source

fn from_bits(bits: Vector2D<S::Bits, U>) -> Self

Source

fn to_num<N: FromFixed>(self) -> Vector2D<N, U>

Examples found in repository?
examples/example.rs (line 56)
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}
Source

fn to_bits(self) -> Vector2D<S::Bits, U>

Examples found in repository?
examples/example.rs (line 55)
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}
Source

fn scale(self, s: S) -> Self

Source

fn magnitude(self) -> Option<S>

Examples found in repository?
examples/example.rs (line 59)
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}
Source

fn normalized(self) -> Self

Examples found in repository?
examples/example.rs (line 60)
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.

Implementations on Foreign Types§

Source§

impl<S, U> Vector2d<S, U> for Vector2D<S, U>
where S: FixedSqrt,

Source§

fn new(x: S, y: S) -> Self

Source§

fn map<F, T>(self, f: F) -> Vector2D<T, U>
where F: FnMut(S) -> T,

Source§

fn magnitude2(self) -> Option<S>

Source§

fn norm(self) -> Norm<S>
where S: FixedSigned,

Implementors§