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

add triangle shape #350

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ mod stroke;
#[cfg(feature = "std")]
mod svg;
mod translate_scale;
mod triangle;
mod vec2;

pub use crate::affine::*;
Expand All @@ -136,4 +137,5 @@ pub use crate::stroke::*;
#[cfg(feature = "std")]
pub use crate::svg::*;
pub use crate::translate_scale::*;
pub use crate::triangle::*;
pub use crate::vec2::*;
25 changes: 25 additions & 0 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//! A 2D point.

use core::cmp::Ordering;
use core::fmt;
use core::ops::{Add, AddAssign, Sub, SubAssign};

Expand Down Expand Up @@ -185,6 +186,30 @@ impl Point {
pub fn is_nan(self) -> bool {
self.x.is_nan() || self.y.is_nan()
}

juliapaci marked this conversation as resolved.
Show resolved Hide resolved
/// The topmost [`Point`]
#[inline]
pub fn topmost(&self, other: &Self) -> Ordering {
juliapaci marked this conversation as resolved.
Show resolved Hide resolved
self.y.total_cmp(&other.y)
}

/// The bottommost [`Point`]
#[inline]
pub fn bottommost(&self, other: &Self) -> Ordering {
other.y.total_cmp(&self.y)
}

/// The rightmost [`Point`]
#[inline]
pub fn rightmost(&self, other: &Self) -> Ordering {
self.x.total_cmp(&other.x)
}

/// The leftmost [`Point`]
#[inline]
pub fn leftmost(&self, other: &Self) -> Ordering {
other.x.total_cmp(&self.x)
}
juliapaci marked this conversation as resolved.
Show resolved Hide resolved
juliapaci marked this conversation as resolved.
Show resolved Hide resolved
}

impl From<(f32, f32)> for Point {
Expand Down
Loading