Skip to content

Commit

Permalink
Don't recompute point that is already available
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Aug 29, 2022
1 parent 7b109d1 commit be49a75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
13 changes: 7 additions & 6 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ fn approx_circle(
let n = number_of_vertices_for_circle(tolerance, radius, range.length());

let mut points = Vec::new();
points.push(range.start());

for i in 0..n {
let angle = range.start().t
for i in 1..n {
let angle = range.start().0.t
+ (Scalar::TAU / n as f64 * i as f64) * range.direction();

let point_curve = Point::from([angle]);
Expand All @@ -91,20 +92,20 @@ fn number_of_vertices_for_circle(
}

pub struct RangeOnCurve {
pub boundary: [Point<1>; 2],
pub boundary: [(Point<1>, Point<3>); 2],
}

impl RangeOnCurve {
fn start(&self) -> Point<1> {
fn start(&self) -> (Point<1>, Point<3>) {
self.boundary[0]
}

fn end(&self) -> Point<1> {
fn end(&self) -> (Point<1>, Point<3>) {
self.boundary[1]
}

fn signed_length(&self) -> Scalar {
(self.end() - self.start()).t
(self.end().0 - self.start().0).t
}

fn length(&self) -> Scalar {
Expand Down
13 changes: 12 additions & 1 deletion crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@ impl Approx for Edge {
let start_curve = Point::from([Scalar::ZERO]);
let end_curve = Point::from([Scalar::TAU]);

// We're dealing with a circle here. Start and end are identical
// points, in global coordinates.
let point_global = self
.global()
.curve()
.kind()
.point_from_curve_coords(start_curve);

RangeOnCurve {
boundary: [start_curve, end_curve],
boundary: [
(start_curve, point_global),
(end_curve, point_global),
],
}
};

Expand Down

0 comments on commit be49a75

Please sign in to comment.