Example #1
0
 public void Point()
 {
     //Do various Point method calls to cover the point class with sufficient testing
     Point p0 = new Point();
     Point p1 = new Point(0, 0);
     Point p2 = new Point(450, 120);
     Assert.IsTrue(p0.IsEmpty());
     Assert.IsFalse(p1.IsEmpty());
     Assert.AreNotEqual(p0, p1);
     Assert.AreEqual(450, p2.X);
     Assert.AreEqual(120, p2.Y);
     Assert.AreNotSame(p2.Clone(), p2);
     p0 = p2.Clone();
     p0.X += 100;
     p0.Y = 150;
     p0[0] += p0[1];
     Assert.AreEqual(new Point(700, 150), p0);
     Assert.AreEqual(p2, p2.GetBoundingBox().Min);
     Assert.AreEqual(p2, p2.GetBoundingBox().Max);
     Assert.IsTrue(p2.IsSimple());
     Assert.IsFalse(p2.IsEmpty());
     Assert.AreEqual(2, p2.NumOrdinates);
     Assert.AreEqual(new Point(400, 100), p2 + new Point(-50, -20));
     Assert.AreEqual(new Point(500, 100), p2 - new Point(-50, 20));
     Assert.AreEqual(new Point(900, 240), p2*2);
     Assert.AreEqual(0, p2.Dimension);
     Assert.AreEqual(450, p2[0]);
     Assert.AreEqual(120, p2[1]);
     Assert.IsNull(p2.Boundary());
     Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.IsEmpty().GetHashCode(), p2.GetHashCode());
     Assert.Greater(p2.CompareTo(p1), 0);
     Assert.Less(p1.CompareTo(p2), 0);
     Assert.AreEqual(p2.CompareTo(new Point(450, 120)), 0);
 }
Example #2
0
 public static void Main3()
 {
     // Create two Point instances on the stack. 
     Point p1 = new Point(10, 10);
     Point p2 = new Point(20, 20);
     // p1 does NOT get boxed to call ToString (a virtual method). 
     Console.WriteLine(p1.ToString());// "(10, 10)" 
     // p DOES get boxed to call GetType (a non-virtual method). 
     Console.WriteLine(p1.GetType());// "Point" 
     // p1 does NOT get boxed to call CompareTo. 
     // p2 does NOT get boxed because CompareTo(Point) is called. 
     Console.WriteLine(p1.CompareTo(p2));// "-1" 
     // p1 DOES get boxed, and the reference is placed in c. 
     IComparable c = p1;
     Console.WriteLine(c.GetType());// "Point" 
     // p1 does NOT get boxed to call CompareTo. 
     // Since CompareTo is not being passed a Point variable, 
     // CompareTo(Object) is called which requires a reference to 
     // a boxed Point. 
     // c does NOT get boxed because it already refers to a boxed Point. 
     Console.WriteLine(p1.CompareTo(c));// "0" 
     // c does NOT get boxed because it already refers to a boxed Point. 
     // p2 does get boxed because CompareTo(Object) is called. 
     Console.WriteLine(c.CompareTo(p2));// "-1" 
     // c is unboxed, and fields are copied into p2. 
     p2 = (Point)c;
     // Proves that the fields got copied into p2. 
     Console.WriteLine(p2.ToString());// "(10, 10)" 
 }
        public int Compare(BasicObstacleSide first, BasicObstacleSide second)
        {
            ValidateArg.IsNotNull(first, "first");
            ValidateArg.IsNotNull(second, "second");

            // If these are two sides of the same obstacle then the ordering is obvious.
            if (first.Obstacle == second.Obstacle)
            {
                if (first == second)
                {
                    return(0);
                }

                return((first is LowObstacleSide) ? -1 : 1);
            }

            Debug_VerifySidesDoNotIntersect(first, second);

            // Other than intersecting sides at vertices of the same obstacle, there should be no interior intersections...
            Point firstIntersect  = VisibilityGraphGenerator.ScanLineIntersectSide(this.linePositionAtLastInsertOrRemove, first, scanDirection);
            Point secondIntersect = VisibilityGraphGenerator.ScanLineIntersectSide(this.linePositionAtLastInsertOrRemove, second, scanDirection);
            var   cmp             = firstIntersect.CompareTo(secondIntersect);

            // ... but we may still have rectangular sides that coincide, or angled sides that are close enough here but
            // are not detected by the convex-hull overlap calculations.  In those cases, we refine the comparison by side
            // type, with High coming before Low, and then by obstacle ordinal if needed. Because there are no interior
            // intersections, this ordering will remain valid as long as the side(s) are in the scanline.
            if (0 == cmp)
            {
                bool firstIsLow  = first is LowObstacleSide;
                bool secondIsLow = second is LowObstacleSide;
                cmp = firstIsLow.CompareTo(secondIsLow);
                if (0 == cmp)
                {
                    cmp = first.Obstacle.Ordinal.CompareTo(second.Obstacle.Ordinal);
                }
            }

            DevTraceInfo(4, "Compare {0} @ {1:F5} {2:F5} and {3:F5} {4:F5}: {5} {6}",
                         cmp, firstIntersect.X, firstIntersect.Y, secondIntersect.X, secondIntersect.Y, first, second);
            return(cmp);
        }
        public void CompareToOrdersByDistanceFromOriginAscending(short invokedX, short invokedY, short otherX, short otherY, int expectedSignedInt)
        {
            var invoked = new Point(invokedX, invokedY);
            var other   = new Point(otherX, otherY);

            var result = invoked.CompareTo(other);

            if (expectedSignedInt == 0)
            {
                // The 'invoked' point and the 'other' point are in the same position when ordering.
                Assert.True(result == 0);
            }
            else if (expectedSignedInt > 0)
            {
                // The 'invoked' point follows the 'other' point.
                Assert.True(result > 0);
            }
            else if (expectedSignedInt < 0)
            {
                // The 'invoked' point precedes the 'other' point.
                Assert.True(result < 0);
            }
        }
 /* Compare any two R1Point objects, the returned values is -1, 0, 1, or -99
  * if the returned value is -99 it means the two points are of different dimension.*/
 public int CompareTo(R1Point other)
 {
     return(_point.CompareTo(other.Position));
 }
