示例#1
0
        public Polygon ClipToPolygon(Polygon clipper)
        {
            Point[] inPolygonVertices = new Point[this.Points.Length + 2 * clipper.Points.Length];
            for (int i = 0; i < this.Points.Length; i++)
            {
                inPolygonVertices[i] = this.Points[i];
            }
            Point[] outPolygonVertices = new Point[this.Points.Length + 2 * clipper.Points.Length];

            Polygon.ClipEdge clipEdge = new Polygon.ClipEdge(clipper.Points.Last(), clipper.Points.First());
            int num = this.SutherlandHodgmanPolygonClip(inPolygonVertices, this.Points.Length, outPolygonVertices, clipEdge);

            for (int j = 0; j < clipper.points.Length - 1; j++)
            {
                Point[] tmpVertices = inPolygonVertices;
                inPolygonVertices = outPolygonVertices;
                outPolygonVertices = tmpVertices;
                clipEdge = new Polygon.ClipEdge(clipper.Points[j], clipper.Points[j + 1]);
                num = this.SutherlandHodgmanPolygonClip(inPolygonVertices, num, outPolygonVertices, clipEdge);
            }

            Point[] clippedPolygonVertices = new Point[num];
            for (int k = 0; k < num; k++)
            {
                clippedPolygonVertices[k] = outPolygonVertices[k];
            }
            return new Polygon(clippedPolygonVertices);
        }
        public static void FillPolygon(this Graphics g, Polygon polygon, Color color)
        {
            var polygonFillHelper = new PolygonFillHelper(new List<Point>(polygon.Points));
            var segments = polygonFillHelper.FillPolygon(g);

            using (Pen pen = new Pen(color))
            {
                foreach (var segment in segments)
                {
                    g.DrawLine(pen, segment.p1, segment.p2);
                }
            }
        }
        public static void FillPolygon(this Graphics g, Polygon polygon, Bitmap texture, Bitmap destination)
        {
            var polygonFillHelper = new PolygonFillHelper(new List<Point>(polygon.Points));
            var segments = polygonFillHelper.FillPolygon(g);

            for (int y = 0; y < segments.Count; y++)
            {
                for (int x = 0; x < segments[y].p2.X - segments[y].p1.X; x++)
                {
                    Color color = texture.GetPixel(x % texture.Width, y % texture.Height);
                    if (segments[y].p1.X + x < destination.Width && segments[y].p1.X + x > 0 && segments[y].p1.Y > 0 && segments[y].p1.Y < destination.Height)
                        destination.SetPixel(segments[y].p1.X + x, segments[y].p1.Y, color);
                }
            }
        }
示例#4
0
 public WindowPolygon(List<Point> vertices)
     : base(vertices)
 {
     basePolygon = new Polygon(vertices);
     _clipper = new Rectangle(MinX, MinY, MaxX - MinX, MaxY - MinY);
 }
示例#5
0
        public override void CalculatePositions()
        {
            //double scaledStripLength = StripLength
            double scale1 = DistFromCar / _roadStateManager.RoadLength;

            double scale2 = (DistFromCar+StripLength*(DistFromCar/_roadStateManager.RoadLength)) / _roadStateManager.RoadLength;

            double rwdiv2 = (_roadStateManager.RoadWidth/2);

            double y1screen = _roadStateManager.RoadY + DistFromCar;
            double y2screen = _roadStateManager.RoadY + _roadStateManager.RoadLength*scale2;

            double x1screen = rwdiv2*(1 + X*scale1) - StripWidth * scale1;
            double x2screen = rwdiv2 * (1 + X * scale1) + StripWidth * scale1;

            double x3screen = rwdiv2 * (1 + X * scale2) - StripWidth * scale2;
            double x4screen = rwdiv2 * (1 + X * scale2) + StripWidth * scale2;

            List<Point> vertices = new List<Point>();
            //dodaje przeciwnie do wsk zegara
            vertices.Add(new Point((int)x2screen, (int)y1screen));
            vertices.Add(new Point((int)x1screen, (int)y1screen));
            vertices.Add(new Point((int)x3screen, (int)y2screen));
            vertices.Add(new Point((int)x4screen, (int)y2screen));

            PolygonRepresentation = new Polygon(vertices);
        }
示例#6
0
        private int SutherlandHodgmanPolygonClip(Point[] inArray, int inLength, Point[] outArray, Polygon.ClipEdge clipBoundary)
        {
            if (inLength < 3)
            {
                return 0;
            }
            int num = 0;

            Point point = inArray[inLength - 1];
            for (int i = 0; i < inLength; i++)
            {
                Point point1 = inArray[i];
                if (this.Inside(point1, clipBoundary))
                {
                    if (!this.Inside(point, clipBoundary))
                    {
                        int num1 = num;
                        num = num1 + 1;
                        outArray[num1] = this.Intersect(point, point1, clipBoundary);
                        int num2 = num;
                        num = num2 + 1;
                        outArray[num2] = point1;
                    }
                    else
                    {
                        int num3 = num;
                        num = num3 + 1;
                        outArray[num3] = point1;
                    }
                }
                else if (this.Inside(point, clipBoundary))
                {
                    int num4 = num;
                    num = num4 + 1;
                    outArray[num4] = this.Intersect(point, point1, clipBoundary);
                }
                point = point1;
            }
            return num;
        }
示例#7
0
 private Point Intersect(Point s, Point p, Polygon.ClipEdge ClipBoundary)
 {
     return ClipBoundary.IntersectWith(s, p);
 }
示例#8
0
 private bool Inside(Point p, Polygon.ClipEdge ClipBoundary)
 {
     return ClipBoundary.IsPointInside(p);
 }