/// <summary> /// Determines if two rings are spatially equal. /// </summary> /// <param name="other">Another ring to compare.</param> /// <returns>true when the given ring is spatially equal to this ring.</returns> public bool SpatiallyEqual(Ring2 other) { if (ReferenceEquals(null, other)) { return(false); } if (Equals(other)) { return(true); } if (GetMbr() != other.GetMbr()) { return(false); } if (DetermineWinding() != other.DetermineWinding()) { return(false); } if (!Hole.HasValue && other.Hole.HasValue || Hole.HasValue && !other.Hole.HasValue) { if (DetermineWinding() != other.DetermineWinding()) { return(false); } } else { if (FillSide != other.FillSide) { return(false); } } // TODO: MUST OPTIMIZE THIS GARBAGE if (!AllPointsOnBoundary(this, other)) { return(false); } if (!AllPointsOnBoundary(other, this)) { return(false); } return(true); }
/// <summary> /// Determines if this ring is within the given ring. /// </summary> /// <param name="testContainer">The ring to test with.</param> /// <returns>true if this ring is within the other ring.</returns> internal bool NonIntersectingWithin(Ring2 testContainer) { Contract.Ensures(testContainer != null || !Contract.Result <bool>()); if (testContainer == null) { return(false); } var thisMbr = GetMbr(); if (thisMbr == null) { return(false); } var containerMbr = testContainer.GetMbr(); if (containerMbr == null) { return(false); } var notEqual = !thisMbr.Equals(containerMbr); var bestResultGuess = notEqual; if (testContainer.Hole.HasValue && testContainer.Hole.Value) { if (thisMbr.Intersects(containerMbr)) { if (notEqual) { if (thisMbr.Contains(containerMbr)) { bestResultGuess = true; } else if (containerMbr.Contains(thisMbr)) { bestResultGuess = false; } } } else { return(true); } } else { if (thisMbr.Intersects(containerMbr)) { if (notEqual) { if (thisMbr.Contains(containerMbr)) { bestResultGuess = false; } if (containerMbr.Contains(thisMbr)) { bestResultGuess = true; } } } else { return(false); } } // need to test points bool mayHaveIt = false; foreach (var p in this) { int res = testContainer.AdvancedIntersectionTest(p); if (res > 0) { return(true); } if (res < 0) { return(false); } mayHaveIt = bestResultGuess; } return(mayHaveIt); }