Example #6
0
 public int CompareTo(FixedPointVector2 other)
 {
     return(Point.CompareTo(other.Point));
 }
Example #7
0
 public static bool LeftCloserThanRight(Point p1, Point p2)
 {
     return p1.CompareTo(p2) > 0;
 }
Example #8
0
        public void point_is_bigger_than_null()
        {
            var point1 = new Point(20);

            point1.CompareTo(null).Should().Be(1);
        }
Example #9
0
        public void point_is_equal_to_itself()
        {
            var point1 = new Point(20);

            point1.CompareTo(point1).Should().Be(0);
        }
Example #10
0
        /// <summary>
        /// Updates range for markers that intersect with the given text range.
        /// For example, in cases when text is inserted within the active selection - it should be expanded.
        /// </summary>
        /// <param name="oldStart">Original start of the text range</param>
        /// <param name="oldEnd">Original end of the text range</param>
        /// <param name="newEnd">New end of the text range</param>
        private void SpliceMarkers(Point oldStart, Point oldEnd, Point newEnd)
        {
            var isInsertion = oldStart.CompareTo(oldEnd) == 0;

            foreach (var layersForSite in Markers)
            {
                var layersById = layersForSite.Value;

                foreach (var markersForLayer in layersById)
                {
                    var markersById = markersForLayer.Value;

                    foreach (var markerWithId in markersById)
                    {
                        var existingMarker = markerWithId.Value;
                        var range          = existingMarker.Range;
                        var exclusive      = existingMarker.Exclusive;

                        var rangeIsEmpty = range.Start.CompareTo(range.End) == 0;

                        var moveMarkerStart =
                            oldStart.CompareTo(range.Start) < 0 ||
                            (exclusive &&
                             (!rangeIsEmpty || isInsertion) &&
                             oldStart.CompareTo(range.Start) == 0);

                        var moveMarkerEnd =
                            moveMarkerStart ||
                            oldStart.CompareTo(range.End) < 0 ||
                            (!exclusive && oldEnd.CompareTo(range.End) == 0);

                        Point?newMarkerStart = null, newMarkerEnd = null;

                        if (moveMarkerStart)
                        {
                            if (oldEnd.CompareTo(range.Start) <= 0)
                            {
                                // splice precedes marker start
                                newMarkerStart = newEnd.Traverse(Point.Traversal(range.Start, oldEnd));
                            }
                            else
                            {
                                // splice surrounds marker start
                                newMarkerStart = newEnd;
                            }
                        }

                        if (moveMarkerEnd)
                        {
                            if (oldEnd.CompareTo(range.End) <= 0)
                            {
                                // splice precedes marker end
                                newMarkerEnd = newEnd.Traverse(Point.Traversal(range.End, oldEnd));
                            }
                            else
                            {
                                // splice surrounds marker end
                                newMarkerEnd = newEnd;
                            }
                        }

                        markersById[markerWithId.Key] =
                            new Marker <Range>(
                                existingMarker.Exclusive,
                                existingMarker.Reversed,
                                existingMarker.Tailed,
                                new Range(
                                    newMarkerStart.HasValue ? newMarkerStart.Value : existingMarker.Range.Start,
                                    newMarkerEnd.HasValue ? newMarkerEnd.Value : existingMarker.Range.End));
                    }
                }
            }
        }
Example #11
0
        public void CompareToTest()
        {
            Point testPoint = new Point(5, 2);

            Assert.IsTrue(instance.CompareTo(testPoint) < 0);
        }
