From a4089a7ee01d4007d32ce5f62d907ef26d48d6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Wed, 15 Feb 2017 23:42:03 +0100 Subject: [PATCH] Add missing examples from the website. --- examples/cargo/Cargo.toml | 11 +++++++++++ examples/point_construction.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 examples/cargo/Cargo.toml create mode 100644 examples/point_construction.rs diff --git a/examples/cargo/Cargo.toml b/examples/cargo/Cargo.toml new file mode 100644 index 00000000..6f450ec7 --- /dev/null +++ b/examples/cargo/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "example-using-nalgebra" +version = "0.0.0" +authors = [ "You" ] + +[dependencies] +nalgebra = "0.11.0" + +[[bin]] +name = "example" +path = "./example.rs" diff --git a/examples/point_construction.rs b/examples/point_construction.rs new file mode 100644 index 00000000..14f5e28d --- /dev/null +++ b/examples/point_construction.rs @@ -0,0 +1,26 @@ +extern crate nalgebra as na; + +use na::{Vector3, Vector4, Point3}; + + +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_coordinates(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()); +}