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

feat: Add a function to compute closest points #1039

Merged
merged 44 commits into from Feb 14, 2023
Merged

Conversation

rhit-chois3
Copy link
Contributor

@rhit-chois3 rhit-chois3 commented Jun 1, 2022

Description

This PR adds a closestPoint function which takes in a shape and a point, and returns the closest point on that shape to the given point.

Implementation strategy and design decisions

This PR changes the type of the clamp function to accept ad.Nums for all parameters, instead of requiring the bounds of the range to be fixed numbers. The body of the function is the same.

Examples with steps to reproduce them

The example in packages/examples/src/closest-point/ plots the closest point to several basic shapes for a single query point (resampling picks new shapes and a new point):

image

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new ESLint warnings
  • I have reviewed any generated changes to the diagrams/ folder

@codecov
Copy link

codecov bot commented Jun 1, 2022

Codecov Report

Merging #1039 (1dc4bde) into main (70d190e) will increase coverage by 0.57%.
The diff coverage is 99.10%.

@@            Coverage Diff             @@
##             main    #1039      +/-   ##
==========================================
+ Coverage   60.81%   61.39%   +0.57%     
==========================================
  Files          62       62              
  Lines        7582     7693     +111     
  Branches     1811     1822      +11     
==========================================
+ Hits         4611     4723     +112     
+ Misses       2870     2869       -1     
  Partials      101      101              
