本文整理汇总了C#中Polyline.ClosestParameterWithinBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Polyline.ClosestParameterWithinBounds方法的具体用法?C# Polyline.ClosestParameterWithinBounds怎么用?C# Polyline.ClosestParameterWithinBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polyline
的用法示例。
在下文中一共展示了Polyline.ClosestParameterWithinBounds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClosestParameterWithinBounds
public void ClosestParameterWithinBounds() {
#if GDI_DEBUG_VIEWER
if (!MsaglTestBase.DontShowTheDebugViewer()) {
DisplayGeometryGraph.SetShowFunctions();
}
#endif
var ellipse = CurveFactory.CreateEllipse(8, 10, new Point());
var point = new Point(20, 1);
var t = ellipse.ClosestParameter(point);
var low = t - 1;
var high = t + 1;
var t1 = ellipse.ClosestParameterWithinBounds(point, low, high);
#if GDI_DEBUG_VIEWER
if (!MsaglTestBase.DontShowTheDebugViewer()) {
LayoutAlgorithmSettings.ShowDebugCurves(new DebugCurve(100, 0.1, "black", ellipse),
new DebugCurve(100, 0.01, "brown", new LineSegment(ellipse[t], point)),
new DebugCurve(100, 0.01, "green", new LineSegment(ellipse[t1], point)));
}
#endif
var dist = point - ellipse[t];
var dist1 = point - ellipse[t1];
Assert.IsTrue(ApproximateComparer.Close(dist.Length, dist1.Length) && ApproximateComparer.Close(t, t1));
#if GDI_DEBUG_VIEWER
if (!MsaglTestBase.DontShowTheDebugViewer()) {
LayoutAlgorithmSettings.ShowDebugCurves(new DebugCurve(ellipse), new DebugCurve("red", new LineSegment(point, ellipse[t])));
}
#endif
var curve = new Curve();
curve.AddSegment(new LineSegment(new Point(-10, -10), new Point(10, -10)));
curve.AddSegment(new Ellipse(0, Math.PI / 2, new Point(0, -10), new Point(10, 0), new Point(10, 0)));
Curve.ContinueWithLineSegment(curve, new Point(20, 10));
curve.AddSegment(new CubicBezierSegment(curve.End, new Point(20, 20), new Point(15, 25), new Point(10, 25)));
Curve.ContinueWithLineSegment(curve, new Point(-10, 25));
Point p = new Point(11, 0);
t = curve.ClosestParameter(p);
#if GDI_DEBUG_VIEWER
if (!MsaglTestBase.DontShowTheDebugViewer()) {
LayoutAlgorithmSettings.ShowDebugCurves(new DebugCurve(curve), new DebugCurve("red", new LineSegment(p, curve[t])));
}
#endif
t1 = curve.ClosestParameterWithinBounds(p, 1 + Math.PI / 4, 2);
#if GDI_DEBUG_VIEWER
if (!MsaglTestBase.DontShowTheDebugViewer()) {
LayoutAlgorithmSettings.ShowDebugCurves(new DebugCurve(curve), new DebugCurve("red", new LineSegment(p, curve[t1])));
}
#endif
Assert.IsTrue(t1 < t);
p = new Point(30, 30);
t = curve.ClosestParameter(p);
t1 = curve.ClosestParameterWithinBounds(p, t - 0.5, t + 0.5);
Assert.IsTrue(t > 1 + Math.PI / 2 + 1 && t < 1 + Math.PI / 2 + 2);
Assert.IsTrue(ApproximateComparer.Close(t, t1));
var poly = new Polyline(new Point(0, 0), new Point(10, 0), new Point(20, 10));
p = new Point(9, 9);
const double l = 0.7;
const double h = 1.3;
t = poly.ClosestParameterWithinBounds(p, l, h);
#if GDI_DEBUG_VIEWER
if (!MsaglTestBase.DontShowTheDebugViewer()) {
LayoutAlgorithmSettings.ShowDebugCurves(new DebugCurve(poly), new DebugCurve("red", new LineSegment(p, poly[t])));
}
#endif
var d = (p - poly[t]).Length;
Assert.IsTrue(d <= (p - poly[l]).Length + ApproximateComparer.Tolerance && d < (p - poly[h]).Length + ApproximateComparer.Tolerance && d < (p - poly[(l + h) / 2]).Length + ApproximateComparer.Tolerance);
}