PR fixes
This commit is contained in:
parent
7e7cb3ae85
commit
54ac95c4e6
111
Frontline.js
111
Frontline.js
@ -32,17 +32,11 @@ export function getFrontline(frontlineData, protrusionData = null) {
|
|||||||
let bodyPolygonRight = [];
|
let bodyPolygonRight = [];
|
||||||
|
|
||||||
if (style === BOTH_SIDES) {
|
if (style === BOTH_SIDES) {
|
||||||
const {
|
const left = computeSides(splinePoints, frontlineData.offsetDistance, LEFT_SIDE);
|
||||||
leftSidePoints: leftSidePointsLeftSide,
|
bodyPolygonLeft = [...left.leftSidePoints, ...left.rightSidePoints.reverse()];
|
||||||
rightSidePoints: rightSidePointsLeftSide
|
|
||||||
} = computeSides(splinePoints, frontlineData.offsetDistance, LEFT_SIDE);
|
|
||||||
bodyPolygonLeft = [...leftSidePointsLeftSide, ...rightSidePointsLeftSide.reverse()];
|
|
||||||
|
|
||||||
const {
|
const right = computeSides(splinePoints, frontlineData.offsetDistance, RIGHT_SIDE);
|
||||||
leftSidePoints: leftSidePointsRightSide,
|
bodyPolygonRight = [...right.leftSidePoints, ...right.rightSidePoints.reverse()];
|
||||||
rightSidePoints: rightSidePointsRightSide
|
|
||||||
} = computeSides(splinePoints, frontlineData.offsetDistance, RIGHT_SIDE);
|
|
||||||
bodyPolygonRight = [...leftSidePointsRightSide, ...rightSidePointsRightSide.reverse()];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { leftSidePoints, rightSidePoints } = computeSides(splinePoints, frontlineData.offsetDistance, frontlineData.style);
|
const { leftSidePoints, rightSidePoints } = computeSides(splinePoints, frontlineData.offsetDistance, frontlineData.style);
|
||||||
@ -64,50 +58,29 @@ export function getFrontline(frontlineData, protrusionData = null) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultPolygon = turf.polygon([polygonCoords]);
|
return turf.polygon([polygonCoords]);
|
||||||
return resultPolygon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const polygonCoordsLeft= [
|
|
||||||
...bodyPolygonLeft,
|
|
||||||
bodyPolygonLeft[0]
|
|
||||||
];
|
|
||||||
|
|
||||||
const polygonCoordsRight= [
|
|
||||||
...bodyPolygonRight,
|
|
||||||
bodyPolygonRight[0]
|
|
||||||
];
|
|
||||||
|
|
||||||
const polygonCoords = [
|
const prostrusionsData = (points, sidePoints) => {
|
||||||
...bodyPolygon,
|
const coords = [...points, points[0]];
|
||||||
bodyPolygon[0]
|
const basePoly = turf.polygon([coords]);
|
||||||
];
|
return constructProstrusions(basePoly, sidePoints, protrusionData, frontlineData);
|
||||||
|
};
|
||||||
|
|
||||||
if (style === LEFT_SIDE) {
|
if (style === LEFT_SIDE) {
|
||||||
let mainPoly = turf.polygon([[...polygonCoords]]);
|
return {
|
||||||
const finalPoly = constructProstrusions(mainPoly, leftSidePoints, protrusionData, frontlineData);
|
|
||||||
|
|
||||||
return {
|
|
||||||
rightPoly: null,
|
rightPoly: null,
|
||||||
leftPoly: finalPoly,
|
leftPoly: prostrusionsData(bodyPolygon, leftSidePoints)
|
||||||
};
|
};
|
||||||
} else if (style === RIGHT_SIDE) {
|
} else if (style === RIGHT_SIDE) {
|
||||||
let mainPoly = turf.polygon([[...polygonCoords]]);
|
return {
|
||||||
const finalPoly = constructProstrusions(mainPoly, rightSidePoints, protrusionData, frontlineData);
|
rightPoly: prostrusionsData(bodyPolygon, rightSidePoints),
|
||||||
|
leftPoly: null
|
||||||
return {
|
|
||||||
rightPoly: finalPoly,
|
|
||||||
leftPoly: null,
|
|
||||||
};
|
};
|
||||||
} else if (style === BOTH_SIDES) {
|
} else if (style === BOTH_SIDES) {
|
||||||
let mainPoly = turf.polygon([[...polygonCoordsRight]]);
|
return {
|
||||||
const finalPoly = constructProstrusions(mainPoly, rightSidePoints, protrusionData, frontlineData);
|
rightPoly: prostrusionsData(bodyPolygonRight, rightSidePoints),
|
||||||
let secondaryPoly = turf.polygon([[...polygonCoordsLeft]]);
|
leftPoly: prostrusionsData(bodyPolygonLeft, leftSidePoints),
|
||||||
const secondaryfinalPoly = constructProstrusions(secondaryPoly, leftSidePoints, protrusionData, frontlineData);
|
|
||||||
|
|
||||||
return {
|
|
||||||
rightPoly: finalPoly,
|
|
||||||
leftPoly: secondaryfinalPoly,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,31 +120,23 @@ function computeSplinePoints(points, density) {
|
|||||||
function computeSides(splinePoints, offsetDistance, style = LEFT_SIDE) {
|
function computeSides(splinePoints, offsetDistance, style = LEFT_SIDE) {
|
||||||
let leftSidePoints = [];
|
let leftSidePoints = [];
|
||||||
let rightSidePoints = [];
|
let rightSidePoints = [];
|
||||||
let accumulatedDistance = 0;
|
|
||||||
|
|
||||||
for (let i = 1; i < splinePoints.length; i++) {
|
for (let i = 1; i < splinePoints.length; i++) {
|
||||||
const previousPoint = splinePoints[i - 1];
|
const previousPoint = splinePoints[i - 1];
|
||||||
const currentPoint = splinePoints[i];
|
const currentPoint = splinePoints[i];
|
||||||
|
|
||||||
const segmentDistance = turf.distance(turf.point(previousPoint), turf.point(currentPoint), { units: METERS });
|
|
||||||
accumulatedDistance += segmentDistance;
|
|
||||||
const bearing = turf.bearing(turf.point(previousPoint), turf.point(currentPoint));
|
const bearing = turf.bearing(turf.point(previousPoint), turf.point(currentPoint));
|
||||||
let leftPoint, rightPoint;
|
|
||||||
|
|
||||||
if (style === LEFT_SIDE) {
|
const leftPoint = style === RIGHT_SIDE
|
||||||
leftPoint = turf.destination(turf.point(currentPoint), offsetDistance, bearing - 90, { units: METERS }).geometry.coordinates;
|
? currentPoint
|
||||||
rightPoint = currentPoint;
|
: turf.destination(turf.point(currentPoint), offsetDistance, bearing - 90, { units: METERS }).geometry.coordinates;
|
||||||
} else if (style === RIGHT_SIDE) {
|
|
||||||
leftPoint = currentPoint;
|
const rightPoint = style === LEFT_SIDE
|
||||||
rightPoint = turf.destination(turf.point(currentPoint), offsetDistance, bearing + 90, { units: METERS }).geometry.coordinates;
|
? currentPoint
|
||||||
} else if (style === BOTH_SIDES) {
|
: turf.destination(turf.point(currentPoint), offsetDistance, bearing + 90, { units: METERS }).geometry.coordinates;
|
||||||
leftPoint = turf.destination(turf.point(currentPoint), offsetDistance, bearing - 90, { units: METERS }).geometry.coordinates;
|
|
||||||
rightPoint = turf.destination(turf.point(currentPoint), offsetDistance, bearing + 90, { units: METERS }).geometry.coordinates;
|
|
||||||
}
|
|
||||||
|
|
||||||
leftSidePoints.push(leftPoint);
|
leftSidePoints.push(leftPoint);
|
||||||
rightSidePoints.push(rightPoint);
|
rightSidePoints.push(rightPoint);
|
||||||
accumulatedDistance = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { leftSidePoints, rightSidePoints };
|
return { leftSidePoints, rightSidePoints };
|
||||||
@ -181,7 +146,7 @@ function computeProtrusion(leftSidePoints, protrusionData, sideOffset) {
|
|||||||
const protrusions = [];
|
const protrusions = [];
|
||||||
const segments = [];
|
const segments = [];
|
||||||
let totalLength = 0;
|
let totalLength = 0;
|
||||||
|
|
||||||
for (let i = 0; i < leftSidePoints.length - 1; i++) {
|
for (let i = 0; i < leftSidePoints.length - 1; i++) {
|
||||||
const p0 = leftSidePoints[i];
|
const p0 = leftSidePoints[i];
|
||||||
const p1 = leftSidePoints[i + 1];
|
const p1 = leftSidePoints[i + 1];
|
||||||
@ -215,22 +180,26 @@ function computeProtrusion(leftSidePoints, protrusionData, sideOffset) {
|
|||||||
|
|
||||||
const seg = segments[currentSegmentIndex];
|
const seg = segments[currentSegmentIndex];
|
||||||
const localDistance = distance - currentSegmentPos;
|
const localDistance = distance - currentSegmentPos;
|
||||||
|
|
||||||
const pointOnSegment = turf.along(turf.lineString([seg.p0, seg.p1]), localDistance, { units: METERS }).geometry.coordinates;
|
const pointOnSegment = turf.along(turf.lineString([seg.p0, seg.p1]), localDistance, { units: METERS }).geometry.coordinates;
|
||||||
const thicknessOffset = sideOffset * 0.2;
|
const thicknessOffset = sideOffset * 0.2;
|
||||||
const adjustedPoint = turf.destination(turf.point(pointOnSegment), thicknessOffset, seg.bearing + 90, { units: METERS }).geometry.coordinates;
|
|
||||||
const normalBearing = seg.bearing - 90;
|
|
||||||
const tangentBearing = seg.bearing;
|
|
||||||
const centerPoint = turf.destination(turf.point(adjustedPoint), protrusionData.length, normalBearing, { units: METERS }).geometry.coordinates;
|
|
||||||
|
|
||||||
const corner1 = turf.destination(turf.point(adjustedPoint), -protrusionData.startSize, tangentBearing, { units: METERS }).geometry.coordinates;
|
const adjustedPoint = movePoint(pointOnSegment, thicknessOffset, seg.bearing + 90);
|
||||||
const corner2 = turf.destination(turf.point(adjustedPoint), protrusionData.startSize, tangentBearing, { units: METERS }).geometry.coordinates;
|
const centerPoint = movePoint(adjustedPoint, protrusionData.length, seg.bearing - 90);
|
||||||
const corner3 = turf.destination(turf.point(centerPoint), protrusionData.endSize, tangentBearing, { units: METERS }).geometry.coordinates;
|
|
||||||
const corner4 = turf.destination(turf.point(centerPoint), -protrusionData.endSize, tangentBearing, { units: METERS }).geometry.coordinates;
|
|
||||||
|
|
||||||
const polygonCoords = [corner1, corner2, corner3, corner4, corner1];
|
|
||||||
const polygon = turf.polygon([polygonCoords]);
|
const corner1 = movePoint(adjustedPoint, -protrusionData.startSize, seg.bearing);
|
||||||
|
const corner2 = movePoint(adjustedPoint, protrusionData.startSize, seg.bearing);
|
||||||
|
const corner3 = movePoint(centerPoint, protrusionData.endSize, seg.bearing);
|
||||||
|
const corner4 = movePoint(centerPoint, -protrusionData.endSize, seg.bearing);
|
||||||
|
|
||||||
|
const polygon = turf.polygon([[corner1, corner2, corner3, corner4, corner1]]);
|
||||||
protrusions.push(polygon);
|
protrusions.push(polygon);
|
||||||
}
|
}
|
||||||
|
|
||||||
return protrusions;
|
return protrusions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function movePoint(point, distance, bearing) {
|
||||||
|
return turf.destination(turf.point(point), distance, bearing, { units: METERS }).geometry.coordinates;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user