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 examples with nonconvex shapes #893

Merged
merged 11 commits into from Mar 1, 2022
Merged

Conversation

jiriminarcik
Copy link
Contributor

@jiriminarcik jiriminarcik commented Feb 21, 2022

Description

Followup to #877.

Added new examples with non-convex shapes and fixed some issues with the convex partitioning algorithm by switching to library poly-partition (see comments below).

Examples with steps to reproduce them

  • Triangle maze example:

Run npx roger watch maze.sub maze.sty maze.dsl in folder examples/minkowski-tests/maze.

Screenshot 2022-02-21 at 1 12 53

  • Yin-Yang example:

Run npx roger watch yin-yang.sub yin-yang.sty yin-yang.dsl in folder examples/minkowski-tests/yin-yang.

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

Open questions

The optimiser struggles with the Yin-Yang example and often get stuck at an undesirable local minimum.

Screenshot 2022-02-28 at 20 55 36

@cloudflare-pages
Copy link

cloudflare-pages bot commented Feb 21, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ddea702
Status: ✅  Deploy successful!
Preview URL: https://b60c7b8e.penrose-panes.pages.dev

View logs

@codecov
Copy link

codecov bot commented Feb 21, 2022

Codecov Report

Merging #893 (f05a3fa) into main (009a1bc) will increase coverage by 0.73%.
The diff coverage is 100.00%.

❗ Current head f05a3fa differs from pull request most recent head ddea702. Consider uploading reports for the commit ddea702 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #893      +/-   ##
==========================================
+ Coverage   67.43%   68.17%   +0.73%     
==========================================
  Files          62       62              
  Lines        8181     8115      -66     
  Branches     1771     1767       -4     
==========================================
+ Hits         5517     5532      +15     
+ Misses       2657     2576      -81     
  Partials        7        7              
Impacted Files Coverage Δ
packages/core/src/engine/Autodiff.ts 81.41% <ø> (+6.74%) ⬆️
packages/core/src/types/ad.ts 100.00% <ø> (ø)
packages/core/src/contrib/Minkowski.ts 100.00% <100.00%> (+2.43%) ⬆️
packages/core/src/engine/AutodiffFunctions.ts 50.16% <100.00%> (+0.08%) ⬆️
packages/core/src/engine/Evaluator.ts 62.20% <0.00%> (+0.52%) ⬆️
packages/core/src/engine/EngineUtils.ts 68.64% <0.00%> (+0.95%) ⬆️
packages/core/src/renderer/AttrHelper.ts 83.73% <0.00%> (+9.03%) ⬆️
packages/core/src/renderer/Polygon.ts 100.00% <0.00%> (+75.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 009a1bc...ddea702. Read the comment docs.

@samestep
Copy link
Collaborator

Visualization of the TypeError: polygon decomposition unexpectedly created a new point for examples/minkowski-test/yin-yang/ (it is indeed creating a new point):

@samestep
Copy link
Collaborator

The poly-decomp.js library (linked from #877) links to this page describing an algorithm, which explains the circumstances under which it inserts these Steiner points: https://mpen.ca/406/bayazit

@samestep
Copy link
Collaborator

samestep commented Mar 1, 2022

I opened x6ud/poly-partition-js#1 which would allow make convexPartitions work for polygons of arbitrary orientation:

diff --git a/packages/core/src/contrib/Minkowski.ts b/packages/core/src/contrib/Minkowski.ts
index d774e67f0..cd235e3a4 100644
--- a/packages/core/src/contrib/Minkowski.ts
+++ b/packages/core/src/contrib/Minkowski.ts
@@ -161,6 +161,9 @@ export const convexPartitions = (p: VarAD[][]): VarAD[][][] => {
   );
 
   const contour = [...pointMap.keys()];
+  if (isClockwise(contour)) {
+    contour.reverse();
+  }
   const convexPolygons = convexPartition(contour);
 
   return convexPolygons.map((poly) =>

Copy link
Collaborator

@samestep samestep left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @jiriminarcik! Do you want to add any of these to the registry?

@jiriminarcik
Copy link
Contributor Author

Looks great, thanks @jiriminarcik! Do you want to add any of these to the registry?

I added the maze example.

@jiriminarcik jiriminarcik merged commit 91edc5c into main Mar 1, 2022
@samestep samestep deleted the nonconvex-examples 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

3 participants