// Move a gap start/stop point to a new location. Return the new gap array. The gap array is NOT simplified. public static LegGap[] MoveStartStopPoint(SymPath path, LegGap[] gaps, PointF oldPt, PointF newPt) { LegGap[] newGaps = (LegGap[]) gaps.Clone(); float newLengthAlongPath = path.LengthToPoint(newPt); for (int i = 0; i < newGaps.Length; ++i) { PointF startPt = path.PointAtLength(gaps[i].distanceFromStart); PointF endPt = path.PointAtLength(gaps[i].distanceFromStart + gaps[i].length); if (Geometry.Distance(startPt, oldPt) < 0.01) { // Moving start point of the gap. newGaps[i].length -= (newLengthAlongPath - newGaps[i].distanceFromStart); newGaps[i].distanceFromStart = newLengthAlongPath; } else if (Geometry.Distance(endPt, oldPt) < 0.01) { // Moving end point of the gap. newGaps[i].length = newLengthAlongPath - gaps[i].distanceFromStart; } } return newGaps; }
// Change the gaps associated with a leg. public static void ChangeLegGaps(EventDB eventDB, Id<ControlPoint> controlId1, Id<ControlPoint> controlId2, LegGap[] newGaps) { // Get the leg object for this leg. Create one if needed. Id<Leg> legId = QueryEvent.FindLeg(eventDB, controlId1, controlId2); Leg leg; if (legId.IsNone) leg = new Leg(controlId1, controlId2); else leg = (Leg) eventDB.GetLeg(legId).Clone(); // Change the gaps. leg.gaps = (newGaps == null) ? null : (LegGap[]) newGaps.Clone(); // Write the change leg object to the event DB. If the leg is vacuous, could involve removing the leg. if (leg.IsVacuous()) { if (legId.IsNotNone) eventDB.RemoveLeg(legId); } else { if (legId.IsNone) eventDB.AddLeg(leg); else eventDB.ReplaceLeg(legId, leg); } }