예제 #1
0
 /// <summary>
 /// Puts the line segment into a normalized form.
 /// </summary>
 /// <remarks>
 /// This is useful for using line segments in maps and indexes when
 /// topological equality rather than exact equality is desired.
 /// <para>
 /// A segment in normalized form has the first point smaller than
 /// the second (according to the standard ordering on
 /// <see cref="Coordinate"/>).
 /// </para>
 /// </remarks>
 public override void Normalize()
 {
     if (p1.CompareTo(p0) < 0)
     {
         Reverse();
     }
 }
예제 #2
0
        public void TestCompareTo()
        {
            Coordinate lowest         = new Coordinate(10.0, 100.0, 50.0);
            Coordinate highest        = new Coordinate(20.0, 100.0, 50.0);
            Coordinate equalToHighest = new Coordinate(20.0, 100.0, 50.0);
            Coordinate higherStill    = new Coordinate(20.0, 200.0, 50.0);

            Assert.AreEqual(-1, lowest.CompareTo(highest));
            Assert.AreEqual(1, highest.CompareTo(lowest));
            Assert.AreEqual(-1, highest.CompareTo(higherStill));
            Assert.AreEqual(0, highest.CompareTo(equalToHighest));
        }
예제 #3
0
        /// <summary>
        /// Adds an edge between the coordinates orig and dest
        /// to this graph.
        /// </summary>
        /// <param name="orig">the edge origin location</param>
        /// <param name="dest">the edge destination location</param>
        /// <returns>the created edge</returns>
        public virtual HalfEdge AddEdge(Coordinate orig, Coordinate dest)
        {
            int cmp = dest.CompareTo(orig);

            // ignore zero-length edges
            if (cmp == 0)
            {
                return(null);
            }

            // Attempt to find the edge already in the graph.
            // Return it if found.
            // Otherwise, use a found edge with same origin (if any) to construct new edge.
            HalfEdge eAdj;
            bool     eAdjFound = vertexMap.TryGetValue(orig, out eAdj);
            HalfEdge eSame     = null;

            if (eAdjFound)
            {
                eSame = eAdj.Find(dest);
            }
            if (eSame != null)
            {
                return(eSame);
            }

            HalfEdge e = Insert(orig, dest, eAdj);

            return(e);
        }
예제 #4
0
        /// <summary>
        /// Compares this object with the specified object for order.
        /// Uses the standard lexicographic ordering for the points in the LineSegment.
        /// </summary>
        /// <param name="o">
        /// The <c>LineSegment</c> with which this <c>LineSegment</c>
        /// is being compared.
        /// </param>
        /// <returns>
        /// A negative integer, zero, or a positive integer as this <c>LineSegment</c>
        /// is less than, equal to, or greater than the specified <c>LineSegment</c>.
        /// </returns>
        public int CompareTo(object o)
        {
            var other = (LineSegment)o;
            var comp0 = _p0.CompareTo(other._p0);

            return(comp0 != 0 ? comp0 : _p1.CompareTo(other._p1));
        }
예제 #5
0
        /// <summary>
        /// Updates the tracked ringStartEdge
        /// if the given edge has a lower origin
        /// (using the standard <see cref="Coordinate"/> ordering).
        /// </summary>
        /// <remarks>
        /// Identifying the lowest starting node meets two goals:
        /// * It ensures that isolated input rings are created using the original node and orientation.
        /// * For isolated rings formed from multiple input linestrings,
        /// it provides a canonical node and orientation for the output
        /// (rather than essentially random, and thus hard to test).
        /// </remarks>
        /// <param name="e"></param>
        private void UpdateRingStartEdge(DissolveHalfEdge e)
        {
            if (!e.IsStart)
            {
                e = (DissolveHalfEdge)e.Sym;
                if (!e.IsStart)
                {
                    return;
                }
            }
            // here e is known to be a start edge
            if (_ringStartEdge == null)
            {
                _ringStartEdge = e;
                return;
            }

            Coordinate eOrig     = e.Orig;
            Coordinate rseOrig   = _ringStartEdge.Orig;
            int        compareTo = eOrig.CompareTo(rseOrig);

            if (compareTo < 0)
            {
                _ringStartEdge = e;
            }
        }