Example #12
0
 public void TestCompareEmptyPoint()
 {
     Point p1 = (Point)reader.Read("POINT (30 30)");
     Point p2 = (Point)reader.Read("POINT EMPTY");
     Assert.IsTrue(p1.CompareTo(p2) > 0);
 }
Example #13
0
 public void TestComparePoint()
 {
     Point p1 = (Point)reader.Read("POINT (30 30)");
     Point p2 = (Point)reader.Read("POINT (30 40)");
     Assert.IsTrue(p1.CompareTo(p2) < 0);
 }
Example #14
0
        public override void Run(List <CGUtilities.Point> points, List <CGUtilities.Line> lines, List <CGUtilities.Polygon> polygons, ref List <CGUtilities.Point> outPoints, ref List <CGUtilities.Line> outLines, ref List <CGUtilities.Polygon> outPolygons)
        {
            OrderedSet <Event> sweep_line = new OrderedSet <Event>(new Comparison <Event>(sweep_line_compare));
            OrderedSet <Event> events     = new OrderedSet <Event>();

            // get the events
            for (int i = 0; i < lines.Count; i++)
            {
                Point start = lines[i].Start;
                Point end   = lines[i].End;
                if (start.CompareTo(end) == 1)
                {
                    // swap ends of the line
                    lines[i].Start = end;
                    lines[i].End   = start;
                }
                // what if we have a degenerate line
                Event beginp = new Event(lines[i].Start, lines[i].End, 0, i, -1); // begin
                Event endp   = new Event(lines[i].End, lines[i].Start, 1, i, -1); //  end
                events.Add(beginp);
                events.Add(endp);
            }

            // sweep left to right
            OrderedSet <Point> inter_points = new OrderedSet <Point>();

            while (events.Count != 0)
            {
                Event tevent = events.GetFirst();
                events.RemoveFirst();

                int    line_index1 = tevent.line_index1;
                int    line_index2 = tevent.line_index2;
                double current_x   = lines[line_index1].Start.X;
                if (tevent.event_type == 0) // start
                {
                    sweep_line.Add(tevent);
                    KeyValuePair <Event, Event> UL = sweep_line.DirectUpperAndLower(tevent);
                    // intersection between the smaller , bigger
                    if (UL.Key != null)
                    {
                        get_inter(tevent, UL.Key, ref inter_points, ref events, current_x);
                    }
                    if (UL.Value != null)
                    {
                        get_inter(UL.Value, tevent, ref inter_points, ref events, current_x);
                    }
                }
                else if (tevent.event_type == 1) // end
                {
                    // edit  the event so we can match
                    // potional bug
                    Point tpoint = tevent.start;
                    tevent.start      = tevent.end;
                    tevent.end        = tpoint;
                    tevent.event_type = 0;

                    KeyValuePair <Event, Event> UL = sweep_line.DirectUpperAndLower(tevent);
                    sweep_line.Remove(tevent); // potional bug
                    // smaller - bigger
                    if (UL.Key != null && UL.Value != null)
                    {
                        get_inter(UL.Value, UL.Key, ref inter_points, ref events, current_x);
                    }
                }
                else // intersection
                {
                    // don't change the original line
                    // smaller, bigger
                    Line line1 = lines[line_index1].Clone() as Line;
                    Line line2 = lines[line_index2].Clone() as Line;
                    // get events
                    Event event1 = new Event(line1.Start, line1.End, 0, line_index1, -1);
                    Event event2 = new Event(line2.Start, line2.End, 0, line_index2, -1);
                    // remove them from the sweep line tree
                    sweep_line.Remove(event1);
                    sweep_line.Remove(event2);
                    // put the intersecction point as the start point = swap them in order
                    event1.start = tevent.start;
                    event2.start = tevent.start;
                    // insert them back again
                    sweep_line.Add(event1);
                    sweep_line.Add(event2);

                    // ****** potional bug  ******
                    // get the upper and lower for line 1 , line 2 respectivally
                    KeyValuePair <Event, Event> ULE1 = sweep_line.DirectUpperAndLower(event1);
                    KeyValuePair <Event, Event> ULE2 = sweep_line.DirectUpperAndLower(event2);
                    // check event 1 with it's upper
                    if (ULE1.Key != null)
                    {
                        get_inter(event1, ULE1.Key, ref inter_points, ref events, current_x);
                        //get_inter(event2, ULE1.Key, ref inter_points, ref events, current_x);
                    }
                    // check event2 with it's lower
                    if (ULE2.Value != null)
                    {
                        get_inter(event2, ULE2.Value, ref inter_points, ref events, current_x);
                        //get_inter(ULE2.Value, event1,ref inter_points, ref events, current_x);
                    }
                }
            }
            // get points
            while (inter_points.Count != 0)
            {
                outPoints.Add(inter_points.GetFirst());
                inter_points.RemoveFirst();
            }
        }