本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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));
}
示例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)));
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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());
}
示例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));
}
示例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)));
}
示例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>();
}
}
}