Exemplo n.º 1
0
 public Bounds2(Bounds2 original)
 {
     this.minX = original.minX;
     this.minY = original.minY;
     this.maxX = original.maxX;
     this.maxY = original.maxY;
 }
Exemplo n.º 2
0
 public Bounds2(Bounds2 original)
 {
     this.minX = original.minX;
     this.minY = original.minY;
     this.maxX = original.maxX;
     this.maxY = original.maxY;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the union of two <see cref="GeoBounds"/> objects.
        /// </summary>
        /// <param name="with"><see cref="GeoBounds"/> object to unite with.</param>
        /// <returns>Union of two <see cref="GeoBounds"/> objects.</returns>
        public Bounds2 Union(Bounds2 with)
        {
            if (with == null)
            {
                throw new ArgumentNullException("with");
            }

            return(new Bounds2(Math.Min(MinX, with.MinX), Math.Min(MinY, with.MinY),
                               Math.Max(MaxX, with.MaxX), Math.Max(MaxY, with.MaxY)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Compares the current <see cref="Bounds2"/> object to the specified object for equivalence.
        /// </summary>
        /// <param name="obj">The <see cref="Bounds2"/> object to test for equivalence with the current object.</param>
        /// <returns>
        /// <c>true</c> if the two <see cref="Bounds2"/> objects are equal; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            Bounds2 that = obj as Bounds2;

            if (that == null)
            {
                return(false);
            }

            return(minX.Equals(that.minX) && minY.Equals(that.minY) && maxX.Equals(that.maxX) && maxY.Equals(that.MaxY));
        }
Exemplo n.º 5
0
        private static int OutCodes(Bounds2 bounds, Point2 <double> P)
        {
            int Code = 0;

            if (P.Y > bounds.MaxY)
            {
                Code += 1;                    /* code for above */
            }
            else if (P.Y < bounds.MinY)
            {
                Code += 2;                         /* code for below */
            }
            if (P.X > bounds.MaxX)
            {
                Code += 4;                    /* code for right */
            }
            else if (P.X < bounds.MinX)
            {
                Code += 8;                         /* code for left */
            }
            return(Code);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Checks if the object intersects with specified boundaries.
 /// </summary>
 /// <param name="other">The other boundaries.</param>
 /// <returns>
 ///     <c>True</c> if it intersects, <c>false</c> otherwise.
 /// </returns>
 public bool IntersectsWith(Bounds2 other)
 {
     return(IntersectsWith(other.minX, other.minY, other.maxX, other.maxY));
 }
Exemplo n.º 7
0
        private static int OutCodes(Bounds2 bounds, Point2<double> P)
        {
            int Code = 0;

            if (P.Y > bounds.MaxY) Code += 1; /* code for above */
            else if (P.Y < bounds.MinY) Code += 2; /* code for below */

            if (P.X > bounds.MaxX) Code += 4; /* code for right */
            else if (P.X < bounds.MinX) Code += 8; /* code for left */

            return Code;
        }
Exemplo n.º 8
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;
                            }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns the union of two <see cref="Bounds2"/> objects.
        /// </summary>
        /// <param name="with"><see cref="Bounds2"/> object to unite with.</param>
        /// <returns>Union of two <see cref="Bounds2"/> objects.</returns>
        public Bounds2 Union(Bounds2 with)
        {
            if (with == null)
                throw new ArgumentNullException ("with");

            return new Bounds2 (Math.Min (MinX, with.MinX), Math.Min (MinY, with.MinY),
                Math.Max (MaxX, with.MaxX), Math.Max (MaxY, with.MaxY));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Checks if the object intersects with specified boundaries.
 /// </summary>
 /// <param name="other">The other boundaries.</param>
 /// <returns>
 /// 	<c>True</c> if it intersects, <c>false</c> otherwise.
 /// </returns>
 public bool IntersectsWith(Bounds2 other)
 {
     return IntersectsWith (other.minX, other.minY, other.maxX, other.maxY);
 }
Exemplo n.º 11
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;
                }
            }
        }