public ILayoutLine GetExtendedFretLine(Measure amount) { if ((Length + (amount * 2)).NormalizedValue > 0) { if (IsStraight) { var layoutLine = new LayoutLine(Points.First(), Points.Last()); layoutLine.P2 += (layoutLine.Direction * amount); layoutLine.P1 += (layoutLine.Direction * (amount * -1)); return(layoutLine); } else { RebuildSpline(); var tmpLine = new LayoutPolyLine(Points); var bounds = GetFretBoundaries(false); var offset1 = LayoutLine.Offset(bounds.Item1, amount * -1); var offset2 = LayoutLine.Offset(bounds.Item2, amount); tmpLine.TrimBetween(offset1, offset2, true); if (Spline != null) { tmpLine.InterpolateSpline(0.5); } return(tmpLine); } } return(null); }
public static LayoutLine Offset(LayoutLine line, Measure amount) { var p1 = line.GetPerpendicularPoint(line.P1, amount); var p2 = line.GetPerpendicularPoint(line.P2, amount); return(new LayoutLine(p1, p2)); }
public void TrimEnd(LayoutLine trimLine, bool extendIfNeeded = false) { int interIdx; PointM interPt = PointM.Empty; if (!Intersects(trimLine, out interPt, out interIdx, extendIfNeeded)) { return; } var pointsToKeep = new List <PointM>(); for (int i = 0; i <= interIdx; i++) { pointsToKeep.Add(Points[i]); if (interIdx == i) { var ptRel = GetLocationRelativeToSegment(Points[i].ToVector(), Points[i + 1].ToVector(), interPt.ToVector()); if (ptRel == PointRelation.After) { pointsToKeep.Add(Points[i + 1]); } } } pointsToKeep.Add(interPt); Points.Clear(); _Points.AddRange(pointsToKeep); //remove points that are very close MergePoints(0.05); }
public PointM GetIntersection(LayoutLine other, out int segmentIndex, bool infiniteLine = true) { var intersection = PointM.Empty; Intersects(other, out intersection, out segmentIndex, infiniteLine); return(intersection); }
public PointM GetIntersection(LayoutLine other) { var intersection = PointM.Empty; Intersects(other, out intersection, true); return(intersection); }
public bool Intersects(LayoutLine line, out PointM intersection, bool infiniteLine = true) { intersection = PointM.Empty; if (Intersects(line.Equation, out Vector inter, infiniteLine)) { intersection = PointM.FromVector(inter, P1.Unit ?? P2.Unit); return(true); } return(false); }
public void TrimBetween(LayoutLine l1, LayoutLine l2, bool extendIfNeeded = false) { bool canTrimStart = Intersects(l1, out PointM p1, out int inter1Idx, extendIfNeeded); bool canTrimEnd = Intersects(l2, out PointM p2, out int inter2Idx, extendIfNeeded); if (!canTrimStart || !canTrimEnd) { if (canTrimStart) { TrimStart(l1, extendIfNeeded); } else if (canTrimEnd) { TrimEnd(l2, extendIfNeeded); } return; } var pointsToKeep = new List <PointM>(); pointsToKeep.Add(p1); for (int i = inter1Idx; i <= inter2Idx; i++) { if (inter1Idx == i) { var ptRel = GetLocationRelativeToSegment(Points[i].ToVector(), Points[i + 1].ToVector(), p1.ToVector()); if (ptRel != PointRelation.Before) { continue; } } pointsToKeep.Add(Points[i]); if (inter2Idx == i) { var ptRel = GetLocationRelativeToSegment(Points[i].ToVector(), Points[i + 1].ToVector(), p2.ToVector()); if (ptRel == PointRelation.After) { pointsToKeep.Add(Points[i + 1]); } } } pointsToKeep.Add(p2); Points.Clear(); _Points.AddRange(pointsToKeep); //remove points that are very close MergePoints(0.05); }
public bool Intersects(LayoutLine line, out PointM intersection, out int segmentIndex, bool infiniteLine = true) { intersection = PointM.Empty; if (Intersects(line.Equation, out Vector virtualInter, out segmentIndex, infiniteLine)) { intersection = PointM.FromVector(virtualInter, Points.First().Unit); return(true); } return(false); }
public PointM GetIntersection(LayoutLine line) { var inter = Equation.GetIntersection(line.Equation); return(PointM.FromVector(inter, P1.Unit)); }
public bool Intersects(LayoutLine line, out PointM intersection, bool infiniteLine = true) { return(Intersects(line, out intersection, out _, infiniteLine)); }