// Cut the leg "legObj" with respect to "otherObj", if they overlap private static void CutLegWithRespectTo(EventDB eventDB, CourseAppearance appearance, CourseDesignator courseDesignator, LineCourseObj legObj, PointCourseObj otherObj) { float radiusOther = otherObj.ApparentRadius; PointF nearestPointOnLeg; float distance = legObj.path.DistanceFromPoint(otherObj.location, out nearestPointOnLeg); if (distance < radiusOther && Geometry.Distance(nearestPointOnLeg, legObj.path.FirstPoint) > 0.5 && Geometry.Distance(nearestPointOnLeg, legObj.path.LastPoint) > 0.5) { float gapRadius = (float) Math.Sqrt(radiusOther * radiusOther - distance * distance); // pythagorean theorem. gapRadius += appearance.autoLegGapSize / 2; CutLegAtPoint(legObj, nearestPointOnLeg, gapRadius); } }
// Cut the leg "legObj" with respect to "otherObj", if they intersect private static void CutLegWithRespectTo(EventDB eventDB, CourseAppearance appearance, CourseDesignator courseDesignator, LineCourseObj legObj, LineCourseObj otherObj) { PointF[] intersectionPoints; if (legObj.path.Intersects(otherObj.path, out intersectionPoints) && intersectionPoints != null) { // The other line intersections this one. Only the later leg is split. if (QueryEvent.DoesCourseControlPrecede(eventDB, courseDesignator, otherObj.courseControlId, legObj.courseControlId)) { foreach (PointF intersectionPoint in intersectionPoints) { float gapRadius = appearance.autoLegGapSize / 2; CutLegAtPoint(legObj, intersectionPoint, gapRadius); } } } }
// Check this leg and add cuts to it if needed. private static void AutoCutLeg(EventDB eventDB, CourseAppearance appearance, CourseDesignator courseDesignator, LineCourseObj legObj, CourseLayout courseLayout) { foreach (CourseObj courseObj in courseLayout) { if (courseObj != legObj && courseObj.layer == legObj.layer && (courseObj is LegCourseObj || courseObj is FlaggedLegCourseObj)) CutLegWithRespectTo(eventDB, appearance, courseDesignator, legObj, (LineCourseObj)courseObj); if (courseObj != legObj && courseObj.layer == legObj.layer && courseObj is PointCourseObj) CutLegWithRespectTo(eventDB, appearance, courseDesignator, legObj, (PointCourseObj)courseObj); } }
private static void CutLegAtPoint(LineCourseObj legObj, PointF intersectionPoint, float gapRadius) { float distanceAlongLine = legObj.path.LengthToPoint(intersectionPoint); PointF pt1 = legObj.path.PointAtLength(distanceAlongLine - gapRadius); PointF pt2 = legObj.path.PointAtLength(distanceAlongLine + gapRadius); legObj.gaps = LegGap.AddGap(legObj.path, legObj.gaps, pt1, pt2); }
LineCourseObj courseObj; // object to modify. #endregion Fields #region Constructors public RemoveLegGapMode(Controller controller, LineCourseObj courseObj) { this.controller = controller; this.courseObj = (LineCourseObj) courseObj.Clone(); }