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 5 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
20 changes: 19 additions & 1 deletion src/ellipse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::{
ops::{Add, Mul, Sub},
};

use crate::{Affine, Arc, ArcAppendIter, Circle, PathEl, Point, Rect, Shape, Size, Vec2};
use crate::{Affine, Arc, ArcAppendIter, Circle, PathEl, Point, Rect, Shape, Size, Triangle, Vec2};

#[cfg(not(feature = "std"))]
use crate::common::FloatFuncs;
Expand Down Expand Up @@ -58,6 +58,24 @@ impl Ellipse {
Ellipse::private_new(center, width, height, 0.0)
}

// TODO: this returns the largest circle not ellipse
/// Returns the largest ellipse that can be bounded by this [`Triangle`].
///
/// This ellipse is always axis-aligned; to apply rotation you can call
/// [`with_rotation`] with the result.
///
/// [`with_rotation`]: Ellipse::with_rotation
#[inline]
pub fn from_triangle(triangle: Triangle) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is justified.

Perhaps there should be incircle and circumcircle methods on Triangle; I'd be open to that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right

let radius = triangle.radius();
Ellipse::private_new(
triangle.centroid().to_vec2(),
radius / 2.0,
radius / 2.0,
0.0,
)
}

/// Create an ellipse from an affine transformation of the unit circle.
#[inline]
pub fn from_affine(affine: Affine) -> Self {
Expand Down
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::*;
Loading
Loading