/**
* Expands the last point in the list if it is an arc according to the
* the parsers settings.
*/
public List<PointSegment> expandArc() {
PointSegment startSegment = this.points.get(this.points.size() - 2);
PointSegment lastSegment = this.points.get(this.points.size() - 1);
// Can only expand arcs.
if (!lastSegment.isArc()) {
return null;
}
// Get precalculated stuff.
Point3d start = startSegment.point();
Point3d end = lastSegment.point();
Point3d center = lastSegment.center();
double radius = lastSegment.getRadius();
boolean clockwise = lastSegment.isClockwise();
//
// Start expansion.
//
List<Point3d> expandedPoints =
GcodePreprocessorUtils.generatePointsAlongArcBDring(
start, end, center, clockwise, radius,
smallArcThreshold, smallArcSegmentLength);
// Validate output of expansion.
if (expandedPoints == null) {
return null;
}
// Remove the last point now that we're about to expand it.
this.points.remove(this.points.size() - 1);
commandNumber--;
// Initialize return value
List<PointSegment> psl = new ArrayList<PointSegment>();
// Create line segments from points.
PointSegment temp;
// skip first element.
Iterator<Point3d> psi = expandedPoints.listIterator(1);
while (psi.hasNext()) {
temp = new PointSegment(psi.next(), commandNumber++);
temp.setIsMetric(lastSegment.isMetric());
// Add new points.
this.points.add(temp);
psl.add(temp);
}