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 Circle::from_center_and_radius #1086

Merged
merged 1 commit into from
Sep 14, 2022
Merged
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
10 changes: 4 additions & 6 deletions crates/fj-kernel/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ impl SurfacePath {
pub fn circle_from_radius(radius: impl Into<Scalar>) -> Self {
let radius = radius.into();

SurfacePath::Circle(Circle::new(
SurfacePath::Circle(Circle::from_center_and_radius(
Point::origin(),
Vector::from([radius, Scalar::ZERO]),
Vector::from([Scalar::ZERO, radius]),
radius,
))
}

Expand Down Expand Up @@ -106,10 +105,9 @@ impl GlobalPath {
pub fn circle_from_radius(radius: impl Into<Scalar>) -> Self {
let radius = radius.into();

GlobalPath::Circle(Circle::new(
GlobalPath::Circle(Circle::from_center_and_radius(
Point::origin(),
Vector::from([radius, Scalar::ZERO, Scalar::ZERO]),
Vector::from([Scalar::ZERO, radius, Scalar::ZERO]),
radius,
))
}

Expand Down
16 changes: 16 additions & 0 deletions crates/fj-math/src/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ impl<const D: usize> Circle<D> {
Self { center, a, b }
}

/// Construct a `Circle` from a center point and a radius
pub fn from_center_and_radius(
center: impl Into<Point<D>>,
radius: impl Into<Scalar>,
) -> Self {
let radius = radius.into();

let mut a = [Scalar::ZERO; D];
let mut b = [Scalar::ZERO; D];

a[0] = radius;
b[1] = radius;

Circle::new(center, a, b)
}

/// Access the center point of the circle
pub fn center(&self) -> Point<D> {
self.center
Expand Down