Skip to content

#6182 Improve calculate_circle_center#6192

Merged
andrewvarga merged 14 commits intomainfrom
andrewvarga/6182/calculate-circle-center-edge-cases
Apr 11, 2025
Merged

#6182 Improve calculate_circle_center#6192
andrewvarga merged 14 commits intomainfrom
andrewvarga/6182/calculate-circle-center-edge-cases

Conversation

@andrewvarga
Copy link
Contributor

@andrewvarga andrewvarga commented Apr 7, 2025

Fixes #6182

This fixes the returned NaNs in this example kcl:

sketch001 = startSketchOn(XZ)
profile001 = startProfileAt([200.58, 199.26], sketch001)
  |> line(endAbsolute = [0, 0])
  |> arcTo({
       interior = [0, -99.85],
       end = [99.41, -99.85]
     }, %)

The existing implementation of calculate_circle_center returned NaN because of division by zeros when 2 points had the same x coordinates resulting in Infinite slopes.
I think instead of calculating slopes and handling special cases it's simpler and more robust to just solve the equations.
There are still edge cases like when the 3 points are collinear but that's handled now so at least it doesn't return NaNs.
A slightly different but still robust approach would be to still calculate the 2 bisectors and solving the line intersections.

Added some unit tests as well.

I think the intersect function could be reworked the same way without using slopes.

@qa-wolf
Copy link

qa-wolf bot commented Apr 7, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@vercel
Copy link

vercel bot commented Apr 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Apr 11, 2025 8:48am

@codspeed-hq
Copy link

codspeed-hq bot commented Apr 7, 2025

CodSpeed Walltime Performance Report

Merging #6192 will degrade performances by 14.92%

Comparing andrewvarga/6182/calculate-circle-center-edge-cases (fedf812) with main (c45c2e2)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

⚡ 2 improvements
❌ 1 regressions
✅ 89 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
execute_80-20-rail 3.8 s 3.4 s +11.69%
execute_gear-rack 1.7 s 1.5 s +11.97%
execute_socket-head-cap-screw 1.6 s 1.9 s -14.92%

@andrewvarga andrewvarga changed the title #6182 Improve line intersection problems #6182 Improve calculate_circle_center Apr 7, 2025
… changes introduced by calculate_circle_center refactor
@codecov
Copy link

codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.97%. Comparing base (c45c2e2) to head (fedf812).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6192      +/-   ##
==========================================
+ Coverage   84.95%   84.97%   +0.01%     
==========================================
  Files         108      108              
  Lines       45121    45169      +48     
==========================================
+ Hits        38333    38381      +48     
  Misses       6788     6788              
Flag Coverage Δ
rust 84.97% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

let points_array = [[0.0, 0.33, 0.66], [0.0, 0.1, 0.2], [0.0, -0.1, 0.1], [0.0, 0.5, 0.7]];

let get_point = |radius: f64, t: f64| {
let angle = t * 2.0 * PI;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed opportunity to use TAU. We're big fans of tau 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see, I've updated that :)

@andrewvarga andrewvarga merged commit 1f6b90d into main Apr 11, 2025
62 checks passed
@andrewvarga andrewvarga deleted the andrewvarga/6182/calculate-circle-center-edge-cases branch April 11, 2025 10:43
modeling-app-github-app bot pushed a commit that referenced this pull request Apr 11, 2025
* add tests for calculate_circle_center - the first one succeeds with the current impl

* fix calculate_circle_center

* comment cleanup

* clippy

* comment format

* update circle_three_point sim test snapshot for slight floating point changes introduced by calculate_circle_center refactor

* use TAU instead of 2 * PI

* clippy
modeling-app-github-app bot pushed a commit that referenced this pull request Apr 11, 2025
* add tests for calculate_circle_center - the first one succeeds with the current impl

* fix calculate_circle_center

* comment cleanup

* clippy

* comment format

* update circle_three_point sim test snapshot for slight floating point changes introduced by calculate_circle_center refactor

* use TAU instead of 2 * PI

* clippy
modeling-app-github-app bot pushed a commit that referenced this pull request Apr 11, 2025
* add tests for calculate_circle_center - the first one succeeds with the current impl

* fix calculate_circle_center

* comment cleanup

* clippy

* comment format

* update circle_three_point sim test snapshot for slight floating point changes introduced by calculate_circle_center refactor

* use TAU instead of 2 * PI

* clippy
jacebrowning added a commit that referenced this pull request Apr 11, 2025
* main:
  #6182 Improve calculate_circle_center (#6192)
  make sure the nix flake never breaks (#6273)
  Add CSG operations to the artifact graph (#6104)
  refactor: Change to use topLevelModule helper function (#6264)
  Remove experimental warning on whole-module imports (#6240)
  Insert a newline between block comments and attributes (#6250)
  Remove import function from std (#6241)
  Fix vscode lsp bugs (#6271)
  bump kcl friends (#6272)
  Bump modeling api & pull thru csg endpoints (#6245)
  Franknoirot/adhoc/improve e2e (#6265)
  Fix URL encoded names after rename to Zoo Design Studio (#6269)
  Repetitive structs removed for import file extensions (#6211)
modeling-app-github-app bot pushed a commit that referenced this pull request Apr 11, 2025
* add tests for calculate_circle_center - the first one succeeds with the current impl

* fix calculate_circle_center

* comment cleanup

* clippy

* comment format

* update circle_three_point sim test snapshot for slight floating point changes introduced by calculate_circle_center refactor

* use TAU instead of 2 * PI

* clippy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Line intersection problems

2 participants