Skip to content

Commit

Permalink
Merge pull request #1086 from hannobraun/math
Browse files Browse the repository at this point in the history
Add `Circle::from_center_and_radius`
  • Loading branch information
hannobraun authored Sep 14, 2022
2 parents 6f60add + 37b5cc9 commit 0bfb906
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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

0 comments on commit 0bfb906

Please sign in to comment.