(polygon, offset, arcSegments)
| 127 | return marginPolygon; |
| 128 | } |
| 129 | function 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 | } |
| 156 | export default function offsetPolygon(vertices, offset, arcSegments = 0) { |
| 157 | const polygon = createPolygon(vertices); |
| 158 | if (offset > 0) { |
no test coverage detected