C# PathGeometry.FillContainsWithDetail()始终返回IntersectionDetail.Empty
下面的代码始终可以访问IntersectionDetail.Empty,但也可以访问FullyContains或FullyInside。为什么?C# PathGeometry.FillContainsWithDetail()始终返回IntersectionDetail.Empty,c#,.net,wpf,path,intersection,C#,.net,Wpf,Path,Intersection,下面的代码始终可以访问IntersectionDetail.Empty,但也可以访问FullyContains或FullyInside。为什么? Path p1; // filled with a polygon Path p2; // filled with another polygon PathGeometry pg1 = p1.RenderedGeometry.GetFlattenedPathGeometry().GetWidenedPathGeometry(new Pen(new S
Path p1; // filled with a polygon
Path p2; // filled with another polygon
PathGeometry pg1 = p1.RenderedGeometry.GetFlattenedPathGeometry().GetWidenedPathGeometry(new Pen(new SolidColorBrush(), 1)).GetOutlinedPathGeometry(1, ToleranceType.Absolute);
pg1.FillRule = FillRule.EvenOdd;
PathGeometry pg2 = p2.RenderedGeometry.GetFlattenedPathGeometry().GetWidenedPathGeometry(new Pen(new SolidColorBrush(), 1)).GetOutlinedPathGeometry(1, ToleranceType.Absolute);
pg2.FillRule = FillRule.EvenOdd;
IntersectionDetail id = pg1.FillContainsWithDetail(pg2);
if (id == IntersectionDetail.FullyContains) // never reached but should
if (id == IntersectionDetail.FullyInside) //never reached but should
if (id == IntersectionDetail.Intersect) // always reached (edit: found a bug no more the error case)
if (id == IntersectionDetail.Empty) // edit: after bug fix now always reached
多边形被绘制到屏幕上,所以我可以说这应该真正达到案例FullyContains/FullyInside。
有什么办法让它工作吗
编辑:由我自己解决,请参见下面的答案。看来GetWideedPathGeometry和GetOutlinedPathGeometry以某种方式操纵PathGeometry,使交叉点变为空。删除这些后,只需调用GetFlattedPathGeometry,我的代码就能按预期运行良好 以下是固定代码:
Path p1; // filled with a polygon
Path p2; // filled with another polygon
PathGeometry pg1 = p1.RenderedGeometry.GetFlattenedPathGeometry();
pg1.FillRule = FillRule.EvenOdd;
PathGeometry pg2 = p2.RenderedGeometry.GetFlattenedPathGeometry();
pg2.FillRule = FillRule.EvenOdd;
IntersectionDetail id = pg1.FillContainsWithDetail(pg2);
if (id == IntersectionDetail.FullyContains) // now reached as expected
if (id == IntersectionDetail.FullyInside) // now reached as expected
if (id == IntersectionDetail.Intersect)
if (id == IntersectionDetail.Empty)
您是否已将
pg1
和pg2
放入另外两个路径控件中,并对它们进行了目视检查?谢谢,这帮助我找到了一个bug。我忘记设置路径图的起始点
,IsClosed=true
和IsFilled=true
。但是现在我得到了IntersectionDetail.Empty
并且没有FullyInside/FullyContains。我正在用画布中绘制的两个椭圆对象尝试同样的方法。我总是有交叉点。有什么想法吗?