2

我正在尝试使用 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

你能帮我如何正确地做到这一点吗?

4

1 回答 1

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);
于 2012-09-13T13:50:37.187 回答