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


C# Point.Equals方法代码示例

本文整理汇总了C#中System.Point.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Point.Equals方法的具体用法?C# Point.Equals怎么用?C# Point.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.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>
            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);
                var coord = new Point { X = lineSegFrom.X + r * (lineSegTo.X - lineSegFrom.X), Y = lineSegFrom.Y + r * (lineSegTo.Y - lineSegFrom.Y) };
                return coord;
            }
开发者ID:HackatonArGP,项目名称:Guardianes,代码行数:15,代码来源:CGAlgoritm.cs

示例2: Main

        public static void Main(string[] args)
        {
            var x = new Point(1, 2);
            var y = x;

            Console.WriteLine(y); // x のメンバー毎コピー = (1, 2)

            // メンバー毎比較(全メンバー一致なら一致)
            Console.WriteLine(x.Equals(new Point(1, 2))); // true
            Console.WriteLine(x.Equals(new Point(1, 3))); // false
        }
开发者ID:ufcpp,项目名称:UfcppSample,代码行数:11,代码来源:Memberwise.cs

示例3: DistanceLineLine

        /// <summary>
        ///     Computes the distance from a line segment AB to a line segment CD.
        ///     Note: NON-ROBUST!
        /// </summary>
        /// <param name="a">A point of one line.</param>
        /// <param name="b">The second point of the line (must be different to A).</param>
        /// <param name="c">One point of the line.</param>
        /// <param name="d">Another point of the line (must be different to A).</param>
        /// <returns>The distance from line segment AB to line segment CD.</returns>
        public static double DistanceLineLine(Point a, Point b, Point c, Point d)
        {
            // check for zero-length segments
            if (a.Equals(b))
                return DistancePointLine(a, c, d);
            if (c.Equals(d))
                return DistancePointLine(d, a, b);

            // AB and CD are line segments
            /* from comp.graphics.algo

                Solving the above for r and s yields
                            (Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy)
                        r = ----------------------------- (eqn 1)
                            (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)

                            (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
                        s = ----------------------------- (eqn 2)
                            (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
                Let Point be the position vector of the intersection point, then
                    Point=A+r(B-A) or
                    Px=Ax+r(Bx-Ax)
                    Py=Ay+r(By-Ay)
                By examining the values of r & s, you can also determine some other
                limiting conditions:
                    If 0<=r<=1 & 0<=s<=1, intersection exists
                    r<0 or r>1 or s<0 or s>1 line segments do not intersect
                    If the denominator in eqn 1 is zero, AB & CD are parallel
                    If the numerator in eqn 1 is also zero, AB & CD are collinear.

            */
            var rTop = (a.Y - c.Y)*(d.X - c.X) - (a.X - c.X)*(d.Y - c.Y);
            var rBottom = (b.X - a.X)*(d.Y - c.Y) - (b.Y - a.Y)*(d.X - c.X);

            var sTop = (a.Y - c.Y)*(b.X - a.X) - (a.X - c.X)*(b.Y - a.Y);
            var sBottom = (b.X - a.X)*(d.Y - c.Y) - (b.Y - a.Y)*(d.X - c.X);

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if ((rBottom == 0) || (sBottom == 0))

                return Math.Min(DistancePointLine(a, c, d),
                    Math.Min(DistancePointLine(b, c, d),
                        Math.Min(DistancePointLine(c, a, b),
                            DistancePointLine(d, a, b))));
            // ReSharper restore CompareOfFloatsByEqualityOperator

            var s = sTop/sBottom;
            var r = rTop/rBottom;

            if ((r < 0) || (r > 1) || (s < 0) || (s > 1))
                //no intersection
                return Math.Min(DistancePointLine(a, c, d),
                    Math.Min(DistancePointLine(b, c, d),
                        Math.Min(DistancePointLine(c, a, b),
                            DistancePointLine(d, a, b))));

            return 0.0; //intersection exists
        }
开发者ID:pauldendulk,项目名称:Mapsui,代码行数:67,代码来源:CGAlgoritm.cs

