当前位置: 首页>>代码示例>>C#>>正文


C# Point.CompareTo方法代码示例

本文整理汇总了C#中System.Point.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Point.CompareTo方法的具体用法?C# Point.CompareTo怎么用?C# Point.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Point的用法示例。


在下文中一共展示了Point.CompareTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

		public static void Run() {
			var p1 = new Point(10, 10);
			var 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 ComapreTo
			// 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 is already refers ti 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)
		}
开发者ID:Helen1987,项目名称:edu,代码行数:35,代码来源:StructBoxingBehavior.cs

示例2: Point

		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);
		}
开发者ID:lishxi,项目名称:_SharpMap,代码行数:33,代码来源:PointTests.cs

示例3: InsideObstacleHitTest

        HitTestBehavior InsideObstacleHitTest(Point location, Obstacle obstacle) {
            if ((obstacle == insideHitTestIgnoreObstacle1) || (obstacle == insideHitTestIgnoreObstacle2)) {
                // It's one of the two obstacles we already know about.
                return HitTestBehavior.Continue;
            }

            if (obstacle.IsGroup) {
                // Groups are handled differently from overlaps; we create ScanSegments (overlapped
                // if within a non-group obstacle, else non-overlapped), and turn on/off access across
                // the Group boundary vertices.
                return HitTestBehavior.Continue;
            }

            if (!StaticGraphUtility.PointIsInRectangleInterior(location, obstacle.VisibilityBoundingBox)) {
                // The point is on the obstacle boundary, not inside it.
                return HitTestBehavior.Continue;
            }

            // Note: There are rounding issues using Curve.PointRelativeToCurveLocation at angled
            // obstacle boundaries, hence this function.
            Point high = StaticGraphUtility.RectangleBorderIntersect(obstacle.VisibilityBoundingBox, location
                                , insideHitTestScanDirection.Direction)
                        + insideHitTestScanDirection.DirectionAsPoint;
            Point low = StaticGraphUtility.RectangleBorderIntersect(obstacle.VisibilityBoundingBox, location
                                , insideHitTestScanDirection.OppositeDirection)
                        - insideHitTestScanDirection.DirectionAsPoint;
            var testSeg = new LineSegment(low, high);
            IList<IntersectionInfo> xxs = Curve.GetAllIntersections(testSeg, obstacle.VisibilityPolyline, true /*liftIntersections*/);

            // If this is an extreme point it can have one intersection, in which case we're either on the border
            // or outside; if it's a collinear flat boundary, there can be 3 intersections to this point which again
            // means we're on the border (and 3 shouldn't happen anymore with the curve intersection fixes and 
            // PointIsInsideRectangle check above).  So the interesting case is that we have 2 intersections.
            if (2 == xxs.Count) {
                Point firstInt = SpliceUtility.RawIntersection(xxs[0], location);
                Point secondInt = SpliceUtility.RawIntersection(xxs[1], location);

                // If we're on either intersection, we're on the border rather than inside.
                if (!PointComparer.Equal(location, firstInt) && !PointComparer.Equal(location, secondInt)
                            && (location.CompareTo(firstInt) != location.CompareTo(secondInt))) {
                    // We're inside.  However, this may be an almost-flat side, in which case rounding
                    // could have reported the intersection with the start or end of the same side and
                    // a point somewhere on the interior of that side.  Therefore if both intersections
                    // are on the same side (integral portion of the parameter), we consider location 
                    // to be on the border.  testSeg is always xxs[*].Segment0.
                    Debug.Assert(testSeg == xxs[0].Segment0, "incorrect parameter ordering to GetAllIntersections");
                    if (!ApproximateComparer.Close(Math.Floor(xxs[0].Par1), Math.Floor(xxs[1].Par1))) {
                        return HitTestBehavior.Stop;
                    }
                }
            }
            return HitTestBehavior.Continue;
        }
开发者ID:danielskowronski,项目名称:network-max-flow-demo,代码行数:53,代码来源:ObstacleTree.cs


注:本文中的System.Point.CompareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。