本文整理汇总了C#中Polygon.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.Clear方法的具体用法?C# Polygon.Clear怎么用?C# Polygon.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon
的用法示例。
在下文中一共展示了Polygon.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SplitConvexPolygon
public void SplitConvexPolygon()
{
Polygon poly = new Polygon();
Polygon expectedLeft = new Polygon();
Polygon expectedRight = new Polygon();
V2 p1, p2;
Tuple<Polygon, Polygon> returned;
// --- TEST ---
// 4 points, valid clockwise rectangle ABCD
// intersect nothing from south to north
// |
// B----------C |
// | | |
// | | |
// | | |
// A----------D |
// |
p1 = new V2(20.5f, -15f);
p2 = new V2(20.5f, 15);
poly.Clear();
expectedLeft.Clear();
expectedRight.Clear();
poly.Add(new V2(0.0f, 0.0f)); // A
poly.Add(new V2(0.0f, 5.0f)); // B
poly.Add(new V2(5.0f, 5.0f)); // C
poly.Add(new V2(5.0f, 0.0f)); // D
// right empty
// left = old
expectedLeft.Add(new V2(0.0f, 0.0f));
expectedLeft.Add(new V2(0.0f, 5.0f));
expectedLeft.Add(new V2(5.0f, 5.0f));
expectedLeft.Add(new V2(5.0f, 0.0f));
returned = poly.SplitConvexPolygon(p1, p2);
Assert.AreEqual(returned.Item1.IsIdentical(expectedRight), true);
Assert.AreEqual(returned.Item2.IsIdentical(expectedLeft), true);
// --- TEST ---
// 4 points, valid clockwise rectangle ABCD
// intersect nothing from north to south
// |
// B----------C |
// | | |
// | | |
// | | |
// A----------D |
// |
p1 = new V2(20.5f, 15f);
p2 = new V2(20.5f, -15);
poly.Clear();
expectedLeft.Clear();
expectedRight.Clear();
poly.Add(new V2(0.0f, 0.0f)); // A
poly.Add(new V2(0.0f, 5.0f)); // B
poly.Add(new V2(5.0f, 5.0f)); // C
poly.Add(new V2(5.0f, 0.0f)); // D
// right = old
expectedRight.Add(new V2(0.0f, 0.0f));
expectedRight.Add(new V2(0.0f, 5.0f));
expectedRight.Add(new V2(5.0f, 5.0f));
expectedRight.Add(new V2(5.0f, 0.0f));
// left empty
returned = poly.SplitConvexPolygon(p1, p2);
Assert.AreEqual(returned.Item1.IsIdentical(expectedRight), true);
Assert.AreEqual(returned.Item2.IsIdentical(expectedLeft), true);
// --- TEST ---
// 4 points, valid clockwise rectangle ABCD
// intersect edges BC, DA from south to north
// |
// B----I1----C
// | | |
// | | |
// | | |
// A----I2----D
// |
p1 = new V2(2.5f, -10f);
p2 = new V2(2.5f, 10);
poly.Clear();
expectedLeft.Clear();
expectedRight.Clear();
poly.Add(new V2(0.0f, 0.0f)); // A
poly.Add(new V2(0.0f, 5.0f)); // B
poly.Add(new V2(5.0f, 5.0f)); // C
poly.Add(new V2(5.0f, 0.0f)); // D
expectedRight.Add(new V2(2.5f, 5.0f));
expectedRight.Add(new V2(5.0f, 5.0f));
expectedRight.Add(new V2(5.0f, 0.0f));
expectedRight.Add(new V2(2.5f, 0.0f));
expectedLeft.Add(new V2(2.5f, 0.0f));
expectedLeft.Add(new V2(0.0f, 0.0f));
expectedLeft.Add(new V2(0.0f, 5.0f));
expectedLeft.Add(new V2(2.5f, 5.0f));
returned = poly.SplitConvexPolygon(p1, p2);
//.........这里部分代码省略.........
示例2: IsConvexPolygon
public void IsConvexPolygon()
{
Polygon poly = new Polygon();
bool expected;
bool returned;
// --- TEST ---
// 3 points, valid triangle
poly.Clear();
poly.Add(new V2(10.0f, 10.0f));
poly.Add(new V2(5.0f, 0.0f));
poly.Add(new V2(10.0f, -10.0f));
expected = true;
returned = poly.IsConvexPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 4 points, valid rectangle
poly.Clear();
poly.Add(new V2(0.0f, 0.0f));
poly.Add(new V2(0.0f, 5.0f));
poly.Add(new V2(5.0f, 5.0f));
poly.Add(new V2(5.0f, 0.0f));
expected = true;
returned = poly.IsConvexPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 5 points, rectangle, but two points not of first three in on same coords
poly.Clear();
poly.Add(new V2(0.0f, 0.0f));
poly.Add(new V2(0.0f, 5.0f));
poly.Add(new V2(5.0f, 5.0f));
poly.Add(new V2(5.0f, 0.0f));
poly.Add(new V2(5.0f, 0.0f));
expected = true;
returned = poly.IsConvexPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 4 points, no rectangle ordered, not convex
poly.Clear();
poly.Add(new V2(0.0f, 0.0f));
poly.Add(new V2(5.0f, 5.0f));
poly.Add(new V2(0.0f, 5.0f));
poly.Add(new V2(5.0f, 0.0f));
expected = false;
returned = poly.IsConvexPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// n points, concave polygon
poly.Clear();
poly.Add(new V2(0.0f, 0.0f));
poly.Add(new V2(10.0f, 0.0f));
poly.Add(new V2(10.0f, 5.0f));
poly.Add(new V2(5.0f, 5.0f));
poly.Add(new V2(5.0f, 10.0f));
poly.Add(new V2(10.0f, 10.0f));
poly.Add(new V2(10.0f, 15.0f));
poly.Add(new V2(0.0f, 15.0f));
expected = false;
returned = poly.IsConvexPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 5 points, convex
poly.Clear();
poly.Add(new V2(2512.0f, 5490.0f));
poly.Add(new V2(2304.0f, 5568.0f));
poly.Add(new V2(2304.0f, 5376.0f));
poly.Add(new V2(2304.0f, 5120.0f));
poly.Add(new V2(2512.0f, 5120.0f));
expected = true;
returned = poly.IsConvexPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 6 points, convex
poly.Clear();
poly.Add(new V2(5376f, 6032f));
poly.Add(new V2(5376f, 7936f));
poly.Add(new V2(5376f, 8192f));
poly.Add(new V2(5136f, 8192f));
poly.Add(new V2(4752f, 6656f));
poly.Add(new V2(4940.339f, 6467.661f));
//.........这里部分代码省略.........
示例3: IsPolygon
public void IsPolygon()
{
Polygon poly = new Polygon();
bool expected;
bool returned;
// --- TEST ---
// no points
poly.Clear();
expected = false;
returned = poly.IsPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 1 point
poly.Clear();
poly.Add(new V2(35.0f, 2.0f));
expected = false;
returned = poly.IsPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 2 points
poly.Clear();
poly.Add(new V2(35.0f, 2.0f));
poly.Add(new V2(365.0f, 23.0f));
expected = false;
returned = poly.IsPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 3 points all equal
poly.Clear();
poly.Add(new V2(35.0f, 2.0f));
poly.Add(new V2(35.0f, 2.0f));
poly.Add(new V2(35.0f, 2.0f));
expected = false;
returned = poly.IsPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 3 points, 1&3 equal
poly.Clear();
poly.Add(new V2(35.0f, 2.0f));
poly.Add(new V2(3.0f, 6.0f));
poly.Add(new V2(35.0f, 2.0f));
expected = false;
returned = poly.IsPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 3 points, 1&2 equal
poly.Clear();
poly.Add(new V2(3.0f, 6.0f));
poly.Add(new V2(3.0f, 6.0f));
poly.Add(new V2(35.0f, 2.0f));
expected = false;
returned = poly.IsPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 3 points, 2&3 equal
poly.Clear();
poly.Add(new V2(35.0f, 2.0f));
poly.Add(new V2(3.0f, 6.0f));
poly.Add(new V2(3.0f, 6.0f));
expected = false;
returned = poly.IsPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 3 points on same line
poly.Clear();
poly.Add(new V2(5.0f, 7.0f));
poly.Add(new V2(5.0f, 5.0f));
poly.Add(new V2(5.0f, 10.0f));
expected = false;
returned = poly.IsPolygon();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 3 points, valid triangle
poly.Clear();
//.........这里部分代码省略.........
示例4: RemoveZeroEdges
public void RemoveZeroEdges()
{
Polygon poly = new Polygon();
int expected;
int returned;
// --- TEST ---
// 5 points, rectangle, but two points not of first three in on same coords
poly.Clear();
poly.Add(new V2(0.0f, 0.0f));
poly.Add(new V2(0.0f, 5.0f));
poly.Add(new V2(5.0f, 5.0f));
poly.Add(new V2(5.0f, 0.0f));
poly.Add(new V2(5.0f, 0.0f));
expected = 1;
returned = poly.RemoveZeroEdges();
Assert.AreEqual(expected, returned);
// --- TEST ---
// 5 points, rectangle, but two points not of first three in on same coords
poly.Clear();
poly.Add(new V2(0.0f, 0.0f));
poly.Add(new V2(0.0f, 5.0f));
poly.Add(new V2(5.0f, 5.0f));
poly.Add(new V2(5.0f, 0.0f));
poly.Add(new V2(5.0f, 0.0f));
expected = 1;
returned = poly.RemoveZeroEdges();
Assert.AreEqual(expected, returned);
// --- TEST ---
// n points, concave polygon
poly.Clear();
poly.Add(new V2(0.0f, 0.0f));
poly.Add(new V2(10.0f, 0.0f));
poly.Add(new V2(10.0f, 5.0f));
poly.Add(new V2(5.0f, 5.0f));
poly.Add(new V2(5.0f, 10.0f));
poly.Add(new V2(10.0f, 10.0f));
poly.Add(new V2(10.0f, 15.0f));
poly.Add(new V2(0.0f, 15.0f));
expected = 0;
returned = poly.RemoveZeroEdges();
Assert.AreEqual(expected, returned);
}