MCPcopy Create free account
hub / github.com/Stanko/offset-polygon / createPaddingPolygon

Function createPaddingPolygon

docs/src/offset-polygon.js:129–155  ·  view source on GitHub ↗
(polygon, offset, arcSegments)

Source from the content-addressed store, hash-verified

127 return marginPolygon;
128}
129function createPaddingPolygon(polygon, offset, arcSegments) {
130 const offsetEdges = [];
131 for (let i = 0; i < polygon.edges.length; i++) {
132 const edge = polygon.edges[i];
133 const dx = edge.inwardNormal.x * offset;
134 const dy = edge.inwardNormal.y * offset;
135 offsetEdges.push(createOffsetEdge(edge, dx, dy));
136 }
137 const vertices = [];
138 for (let i = 0; i < offsetEdges.length; i++) {
139 const thisEdge = offsetEdges[i];
140 const prevEdge = offsetEdges[(i + offsetEdges.length - 1) % offsetEdges.length];
141 const vertex = edgesIntersection(prevEdge, thisEdge);
142 if (vertex && (!vertex.isIntersectionOutside || arcSegments < 1)) {
143 vertices.push({
144 x: vertex.x,
145 y: vertex.y
146 });
147 } else {
148 const arcCenter = polygon.edges[i].vertex1;
149 appendArc(arcSegments, vertices, arcCenter, offset, prevEdge.vertex2, thisEdge.vertex1, true);
150 }
151 }
152 const paddingPolygon = createPolygon(vertices);
153 paddingPolygon.offsetEdges = offsetEdges;
154 return paddingPolygon;
155}
156export default function offsetPolygon(vertices, offset, arcSegments = 0) {
157 const polygon = createPolygon(vertices);
158 if (offset > 0) {

Callers 1

offsetPolygonFunction · 0.70

Calls 4

createOffsetEdgeFunction · 0.70
edgesIntersectionFunction · 0.70
appendArcFunction · 0.70
createPolygonFunction · 0.70

Tested by

no test coverage detected