示例4: DistanceLineLine

        /// <summary> 
        /// Computes the distance from a line segment AB to a line segment CD.
        /// Note: NON-ROBUST!
        /// </summary>
        /// <param name="A">A point of one line.</param>
        /// <param name="B">The second point of the line (must be different to A).</param>
        /// <param name="C">One point of the line.</param>
        /// <param name="D">Another point of the line (must be different to A).</param>
        /// <returns>The distance from line segment AB to line segment CD.</returns>
        public static double DistanceLineLine(Point A, Point B, Point C, Point D)
        {
            // check for zero-length segments
                if (A.Equals(B))
                    return DistancePointLine(A, C, D);
                if (C.Equals(D))
                    return DistancePointLine(D, A, B);

                // AB and CD are line segments
                /* from comp.graphics.algo

                    Solving the above for r and s yields
                                (Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy)
                            r = ----------------------------- (eqn 1)
                                (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)

                                (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
                            s = ----------------------------- (eqn 2)
                                (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
                    Let Point be the position vector of the intersection point, then
                        Point=A+r(B-A) or
                        Px=Ax+r(Bx-Ax)
                        Py=Ay+r(By-Ay)
                    By examining the values of r & s, you can also determine some other
                    limiting conditions:
                        If 0<=r<=1 & 0<=s<=1, intersection exists
                        r<0 or r>1 or s<0 or s>1 line segments do not intersect
                        If the denominator in eqn 1 is zero, AB & CD are parallel
                        If the numerator in eqn 1 is also zero, AB & CD are collinear.

                */
                double r_top = (A.Y - C.Y) * (D.X - C.X) - (A.X - C.X) * (D.Y - C.Y);
                double r_bot = (B.X - A.X) * (D.Y - C.Y) - (B.Y - A.Y) * (D.X - C.X);

                double s_top = (A.Y - C.Y) * (B.X - A.X) - (A.X - C.X) * (B.Y - A.Y);
                double s_bot = (B.X - A.X) * (D.Y - C.Y) - (B.Y - A.Y) * (D.X - C.X);

                if ((r_bot == 0) || (s_bot == 0))
                    return Math.Min(DistancePointLine(A, C, D),
                            Math.Min(DistancePointLine(B, C, D),
                            Math.Min(DistancePointLine(C, A, B),
                            DistancePointLine(D, A, B))));

                double s = s_top / s_bot;
                double r = r_top / r_bot;

                if ((r < 0) || (r > 1) || (s < 0) || (s > 1))
                    //no intersection
                    return Math.Min(DistancePointLine(A, C, D),
                            Math.Min(DistancePointLine(B, C, D),
                            Math.Min(DistancePointLine(C, A, B),
                            DistancePointLine(D, A, B))));

                return 0.0; //intersection exists
        }
开发者ID:PedroMaitan,项目名称:sharpmap,代码行数:64,代码来源:CGAlgoritm.cs

示例5: TestEquality

        public void TestEquality()
        {
            // Setup.
            var p1 = new Point(1, 0);
            var p2 = new Point(1, 0);
            var p3 = new Point(0, 1);

            // Dissimilar objects.
            var s = "Test";
            Assert.IsFalse(p1.Equals(s));

            // Null object.
            Assert.IsFalse(p1.Equals((object) null));

            // Null point.
            Assert.IsFalse(p1.Equals(null));

            // Point as object equals.
            Assert.IsTrue(p1.Equals((object) p2));
            Assert.IsTrue(p2.Equals((object) p1));
            Assert.IsFalse(p3.Equals((object) p1));

            // Point as point equals.
            Assert.IsTrue(p1.Equals(p2));
            Assert.IsTrue(p2.Equals(p1));
            Assert.IsFalse(p3.Equals(p1));

            // Reference equals.
            Assert.IsTrue(p1 == p1);

            // Null checks.
            Assert.IsFalse(null == p1);
            Assert.IsFalse(p1 == null);

            // Two different objects.
            Assert.IsTrue(p1 == p2);

            // Inequality operator.
            Assert.IsTrue(p1 != p3);

        }
开发者ID:mattmemmesheimer,项目名称:minesearch-reboot,代码行数:41,代码来源:PointTest.cs

示例6: 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>
            /// <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:HackatonArGP,项目名称:Guardianes,代码行数:29,代码来源:CGAlgoritm.cs

示例7: IsValidMove

        public override bool IsValidMove(Point target)
        {
            Point[] jiugong = this.Side.sideType == SideType.Bottom ?
                Board.BottomJiuGong : Board.TopJiuGong;
            if (!jiugong.Contains(target)) return false;
            if (target.Equals(this.Position)) return false;

            // * can horizontally or vertically move 1 position
            // * the target position must NOT be under attack
            if (((target.X == this.Position.X && Math.Abs(target.Y - this.Position.Y) == 1)
                || (target.Y == this.Position.Y && Math.Abs(target.X - this.Position.X) == 1))
                && !this.Side.Opponent.PointInAttackRange(target))
                return true;
            //otherwise...
            return false;
        }
