public static void DrawGradientIntPolygon(this Texture2D texture, IntPolygon polygon, Color color0, Color color1) { if (polygon.Count < 2) { return; } for (var i = 0; i < polygon.Count; i++) { var distance = Vertex2.Distance((Vertex2)polygon[i], (Vertex2)polygon[i + 1]); Action <int, int> draw; if (distance > 0) { draw = (x, y) => { var percent = Vertex2.Distance((Vertex2)polygon[i], new Vertex2(x, y)) / distance; texture.SetPixel(x, y, Color.Lerp(color0, color1, percent)); }; } else { draw = (x, y) => texture.SetPixel(x, y, color0); } BresenhamLine(polygon[i], polygon[i + 1], draw); } texture.Apply(); }
public static IntPolygon operator -(IntPolygon polygon, IntVertex2 vector) { var newPolygon = new IntPolygon(polygon); newPolygon.Move(-vector); return(newPolygon); }
public Polygon(IntPolygon polygon) : base(polygon.Count) { foreach (var vertex in polygon) { Add((Vertex2)vertex); } }
public static void DrawIntPolygon(IntPolygon polygon, Color color, float duration, bool depthTest) { if (polygon.Count < 2) { return; } for (var i = 0; i < polygon.Count - 1; i++) { Debug.DrawLine((Vector3)polygon[i], (Vector3)polygon[i + 1], color, duration, depthTest); } Debug.DrawLine((Vector3)polygon[polygon.Count - 1], (Vector3)polygon[0], color, duration, depthTest); }
public static IntPolygon operator *(IntPolygon polygon, IntVertex2 vector) { var newPolygon = new IntPolygon(polygon); var c = newPolygon.center; for (int i = 0; i < newPolygon.Count; i++) { newPolygon[i] = new IntVertex2(newPolygon[i].x * vector.x, newPolygon[i].y * vector.y); } newPolygon.center = c; return(newPolygon); }
public static IntPolygon operator *(IntPolygon polygon, int x) { var newPolygon = new IntPolygon(polygon); var c = newPolygon.center; for (int i = 0; i < newPolygon.Count; i++) { newPolygon[i] *= x; } newPolygon.center = c; return(newPolygon); }
public static void DrawIntPolygon(this Texture2D texture, IntPolygon polygon, Color color) { if (polygon.Count < 2) { return; } Action <int, int> draw = (x, y) => texture.SetPixel(x, y, color); for (var i = 0; i < polygon.Count; i++) { BresenhamLine(polygon[i], polygon[i + 1], draw); } texture.Apply(); }
public static bool IntPolygonToIntPolygon(IntPolygon polygon1, IntPolygon polygon2, out List <IntSegment2> intersections) { intersections = new List <IntSegment2>(); foreach (var s1 in polygon1.segments) { foreach (var s2 in polygon2.segments) { IntSegment2 intersection; if (s1.Intersects(s2, out intersection)) { intersections.Add(intersection); } } } return(intersections.Count > 0); }
public static IntPolygon RemoveCollinearVertices(IntPolygon polygon) { if (polygon.Count <= 3) { return(polygon); } var newPolygon = new IntPolygon(); for (int i = 0; i < polygon.Count; i++) { if (PGUtils.LocatePointOnLine(polygon[i - 1], polygon[i + 1], polygon[i]) != 0) { newPolygon.Add(polygon[i]); } } return(newPolygon); }
public static bool IntPolygonToIntSegment(IntPolygon polygon, IntSegment2 segment) { return(polygon.segments.Any(s => s.Intersects(segment))); }
public static bool IntPolygonToIntPolygon(IntPolygon polygon1, IntPolygon polygon2) { return(polygon1.segments.Any(s1 => polygon2.segments.Any(s2 => s1.Intersects(s2)))); }
public static void DrawIntPolygon(IntPolygon polygon, Color color, float duration) { DrawIntPolygon(polygon, color, duration, true); }
public static void DrawIntPolygon(IntPolygon polygon, Color color) { DrawIntPolygon(polygon, color, 0f, true); }
public static void DrawIntPolygon(IntPolygon polygon) { DrawIntPolygon(polygon, Color.white, 0f, true); }
public bool Intersects(IntPolygon polygon, out List <IntSegment2> intersections) { return(Intersection.IntPolygonToIntPolygon(this, polygon, out intersections)); }
public bool Intersects(IntPolygon polygon) { return(Intersection.IntPolygonToIntPolygon(this, polygon)); }