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

Function createPaddingPolygon

lib/offset-polygon.js:130–156  ·  view source on GitHub ↗
(polygon, offset, arcSegments)

Source from the content-addressed store, hash-verified

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