本文整理汇总了C#中Vertices.IsSimple方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.IsSimple方法的具体用法?C# Vertices.IsSimple怎么用?C# Vertices.IsSimple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.IsSimple方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Implements "A new algorithm for Boolean operations on general polygons"
/// available here: http://liama.ia.ac.cn/wiki/_media/user:dong:dong_cg_05.pdf
/// Merges two polygons, a subject and a clip with the specified operation. Polygons may not be
/// self-intersecting.
///
/// Warning: May yield incorrect results or even crash if polygons contain collinear points.
/// </summary>
/// <param name="subject">The subject polygon.</param>
/// <param name="clip">The clip polygon, which is added,
/// substracted or intersected with the subject</param>
/// <param name="clipType">The operation to be performed. Either
/// Union, Difference or Intersection.</param>
/// <param name="error">The error generated (if any)</param>
/// <returns>A list of closed polygons, which make up the result of the clipping operation.
/// Outer contours are ordered counter clockwise, holes are ordered clockwise.</returns>
private static List<Vertices> Execute(Vertices subject, Vertices clip,
PolyClipType clipType, out PolyClipError error)
{
Debug.Assert(subject.IsSimple() && clip.IsSimple(), "Non simple input!", "Input polygons must be simple (cannot intersect themselves).");
// Copy polygons
Vertices slicedSubject;
Vertices slicedClip;
// Calculate the intersection and touch points between
// subject and clip and add them to both
CalculateIntersections(subject, clip, out slicedSubject, out slicedClip);
// Translate polygons into upper right quadrant
// as the algorithm depends on it
Vector2 lbSubject = subject.GetAABB().LowerBound;
Vector2 lbClip = clip.GetAABB().LowerBound;
Vector2 translate;
Vector2.Min(ref lbSubject, ref lbClip, out translate);
translate = Vector2.One - translate;
if (translate != Vector2.Zero)
{
slicedSubject.Translate(ref translate);
slicedClip.Translate(ref translate);
}
// Enforce counterclockwise contours
slicedSubject.ForceCounterClockWise();
slicedClip.ForceCounterClockWise();
List<Edge> subjectSimplices;
List<float> subjectCoeff;
List<Edge> clipSimplices;
List<float> clipCoeff;
// Build simplical chains from the polygons and calculate the
// the corresponding coefficients
CalculateSimplicalChain(slicedSubject, out subjectCoeff, out subjectSimplices);
CalculateSimplicalChain(slicedClip, out clipCoeff, out clipSimplices);
List<Edge> resultSimplices;
// Determine the characteristics function for all non-original edges
// in subject and clip simplical chain and combine the edges contributing
// to the result, depending on the clipType
CalculateResultChain(subjectCoeff, subjectSimplices, clipCoeff, clipSimplices, clipType,
out resultSimplices);
List<Vertices> result;
// Convert result chain back to polygon(s)
error = BuildPolygonsFromChain(resultSimplices, out result);
// Reverse the polygon translation from the beginning
// and remove collinear points from output
translate *= -1f;
for (int i = 0; i < result.Count; ++i)
{
result[i].Translate(ref translate);
SimplifyTools.CollinearSimplify(result[i]);
}
return result;
}
示例2: updateSS
private void updateSS()
{
output = new float[5000];
output2 = new float[5000];
Vertices ssVertices = new Vertices();
ssVertices.Holes = polygon.ControlVertices.Holes;
foreach (Point2D point in polygon.ControlVertices)
{
ssVertices.Add(point);
}
if (mirrorMode)
{
for (int x = polygon.MirrorVertices.Count - 1; x >= 0; x--)
{
ssVertices.Add(polygon.MirrorVertices[x]);
}
foreach (Vertices hole in polygon.MirrorVertices.Holes)
{
ssVertices.Holes.Add(hole);
}
}
if (ssVertices.IsSimple())
{
ssVertices.ForceCounterClockWise();
float[] points = new float[ssVertices.Count * 2];
for (int i = 0, j = 0; i < ssVertices.Count * 2; j++, i = i + 2)
{
points[i] = ssVertices[j].X;
points[i + 1] = ssVertices[j].Y;
}
if (ssVertices.Holes.Count > 0)
{
int i = 0;
int totalSpaceNeeded = 0;
foreach (Vertices hole in ssVertices.Holes)
{
hole.ForceClockWiseHole();
totalSpaceNeeded += hole.Count * 2;
}
float[] holes = new float[totalSpaceNeeded];
int[] holeEnds = new int[ssVertices.Holes.Count];
int x = 0;
foreach (Vertices hole in ssVertices.Holes)
{
for (int j = 0; j < hole.Count; j++, i = i + 2)
{
holes[i] = hole[j].X;
holes[i + 1] = hole[j].Y;
}
holeEnds[x++] = hole.Count;
}
cpp.SSAwithHoles(points, points.Length, holes, holeEnds, holeEnds.Length, output, output2, _gui.getSubdivideSize());
}
else
{
cpp.SSAwithoutHoles(points, points.Length, output, output2, _gui.getSubdivideSize());
}
}
}