UNPKG

gl2d

Version:

2D graphics package for WebGL

34 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var vec2_1 = require("../struct/vec2"); /** * Measures the miter vector needed to join the two specified lines. Assumes the lines are measured from points listed in CCW order. * @param line1 The nonzero vector from the start of the first line to the end of the first line. Will not be modified. * @param line2 The nonzero vector from the start of the second line to the end of the second line. Will not be modified. * @param lineWidth The width of the second line (or half the width, if joining at the center of the lines). * @param miterLimit The maximum allowable miter length before a bevel is applied. Usually some multiple of lineWidth. */ function measureMiter(line1, line2, lineWidth, miterLimit) { // Measure the ortho norm of the previous vector and the next vector. var n1 = vec2_1.Vec2.create(line1); n1.normalize(); n1.rotateRight(); var n2 = vec2_1.Vec2.create(line2); n2.normalize(); n2.rotateRight(); // Average the ortho norms to get the miter vector. var miter = vec2_1.Vec2.create(n1); miter.add(n2); miter.normalize(); // Measure the length of the miter by projecting it onto one of the ortho norms and inverting it. var length = lineWidth / miter.dot(n2); // Ensure length does not exceed miter limit if (length > miterLimit) { length = miterLimit; } // Scale vector to the measured length miter.mulScalar(length); return miter; } exports.measureMiter = measureMiter; //# sourceMappingURL=miter.js.map