File: point_construction.rs

package info (click to toggle)
rust-nalgebra 0.33.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,340 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 796 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
extern crate nalgebra as na;

use na::{Point3, Vector3, Vector4};

fn main() {
    // Build using components directly.
    let p0 = Point3::new(2.0, 3.0, 4.0);

    // Build from a coordinates vector.
    let coords = Vector3::new(2.0, 3.0, 4.0);
    let p1 = Point3::from(coords);

    // Build by translating the origin.
    let translation = Vector3::new(2.0, 3.0, 4.0);
    let p2 = Point3::origin() + translation;

    // Build from homogeneous coordinates. The last component of the
    // vector will be removed and all other components divided by 10.0.
    let homogeneous_coords = Vector4::new(20.0, 30.0, 40.0, 10.0);
    let p3 = Point3::from_homogeneous(homogeneous_coords);

    assert_eq!(p0, p1);
    assert_eq!(p0, p2);
    assert_eq!(p0, p3.unwrap());
}