Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sum = d0 + d1;
if (sum !== 0) {
d0 /= sum;
d1 /= sum;
}
const v1 = vec2.scale([], v, -d0);
const v2 = vec2.scale([], v, d1);
let cp0 = vec2.add([], point, v1);
let cp1 = vec2.add([], point, v2);
if (hasConstraint) {
cp0 = vec2.max([], cp0, min);
cp0 = vec2.min([], cp0, max);
cp1 = vec2.max([], cp1, min);
cp1 = vec2.min([], cp1, max);
}
cps.push(cp0);
cps.push(cp1);
}
if (isLoop) {
cps.push(cps.shift());
}
return cps;
};
constraint: PointArray[],
): PointArray[] => {
const cps = [];
let prevPoint: PointArray;
let nextPoint: PointArray;
const hasConstraint = !!constraint;
let min: PointArray;
let max: PointArray;
if (hasConstraint) {
min = [ Infinity, Infinity ];
max = [ -Infinity, -Infinity ];
for (let i = 0, l = points.length; i < l; i++) {
const point = points[i];
min = vector2.min([], min, point);
max = vector2.max([], max, point);
}
min = vector2.min([], min, constraint[0]);
max = vector2.max([], max, constraint[1]);
}
for (let i = 0, len = points.length; i < len; i++) {
const point = points[i];
if (isLoop) {
prevPoint = points[i ? i - 1 : len - 1];
nextPoint = points[(i + 1) % len];
} else {
if (i === 0 || i === len - 1) {
cps.push(point);
continue;
} else {
constraint: Position[]
): Position[] => {
const cps = [];
let prevPoint: Position;
let nextPoint: Position;
const hasConstraint = !!constraint;
let min: Position;
let max: Position;
if (hasConstraint) {
min = [Infinity, Infinity];
max = [-Infinity, -Infinity];
for (let i = 0, l = points.length; i < l; i++) {
const point = points[i];
min = vec2.min([], min, point);
max = vec2.max([], max, point);
}
min = vec2.min([], min, constraint[0]);
max = vec2.max([], max, constraint[1]);
}
for (let i = 0, len = points.length; i < len; i++) {
const point = points[i];
if (isLoop) {
prevPoint = points[i ? i - 1 : len - 1];
nextPoint = points[(i + 1) % len];
} else {
if (i === 0 || i === len - 1) {
cps.push(point);
continue;
} else {
if (sum !== 0) {
d0 /= sum;
d1 /= sum;
}
const v1 = vec2.scale([], v, -d0);
const v2 = vec2.scale([], v, d1);
let cp0 = vec2.add([], point, v1);
let cp1 = vec2.add([], point, v2);
if (hasConstraint) {
cp0 = vec2.max([], cp0, min);
cp0 = vec2.min([], cp0, max);
cp1 = vec2.max([], cp1, min);
cp1 = vec2.min([], cp1, max);
}
cps.push(cp0);
cps.push(cp1);
}
if (isLoop) {
cps.push(cps.shift());
}
return cps;
};
const sum = d0 + d1;
if (sum !== 0) {
d0 /= sum;
d1 /= sum;
}
const v1 = vector2.scale([], v, -d0);
const v2 = vector2.scale([], v, d1);
let cp0 = vector2.add([], point, v1);
let cp1 = vector2.add([], point, v2);
if (hasConstraint) {
cp0 = vector2.max([], cp0, min);
cp0 = vector2.min([], cp0, max);
cp1 = vector2.max([], cp1, min);
cp1 = vector2.min([], cp1, max);
}
cps.push(cp0);
cps.push(cp1);
}
if (isLoop) {
cps.push(cps.shift());
}
return cps;
};
let prevPoint: PointArray;
let nextPoint: PointArray;
const hasConstraint = !!constraint;
let min: PointArray;
let max: PointArray;
if (hasConstraint) {
min = [ Infinity, Infinity ];
max = [ -Infinity, -Infinity ];
for (let i = 0, l = points.length; i < l; i++) {
const point = points[i];
min = vector2.min([], min, point);
max = vector2.max([], max, point);
}
min = vector2.min([], min, constraint[0]);
max = vector2.max([], max, constraint[1]);
}
for (let i = 0, len = points.length; i < len; i++) {
const point = points[i];
if (isLoop) {
prevPoint = points[i ? i - 1 : len - 1];
nextPoint = points[(i + 1) % len];
} else {
if (i === 0 || i === len - 1) {
cps.push(point);
continue;
} else {
prevPoint = points[i - 1];
nextPoint = points[i + 1];
}
let prevPoint: Position;
let nextPoint: Position;
const hasConstraint = !!constraint;
let min: Position;
let max: Position;
if (hasConstraint) {
min = [Infinity, Infinity];
max = [-Infinity, -Infinity];
for (let i = 0, l = points.length; i < l; i++) {
const point = points[i];
min = vec2.min([], min, point);
max = vec2.max([], max, point);
}
min = vec2.min([], min, constraint[0]);
max = vec2.max([], max, constraint[1]);
}
for (let i = 0, len = points.length; i < len; i++) {
const point = points[i];
if (isLoop) {
prevPoint = points[i ? i - 1 : len - 1];
nextPoint = points[(i + 1) % len];
} else {
if (i === 0 || i === len - 1) {
cps.push(point);
continue;
} else {
prevPoint = points[i - 1];
nextPoint = points[i + 1];
}
if (sum !== 0) {
d0 /= sum;
d1 /= sum;
}
const v1 = vector2.scale([], v, -d0);
const v2 = vector2.scale([], v, d1);
let cp0 = vector2.add([], point, v1);
let cp1 = vector2.add([], point, v2);
if (hasConstraint) {
cp0 = vector2.max([], cp0, min);
cp0 = vector2.min([], cp0, max);
cp1 = vector2.max([], cp1, min);
cp1 = vector2.min([], cp1, max);
}
cps.push(cp0);
cps.push(cp1);
}
if (isLoop) {
cps.push(cps.shift());
}
return cps;
};