本文整理汇总了C#中Polyline.AddPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Polyline.AddPoint方法的具体用法?C# Polyline.AddPoint怎么用?C# Polyline.AddPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polyline
的用法示例。
在下文中一共展示了Polyline.AddPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PolylineAroundClosedCurve
public static Polyline PolylineAroundClosedCurve(ICurve curve) {
Polyline poly = new Polyline();
foreach (Point point in PointsOnAroundPolyline(curve))
poly.AddPoint(point);
if (Point.GetTriangleOrientation(poly.StartPoint.Point, poly.StartPoint.Next.Point, poly.StartPoint.Next.Next.Point) == TriangleOrientation.Counterclockwise)
poly = (Polyline)poly.Reverse();
poly.Closed = true;
return poly;
}
示例2: PolyFromBox
/// <summary>
/// Create a closed Polyline from a rectangle
/// </summary>
/// <returns></returns>
public static Polyline PolyFromBox(Rectangle rectangle) {
var p = new Polyline();
p.AddPoint(rectangle.LeftTop);
p.AddPoint(rectangle.RightTop);
p.AddPoint(rectangle.RightBottom);
p.AddPoint(rectangle.LeftBottom);
p.Closed = true;
return p;
}
示例3: PolylineAroundClosedCurve
/// <summary>
///
/// </summary>
/// <param name="curve"></param>
/// <returns></returns>
public static Polyline PolylineAroundClosedCurve(ICurve curve) {
Polyline ret;
var ellipse = curve as Ellipse;
if (ellipse != null)
ret = RefineEllipse(ellipse);
else {
var poly = curve as Polyline;
if (poly != null)
return poly;
var c = curve as Curve;
if (c != null && AllSegsAreLines(c)) {
ret = new Polyline();
foreach (LineSegment ls in c.Segments)
ret.AddPoint(ls.Start);
ret.Closed = true;
if (!ret.IsClockwise())
ret = (Polyline) ret.Reverse();
}
else
ret = StandardRectBoundary(curve);
}
return ret;
}
示例4: CreateLoosePolylineOnBisectors
//private Polyline CutCorners(Polyline loosePolyline, Polyline tightPolyline) {
// Polyline ret = new Polyline();
// ret.Closed = true;
// PolylinePoint pp = loosePolyline.StartPoint;
// PolylinePoint tpp=tightPolyline.StartPoint;
// do {
// PolylinePoint furthestVisible = GetFurthestVisible(pp, ref tpp);
// ret.AddPoint(furthestVisible.Point);
// pp = furthestVisible;
// }
// while (pp != loosePolyline.StartPoint);
// System.Diagnostics.Debug.Assert(pp == loosePolyline.StartPoint);
// //distangle ret.StartPoint and ret.LastPoint
// return ret;
//}
//static PolylinePoint GetFurthestVisible(PolylinePoint pp, ref PolylinePoint tpp) {
// Point pivot = pp.Point;
// Point blockingPoint = tpp.NextOnPolyline.Point;
// while (Point.GetTriangleOrientation(pivot, blockingPoint, pp.NextOnPolyline.Point) == TriangleOrientation.Counterclockwise) {
// pp = pp.NextOnPolyline;
// tpp = tpp.NextOnPolyline;
// }
// return pp;
//}
static Polyline CreateLoosePolylineOnBisectors(Polyline tightPolyline, double p) {
var ret = new Polyline();
ret.AddPoint(GetStickingVertexOnBisector(tightPolyline.StartPoint, p));
var blockingPoint = new Point(); //to silence the compiler
var candidate = new Point();
bool justAdded = true;
for (PolylinePoint pp = tightPolyline.StartPoint.Next; pp != null; pp = pp.Next) {
Point currentSticking = GetStickingVertexOnBisector(pp, p);
if (justAdded) {
blockingPoint = pp.Point;
candidate = currentSticking;
justAdded = false;
} else {
if (ret.Count > 1) {
// SugiyamaLayoutSettings.Show(tightPolyline, ret, new LineSegment(ret.StartPoint.Point, currentSticking));
}
//SugiyamaLayoutSettings.Show(new LineSegment(ret.EndPoint.Point, blockingPoint), tightPolyline, new LineSegment(ret.EndPoint.Point, currentSticking));
if (Point.GetTriangleOrientation(ret.EndPoint.Point, blockingPoint, currentSticking) !=
TriangleOrientation.Counterclockwise) {
ret.AddPoint(candidate);
// SugiyamaLayoutSettings.Show(ret, tightPolyline);
justAdded = true;
pp = pp.Prev;
} else {
candidate = currentSticking;
if (Point.GetTriangleOrientation(ret.EndPoint.Point, blockingPoint, pp.Point) ==
TriangleOrientation.Counterclockwise)
blockingPoint = pp.Point;
}
}
}
//process the last point
if (!justAdded) {
if (Point.GetTriangleOrientation(ret.EndPoint.Point, blockingPoint, ret.StartPoint.Point) ==
TriangleOrientation.Counterclockwise) {
//the first point is visible, but now can we cut it
if (Point.GetTriangleOrientation(ret.EndPoint.Point, blockingPoint, ret.StartPoint.Next.Point) ==
TriangleOrientation.Counterclockwise)
ret.RemoveStartPoint();
} else {
ret.AddPoint(candidate);
}
} else {
//trying to cut away the first point
if (
Point.GetTriangleOrientation(ret.EndPoint.Point, tightPolyline.StartPoint.Point,
ret.StartPoint.Next.Point) == TriangleOrientation.Counterclockwise)
ret.RemoveStartPoint();
else { }
}
ret.Closed = true;
// SugiyamaLayoutSettings.Show(tightPolyline, ret);
return ret;
}
示例5: GetShortestPolyline
Polyline GetShortestPolyline() {
var pathCalc = new SingleSourceSingleTargetShortestPathOnVisibilityGraph(_visGraph, this.sourceVisibilityVertex,
TargetVisibilityVertex);
var path = pathCalc.GetPath(false);
var ret = new Polyline();
foreach (var v in path)
ret.AddPoint(v.Point);
return RemoveCollinearPoint(ret);
}
示例6: ReadPolyline
private Polyline ReadPolyline()
{
var p = new Polyline();
Match m;
while ((m = ParseNextOrDone(RectFileStrings.ParsePoint, RectFileStrings.EndPolyline)).Success)
{
var x = double.Parse(m.Groups["X"].ToString());
var y = double.Parse(m.Groups["Y"].ToString());
p.AddPoint(new Point(x, y));
}
p.Closed = true;
return p;
}
示例7: ExtendPolylineEndToClusterBoundary
static void ExtendPolylineEndToClusterBoundary(Polyline poly, ICurve curve) {
var par = curve.ClosestParameter(poly.End);
poly.AddPoint(curve[par]);
}
示例8: StandardRectBoundary
private Polyline StandardRectBoundary() {
Polyline poly = new Polyline();
poly.AddPoint(LeftTop);
poly.AddPoint(RightTop);
poly.AddPoint(RightBottom);
poly.AddPoint(LeftBottom);
poly.Closed = true;
return poly;
}
示例9: RouteEdgeToLocation
// int count;
/// <summary>
///
/// </summary>
/// <param name="targetLocation"></param>
/// <returns></returns>
public EdgeGeometry RouteEdgeToLocation(Point targetLocation) {
TargetPort = new FloatingPort((ICurve) null, targetLocation); //otherwise route edge to a port would be called
TargetTightPolyline = null;
TargetLoosePolyline = null;
var edgeGeometry = new EdgeGeometry();
var ls = new LineSegment(SourcePort.Location, targetLocation);
if (LineCanBeAcceptedForRouting(ls)) {
_polyline = new Polyline();
_polyline.AddPoint(ls.Start);
_polyline.AddPoint(ls.End);
edgeGeometry.SmoothedPolyline = SmoothedPolyline.FromPoints(_polyline);
edgeGeometry.Curve = edgeGeometry.SmoothedPolyline.CreateCurve();
return edgeGeometry;
}
//can we do with just two line segments?
if (SourcePort is CurvePort) {
ls = new LineSegment(StartPointOfEdgeRouting, targetLocation);
if (
IntersectionsOfLineAndRectangleNodeOverPolyline(ls, ObstacleCalculator.RootOfTightHierarchy).Count ==
0) {
_polyline = new Polyline();
_polyline.AddPoint(SourcePort.Location);
_polyline.AddPoint(ls.Start);
_polyline.AddPoint(ls.End);
//RelaxPolyline();
edgeGeometry.SmoothedPolyline = SmoothedPolyline.FromPoints(_polyline);
edgeGeometry.Curve = edgeGeometry.SmoothedPolyline.CreateCurve();
return edgeGeometry;
}
}
ExtendVisibilityGraphToLocation(targetLocation);
_polyline = GetShortestPolyline(SourceVisibilityVertex, TargetVisibilityVertex);
RelaxPolyline();
if (SourcePort is CurvePort)
_polyline.PrependPoint(SourcePort.Location);
edgeGeometry.SmoothedPolyline = SmoothedPolyline.FromPoints(_polyline);
edgeGeometry.Curve = edgeGeometry.SmoothedPolyline.CreateCurve();
return edgeGeometry;
}
示例10: GetShortestPolyline
//internal Point TargetPoint {
// get {
// CurvePort tp = this.TargetPort as CurvePort;
// if (tp != null)
// return this.Target.BoundaryCurve[tp.Parameter];
// else
// return (this.TargetPort as FloatingPort).Location;
// }
//}
//internal Point SourcePoint {
// get {
// CurvePort sp = this.SourcePort as CurvePort;
// if (sp != null)
// return this.Source.BoundaryCurve[sp.Parameter];
// else
// return (this.SourcePort as FloatingPort).Location;
// }
//}
Polyline GetShortestPolyline(VisibilityVertex sourceVisVertex, VisibilityVertex _targetVisVertex) {
CleanTheGraphForShortestPath();
var pathCalc = new SingleSourceSingleTargetShortestPathOnVisibilityGraph(this.visibilityGraph, sourceVisVertex, _targetVisVertex);
IEnumerable<VisibilityVertex> path = pathCalc.GetPath(UseEdgeLengthMultiplier);
if (path == null) {
//ShowIsPassable(_sourceVisibilityVertex, _targetVisVertex);
return null;
}
Debug.Assert(path.First() == sourceVisVertex && path.Last() == _targetVisVertex);
var ret = new Polyline();
foreach (VisibilityVertex v in path)
ret.AddPoint(v.Point);
return RemoveCollinearVertices(ret);
}
示例11: GetShortestPolylineToMulitpleTargets
Polyline GetShortestPolylineToMulitpleTargets(VisibilityVertex sourceVisVertex, IEnumerable<VisibilityVertex> targets) {
CleanTheGraphForShortestPath();
//ShowPolylineAndObstacles(targets.Select(t=>new Ellipse(3,3,t.Point)).ToArray());
var pathCalc = new SingleSourceMultipleTargetsShortestPathOnVisibilityGraph(sourceVisVertex, targets, VisibilityGraph);// { dd = ShowPolylineAndObstacles };
IEnumerable<VisibilityVertex> path = pathCalc.GetPath();
if (path == null)
return null;
Debug.Assert(path.First() == sourceVisVertex && targets.Contains(path.Last()));
var ret = new Polyline();
foreach (VisibilityVertex v in path)
ret.AddPoint(v.Point);
return RemoveCollinearVertices(ret);
}
示例12: RouteFromFloatingPortToBoundaryPort
ICurve RouteFromFloatingPortToBoundaryPort(bool smooth, out SmoothedPolyline smoothedPolyline) {
Point targetPortLocation = targetPort.Location;
LineSegment ls;
if (InsideOfTheAllowedConeOfBoundaryPort(sourcePort.Location, (CurvePort)targetPort)) {
ls = new LineSegment(SourcePort.Location, targetPortLocation);
if (LineCanBeAcceptedForRouting(ls)) {
smoothedPolyline = SmoothedPolylineFromTwoPoints(ls.Start, ls.End);
return ls;
}
}
Point takenOutTargetPortLocation = TakeBoundaryPortOutsideOfItsLoosePolyline(TargetPort.Curve,
((CurvePort) TargetPort).
Parameter,
TargetLoosePolyline);
//can we do with just two line segments?
ls = new LineSegment(SourcePort.Location, takenOutTargetPortLocation);
if (LineAvoidsTightHierarchy(ls, _sourceTightPolyline)) {
_polyline=new Polyline(ls.Start, ls.End, targetPortLocation);
smoothedPolyline = SmoothedPolyline.FromPoints(_polyline);
return smoothedPolyline.CreateCurve();
}
ExtendVisibilityGraphToTargetBoundaryPort(takenOutTargetPortLocation);
_polyline = GetShortestPolyline(SourceVisibilityVertex, TargetVisibilityVertex);
RelaxPolyline();
_polyline.AddPoint(targetPortLocation);
return SmoothCornersAndReturnCurve(smooth, out smoothedPolyline);
}
示例13: RouteFromBoundaryPortToBoundaryPort
ICurve RouteFromBoundaryPortToBoundaryPort(bool smooth, out SmoothedPolyline smoothedPolyline) {
Point sourcePortLocation = SourcePort.Location;
ICurve curve;
Point targetPortLocation = targetPort.Location;
var ls = new LineSegment(sourcePortLocation, targetPortLocation);
if (LineCanBeAcceptedForRouting(ls)) {
_polyline = new Polyline();
_polyline.AddPoint(ls.Start);
_polyline.AddPoint(ls.End);
smoothedPolyline = SmoothedPolylineFromTwoPoints(ls.Start,ls.End);
curve = SmoothedPolyline.FromPoints(_polyline).CreateCurve();
} else {
//try three variants with two segments
Point takenOutPoint = TakeBoundaryPortOutsideOfItsLoosePolyline(targetPort.Curve,
((CurvePort) targetPort).Parameter,
TargetLoosePolyline);
ls = new LineSegment(sourcePortLocation, takenOutPoint);
if (InsideOfTheAllowedConeOfBoundaryPort(takenOutPoint, SourcePort as CurvePort) &&
LineAvoidsTightHierarchy(ls, _sourceTightPolyline)) {
_polyline = new Polyline();
_polyline.AddPoint(ls.Start);
_polyline.AddPoint(ls.End);
_polyline.AddPoint(targetPortLocation);
curve = SmoothCornersAndReturnCurve(smooth, out smoothedPolyline);
} else {
ls = new LineSegment(StartPointOfEdgeRouting, targetPortLocation);
if (InsideOfTheAllowedConeOfBoundaryPort(StartPointOfEdgeRouting, TargetPort as CurvePort) &&
LineAvoidsTightHierarchy(ls)) {
_polyline = new Polyline();
_polyline.AddPoint(sourcePortLocation);
_polyline.AddPoint(ls.Start);
_polyline.AddPoint(ls.End);
curve = SmoothCornersAndReturnCurve(smooth, out smoothedPolyline);
} else {
// we still can make the polyline with two segs when the port sticking segs are intersecting
Point x;
if (LineSegment.Intersect(sourcePortLocation, StartPointOfEdgeRouting, targetPortLocation,
takenOutPoint, out x)) {
_polyline = new Polyline();
_polyline.AddPoint(sourcePortLocation);
_polyline.AddPoint(x);
_polyline.AddPoint(targetPortLocation);
curve = SmoothCornersAndReturnCurve(smooth, out smoothedPolyline);
} else if (ApproximateComparer.Close(StartPointOfEdgeRouting, takenOutPoint)) {
_polyline = new Polyline();
_polyline.AddPoint(sourcePortLocation);
_polyline.AddPoint(takenOutPoint);
_polyline.AddPoint(targetPortLocation);
curve = SmoothCornersAndReturnCurve(smooth, out smoothedPolyline);
} else if (LineAvoidsTightHierarchy(new LineSegment(StartPointOfEdgeRouting, takenOutPoint))) {
//can we do three segments?
_polyline = new Polyline();
_polyline.AddPoint(sourcePortLocation);
_polyline.AddPoint(StartPointOfEdgeRouting);
_polyline.AddPoint(takenOutPoint);
_polyline.AddPoint(targetPortLocation);
curve = SmoothCornersAndReturnCurve(smooth, out smoothedPolyline);
} else {
ExtendVisibilityGraphToTargetBoundaryPort(takenOutPoint);
_polyline = GetShortestPolyline(SourceVisibilityVertex, TargetVisibilityVertex);
Polyline tmpTargetTight;
Polyline tmpSourceTight = HideSourceTargetTightsIfNeeded(out tmpTargetTight);
TryShortcutPolyline();
RecoverSourceTargetTights(tmpSourceTight, tmpTargetTight);
RelaxPolyline();
_polyline.PrependPoint(sourcePortLocation);
_polyline.AddPoint(targetPortLocation);
curve = SmoothCornersAndReturnCurve(smooth, out smoothedPolyline);
}
}
}
}
return curve;
}
示例14: RemoveOverlaps
/// <summary>
/// Removes the overlap according to the defined settings.
/// </summary>
/// <returns></returns>
public void RemoveOverlaps() {
if (_nodes == null || _nodes.Length == 0) return;
#if DEBUG
// if (DebugMode) {
// Console.WriteLine("Showing graph on startup.");
// LayoutAlgorithmSettings.ShowGraph(Graph);
// }
#endif
// init some things
InitNodePositionsAndBoxes(Settings, _nodes, out nodePositions, out nodeSizes);
if (!(Settings.InitialScaling == InitialScaling.None))
DoInitialScaling();
InitStressWithGraph(StressSolver, _nodes, nodePositions);
#if DEBUG
//debugging the node movements
trajectories = new List<Polyline>(_nodes.Length);
//add starting positions
for (int i = 0; i < nodePositions.Length; i++) {
var poly = new Polyline();
poly.AddPoint(nodePositions[i]);
trajectories.Add(poly);
}
#endif
#if !SILVERLIGHT && !SHARPKIT
var stopWatch = new Stopwatch();
stopWatch.Start();
#endif
bool scanlinePhase = false;
int iter = 0;
bool finished = false;
while (!finished && ((iter++) < Settings.IterationsMax || !Settings.StopOnMaxIterat)) {
finished = DoSingleIteration(iter, ref scanlinePhase);
}
#if !SILVERLIGHT && !SHARPKIT
stopWatch.Stop();
#endif
LastRunIterations = iter;
#if DEBUG && !SILVERLIGHT && !SHARPKIT
if (DebugMode) {
ShowTrajectoriesOfNodes(trajectories);
//LayoutAlgorithmSettings.ShowGraph(Graph);
}
#endif
SetPositionsToGraph();
#if !SILVERLIGHT && !SHARPKIT
PrintTimeSpan(stopWatch);
#endif
double nodeBoxArea = nodeSizes.Sum(r => r.Width*r.Height);
var boundingBox = GetCommonRectangle(nodeSizes, nodePositions);
double boundingBoxArea = boundingBox.Width*boundingBox.Height;
Console.WriteLine("Needed maxIterat: {0}", iter);
Console.WriteLine("BBox Area Ratio: {0}", boundingBoxArea/nodeBoxArea);
// nodePositions = null;
// nodeBoxes = null;
#if DEBUG && !SILVERLIGHT && !SHARPKIT
if (DebugMode) {
//LayoutAlgorithmSettings.ShowGraph(Graph);
}
#endif
#if !SILVERLIGHT && !SHARPKIT
lastCpuTime = stopWatch.Elapsed;
return;
#else
return;// new TimeSpan(0);
#endif
}
示例15: ReadPolygon
ICurve ReadPolygon() {
var pointString = GetMustAttribute(GeometryToken.Points);
var t = pointString.Split(' ');
if (t.Length == 0 || t.Length%2 != 0)
Error("invalid input for the polygon");
var poly = new Polyline {Closed = true};
for (int i = 0; i < t.Length; i += 2)
poly.AddPoint(new Point(ParseDouble(t[i]), ParseDouble(t[i + 1])));
return poly;
}