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

Small polygons under rotation result in SDF flipping its sign #449

Open
sorki opened this issue Oct 31, 2023 · 1 comment
Open

Small polygons under rotation result in SDF flipping its sign #449

sorki opened this issue Oct 31, 2023 · 1 comment

Comments

@sorki
Copy link
Contributor

sorki commented Oct 31, 2023

These two should be equal, but internally when sampled at (V2 (-1) 0)
the sign of the SDF differs yet they both get rendered correctly.

let funPoly = polygon [V2 0 0, V2 0 (-0.1), V2 (-2) 0, V2 0 (-1)]
    rotFunPoly = rotate (2*pi) funPoly
> getImplicit funPoly (V2 (-1) 0)
-4.993761694389224e-2
> getBox funPoly
(V2 (-2.0) (-1.0),V2 0.0 0.0)

vs

> getImplicit rotFunPoly (V2 (-1) 0)) 
4.9937616943891996e-2
> getBox rotFunPoly
(V2 (-2.0000000000000004) (-1.0),V2 0.0 4.898587196589413e-16)

This has something to do with isIn

minimum dists * if isIn then -1 else 1

and
relativePairs = fmap (\(a,b) -> (a - p, b - p) ) pairs
crossing_points =
[x2 - y2*(x2-x1)/(y2-y1) | (V2 x1 y1, V2 x2 y2) <- relativePairs,
( (y2 <= 0) && (y1 >= 0) ) || ( (y2 >= 0) && (y1 <= 0) ) ]
-- FIXME: use partition instead?
seemsInRight = odd . length . filter (>0) $ nub crossing_points
seemsInLeft = odd . length . filter (<0) $ nub crossing_points
isIn = seemsInRight && seemsInLeft

and it only seems to affect small polygons + rotation. If the isIn mechanism is dropped, they don't get rendered at all.

sorki added a commit to sorki/ImplicitCAD that referenced this issue Oct 31, 2023
@sorki
Copy link
Contributor Author

sorki commented Oct 31, 2023

be1ee7a adds golden test (since we don't have any 2D ones). The two renders differ in one pixel and 9 bytes..

sorki added a commit to sorki/ImplicitCAD that referenced this issue Oct 31, 2023
sorki added a commit to sorki/ImplicitCAD that referenced this issue Oct 31, 2023
sorki added a commit to sorki/ImplicitCAD that referenced this issue Nov 1, 2023
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

No branches or pull requests

1 participant