addCapGeometry method

dynamic addCapGeometry(
  1. dynamic center,
  2. dynamic p1,
  3. dynamic p2,
  4. dynamic joinIsOnLeftSide,
  5. dynamic start,
  6. dynamic u,
)

Implementation

addCapGeometry(center, p1, p2, joinIsOnLeftSide, start, u) {
  // param center: End point of the path
  // param p1, p2: Left and right cap points

  switch (style["strokeLineCap"]) {
    case 'round':
      if (start) {
        makeCircularSector(center, p2, p1, u, 0.5);
      } else {
        makeCircularSector(center, p1, p2, u, 0.5);
      }

      break;

    case 'square':
      if (start) {
        tempV2_1.subVectors(p1, center);
        tempV2_2.set(tempV2_1.y, -tempV2_1.x);

        tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
        tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);

        // Modify already existing vertices
        if (joinIsOnLeftSide) {
          tempV2_3.toArray(vertices, 1 * 3);
          tempV2_4.toArray(vertices, 0 * 3);
          tempV2_4.toArray(vertices, 3 * 3);
        } else {
          tempV2_3.toArray(vertices, 1 * 3);
          tempV2_3.toArray(vertices, 3 * 3);
          tempV2_4.toArray(vertices, 0 * 3);
        }
      } else {
        tempV2_1.subVectors(p2, center);
        tempV2_2.set(tempV2_1.y, -tempV2_1.x);

        tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
        tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);

        var vl = vertices.length;

        // Modify already existing vertices
        if (joinIsOnLeftSide) {
          tempV2_3.toArray(vertices, vl - 1 * 3);
          tempV2_4.toArray(vertices, vl - 2 * 3);
          tempV2_4.toArray(vertices, vl - 4 * 3);
        } else {
          tempV2_3.toArray(vertices, vl - 2 * 3);
          tempV2_4.toArray(vertices, vl - 1 * 3);
          tempV2_4.toArray(vertices, vl - 4 * 3);
        }
      }

      break;

    case 'butt':
    default:

      // Nothing to do here
      break;
  }
}