Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test edge clipping #3

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 's2'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=s2"
],
"filter": {
"name": "s2",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'test'",
"cargo": {
"args": [
"build",
"--bin=test",
"--package=s2"
],
"filter": {
"name": "test",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'test'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=test",
"--package=s2"
],
"filter": {
"name": "test",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
37 changes: 36 additions & 1 deletion src/r2/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,51 @@ limitations under the License.

use consts::*;
use std;
use std::cmp::Ordering;

/// Point represents a point in ℝ².
#[derive(Clone, Copy, PartialEq, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct Point {
/// x coordinate of the point
pub x: f64,
/// y coordinate of the point
pub y: f64,
}

impl Eq for Point {}

impl Ord for Point {
fn cmp(&self, ov: &Point) -> Ordering {
if self.x < ov.x {
return Ordering::Less
}
if self.x > ov.x {
return Ordering::Greater
}

// First elements were the same, try the next.
if self.y < ov.y {
return Ordering::Less
}
if self.y > ov.y {
return Ordering::Greater
}
return Ordering::Equal
}
}

impl PartialOrd for Point {
fn partial_cmp(&self, other: &Point) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl PartialEq for Point {
fn eq(&self, other: &Point) -> bool {
self.cmp(other) == Ordering::Equal
}
}

impl std::ops::Add<Point> for Point {
type Output = Point;
/// returns the sum of p and other.
Expand Down
28 changes: 28 additions & 0 deletions src/r3/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,34 @@ impl Vector {
}
}
}

pub fn cmp(&self, ov: Vector) -> i64 {
if self.x < ov.x {
return -1
}
if self.x > ov.x {
return 1
}

// First elements were the same, try the next.
if self.y < ov.y {
return -1
}
if self.y > ov.y {
return 1
}

// Second elements were the same return the final compare.
if self.z < ov.z {
return -1
}
if self.z > ov.z {
return 1
}

// Both are equal
return 0
}
}

/// Axis enumerates the 3 axes of ℝ³.
Expand Down
Loading