有没有一种好方法来检查 WPF 中 PathFigure 中的段是否重叠?
我正在 WPF 中开发一个控件,以使用不同的线段类型(圆弧、贝塞尔曲线、线段)绘制区域形状,并希望防止它们创建复杂的区域形状。也就是说,边缘重叠的形状。
我正在使用转换器生成的 PathGeometry,但转换器完成后,XAML 将类似于以下 XAML。
没有重叠:
<Path x:Name="PolygonPath" Fill="Blue" Opacity="75">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="50,50" IsClosed="True" IsFilled="True">
<PathFigure.Segments>
<QuadraticBezierSegment Point1="100,0" Point2="200,50"/>
<LineSegment Point="250,50"/>
<LineSegment Point="250,200"/>
<QuadraticBezierSegment Point1="100,350" Point2="50,50"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
有重叠(应该测试失败):
<Path x:Name="PolygonPath" Fill="Blue" Opacity="75">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="50,50" IsClosed="True" IsFilled="True">
<PathFigure.Segments>
<QuadraticBezierSegment Point1="100,0" Point2="200,60"/>
<LineSegment Point="0,60"/>
<LineSegment Point="250,200"/>
<QuadraticBezierSegment Point1="100,350" Point2="50,50"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
在上面的例子中,第二和第三条线段
和 < ;LineSegment Point="250,200"/>
与最后一段重叠
。
我是否缺少一种方法来测试路径是否在 WPF 中的任何点与其自身相交?
I'm working on a control in WPF to draw area shapes using the different segment types (arc, bezier, line segment) and want to keep them from creating area shapes that are complex. That is to say shapes where the edges overlap.
I am working with a PathGeometry
generated by a converter, but after the converter is finished the XAML would look like the following XAML.
With no overlaps:
<Path x:Name="PolygonPath" Fill="Blue" Opacity="75">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="50,50" IsClosed="True" IsFilled="True">
<PathFigure.Segments>
<QuadraticBezierSegment Point1="100,0" Point2="200,50"/>
<LineSegment Point="250,50"/>
<LineSegment Point="250,200"/>
<QuadraticBezierSegment Point1="100,350" Point2="50,50"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
With overlaps (should fail the test):
<Path x:Name="PolygonPath" Fill="Blue" Opacity="75">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="50,50" IsClosed="True" IsFilled="True">
<PathFigure.Segments>
<QuadraticBezierSegment Point1="100,0" Point2="200,60"/>
<LineSegment Point="0,60"/>
<LineSegment Point="250,200"/>
<QuadraticBezierSegment Point1="100,350" Point2="50,50"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
In the above case, the second and third line segments <LineSegment Point="0,60"/>
and <LineSegment Point="250,200"/>
overlap the last segment <QuadraticBezierSegment Point1="100,350" Point2="50,50"/>
.
Is there a method I am missing to test if a path intersects with itself at any point in WPF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你可以做的是:
通过调用为你正在测试的每个 PathFigure 获取一个边界矩形:
然后使用 rect.IntersectsWith 方法检查矩形是否相交。
像这样:
xaml:
上面的代码返回:
对于这个xaml
希望这有帮助,问候
I guess what you could do is:
get a bounds rectangle for each PathFigure you're testing by calling:
Then use rect.IntersectsWith method to check of rectangles do intersect.
Smth like this:
xaml:
the code above returns:
for this xaml
hope this helps, regards