PathGeometry.FillContainsWithDetail() 总是 returns IntersectionDetail.Empty

PathGeometry.FillContainsWithDetail() always returns IntersectionDetail.Empty

以下代码总是到达 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 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。 有什么想法可以让它发挥作用吗?

编辑:自己解决,见下面的回答。

似乎 GetWidenedPathGeometry 和 GetOutlinedPathGeometry 以某种方式操纵 PathGeometry,交叉点变空了。删除这些后,只需调用 GetFlattenedPathGeometry 即可使我的代码 运行 符合预期。

固定代码如下:

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)