Ejemplo n.º 1
0
        public BoundsLineCrossing CrossLine(Point2 <double> point1, Point2 <double> point2)
        {
            BoundsLineCrossing crossing = new BoundsLineCrossing(point1, point2);

            CohenSutherland2DClipper.Clip(crossing, this);

            return(crossing);
        }
Ejemplo n.º 2
0
        public static void Clip(BoundsLineCrossing crossing, Bounds2 bounds)
        {
            int outCode0, outCode1;

            Point2<double> P0 = crossing.P0;
            Point2<double> P1 = crossing.P1;

            while (true)
            {
                outCode0 = OutCodes (bounds, P0);
                outCode1 = OutCodes (bounds, P1);

                crossing.P0 = P0;
                crossing.P1 = P1;

                if (RejectCheck (outCode0, outCode1))
                    return;

                if (AcceptCheck (outCode0, outCode1))
                    return;

                if (outCode0 == 0)
                {
                    double tempCoord; int tempCode;
                    tempCoord = P0.X; P0.X = P1.X; P1.X = tempCoord;
                    tempCoord = P0.Y; P0.Y = P1.Y; P1.Y = tempCoord;
                    tempCode = outCode0; outCode0 = outCode1; outCode1 = tempCode;
                    BoundsLineCrossingType tempType;
                    tempType = crossing.CrossingTypePoint0; crossing.CrossingTypePoint0 = crossing.CrossingTypePoint1; crossing.CrossingTypePoint1 = tempType;
                }

                if ((outCode0 & 1) != 0)
                {
                    P0.X += (P1.X - P0.X) * (bounds.MaxY - P0.Y) / (P1.Y - P0.Y);
                    P0.Y = bounds.MaxY;
                    crossing.CrossingTypePoint0 = BoundsLineCrossingType.CrossesMaxY;
                    crossing.HasCrossed = true;
                }
                else
                    if ((outCode0 & 2) != 0)
                    {
                        P0.X += (P1.X - P0.X) * (bounds.MinY - P0.Y) / (P1.Y - P0.Y);
                        P0.Y = bounds.MinY;
                        crossing.CrossingTypePoint0 = BoundsLineCrossingType.CrossesMinY;
                        crossing.HasCrossed = true;
                    }
                    else
                        if ((outCode0 & 4) != 0)
                        {
                            P0.Y += (P1.Y - P0.Y) * (bounds.MaxX - P0.X) / (P1.X - P0.X);
                            P0.X = bounds.MaxX;
                            crossing.CrossingTypePoint0 = BoundsLineCrossingType.CrossesMaxX;
                            crossing.HasCrossed = true;
                        }
                        else
                            if ((outCode0 & 8) != 0)
                            {
                                P0.Y += (P1.Y - P0.Y) * (bounds.MinX - P0.X) / (P1.X - P0.X);
                                P0.X = bounds.MinX;
                                crossing.CrossingTypePoint0 = BoundsLineCrossingType.CrossesMinX;
                                crossing.HasCrossed = true;
                            }
            }
        }
Ejemplo n.º 3
0
        public BoundsLineCrossing CrossLine(Point2<double> point1, Point2<double> point2)
        {
            BoundsLineCrossing crossing = new BoundsLineCrossing (point1, point2);

            CohenSutherland2DClipper.Clip (crossing, this);

            return crossing;
        }
Ejemplo n.º 4
0
        static public void Clip(BoundsLineCrossing crossing, Bounds2 bounds)
        {
            int outCode0, outCode1;

            Point2 <double> P0 = crossing.P0;
            Point2 <double> P1 = crossing.P1;

            while (true)
            {
                outCode0 = OutCodes(bounds, P0);
                outCode1 = OutCodes(bounds, P1);

                crossing.P0 = P0;
                crossing.P1 = P1;

                if (RejectCheck(outCode0, outCode1))
                {
                    return;
                }

                if (AcceptCheck(outCode0, outCode1))
                {
                    return;
                }

                if (outCode0 == 0)
                {
                    double tempCoord; int tempCode;
                    tempCoord = P0.X; P0.X = P1.X; P1.X = tempCoord;
                    tempCoord = P0.Y; P0.Y = P1.Y; P1.Y = tempCoord;
                    tempCode  = outCode0; outCode0 = outCode1; outCode1 = tempCode;
                    BoundsLineCrossingType tempType;
                    tempType = crossing.CrossingTypePoint0; crossing.CrossingTypePoint0 = crossing.CrossingTypePoint1; crossing.CrossingTypePoint1 = tempType;
                }

                if ((outCode0 & 1) != 0)
                {
                    P0.X += (P1.X - P0.X) * (bounds.MaxY - P0.Y) / (P1.Y - P0.Y);
                    P0.Y  = bounds.MaxY;
                    crossing.CrossingTypePoint0 = BoundsLineCrossingType.CrossesMaxY;
                    crossing.HasCrossed         = true;
                }
                else
                if ((outCode0 & 2) != 0)
                {
                    P0.X += (P1.X - P0.X) * (bounds.MinY - P0.Y) / (P1.Y - P0.Y);
                    P0.Y  = bounds.MinY;
                    crossing.CrossingTypePoint0 = BoundsLineCrossingType.CrossesMinY;
                    crossing.HasCrossed         = true;
                }
                else
                if ((outCode0 & 4) != 0)
                {
                    P0.Y += (P1.Y - P0.Y) * (bounds.MaxX - P0.X) / (P1.X - P0.X);
                    P0.X  = bounds.MaxX;
                    crossing.CrossingTypePoint0 = BoundsLineCrossingType.CrossesMaxX;
                    crossing.HasCrossed         = true;
                }
                else
                if ((outCode0 & 8) != 0)
                {
                    P0.Y += (P1.Y - P0.Y) * (bounds.MinX - P0.X) / (P1.X - P0.X);
                    P0.X  = bounds.MinX;
                    crossing.CrossingTypePoint0 = BoundsLineCrossingType.CrossesMinX;
                    crossing.HasCrossed         = true;
                }
            }
        }