private void calcHeadTail(PointFP p1, PointFP p2, LineFP head, LineFP tail) {

    LineFP curr = new LineFP(p1, p2);
    head.reset(curr.getHeadOutline(ff_rad));
    int dx = p2.x - p1.x;
    int dy = p2.y - p1.y;
    tail.reset(head.pt1.x + dx, head.pt1.y + dy, head.pt2.x + dx, head.pt2.y + dy);
  }
  private void addLineJoin(PointFP lastPoint, PointFP currPoint, PointFP nextPoint) {
    if (lastPoint == null
        || currPoint == null
        || nextPoint == null
        || nextPoint.equals(currPoint)
        || lastPoint.equals(currPoint)) {
      return;
    }

    PointFP p1 = null, p2 = null;
    LineFP head, tail, lastHead, lastTail;
    calcHeadTail(currPoint, nextPoint, head = new LineFP(), tail = new LineFP());
    calcHeadTail(lastPoint, currPoint, lastHead = new LineFP(), lastTail = new LineFP());
    boolean cross1, cross2, needLineJoin = false;
    PointFP pi1 = new PointFP();
    PointFP pi2 = new PointFP();

    cross1 =
        LineFP.intersects(
            new LineFP(head.pt1, tail.pt1), new LineFP(lastHead.pt1, lastTail.pt1), pi1);
    cross2 =
        LineFP.intersects(
            new LineFP(head.pt2, tail.pt2), new LineFP(lastHead.pt2, lastTail.pt2), pi2);
    if (cross1 && !cross2 && pi1.x != SingleFP.NaN) {
      p1 = lastTail.pt2;
      p2 = head.pt2;
      needLineJoin = true;
    } else if (!cross1 && cross2 && pi2.x != SingleFP.NaN) {
      p1 = lastTail.pt1;
      p2 = head.pt1;
      needLineJoin = true;
    }
    if (needLineJoin) {
      outline.addMoveTo(cross1 ? pi1 : pi2);
      outline.addLineTo(cross1 ? p2 : p1);
      if (lineJoin == PenFP.LINEJOIN_MITER) {
        outline.addLineTo(cross1 ? pi2 : pi1);
      }
      outline.addLineTo(cross1 ? p1 : p2);
      outline.addClose();
      if (lineJoin == PenFP.LINEJOIN_ROUND) {
        addLineCap(cross2 ? pi2 : pi1, currPoint, PenFP.LINECAP_ROUND);
      }
    }
  }