本文整理汇总了C#中SFML.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# SFML.Equals方法的具体用法?C# SFML.Equals怎么用?C# SFML.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SFML
的用法示例。
在下文中一共展示了SFML.Equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Intersection
// this is the general case. Really really general
public static SFML.Window.Vector2f[] Intersection(SFML.Window.Vector2f a1, SFML.Window.Vector2f a2, SFML.Window.Vector2f b1, SFML.Window.Vector2f b2)
{
if (a1.Equals(a2) && b1.Equals(b2))
{
// both "segments" are points, return either point
if (a1.Equals(b1))
return new SFML.Window.Vector2f[] { a1 };
else // both "segments" are different points, return empty set
return new SFML.Window.Vector2f[] { };
}
else if (b1.Equals(b2)) // b is a point, a is a segment
{
if (PointOnLine(b1, a1, a2))
return new SFML.Window.Vector2f[] { b1 };
else
return new SFML.Window.Vector2f[] { };
}
else if (a1.Equals(a2)) // a is a point, b is a segment
{
if (PointOnLine(a1, b1, b2))
return new SFML.Window.Vector2f[] { a1 };
else
return new SFML.Window.Vector2f[] { };
}
// at this point we know both a and b are actual segments
float ua_t = (b2.X - b1.X) * (a1.Y - b1.Y) - (b2.Y - b1.Y) * (a1.X - b1.X);
float ub_t = (a2.X - a1.X) * (a1.Y - b1.Y) - (a2.Y - a1.Y) * (a1.X - b1.X);
float u_b = (b2.Y - b1.Y) * (a2.X - a1.X) - (b2.X - b1.X) * (a2.Y - a1.Y);
// Infinite lines intersect somewhere
if (!(-MyEpsilon < u_b && u_b < MyEpsilon)) // e.g. u_b != 0.0
{
float ua = ua_t / u_b;
float ub = ub_t / u_b;
if (0.0f <= ua && ua <= 1.0f && 0.0f <= ub && ub <= 1.0f)
{
// Intersection
return new SFML.Window.Vector2f[] {
new SFML.Window.Vector2f(a1.X + ua * (a2.X - a1.X),
a1.Y + ua * (a2.Y - a1.Y)) };
}
else
{
// No Intersection
return new SFML.Window.Vector2f[] { };
}
}
else // lines (not just segments) are parallel or the same line
{
// Coincident
// find the common overlapping section of the lines
// first find the distance (squared) from one point (a1) to each point
if ((-MyEpsilon < ua_t && ua_t < MyEpsilon)
|| (-MyEpsilon < ub_t && ub_t < MyEpsilon))
{
if (a1.Equals(a2)) // danger!
return OneD_Intersection(b1, b2, a1, a2);
else // safe
return OneD_Intersection(a1, a2, b1, b2);
}
else
{
// Parallel
return new SFML.Window.Vector2f[] { };
}
}
}