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


C# Point.Equals方法代码示例

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


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

示例1: Project

            /// <summary> 
            /// Compute the projection of a point onto the line determined
            /// by this line segment.
            /// Note that the projected point  may lie outside the line segment.  
            /// If this is the case,  the projection factor will lie outside the range [0.0, 1.0].
            /// </summary>
            /// <param name="p"></param>
            /// <returns></returns>
            public static Point Project(Point p, Point LineSegFrom, Point LineSegTo)
            {
                if (p.Equals(LineSegFrom) || p.Equals(LineSegTo))
                    return new Point(p.X, p.Y);

                var r = ProjectionFactor(p, LineSegFrom,  LineSegTo);
                Point coord = new Point (LineSegFrom.X + r * (LineSegTo.X - LineSegFrom.X), LineSegFrom.Y + r * (LineSegTo.Y - LineSegFrom.Y) );
                return coord;
            }
开发者ID:sridhar19091986,项目名称:sharpmapx,代码行数:17,代码来源:CGAlgoritm.cs

示例2: EqualsThrowsInvalidCastExceptionBugFix

 public void EqualsThrowsInvalidCastExceptionBugFix()
 {
     Point point = new Point(1.0, 1.0);
     Coordinate coordinate = new Coordinate(-1.0, -1.0);
     bool condition = point.Equals(coordinate);
     Assert.IsFalse(condition);
 }
开发者ID:Walt-D-Cat,项目名称:NetTopologySuite,代码行数:7,代码来源:Issue75Tests.cs

示例3: LineSegment

 public LineSegment(Point start, Point end)
 {
     if (start.Equals(end))
     {
         throw new ArgumentException("lenght can not be zero");
     }
     this.start = start;
     this.end = end;
 }
开发者ID:ivanov961,项目名称:HackBulgaria,代码行数:9,代码来源:LineSegment.cs

示例4: Main

    static void Main()
    {
        Point p1 = new Point(5, 7);
        p1.Print();

        Printer pr = p1; // box;
        pr.Print();

        Point p2 = new Point(5, 7);
        Console.WriteLine(p1.Equals(p2));
    }
开发者ID:rcorveira,项目名称:ave-2013-14-sem1,代码行数:11,代码来源:PointApp2.cs

示例5: Equals

        public void Equals()
        {
            var p1 = new Point(1, 2);
            var p2 = new Point(3, 4);

            Assert.AreNotEqual(p1, p2);
            Assert.AreEqual(p1, new Point(1, 2));

            Assert.IsTrue(p1 == new Point(1, 2));
            Assert.IsTrue(p1 != p2);
            Assert.IsTrue(p1.Equals((object)new Point(1, 2)));
        }
开发者ID:lilinghui,项目名称:DeltaEngine,代码行数:12,代码来源:PointTests.cs

示例6: Main

        public static void Main()
        {
            const int TimesToCompare = 10000000;
            var stopwatch = Stopwatch.StartNew();
            var point1 = new Point { X = 1, Y = 2 };
            var point2 = new Point { X = 1, Y = 2 };
            for (var i = 0; i < TimesToCompare; i++)
            {
                point1.Equals(point2);
            }

            Console.WriteLine("Point with value members: {0}", stopwatch.Elapsed);

            stopwatch = Stopwatch.StartNew();
            var pointWithName1 = new PointWithName { X = 1, Y = 2, Name = "Point with name 1" };
            var pointWithName2 = new PointWithName { X = 1, Y = 2, Name = "Point with name 2" };
            for (var i = 0; i < TimesToCompare; i++)
            {
                pointWithName1.Equals(pointWithName2);
            }

            Console.WriteLine("Point with reference member: {0}", stopwatch.Elapsed);

            stopwatch = Stopwatch.StartNew();
            var pointWithNameAndEquals1 = new PointWithNameAndEquals
            {
                X = 1,
                Y = 2,
                Name = "Point with name and Equals() 1"
            };
            var pointWithNameAndEquals2 = new PointWithNameAndEquals
            {
                X = 1,
                Y = 2,
                Name = "Point with name and Equals() 2"
            };
            for (var i = 0; i < TimesToCompare; i++)
            {
                pointWithNameAndEquals1.Equals(pointWithNameAndEquals2);
            }

            Console.WriteLine("Point with reference member and equals: {0}", stopwatch.Elapsed);
        }
