using UnityEngine; using X10D.Drawing; using X10D.Numerics; using X10D.Unity.Numerics; using Quaternion = System.Numerics.Quaternion; namespace X10D.Unity; public static partial class DebugUtility { /// /// Draws a circle with the specified color. /// /// The center point of the circle. /// The radius of the circle. /// The number of segments to generate. public static void DrawCircle(Vector2 center, float radius, int segments) { DrawCircle(center, radius, segments, Color.white, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color. /// /// The center point of the circle. /// The radius of the circle. /// The number of segments to generate. /// The color of the circle. public static void DrawCircle(Vector2 center, float radius, int segments, in Color color) { DrawCircle(center, radius, segments, color, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color and duration. /// /// The center point of the circle. /// The radius of the circle. /// The number of segments to generate. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// public static void DrawCircle(Vector2 center, float radius, int segments, in Color color, float duration) { DrawCircle(center, radius, segments, Vector2.zero, color, duration, DefaultDepthTest); } /// /// Draws a circle with the specified color and duration. /// /// The center point of the circle. /// The radius of the circle. /// The number of segments to generate. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// /// /// if depth test should be applied; otherwise, . Passing /// will have the circle be obscured by objects closer to the camera. /// public static void DrawCircle(Vector2 center, float radius, int segments, in Color color, float duration, bool depthTest) { DrawCircle(center, radius, segments, Vector2.zero, color, duration, depthTest); } /// /// Draws a circle. /// /// The center point of the circle. /// The radius of the circle. /// The number of segments to generate. /// The drawing offset of the circle. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// /// /// if depth test should be applied; otherwise, . Passing /// will have the circle be obscured by objects closer to the camera. /// public static void DrawCircle(Vector2 center, float radius, int segments, in Vector3 offset, in Color color, float duration, bool depthTest) { DrawCircle(new CircleF(center.ToSystemVector(), radius), segments, offset, color, duration, depthTest); } /// /// Draws a circle with the specified color. /// /// The circle to draw. /// The number of segments to generate. public static void DrawCircle(in Circle circle, int segments) { DrawCircle((CircleF)circle, segments, Vector2.zero, Color.white, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color. /// /// The circle to draw. /// The number of segments to generate. /// The drawing offset of the circle. public static void DrawCircle(in Circle circle, int segments, in Vector3 offset) { DrawCircle((CircleF)circle, segments, offset, Color.white, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color. /// /// The circle to draw. /// The number of segments to generate. /// The color of the circle. public static void DrawCircle(in Circle circle, int segments, in Color color) { DrawCircle((CircleF)circle, segments, Vector2.zero, color, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color. /// /// The circle to draw. /// The number of segments to generate. /// The drawing offset of the circle. /// The color of the circle. public static void DrawCircle(in Circle circle, int segments, in Vector3 offset, in Color color) { DrawCircle((CircleF)circle, segments, offset, color, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color and duration. /// /// The circle to draw. /// The number of segments to generate. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// public static void DrawCircle(in Circle circle, int segments, in Color color, float duration) { DrawCircle((CircleF)circle, segments, Vector2.zero, color, duration, DefaultDepthTest); } /// /// Draws a circle with the specified color and duration. /// /// The circle to draw. /// The number of segments to generate. /// The drawing offset of the circle. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// public static void DrawCircle(in Circle circle, int segments, in Vector3 offset, in Color color, float duration) { DrawCircle((CircleF)circle, segments, offset, color, duration, DefaultDepthTest); } /// /// Draws a circle with the specified color and duration. /// /// The circle to draw. /// The number of segments to generate. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// /// /// if depth test should be applied; otherwise, . Passing /// will have the circle be obscured by objects closer to the camera. /// public static void DrawCircle(in Circle circle, int segments, in Color color, float duration, bool depthTest) { DrawCircle((CircleF)circle, segments, Vector2.zero, color, duration, depthTest); } /// /// Draws a circle. /// /// The circle to draw. /// The number of segments to generate. /// The drawing offset of the circle. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// /// /// if depth test should be applied; otherwise, . Passing /// will have the circle be obscured by objects closer to the camera. /// public static void DrawCircle(in Circle circle, int segments, in Vector3 offset, in Color color, float duration, bool depthTest) { DrawCircle((CircleF)circle, segments, offset, color, duration, depthTest); } /// /// Draws a circle with the specified color. /// /// The circle to draw. /// The number of segments to generate. public static void DrawCircle(in CircleF circle, int segments) { DrawCircle(circle, segments, Color.white, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color. /// /// The circle to draw. /// The number of segments to generate. /// The drawing offset of the circle. public static void DrawCircle(in CircleF circle, int segments, in Vector3 offset) { DrawCircle(circle, segments, offset, Color.white, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color. /// /// The circle to draw. /// The number of segments to generate. /// The color of the circle. public static void DrawCircle(in CircleF circle, int segments, in Color color) { DrawCircle(circle, segments, Vector2.zero, color, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color. /// /// The circle to draw. /// The number of segments to generate. /// The drawing offset of the circle. /// The color of the circle. public static void DrawCircle(in CircleF circle, int segments, in Vector3 offset, in Color color) { DrawCircle(circle, segments, offset, color, DefaultDrawDuration, DefaultDepthTest); } /// /// Draws a circle with the specified color and duration. /// /// The circle to draw. /// The number of segments to generate. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// public static void DrawCircle(in CircleF circle, int segments, in Color color, float duration) { DrawCircle(circle, segments, Vector2.zero, color, duration, DefaultDepthTest); } /// /// Draws a circle with the specified color and duration. /// /// The circle to draw. /// The number of segments to generate. /// The drawing offset of the circle. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// public static void DrawCircle(in CircleF circle, int segments, in Vector3 offset, in Color color, float duration) { DrawCircle(circle, segments, offset, color, duration, DefaultDepthTest); } /// /// Draws a circle with the specified color and duration. /// /// The circle to draw. /// The number of segments to generate. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// /// /// if depth test should be applied; otherwise, . Passing /// will have the circle be obscured by objects closer to the camera. /// public static void DrawCircle(in CircleF circle, int segments, in Color color, float duration, bool depthTest) { DrawCircle(circle, segments, Vector2.zero, color, duration, depthTest); } /// /// Draws a circle. /// /// The circle to draw. /// The number of segments to generate. /// The drawing offset of the circle. /// The color of the circle. /// /// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame. /// /// /// if depth test should be applied; otherwise, . Passing /// will have the circle be obscured by objects closer to the camera. /// public static void DrawCircle(in CircleF circle, int segments, in Vector3 offset, in Color color, float duration, bool depthTest) { DrawPolyhedron(CreateCircle(circle.Radius, segments, Vector3.zero), offset, color, duration, depthTest); } private static Polyhedron CreateCircle(float radius, int segments, in Vector3 axis) { const float max = 2.0f * MathF.PI; float step = max / segments; var points = new List(); for (var theta = 0f; theta < max; theta += step) { float x = radius * MathF.Cos(theta); float y = radius * MathF.Sin(theta); var vector = new System.Numerics.Vector3(x, y, 0); if (axis != Vector3.zero) { vector = Quaternion.CreateFromAxisAngle(axis.ToSystemVector(), MathF.PI / 2.0f).Multiply(vector); } points.Add(vector); } return new Polyhedron(points); } }