Impacted Files Coverage Δ
packages/core/src/contrib/Functions.ts 39.58% <99.09%> (+12.75%) ⬆️
packages/core/src/contrib/Utils.ts 51.35% <100.00%> (ø)
packages/core/src/engine/Autodiff.ts 79.38% <0.00%> (+0.23%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jun 1, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: b1ca8e5
Status: ✅  Deploy successful!
Preview URL: https://d001a1ef.penrose-72l.pages.dev
Branch Preview URL: https://closest-point.penrose-72l.pages.dev

View logs

Copy link
Contributor

@cmumatt cmumatt left a comment

Choose a reason for hiding this comment

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

This looks good! Suggested some minor improvements, mostly comment-type items. CI wants you to run yarn format in the monorepo root to take care of some formatting. Still, great job on this PR!!

Would also suggest filling in the "Implementation strategy and design decisions" section of the PR. I think you can just explain at a high level that you're calculating Circles one way, Rect-like shapes another, and note any shapes that aren't supported and why.

packages/core/src/contrib/ClosestPoint.test.ts Outdated Show resolved Hide resolved
packages/core/src/contrib/ClosestPoint.test.ts Outdated Show resolved Hide resolved
packages/core/src/contrib/ClosestPoint.test.ts Outdated Show resolved Hide resolved
packages/core/src/contrib/ClosestPoint.test.ts Outdated Show resolved Hide resolved
packages/core/src/contrib/Functions.ts Outdated Show resolved Hide resolved
packages/core/src/contrib/Functions.ts Outdated Show resolved Hide resolved
packages/core/src/contrib/Functions.ts Outdated Show resolved Hide resolved
packages/core/src/contrib/Functions.ts Outdated Show resolved Hide resolved
packages/core/src/contrib/Functions.ts Outdated Show resolved Hide resolved
@samestep samestep changed the title feat: Closest-point feat: Add a function to compute closest points Sep 9, 2022
@samestep samestep marked this pull request as ready for review September 10, 2022 15:03
@samestep
Copy link
Collaborator

@cmumatt @joshsunshine I cleaned up this PR; do you think it's ready to merge? I haven't yet actually read through all the implementation code for calculating closest points to verify that they're correct.

@wodeni wodeni reopened this Feb 6, 2023
@github-actions
Copy link

github-actions bot commented Feb 6, 2023

± Registry diff

M	3d-projection-fake-3d-linear-algebra.svg
M	arrowheads-arrowheads.svg
A	closest-point-test-closest-point.svg
M	collinear-euclidean.svg
M	continuousmap-continuousmap.svg
M	matrix-matrix-addition-matrix-ops.svg
M	matrix-matrix-division-elementwise-matrix-ops.svg
M	matrix-matrix-multiplication-elementwise-matrix-ops.svg
M	matrix-matrix-multiplication-matrix-ops.svg
M	matrix-matrix-subtraction-matrix-ops.svg
M	matrix-transpose-matrix-ops.svg
M	matrix-vector-left-multiplication-matrix-ops.svg
M	matrix-vector-right-multiplication-matrix-ops.svg
M	parallel-lines-euclidean.svg
M	persistent-homology-persistent-homology.svg
M	scalar-vector-division-matrix-ops.svg
M	scalar-vector-left-multiplication-matrix-ops.svg
M	scalar-vector-right-multiplication-matrix-ops.svg
M	siggraph-teaser-euclidean-teaser.svg
M	tree-tree.svg
M	tree-venn-3d.svg
M	two-vectors-perp-vectors-dashed.svg
M	vector-vector-addition-matrix-ops.svg
M	vector-vector-division-elementwise-matrix-ops.svg
M	vector-vector-multiplication-elementwise-matrix-ops.svg
M	vector-vector-outerproduct-matrix-ops.svg
M	vector-vector-subtraction-matrix-ops.svg
M	vector-wedge-exterior-algebra.svg

📊 Performance

Key

Note that each bar component rounds up to the nearest 100ms, so each full bar is an overestimate by up to 400ms.

     0s   1s   2s   3s   4s   5s   6s   7s   8s   9s
     |    |    |    |    |    |    |    |    |    |
name ▝▀▀▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▄▞▀▀▀▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▄▖
      compilation labelling optimization rendering

Data

                                                    0s   1s   2s   3s   4s   5s   6s   7s
                                                    |    |    |    |    |    |    |    |
3d-projection-fake-3d-linear-algebra                ▝▞▖
allShapes-allShapes                                 ▝▞▄▖
arrowheads-arrowheads                               ▝▞▖
caffeine-structural-formula                         ▝▀▀▞▚
center-shrink-circle-animation                      ▝▞▖
circle-example-euclidean                            ▝▀▞▀▀▖
closest-point-test-closest-point                    ▝▀▀▀▀▀▞▖
collinear-euclidean                                 ▝▚▚
congruent-triangles-euclidean                       ▝▀▚▚
continuousmap-continuousmap                         ▝▞▖
cubic-bezier-cubic-bezier                           ▝▚▀▀▖
glutamine-molecules-basic                           ▝▀▞▖
half-adder-distinctive-shape                        ▝▚▚
hypergraph-hypergraph                               ▝▀▀▚▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▚
incenter-triangle-euclidean                         ▝▀▞▖
lagrange-bases-lagrange-bases                       ▝▞▖
matrix-matrix-addition-matrix-ops                   ▝▚▚
matrix-matrix-division-elementwise-matrix-ops       ▝▚▚
matrix-matrix-multiplication-elementwise-matrix-ops ▝▚▚
matrix-matrix-multiplication-matrix-ops             ▝▚▚
matrix-matrix-subtraction-matrix-ops                ▝▚▚
matrix-transpose-matrix-ops                         ▝▞▖
matrix-vector-left-multiplication-matrix-ops        ▝▞▖
matrix-vector-right-multiplication-matrix-ops       ▝▞▖
midsegment-triangles-euclidean                      ▝▚▚
mobius-mobius                                       ▝▞▖
non-convex-non-convex                               ▝▚▚
one-water-molecule-atoms-and-bonds                  ▝▞▖
parallel-lines-euclidean                            ▝▚▀▖
persistent-homology-persistent-homology             ▝▀▚▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
points-around-line-shape-distance                   ▝▀▞▖
points-around-polyline-shape-distance               ▝▀▚▚
points-around-star-shape-distance                   ▝▀▀▚▚
quaternion-group-group-theory-cayley-graph          ▝▀▚▚
quaternion-group-group-theory-multiplication-table  ▝▀▀▚▞▖
scalar-vector-division-matrix-ops                   ▝▞▖
scalar-vector-left-multiplication-matrix-ops        ▝▞▖
scalar-vector-right-multiplication-matrix-ops       ▝▞▖
siggraph-teaser-euclidean-teaser                    ▝▀▚▚
small-graph-disjoint-rect-line-horiz                ▝▀▚▚
small-graph-disjoint-rects                          ▝▞▖
small-graph-disjoint-rects-large-canvas             ▝▞▖
small-graph-disjoint-rects-small-canvas             ▝▞▖
tree-tree                                           ▝▀▄▚
tree-venn                                           ▝▀▞▖
tree-venn-3d                                        ▝▚▚▄
two-triangles-triangle-mesh-3d                      ▝▚▚
two-vectors-perp-vectors-dashed                     ▝▞▖
vector-vector-addition-matrix-ops                   ▝▞▖
vector-vector-division-elementwise-matrix-ops       ▝▞▖
vector-vector-multiplication-elementwise-matrix-ops ▝▞▖
vector-vector-outerproduct-matrix-ops               ▝▞▖
vector-vector-subtraction-matrix-ops                ▝▞▖
vector-wedge-exterior-algebra                       ▝▞▖
wet-floor-atoms-and-bonds                           ▝▚▀▀▖
word-cloud-example-word-cloud                       ▝▀▞▖
wos-laplace-estimator-walk-on-spheres               ▝▀▞▖
wos-nested-estimator-walk-on-spheres                ▝▀▀▞▀▀▖
wos-offcenter-estimator-walk-on-spheres             ▝▀▚▀▀▀▚
wos-poisson-estimator-walk-on-spheres               ▝▀▞▀▖

@keenancrane
Copy link
Collaborator

One thing I notice is that closestPointPolyline (in Functions.ts) is bitwise identical to closestPointLine, i.e., the former really just computes the closest point on a single line segment, not a polyline. It's otherwise invoked in the right places. So, I'm just gonna kill the latter and stick to closestPointLine (which makes the code more understandable and less redundant).

@keenancrane
Copy link
Collaborator

Also updating file extensions

@keenancrane keenancrane merged commit c2c8fc6 into main Feb 14, 2023
@samestep samestep deleted the closest-point branch March 15, 2023 17:25
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.

None yet

8 participants