예제 #6
0
    public void CompareTo_Returns_Correct_Comparison_For_All_Data(int x1, int y1, int x2, int y2, int result)
    {
        var coord1 = new Coordinate(x1, y1);
        var coord2 = new Coordinate(x2, y2);

        Assert.Equal(result, coord1.CompareTo(coord2));
    }
예제 #7
0
        public void CompareTo_Same_Assert()
        {
            Coordinate left = new Coordinate(10, 10);

            var result = left.CompareTo(left);

            Assert.AreEqual(0, result);
        }
예제 #8
0
        public void CompareTo_Null_Assert()
        {
            Coordinate left = new Coordinate(30, 30);

            var result = left.CompareTo(null);

            Assert.AreEqual(1, result);
        }
예제 #9
0
        public void CompareTo_LessThan_Assert()
        {
            Coordinate left  = new Coordinate(10, 10);
            Coordinate right = new Coordinate(20, 20);

            var result = left.CompareTo(right);

            Assert.AreEqual(-1, result);
        }
예제 #10
0
        public void CompareTo_GreaterThan_Assert()
        {
            Coordinate left  = new Coordinate(30, 30);
            Coordinate right = new Coordinate(20, 20);

            var result = left.CompareTo(right);

            Assert.AreEqual(1, result);
        }
예제 #11
0
        /// <summary>
        /// Compares this object with the specified object for order.
        /// Uses the standard lexicographic ordering for the points in the LineSegment.
        /// </summary>
        /// <param name="o">The LineSegment with which this LineSegment
        /// is being compared
        /// </param>
        /// <returns>A negative integer, zero, or a positive integer as this LineSegment
        /// is less than, equal to, or greater than the specified LineSegment
        /// </returns>
        public override int CompareTo(object o)
        {
            LineSegment other = (LineSegment)o;
            int         comp0 = p0.CompareTo(other.p0);

            if (comp0 != 0)
            {
                return(comp0);
            }

            return(p1.CompareTo(other.p1));
        }
