我正在尝试使用Geometry类中的fillContains方法来检测geometry1是否在geometry2中,但是当geometry1放置在第一个几何体的右边缘或底边缘时,我遇到了问题。这是一个非常奇怪的结果:
var rect = new Rect(new Point(0, 0), new Point(100, 100));
RectangleGeometry geometry1 = new RectangleGeometry(rect);
var rect2 = new Rect(new Point(0, 0), new Size(10, 10));
RectangleGeometry geometry2 = new RectangleGeometry(rect2);
var rect3 = new Rect(new Point(90, 90), new Size(10, 10));
RectangleGeometry geometry3 = new RectangleGeometry(rect3);
var rect4 = new Rect(new Point(90, 80), new Size(10, 10));
RectangleGeometry geometry4 = new RectangleGeometry(rect4);
Assert.True(geometry1.FillContains(geometry2));
Assert.True(geometry1.FillContains(geometry3));
Assert.True(geometry1.FillContains(geometry4)); // Assertion failed
你能帮我解决一下我应该怎样做的吗?
答案 0 :(得分:0)
它可能与容差有关...或者几何交叉算法内部的东西....也许他们正在以某种方式缩放值...而且它取决于你使用的可能导致的值交叉点检查出现意外结果(例如,当点为90,80时)。
我已经扩展了一些代码,以显示有关2个几何形状如何相交的更多细节,并希望允许玩具来确定原因。
var rect = new Rect(new Point(0, 0), new Point(100, 100));
RectangleGeometry geometry1 = new RectangleGeometry(rect);
var rect2 = new Rect(new Point(0, 0), new Size(10, 10));
RectangleGeometry geometry2 = new RectangleGeometry(rect2);
var rect3 = new Rect(new Point(90, 90), new Size(10, 10));
RectangleGeometry geometry3 = new RectangleGeometry(rect3);
var rect4 = new Rect(new Point(90, 80), new Size(10, 10));
RectangleGeometry geometry4 = new RectangleGeometry(rect4);
var rect4fits = new Rect(new Point(90, 80), new Size(9, 10));
RectangleGeometry geometry4fits = new RectangleGeometry(rect4fits);
double tolerance = 0.25; // same as standard flattening tolerance
ToleranceType tolerancetype = ToleranceType.Relative;
var bcontains2 = geometry1.FillContains(geometry2);
var bcontainsdetail2 = geometry1.FillContains(geometry2, tolerance, tolerancetype);
var detail2 = geometry1.FillContainsWithDetail(geometry2);
var detailtolerance2 = geometry1.FillContainsWithDetail(geometry2, tolerance, tolerancetype);
var bcontains3 = geometry1.FillContains(geometry3);
var bcontainsdetail3 = geometry1.FillContains(geometry3, tolerance, tolerancetype);
var detail3 = geometry1.FillContainsWithDetail(geometry3);
var detailtolerance3 = geometry1.FillContainsWithDetail(geometry3, tolerance, tolerancetype);
var bcontains4 = geometry1.FillContains(geometry4);
var bcontainsdetail4 = geometry1.FillContains(geometry4, tolerance, tolerancetype);
var detail4 = geometry1.FillContainsWithDetail(geometry4);
var detailtolerance4 = geometry1.FillContainsWithDetail(geometry4, tolerance, tolerancetype);
var bcontains4fits = geometry1.FillContains(geometry4fits);
var bcontainsdetail4fits = geometry1.FillContains(geometry4fits, tolerance, tolerancetype);
var detail4fits = geometry1.FillContainsWithDetail(geometry4fits);
var detailtolerance4fits = geometry1.FillContainsWithDetail(geometry4fits, tolerance, tolerancetype);