Fil / d3-geo-voronoi

Voronoi / Delaunay tessellations on the sphere
ISC License
229 stars 24 forks source link

Inconsistent broken projection of a 4 - segment beach ball #42

Open martinfrances107 opened 3 years ago

martinfrances107 commented 3 years ago

Before I begin, I should note that the code quality of this module is high and I really like the attention to detail that is apparent in the test coverage.

So I should say I am talking about bug .. which has slipped through high quality testing.

I found this as I am porting this module to rust.. my port has alsmost the same coverage as the original but a whole set of new bugs

So I am developing new test patterns to identify problems with my rust - and I have found a pattern which breaks the javascript version.

I have provded two branches which hightlight the problem.

The branches modify the benchmarks The problem can be exposed from the branches by opening in a browser the file ./benchmark/sphereCanvas.html [from the project root directory]

[The benchmarks normal function is rendering a rotating sphere with a number of random point under the control of the user ... ]

Senario A A have created a new branch showing the bug. https://github.com/martinfrances107/d3-geo-voronoi/tree/broken_4_segment_beech_ball

A rotating sphere with 4 sites to display a 4 - segment beach ball. With sites at

[ [-20, -20], [20, -20], [20, 20], [-20,20]] ( degrees )

as can be seen in this branch .. the rotation is all flickerey it appears, at times, that not all of the of the 4 items are returned by the call to poloygon().

Senario B https://github.com/martinfrances107/d3-geo-voronoi/tree/offset_4_segment_beach_ball

The position of the sites is offset just slightly .. the flicker is disappears and the slightly wonky beach ball is rendered consitently.

[ [-15, -20], [20, -20], [20, 20], [-20,20]] ( degrees )

Fil commented 3 years ago

Is it maybe the same problem as https://github.com/Fil/d3-geo-voronoi/issues/22?

martinfrances107 commented 3 years ago

I think they maybe the same... but I am going to temporarily keep this issue open as I think my desciption below give us a very spefiic route to highlight a very small section of buggy code....

I am having to balance many jobs at the moment so I am just going to document what I have found .. so that I can come back to it later.

In the screenshot below I am showing the quadpole from these 4 points/sites which are shown as circle in the images below.

[ [-20, -20], [20, -20], [20, 20], [-20,20]] ( degrees )

I have cancelled the animation by commenting out this line

        // requestAnimationFrame(render)

I have debug this to the point where I can say the missing segments of the beach ball are being projected to a line ... it is a line from the center of the image just under the top right site. The horizonal line is slighty thicker on the image.

Secondly I have watched the rotation by adjusting

projection.rotate([elapsed / 150, 0]);

to become whatever I choose

the image changes as expected from 0 until 12.47 show just a slight rotation.

projection.rotate([12.48]);

but when I move to 12.48 the nature of the bug changes instead of projecting a one quater segment of the beach ball to a line ... a three quaters segment of a beach ball is incorreclty displayed..

this is green section of the second image.

Anyway now we have a very specific change between two broken outcomes

If this description makes the solution jump out at you please let me know.

I will debug this more when I have the time.

4-segments-not-2-rotation-12 47-degrees

green-segment-3quaters-not-one

Fil commented 3 years ago

the issue is that here we have two centers ([0,0] and [180,0]), and we need to connect them back and forth, and each time through a different great circle, which we need to give explicitly since the two points are antipodal. I dealt with this case when there are only two points (in https://github.com/Fil/d3-geo-voronoi/blob/main/src/delaunay.js#L244 ), but this example shows that it needs to be generalized.