/**
   * speed up for short lines
   *
   * @param p
   * @return
   * @throws ReprapException
   * @throws IOException
   */
  private boolean shortLine(Rr2Point p, boolean stopExtruder, boolean closeValve)
      throws ReprapException, IOException {
    Printer printer = layerConditions.getPrinter();
    double shortLen = printer.getExtruder().getShortLength();
    if (shortLen < 0) return false;
    Rr2Point a = Rr2Point.sub(posNow(), p);
    double amod = a.mod();
    if (amod > shortLen) {
      //			Debug.d("Long segment.  Current feedrate is: " + currentFeedrate);
      return false;
    }

    // printer.setFeedrate(printer.getExtruder().getShortLineFeedrate());
    // TODO: FIX THIS
    //		printer.setSpeed(LinePrinter.speedFix(printer.getExtruder().getXYSpeed(),
    //				printer.getExtruder().getShortSpeed()));
    printer.printTo(
        p.x(),
        p.y(),
        layerConditions.getMachineZ(),
        printer.getExtruder().getShortLineFeedrate(),
        stopExtruder,
        closeValve);
    // printer.setFeedrate(currentFeedrate);
    return true;
  }
  /**
   * @param first
   * @param second
   * @param startUp
   * @param endUp
   * @throws ReprapException
   * @throws IOException
   */
  private void move(Rr2Point first, Rr2Point second, boolean startUp, boolean endUp, boolean fast)
      throws ReprapException, IOException {
    Printer printer = layerConditions.getPrinter();

    if (printer.isCancelled()) return;

    //		 Don't call delay; this isn't controlling the printer
    while (paused) {
      try {
        Thread.sleep(200);
      } catch (Exception ex) {
      }
    }

    double z = layerConditions.getMachineZ();

    // if(startUp)
    if (fast) {
      // printer.setFeedrate(printer.getFastFeedrateXY());
      printer.moveTo(
          first.x(), first.y(), z, printer.getExtruder().getFastXYFeedrate(), startUp, endUp);
      return;
    }

    double speedUpLength = printer.getExtruder().getAngleSpeedUpLength();
    if (speedUpLength > 0) {
      segmentSpeeds ss = new segmentSpeeds(posNow(), first, second, speedUpLength);
      if (ss.abandon) return;

      printer.moveTo(ss.p1.x(), ss.p1.y(), z, printer.getCurrentFeedrate(), startUp, startUp);

      if (ss.plotMiddle) {
        // printer.setFeedrate(currentFeedrate);
        printer.moveTo(ss.p2.x(), ss.p2.y(), z, currentFeedrate, startUp, startUp);
      }

      // TODO: FIX ME!
      // printer.setSpeed(ss.speed(currentSpeed, printer.getExtruder().getAngleSpeedFactor()));

      // printer.setFeedrate(printer.getExtruder().getAngleFeedrate());
      printer.moveTo(
          ss.p3.x(), ss.p3.y(), z, printer.getExtruder().getAngleFeedrate(), startUp, endUp);
      // pos = ss.p3;
      // Leave speed set for the start of the next movement.
    } else printer.moveTo(first.x(), first.y(), z, currentFeedrate, startUp, endUp);
  }
  /**
   * @param first First point, the end of the line segment to be plotted to from the current
   *     position.
   * @param second Second point, the end of the next line segment; used for angle calculations
   * @param turnOff True if the extruder should be turned off at the end of this segment.
   * @throws ReprapException
   * @throws IOException
   */
  private void plot(Rr2Point first, Rr2Point second, boolean stopExtruder, boolean closeValve)
      throws ReprapException, IOException {
    Printer printer = layerConditions.getPrinter();
    if (printer.isCancelled()) return;

    // Don't call delay; this isn't controlling the printer
    while (paused) {
      try {
        Thread.sleep(200);
      } catch (Exception ex) {
      }
    }

    if (shortLine(first, stopExtruder, closeValve)) return;

    double z = layerConditions.getMachineZ();

    double speedUpLength = printer.getExtruder().getAngleSpeedUpLength();
    if (speedUpLength > 0) {
      segmentSpeeds ss = new segmentSpeeds(posNow(), first, second, speedUpLength);
      if (ss.abandon) return;

      printer.printTo(ss.p1.x(), ss.p1.y(), z, currentFeedrate, false, false);

      if (ss.plotMiddle) {
        // TODO: FIX THIS.
        //				int straightSpeed = LinePrinter.speedFix(currentSpeed, (1 -
        //						printer.getExtruder().getAngleSpeedFactor()));
        // printer.setFeedrate(printer.getExtruder().getAngleFeedrate());
        printer.printTo(
            ss.p2.x(), ss.p2.y(), z, printer.getExtruder().getAngleFeedrate(), false, false);
      }

      // printer.setSpeed(ss.speed(currentSpeed, printer.getExtruder().getAngleSpeedFactor()));

      // printer.setFeedrate(printer.getExtruder().getAngleFeedrate());
      printer.printTo(
          ss.p3.x(),
          ss.p3.y(),
          z,
          printer.getExtruder().getAngleFeedrate(),
          stopExtruder,
          closeValve);
      // pos = ss.p3;
      // Leave speed set for the start of the next line.
    } else printer.printTo(first.x(), first.y(), z, currentFeedrate, stopExtruder, closeValve);
  }
 private void singleMove(Rr2Point p) {
   Printer pt = layerConditions.getPrinter();
   pt.singleMove(p.x(), p.y(), pt.getZ(), pt.getFastXYFeedrate());
 }