开发者ID:kflu,项目名称:cnchess,代码行数:16,代码来源:Jiang.cs

示例8: CheckLinesTest

    public void CheckLinesTest()
    {
      Board b = new Board(7, 7, 3);
      Point p, pc;
      List<Point> result;
      List<Point> knownh, knownv, knowndl, knowndr, known;

      pc = new Point(2, 2);

      knownh = new List<Point>();
      ushort row;
      ushort col;
      ushort count;

      /* o o o o o o o o
       * o o o o o o o o
       * + + + + o o o o
       * o o o o o o o o
       * o o o o o o o o
       */
      for (row = pc.Row, col = 0, count = 0; count < 4; col++, count++)
      {
        p = new Point(row, col);
        knownh.Add(p);
        b.PlaceItem(p, 1);
      }

      result = b.CheckLines(knownh.ElementAt(0));
      Assert.AreEqual(0, result.Count);

      /* o o o o o o o o
       * o o o o o o o o
       * + + + + + o o o
       * o o o o o o o o
       * o o o o o o o o
       */
      p = new Point(row, col++);
      knownh.Add(p);
      b.PlaceItem(p, 1);

      // from right
      result = b.CheckLines(knownh.ElementAt(4));
      CollectionAssert.AreEquivalent(knownh, result);
      // from middle
      result = b.CheckLines(knownh.ElementAt(2));
      CollectionAssert.AreEquivalent(knownh, result);
      // from left
      result = b.CheckLines(knownh.ElementAt(0));
      CollectionAssert.AreEquivalent(knownh, result);

      // switch out the color
      b.ClearItem(pc);
      b.PlaceItem(pc, 2);
      // from left
      result = b.CheckLines(knownh.ElementAt(0));
      Assert.AreEqual(0, result.Count);
      // from middle
      result = b.CheckLines(knownh.ElementAt(2));
      Assert.AreEqual(0, result.Count);
      // from right
      result = b.CheckLines(knownh.ElementAt(4));
      Assert.AreEqual(0, result.Count);

      b.ClearItem(pc);
      b.PlaceItem(pc, 1);

      // more than 5
      /* o o o o o o o o
       * o o o o o o o o
       * + + + + + + o o
       * o o o o o o o o
       * o o o o o o o o
       */
      p = new Point(row, col++);
      knownh.Add(p);
      b.PlaceItem(p, 1);
      result = b.CheckLines(p);
      CollectionAssert.AreEquivalent(knownh, result);

      /* o o + o o o o o
       * o o + o o o o o
       * + + + + + + + o
       * o o + o o o o o
       * o o + o o o o o
       */
      knownv = new List<Point>();
      for (row = 0, col = pc.Col, count = 0; count < 5; row++, count++)
      {
        p = new Point(row, col);
        knownv.Add(p);
        if (!p.Equals(pc))
          b.PlaceItem(p, 1);
      }

      // from bottom
      result = b.CheckLines(p);
      CollectionAssert.AreEquivalent(knownv, result);
      // from top
      result = b.CheckLines(knownv.ElementAt(0));
      CollectionAssert.AreEquivalent(knownv, result);
//.........这里部分代码省略.........
开发者ID:cudima,项目名称:lines,代码行数:101,代码来源:BoardTest.cs

示例9: DistancePointLine

        /// <summary>
        ///     Computes the distance from a point p to a line segment AB.
        ///     Note: NON-ROBUST!
        /// </summary>
        /// <param name="p">The point to compute the distance for.</param>
        /// <param name="a">One point of the line.</param>
        /// <param name="b">Another point of the line (must be different to A).</param>
        /// <returns> The distance from p to line segment AB.</returns>
        public static double DistancePointLine(Point p, Point a, Point b)
        {
            // if start == end, then use pt distance
            if (a.Equals(b))
                return p.Distance(a);

            // otherwise use comp.graphics.algorithms Frequently Asked Questions method
            /*(1)     	      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 r = ((p.X - a.X)*(b.X - a.X) + (p.Y - a.Y)*(b.Y - a.Y))
                    /
                    ((b.X - a.X)*(b.X - a.X) + (b.Y - a.Y)*(b.Y - a.Y));

            if (r <= 0.0) return p.Distance(a);
            if (r >= 1.0) return p.Distance(b);

            /*(2)
                                                                (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
                                                            s = -----------------------------
                                                                            Curve^2

                                                            Then the distance from C to Point = |s|*Curve.
                                                */

            var s = ((a.Y - p.Y)*(b.X - a.X) - (a.X - p.X)*(b.Y - a.Y))
                    /
                    ((b.X - a.X)*(b.X - a.X) + (b.Y - a.Y)*(b.Y - a.Y));

            return Math.Abs(s)*Math.Sqrt((b.X - a.X)*(b.X - a.X) + (b.Y - a.Y)*(b.Y - a.Y));
        }
开发者ID:pauldendulk,项目名称:Mapsui,代码行数:48,代码来源:CGAlgoritm.cs

示例10: GetPath

 private static IEnumerable<Rotation> GetPath(Dictionary<Point, int> d, Point from, Point to)
 {
     var res = new List<Rotation>();
     while (!to.Equals(from))
     {
         var i = d[to] - 1;
         var nf = to.NearFour();
         int j;
         for (j = 0; j < nf.Length; j++)
         {
             if (d.ContainsKey(nf[j]) && d[nf[j]] == i)
             {
                 res.Add((Rotation)j);
                 to = nf[j];
                 break;
             }
         }
         if (j == 4) throw new Exception();
     }
     var ress = res.ToArray();
     ReversePath(ress);
     return ress;
 }
开发者ID:exyi,项目名称:LtpRobot,代码行数:23,代码来源:MapUtils.cs

示例11: Line

         public Line(Point beg, Point end) { 
             double l = beg.Distance(end);
             if (FP.eq(l, Math.PI)) {
                 Debug.Assert(FP.eq(beg.ra, end.ra));
                 phi = -Math.PI/2;
                 theta = Math.PI/2;
                 psi = beg.ra < 0.0 ? Math.PI*2 + beg.ra : beg.ra;
                 length = Math.PI;
                 return;
             }
             if (beg.Equals(end)) { 
                 phi    = Math.PI/2;
                 theta  = beg.dec;
                 psi    = beg.ra - Math.PI/2;
                 length = 0.0;
             } else { 
                 Point3D beg3d = new Point3D(beg);
                 Point3D end3d = new Point3D(end);
                 Point3D tp = new Point3D();
                 Point spt = beg3d.cross(end3d).toSpherePoint();
                 Euler euler = new Euler();
                 euler.phi     = - spt.ra - Math.PI/2;
                 euler.theta   =   spt.dec - Math.PI/2;
                 euler.psi     =   0.0 ;
                 euler.psi_a   = Euler.AXIS_Z;
                 euler.theta_a = Euler.AXIS_X;
                 euler.phi_a   = Euler.AXIS_Z;
                 euler.transform(tp, beg3d);
                 spt = tp.toSpherePoint();
 
                 // invert
                 phi = spt.ra;
                 theta = -euler.theta;
                 psi = -euler.phi;
                 length = l;
             }
         }
开发者ID:yan122725529,项目名称:TripRobot.Crawler,代码行数:37,代码来源:Sphere.cs

示例12: Equals

 public void Equals(Point a, Point b, bool result)
 {
     (a == b).Should().Be(result);
     (a.Equals(b)).Should().Be(result);
 }
开发者ID:WinstonSmith77,项目名称:vertrackt,代码行数:5,代码来源:PointTest.cs

示例13: 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 { X = LineSegFrom.X + r * (LineSegTo.X - LineSegFrom.X), Y = LineSegFrom.Y + r * (LineSegTo.Y - LineSegFrom.Y) };
                return coord;
        }
开发者ID:PedroMaitan,项目名称:sharpmap,代码行数:17,代码来源:CGAlgoritm.cs

示例14: TestPointEquals

		public void TestPointEquals ()
		{
			var point = new Point (2, 4);

			Assert.True (point.Equals (new Point (2, 4)));
			Assert.False (point.Equals (new Point (3, 4)));
			Assert.False (point.Equals ("Point"));
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:8,代码来源:PointTests.cs

示例15: GetWarpingPath

        public List<Point> GetWarpingPath(int i, int j)
        {
            List<Point> bSeq = new List<Point>();

            Point p = new Point(i, j);

            while ((!p.Equals(Point.Empty)) && (!p.Equals(new Point(0,0))))
            {
                bSeq.Insert(0, p);
                p = MinimalPath[(int)p.X, (int)p.Y];
                //when reaching end, stop procedure
                if (p.Equals(new Point(0,0)))
                {
                    //insert point <0,0>
                    bSeq.Insert(0, p);
                    break;
                }
            }

            return bSeq;
        }
开发者ID:sbpnlp,项目名称:kanjiteacher,代码行数:21,代码来源:TimeWarping.cs


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