예제 #12
0
 /// <summary>
 /// Determines whether two <see cref="Coordinate" /> arrays of equal length
 /// are equal in opposite directions.
 /// </summary>
 /// <param name="pts1"></param>
 /// <param name="pts2"></param>
 /// <returns></returns>
 private static bool IsEqualReversed(Coordinate[] pts1, Coordinate[] pts2)
 {
     for (int i = 0; i < pts1.Length; i++)
     {
         Coordinate p1 = pts1[i];
         Coordinate p2 = pts2[pts1.Length - i - 1];
         if (p1.CompareTo(p2) != 0)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #13
0
        /// <summary>
        /// Returns the minimum coordinate, using the usual lexicographic comparison.
        /// </summary>
        /// <param name="coordinates">Array to search.</param>
        /// <returns>The minimum coordinate in the array, found using <c>CompareTo</c>.</returns>
        public static Coordinate MinCoordinate(Coordinate[] coordinates)
        {
            Coordinate minCoord = null;

            for (int i = 0; i < coordinates.Length; i++)
            {
                if (minCoord == null || minCoord.CompareTo(coordinates[i]) > 0)
                {
                    minCoord = coordinates[i];
                }
            }
            return(minCoord);
        }
예제 #14
0
 public Segment(Coordinate p1, Coordinate p2)
 {
     if (p1.CompareTo(p2) > 0)
     {
         this.FromPt = p2;
         this.ToPt   = p1;
     }
     else
     {
         this.FromPt = p1;
         this.ToPt   = p2;
     }
 }
예제 #15
0
        public int CompareTo(MatchedAddress other)
        {
            int c = -Score.CompareTo(other.Score);

            if (c == 0)
            {
                c = Address.CompareTo(other.Address);

                if (c == 0)
                {
                    c = Location.CompareTo(other.Location);
                }
            }

            return(c);
        }
예제 #16
0
        public void test_CompareTo()
        {
            //create a coordinate (the z value is not used so there is no need to create it)
            Coordinate coord = new Coordinate(testX, testY);
            //create an equal coordinate
            Coordinate coord2 = new Coordinate(1.0, 2.0);
            //create a coordinate where X is greater & Y is equal
            Coordinate coord3 = new Coordinate(2.0, 2.0);
            //create a coordinate where Y is greater & x is equal
            Coordinate coord4 = new Coordinate(1.0, 3.0);
            //create a coordinate where both X & Y are greater
            Coordinate coord5 = new Coordinate(2.0, 3.0);
            //create a coordinate where X is less & Y is equal
            Coordinate coord6 = new Coordinate(0.0, 2.0);
            //create a coordinate where Y is less & X is equal
            Coordinate coord7 = new Coordinate(1.0, 1.0);
            //create a coordinate where both are less
            Coordinate coord8 = new Coordinate(0.0, 0.0);

            //create a point to send to throw the exception
            _gf = new GeometryFactory(_pm, _srid);
            Point point = _gf.CreatePoint(coord);

            Assertion.AssertEquals("CompareTo1: ", 0, coord.CompareTo(coord2));
            Assertion.AssertEquals("CompareTo2: ", -1, coord.CompareTo(coord3));
            Assertion.AssertEquals("CompareTo3: ", -1, coord.CompareTo(coord4));
            Assertion.AssertEquals("CompareTo4: ", -1, coord.CompareTo(coord5));
            Assertion.AssertEquals("CompareTo5: ", 1, coord.CompareTo(coord6));
            Assertion.AssertEquals("CompareTo6: ", 1, coord.CompareTo(coord7));
            Assertion.AssertEquals("CompareTo7: ", 1, coord.CompareTo(coord8));

            try
            {
                coord.CompareTo(point);
                Assertion.Fail("ArgumentException should have been thrown");
            }
            catch (ArgumentException)
            {
            }
        }
예제 #17
0
        public void CompareTo_InvalidType_Assert()
        {
            Coordinate left = new Coordinate(30, 30);

            var result = left.CompareTo(DateTime.Now);
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        protected internal override int CompareToSameClass(object other)
        {
            Point point = (Point)other;

            return(Coordinate.CompareTo(point.Coordinate));
        }
예제 #19
0
        /// <summary>
        /// Tests whether the query rectangle intersects a given line segment.
        /// </summary>
        /// <param name="p0">The first endpoint of the segment</param>
        /// <param name="p1">The second endpoint of the segment</param>
        /// <returns><c>true</c> if the rectangle intersects the segment</returns>
        public bool Intersects(Coordinate p0, Coordinate p1)
        {
            // TODO: confirm that checking envelopes first is faster

            /**
             * If the segment envelope is disjoint from the
             * rectangle envelope, there is no intersection
             */
            var segEnv = new Envelope(p0, p1);

            if (!_rectEnv.Intersects(segEnv))
            {
                return(false);
            }

            /**
             * If either segment endpoint lies in the rectangle,
             * there is an intersection.
             */
            if (_rectEnv.Intersects(p0))
            {
                return(true);
            }
            if (_rectEnv.Intersects(p1))
            {
                return(true);
            }

            /**
             * Normalize segment.
             * This makes p0 less than p1,
             * so that the segment runs to the right,
             * or vertically upwards.
             */
            if (p0.CompareTo(p1) > 0)
            {
                var tmp = p0;
                p0 = p1;
                p1 = tmp;
            }

            /**
             * Compute angle of segment.
             * Since the segment is normalized to run left to right,
             * it is sufficient to simply test the Y ordinate.
             * "Upwards" means relative to the left end of the segment.
             */
            bool isSegUpwards = p1.Y > p0.Y;

            /**
             * Since we now know that neither segment endpoint
             * lies in the rectangle, there are two possible
             * situations:
             * 1) the segment is disjoint to the rectangle
             * 2) the segment crosses the rectangle completely.
             *
             * In the case of a crossing, the segment must intersect
             * a diagonal of the rectangle.
             *
             * To distinguish these two cases, it is sufficient
             * to test intersection with
             * a single diagonal of the rectangle,
             * namely the one with slope "opposite" to the slope
             * of the segment.
             * (Note that if the segment is axis-parallel,
             * it must intersect both diagonals, so this is
             * still sufficient.)
             */
            if (isSegUpwards)
            {
                _li.ComputeIntersection(p0, p1, _diagDown0, _diagDown1);
            }
            else
            {
                _li.ComputeIntersection(p0, p1, _diagUp0, _diagUp1);
            }
            if (_li.HasIntersection)
            {
                return(true);
            }
            return(false);
        }
예제 #20
0
 public virtual bool within_y_axis(Coordinate y)
 {
     return(top_y_coordinate.CompareTo(y) >= 0);
 }
예제 #21
0
 public virtual bool within_x_axis(Coordinate x)
 {
     return(top_x_coordinate.CompareTo(x) >= 0);
 }
예제 #22
0
        /// <summary>
        /// Test if an the coordinates for an edge form a valid edge (with non-zero length)
        /// </summary>
        /// <param name="orig">The start coordinate</param>
        /// <param name="dest">The end coordinate</param>
        /// <returns><c>true</c> of the edge formed is valid</returns>
        public static bool IsValidEdge(Coordinate orig, Coordinate dest)
        {
            int cmp = dest.CompareTo(orig);

            return(cmp != 0);
        }
예제 #23
0
 public int CompareTo(Robot other) => Coordinate.CompareTo(other.Coordinate);
        /// <summary>
        /// Tests whether the query rectangle intersects a given line segment.
        /// </summary>
        /// <param name="p0">The first endpoint of the segment</param>
        /// <param name="p1">The second endpoint of the segment</param>
        /// <returns><c>true</c> if the rectangle intersects the segment</returns>
        public bool Intersects(Coordinate p0, Coordinate p1)
        {
            // TODO: confirm that checking envelopes first is faster

            /**
             * If the segment envelope is disjoint from the
             * rectangle envelope, there is no intersection
             */
            var segEnv = new Envelope(p0, p1);
            if (!_rectEnv.Intersects(segEnv))
                return false;

            /**
             * If either segment endpoint lies in the rectangle,
             * there is an intersection.
             */
            if (_rectEnv.Intersects(p0)) return true;
            if (_rectEnv.Intersects(p1)) return true;

            /**
             * Normalize segment.
             * This makes p0 less than p1,
             * so that the segment runs to the right,
             * or vertically upwards.
             */
            if (p0.CompareTo(p1) > 0)
            {
                var tmp = p0;
                p0 = p1;
                p1 = tmp;
            }
            /**
             * Compute angle of segment.
             * Since the segment is normalized to run left to right,
             * it is sufficient to simply test the Y ordinate.
             * "Upwards" means relative to the left end of the segment.
             */
            var isSegUpwards = p1.Y > p0.Y;

            /**
             * Since we now know that neither segment endpoint
             * lies in the rectangle, there are two possible 
             * situations:
             * 1) the segment is disjoint to the rectangle
             * 2) the segment crosses the rectangle completely.
             * 
             * In the case of a crossing, the segment must intersect 
             * a diagonal of the rectangle.
             * 
             * To distinguish these two cases, it is sufficient 
             * to test intersection with 
             * a single diagonal of the rectangle,
             * namely the one with slope "opposite" to the slope
             * of the segment.
             * (Note that if the segment is axis-parallel,
             * it must intersect both diagonals, so this is
             * still sufficient.)  
             */
            if (isSegUpwards)
            {
                _li.ComputeIntersection(p0, p1, _diagDown0, _diagDown1);
            }
            else
            {
                _li.ComputeIntersection(p0, p1, _diagUp0, _diagUp1);
            }
            if (_li.HasIntersection)
                return true;
            return false;


        }