本文整理汇总了C#中Coordinate.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Coordinate.CompareTo方法的具体用法?C# Coordinate.CompareTo怎么用?C# Coordinate.CompareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coordinate
的用法示例。
在下文中一共展示了Coordinate.CompareTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Intersects
/// <summary>
/// Tests whether the query rectangle intersects a given line segment.
/// </summary>
/// <param name="p0">The first endpoint of the segment</param>
/// <param name="p1">The second endpoint of the segment</param>
/// <returns><c>true</c> if the rectangle intersects the segment</returns>
public bool Intersects(Coordinate p0, Coordinate p1)
{
// TODO: confirm that checking envelopes first is faster
/**
* If the segment envelope is disjoint from the
* rectangle envelope, there is no intersection
*/
var segEnv = new Envelope(p0, p1);
if (!_rectEnv.Intersects(segEnv))
return false;
/**
* If either segment endpoint lies in the rectangle,
* there is an intersection.
*/
if (_rectEnv.Intersects(p0)) return true;
if (_rectEnv.Intersects(p1)) return true;
/**
* Normalize segment.
* This makes p0 less than p1,
* so that the segment runs to the right,
* or vertically upwards.
*/
if (p0.CompareTo(p1) > 0)
{
var tmp = p0;
p0 = p1;
p1 = tmp;
}
/**
* Compute angle of segment.
* Since the segment is normalized to run left to right,
* it is sufficient to simply test the Y ordinate.
* "Upwards" means relative to the left end of the segment.
*/
var isSegUpwards = p1.Y > p0.Y;
/**
* Since we now know that neither segment endpoint
* lies in the rectangle, there are two possible
* situations:
* 1) the segment is disjoint to the rectangle
* 2) the segment crosses the rectangle completely.
*
* In the case of a crossing, the segment must intersect
* a diagonal of the rectangle.
*
* To distinguish these two cases, it is sufficient
* to test intersection with
* a single diagonal of the rectangle,
* namely the one with slope "opposite" to the slope
* of the segment.
* (Note that if the segment is axis-parallel,
* it must intersect both diagonals, so this is
* still sufficient.)
*/
if (isSegUpwards)
{
_li.ComputeIntersection(p0, p1, _diagDown0, _diagDown1);
}
else
{
_li.ComputeIntersection(p0, p1, _diagUp0, _diagUp1);
}
if (_li.HasIntersection)
return true;
return false;
}