本文整理汇总了C#中Polygon.SplitConvexPolygon方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.SplitConvexPolygon方法的具体用法?C# Polygon.SplitConvexPolygon怎么用?C# Polygon.SplitConvexPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon
的用法示例。
在下文中一共展示了Polygon.SplitConvexPolygon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildNode
private static RooBSPItem BuildNode(List<RooWall> Walls, Polygon Polygon, int Sector)
{
if (Polygon.Count == 0 || (Walls.Count == 0 && Sector == 0))
return null;
Polygon.RemoveZeroEdges();
if (!Polygon.IsConvexPolygon())
{
if (FoundNonConvexPolygon != null)
FoundNonConvexPolygon(null, new PolygonEventArgs(Polygon));
//return null; // WTF ?
}
// No walls left ==> leaf
if (Walls.Count == 0)
{
RooSubSector leaf = new RooSubSector(RooFile.VERSIONHIGHRESGRID, (ushort)Sector, Polygon);
// fills in sector reference
leaf.ResolveIndices(room);
return leaf;
}
// get best splitter of remaining walls
RooWall splitter = ChooseSplitter(Walls);
if (splitter == null)
return null; // WTF ?
// split up walls into right/left
Tuple<List<RooWall>, List<RooWall>> splitWalls =
SplitWalls(Walls, splitter);
// split up polygon into right/left
Tuple<Polygon, Polygon> splitPolygons =
Polygon.SplitConvexPolygon(splitter.P1, splitter.P2);
Real a, b, c;
GetLineEquation2DCoefficients(splitter.P1, splitter.P2,
out a, out b, out c);
// create new splitter node
RooPartitionLine node = new RooPartitionLine(RooFile.VERSIONHIGHRESGRID,
Polygon.GetBoundingBox(), a, b, c, 0, 0, (ushort)splitter.Num);
// fills in wall reference
node.Wall = splitter;
// recursively descend to children
node.LeftChild = BuildNode(splitWalls.Item1, splitPolygons.Item1, splitter.LeftSectorNum);
node.RightChild = BuildNode(splitWalls.Item2, splitPolygons.Item2, splitter.RightSectorNum);
return node;
}
示例2: 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);
//.........这里部分代码省略.........