剪切路径问题
我编写了自己的折线类,它本质上保留了可以使用矩阵修改的点列表。多段线可以添加到其他多段线并在公共端点处连接。当终点等于起点时,多段线将表示一个多边形。
然后,我有一种方法可以通过一系列 lineTo() 调用迭代点列表,将多边形转换为 Path 对象。然后,该路径在我的 View 的 onDraw 方法中作为剪辑路径应用于画布。
它非常适合复杂的多边形,我可以绘制该路径来验证其准确性。
到目前为止一切都很好,除了当我有一个中间有不规则孔的复合多边形时我注意到了一些问题。此时我可能应该停止将其称为多边形,因为它是另一个多边形内的多边形。
例如,考虑下图,其中外框和中间看起来像“城堡”的形状都是用作剪辑路径的同一 Path 对象的一部分。 # 代表绘制区域。
+---------+
|#########|
|#+-+#+-+#|
|#| |#| |#|
|#| +-+ |#|
|#| |#|
|#+-----+#|
|#########|
+---------+
我希望外盒外部和内部“城堡”形状内部的所有内容都被剪掉。我看到的问题是内部形状没有被正确修剪。似乎是光线追踪算法的问题。
任何想法都会有帮助。
编辑:另外,我尝试测试每个 Region.Op 模式,但没有一个解决问题。我怀疑我需要采取措施来检测是否存在“漏洞”并做一些创造性的事情。
I have written my own poly-line class that essentially keeps a list of points that can be modified using a Matrix. The poly lines can be added to other poly lines and joined at common endpoints. The poly line will represent a polygon when the end point equals the starting point.
I then have a method to turn my polygon into a Path object by iterating the list of points with a series of lineTo() calls. This path is then applied to a canvas as a clip path in my View's onDraw method.
It works perfect for complex polygons and I can draw that path to verify it's accuracy.
So far so good, except that I'm noticing issues when I have a compound polygon with an irregular hole in the middle. I should probably stop calling it a polygon at this point since it is a polygon inside another polygon.
For example consider the diagram below where the outer box and "castle" looking shape in the middle are both parts of the same Path object that is used as a clip-path. The # represent painted area.
+---------+
|#########|
|#+-+#+-+#|
|#| |#| |#|
|#| +-+ |#|
|#| |#|
|#+-----+#|
|#########|
+---------+
I expect that everything outside of the outer box and inside the inner "castle" shape to be clipped. The issue I'm seeing is that the inside shape isn't being clipped, properly. Seems to be an issue with the ray-tracing algorithm.
Any ideas would be helpful.
EDIT: Also, I tried testing every Region.Op mode, and none of them solved the problem. I suspect I'll need to put measures in place to detect if there is a "hole" and do something creative.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过几天的研究,我的问题已经解决了一半。
我需要将 Path.FillType 设置为:
但后来我遇到了一个相反的情况,只绘制了中心路径。经过更多的调查,我能够通过添加来解决这个问题:
但是,外部具有单个路径的多边形的剪辑会反转。虽然我很满意我找到了正确的书呆子旋钮来获得正确的剪切行为,但我还没有找到一种方法来确定需要哪种剪切方法。
如果有人有任何想法可以分享,我会很高兴。我怀疑这与行添加到路径的顺序有关,例如内部是否定义在外部之前,等等。
After spending a couple of day's playing with this I've half-solved my problem.
I needed to set the Path.FillType with:
But then I had an instance where the opposite happened and only the center path was painted. A little more investigation and I was able to fix that with adding:
But then polygons with a single path on the outside have their clip inverted. While I'm satisified that I've found the right nerd-knobs to get the right clipping behavior, I haven't found a way to determine which clipping methods are needed.
I'd be happy if someone has any ideas to share. I suspect it has something to do with the order in which lines are added to the path, such as if the inner is defined beore the outer, etc.