开发者ID:NikolayIT,项目名称:CSharp-Tips-and-Tricks,代码行数:43,代码来源:Program.cs

示例7: notSeen

 private static bool notSeen(Point start, List<Path> seenPaths, Point dest)
 {
     if (start.Equals(dest)) {
         return false;
     }
     foreach (Path p in seenPaths) {
         Point pd = p.destination();
         if (pd.Equals(dest)) {
             return false;
         }
     }
     return true;
 }
开发者ID:indspenceable,项目名称:tbs-roguelike,代码行数:13,代码来源:Path.cs

示例8: Point_Equals_compares_two_Points_successfully

 public void Point_Equals_compares_two_Points_successfully()
 {
     var m1 = new Point(1.0f, 1.2f, 1.9f);
     var m2 = new Point(1.0f, 1.2f, 1.9f);
     bool eqeq = m1.Equals(m2);
     Assert.IsTrue(eqeq);
 }
开发者ID:EddPorter,项目名称:RayManCS,代码行数:7,代码来源:PointTests.cs

示例9: Point_Equals_differentiates_two_Points_successfully_on_x

 public void Point_Equals_differentiates_two_Points_successfully_on_x()
 {
     var m1 = new Point(1.0f, 1.2f, 1.9f);
     var m2 = new Point(-1.0f, 1.2f, 1.9f);
     bool eqeq = m1.Equals(m2);
     Assert.IsFalse(eqeq);
 }
开发者ID:EddPorter,项目名称:RayManCS,代码行数:7,代码来源:PointTests.cs

示例10: ProjectionFactor

            /// <summary>
            /// Compute the projection factor for the projection of the point p
            /// onto this <c>LineSegment</c>. The projection factor is the constant k
            /// by which the vector for this segment must be multiplied to
            /// equal the vector for the projection of p.
            /// </summary>
            /// <param name="p"></param>
            /// <returns></returns>
            public static double ProjectionFactor(Point p, Point LineSegFrom, Point LineSegTo)
            {
                if (p.Equals(LineSegFrom)) return 0.0;
                if (p.Equals(LineSegTo)) return 1.0;

                // Otherwise, use comp.graphics.algorithms Frequently Asked Questions method
                /*                    AC dot AB
                            r = ------------
                                  ||AB||^2
                            r has the following meaning:
                            r=0 Point = A
                            r=1 Point = B
                            r<0 Point is on the backward extension of AB
                            r>1 Point is on the forward extension of AB
                            0<r<1 Point is interior to AB
                */
                var dx = LineSegTo.X - LineSegFrom.X;
                var dy = LineSegTo.Y - LineSegFrom.Y;
                var len2 = dx * dx + dy * dy;
                var r = ((p.X - LineSegFrom.X) * dx + (p.Y - LineSegFrom.Y) * dy) / len2;
                return r;
            }
开发者ID:sridhar19091986,项目名称:sharpmapx,代码行数:30,代码来源:CGAlgoritm.cs

示例11: Point_Equals_returns_true_given_same_object_twice

 public void Point_Equals_returns_true_given_same_object_twice()
 {
     var m1 = new Point(1.0f, 1.2f, 1.9f);
     var m2 = m1;
     bool eqeq = m1.Equals(m2);
     Assert.IsTrue(eqeq);
 }
开发者ID:EddPorter,项目名称:RayManCS,代码行数:7,代码来源:PointTests.cs

