public void Intersect() { var segment = new WireSegment(new Point(0, 0), new Point(5, 0)); var segment2 = new WireSegment(new Point(3, -2), new Point(3, 5)); var i = segment.Intersect(segment2, out var intr); Assert.IsTrue(i, "Interescted"); Assert.AreEqual(new Point(3, 0), intr, "Interesction Point"); }
public void IntersectOverlappedVert() { var segment = new WireSegment(new Point(0, 0), new Point(0, 5)); var segment2 = new WireSegment(new Point(0, 3), new Point(0, 7)); var i = segment.Intersect(segment2, out var intr); Assert.IsTrue(i, "Interescted"); Assert.AreEqual(new Point(0, 3), intr, "Interesction Point"); i = segment2.Intersect(segment, out intr); Assert.IsTrue(i, "Interescted 2"); Assert.AreEqual(new Point(0, 3), intr, "Interesction Point 2"); }
public bool Intersect(WireSegment other, out Point intersection) { if (Vertical) { if (!other.Vertical) //Other Horizontal { var potInt = new Point(min.X, other.min.Y); if (potInt == default) { intersection = default; return(false); } if (ContainsPoint(potInt) && other.ContainsPoint(potInt)) { intersection = potInt; return(true); } else { intersection = default; return(false); } } else //Both { if (min.X != other.min.X) { intersection = default; return(false); } else { var overlap = GetOverlap(other); if (overlap.min.ManhattanMagnitude() < overlap.max.ManhattanMagnitude()) { intersection = overlap.min == default ? overlap.max : overlap.min; } else { intersection = overlap.max == default ? overlap.min : overlap.max; } if (intersection == default) { return(false); } return(true); } } } else { if (!other.Vertical) //Other Horizontal { if (min.Y != other.min.Y) { intersection = default; return(false); } var overlap = GetOverlap(other); if (overlap.min.ManhattanMagnitude() < overlap.max.ManhattanMagnitude()) { intersection = overlap.min == default ? overlap.max : overlap.min; } else { intersection = overlap.max == default ? overlap.min : overlap.max; } if (intersection == default) { return(false); } return(true); } else { return(other.Intersect(this, out intersection)); } } }