PolarHelper.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /************************************************/
  2. /* */
  3. /* Copyright (c) 2018 - 2021 monitor1394 */
  4. /* https://github.com/monitor1394 */
  5. /* */
  6. /************************************************/
  7. using UnityEngine;
  8. namespace XCharts
  9. {
  10. public static class PolarHelper
  11. {
  12. public static void UpdatePolarCenter(Polar polar, Vector3 chartPosition, float chartWidth, float chartHeight)
  13. {
  14. if (polar.center.Length < 2) return;
  15. var centerX = polar.center[0] <= 1 ? chartWidth * polar.center[0] : polar.center[0];
  16. var centerY = polar.center[1] <= 1 ? chartHeight * polar.center[1] : polar.center[1];
  17. polar.runtimeCenterPos = chartPosition + new Vector3(centerX, centerY);
  18. if (polar.radius <= 0)
  19. {
  20. polar.runtimeRadius = 0;
  21. }
  22. else if (polar.radius <= 1)
  23. {
  24. polar.runtimeRadius = Mathf.Min(chartWidth, chartHeight) * polar.radius;
  25. }
  26. else
  27. {
  28. polar.runtimeRadius = polar.radius;
  29. }
  30. }
  31. }
  32. }