Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
        public static IntPolygon operator -(IntPolygon polygon, IntVertex2 vector)
        {
            var newPolygon = new IntPolygon(polygon);

            newPolygon.Move(-vector);
            return(newPolygon);
        }
Ejemplo n.º 3
0
 public Polygon(IntPolygon polygon) : base(polygon.Count)
 {
     foreach (var vertex in polygon)
     {
         Add((Vertex2)vertex);
     }
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 public static bool IntPolygonToIntSegment(IntPolygon polygon, IntSegment2 segment)
 {
     return(polygon.segments.Any(s => s.Intersects(segment)));
 }
Ejemplo n.º 11
0
 public static bool IntPolygonToIntPolygon(IntPolygon polygon1, IntPolygon polygon2)
 {
     return(polygon1.segments.Any(s1 => polygon2.segments.Any(s2 => s1.Intersects(s2))));
 }
Ejemplo n.º 12
0
 public static void DrawIntPolygon(IntPolygon polygon, Color color, float duration)
 {
     DrawIntPolygon(polygon, color, duration, true);
 }
Ejemplo n.º 13
0
 public static void DrawIntPolygon(IntPolygon polygon, Color color)
 {
     DrawIntPolygon(polygon, color, 0f, true);
 }
Ejemplo n.º 14
0
 public static void DrawIntPolygon(IntPolygon polygon)
 {
     DrawIntPolygon(polygon, Color.white, 0f, true);
 }
Ejemplo n.º 15
0
 public bool Intersects(IntPolygon polygon, out List <IntSegment2> intersections)
 {
     return(Intersection.IntPolygonToIntPolygon(this, polygon, out intersections));
 }
Ejemplo n.º 16
0
 public bool Intersects(IntPolygon polygon)
 {
     return(Intersection.IntPolygonToIntPolygon(this, polygon));
 }