RudyTheDev/SharpVoronoiLib

the order of clockwisePoints

funny-cat-happy opened this issue · 1 comments

hello,
I am the person who emailed you before,the question has been solved and thank you very much.And I find a new bug.

bug detail

I print a site's ClockwisePoints

foreach (var item in sites[i].ClockwisePoints)
{
        float x = (float)item.X;
        float y = (float)item.Y;
        ver.Add(new Vector3(x, 0, y));
        uv.Add(new Vector2(x / Mapwidth, y / Mapheight));
        DebugInfo.PrintStruct("x is",x,"y is",y);
}

QQ截图20230123171250
QQ截图20230123171329
It is anticlockwise.Not clockwise.

why bug happen

In VoronoiSite.cs file,326 line

private static int SortPointsClockwise(VoronoiPoint point1, VoronoiPoint point2, double x, double y)
{
      // originally, based on: https://social.msdn.microsoft.com/Forums/en-US/c4c0ce02-bbd0-46e7-aaa0-df85a3408c61/sorting-list-of-xy-coordinates-clockwise-sort-works-if-list-is-unsorted-but-fails-if-list-is?forum=csharplanguage
      // comparer to sort the array based on the points relative position to the center
      double atan1 = Atan2(point1.Y - y, point1.X - x);
      double atan2 = Atan2(point2.Y - y, point2.X - x);
      
      if (atan1 < atan2) return -1; //there
      if (atan1 > atan2) return 1;
      return 0;
}

QQ截图20230123174159
if atan2>atan1,it is supposed to return 1 to make atan2 in front of atan1 in the list.
I can't pull request.Maybe do you off the function?Thank you for your reply.

Heya! Sorry for not replying sooner.

You're right, the clockwise is "upside down". I was building it based on quadrant direction/rotation, which is actually counter-clockwise.

I changed it to the other direction exactly where you identified the sign issue.

Thanks for reporting the bug!