public void OnSegmentHoriz() { var segment = new WireSegment(new Point(0, 0), new Point(5, 0)); Assert.IsTrue(segment.ContainsPoint(segment.min), "Start point on segment"); Assert.IsTrue(segment.ContainsPoint(new Point(3, 0)), "Mid point on segment"); Assert.IsTrue(segment.ContainsPoint(segment.max), "End point on segment"); }
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)); } } }