电子围栏推送服务
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

37 行
1.2KB

  1. namespace TelpoPush.Fence.Worker.Models.Fence
  2. {
  3. public static class RayCastingAlgorithm
  4. {
  5. public static bool IsWithin(GpsFencePoint pt, IList<GpsFencePoint> polygon, bool noneZeroMode)
  6. {
  7. int ptNum = polygon.Count();
  8. if (ptNum < 3)
  9. {
  10. return false;
  11. }
  12. int j = ptNum - 1;
  13. bool oddNodes = false;
  14. int zeroState = 0;
  15. for (int k = 0; k < ptNum; k++)
  16. {
  17. var ptK = polygon[k];
  18. var ptJ = polygon[j];
  19. if (ptK.Latitude > pt.Latitude != ptJ.Latitude > pt.Latitude && pt.Longitude < (ptJ.Longitude - ptK.Longitude) * (pt.Latitude - ptK.Latitude) / (ptJ.Latitude - ptK.Latitude) + ptK.Longitude)
  20. {
  21. oddNodes = !oddNodes;
  22. if (ptK.Latitude > ptJ.Latitude)
  23. {
  24. zeroState++;
  25. }
  26. else
  27. {
  28. zeroState--;
  29. }
  30. }
  31. j = k;
  32. }
  33. return noneZeroMode ? zeroState != 0 : oddNodes;
  34. }
  35. }
  36. }