示例12: EqualityTest

        public void EqualityTest(int x, int y)
        {
            Point p1 = new Point(x, y);
            Point p2 = new Point(x / 2 - 1, y / 2 - 1);
            Point p3 = new Point(x, y);

            Assert.True(p1 == p3);
            Assert.True(p1 != p2);
            Assert.True(p2 != p3);

            Assert.True(p1.Equals(p3));
            Assert.False(p1.Equals(p2));
            Assert.False(p2.Equals(p3));

            Assert.Equal(p1.GetHashCode(), p3.GetHashCode());
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:16,代码来源:PointTests.cs

示例13: IntersectionAll

        public void IntersectionAll()
        {
            IList results = session.CreateCriteria(typeof(County))
                .SetProjection(SpatialProjections.Intersection("Boundaries"))
                .List();

            Assert.AreEqual(1, results.Count);

            IGeometry aggregated = (IGeometry)results[0];
            IGeometry expected = new Point(2, 1);

            Assert.IsTrue(expected.Equals(aggregated));
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:13,代码来源:ProjectionsFixture.cs

示例14: EqualityTest_NotPoint

 public static void EqualityTest_NotPoint()
 {
     var point = new Point(0, 0);
     Assert.False(point.Equals(null));
     Assert.False(point.Equals(0));
     Assert.False(point.Equals(new PointF(0, 0)));
 }
开发者ID:Corillian,项目名称:corefx,代码行数:7,代码来源:PointTests.cs

示例15: CalculateShortestWayToTarget

        /// <summary>
        /// The recursive pathfinding-method.
        /// </summary>
        /// <param name="targetPoint">The target point.</param>
        /// <param name="currentPoint">The current point in the grid.</param>
        /// <param name="playerPosition">The position of the player in the grid.</param>
        /// <param name="way"></param>
        /// <param name="shortestWayLength">The length of the best found path to the target.</param>
        /// <param name="failedTriesToBeatPath"></param>
        /// <param name="maximumTries">The maximum amount of tries the algorithm has to beat the best found path.</param>
        /// <returns></returns>
        public List<Point> CalculateShortestWayToTarget(Point targetPoint, Point currentPoint, Point playerPosition, List<Point> way, ref int shortestWayLength, ref int failedTriesToBeatPath, int maximumTries, ref int recursionStep)
        {
            recursionStep++;

            //do not add the current point if it equals the player's position
            if (!playerPosition.Equals(currentPoint))
            {
                way.Add(currentPoint);
            }

            //returns an empty list if the current way is already longer than the best found way.
            //True if no tries are left.
            //True if the recursion step is too high --> emergency exit
            if (recursionStep > 150 || failedTriesToBeatPath >= maximumTries || (shortestWayLength > -1 && way.Count > shortestWayLength))
            {
                failedTriesToBeatPath++;
                return new List<Point>();
            }

            //true if the current point equals the target point or if the target point is unreachable.
            if (currentPoint.Equals(targetPoint) || (!IsValidPosition(targetPoint) && ArePointsNeighbors(currentPoint, targetPoint)) || GetValidNeighborPoints(targetPoint).Count == 0)
            {
                //returns the way and sets the shortest way length if this way is shorter than the currently best way
                if (shortestWayLength == -1 || way.Count < shortestWayLength)
                {
                    shortestWayLength = way.Count;
                    List<Point> pointList = new List<Point>();
                    pointList.Add(currentPoint);
                    return pointList;
                }
                else
                {
                    failedTriesToBeatPath++;
                    return new List<Point>();
                }
            }
            else
            {
                //get current point's neighbors
                List<Point> neighbors = GetValidNeighborPoints(currentPoint);
                Point nearestPoint = new Point();
                List<Point> bestWaypoints = new List<Point>();
                List<Point> newWaypoints = new List<Point>();

                //test all directions
                while(neighbors.Count > 0)
                {
                    nearestPoint = GetNearestPointToTarget(neighbors, targetPoint);
                    if (!way.Contains(nearestPoint))
                    {
                        newWaypoints = CalculateShortestWayToTarget(targetPoint, nearestPoint, playerPosition, new List<Point>(way), ref shortestWayLength, ref failedTriesToBeatPath, maximumTries, ref recursionStep);

                        /*  Adds the found waypoints to the way if the recursive method returns waypoints.
                         *  Remember: It returns waypoints if it finds the target.
                         *  Additionally the new way must be shorter than the current saved test way. */
                        if (newWaypoints.Count > 0 && (bestWaypoints.Count == 0 || newWaypoints.Count < bestWaypoints.Count))
                        {
                            bestWaypoints = new List<Point>(newWaypoints);
                        }
                    }
                    neighbors.Remove(nearestPoint);
                }

                /* Returns the bestWay-list if it's longer than 0. Remember: It's longer if a deeper recursive-method found the target.
                 * Otherwise an empty list. */
                if (bestWaypoints.Count > 0)
                {
                    if (!currentPoint.Equals(playerPosition))
                    {
                        bestWaypoints.Insert(0, currentPoint);
                    }
                    return bestWaypoints;
                }
                else
                {
                    return new List<Point>();
                }
            }
        }
开发者ID:Jecral,项目名称:Football,代码行数:90,代码来源:Pathfinding.cs


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