| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- export type LngLat = [number, number]
- /**
- * generateInnerPolygon (noop)
- * 外圈/回字形内圈生成逻辑已移除 — 保留同名导出以避免调用处报错。
- * 返回空数组表示不生成内圈。
- */
- export function generateInnerPolygon(outer: Array<LngLat>, insetRatio = 0.25): Array<LngLat> {
- // outer: expected 4 points in order (clockwise or ccw). We compute the polygon
- // that is an inward-scaled rectangle centered at the outer centroid.
- // insetRatio: 0..0.5, how far the inner polygon is from the outer towards center.
- if (!outer || outer.length < 4) return []
- // clamp insetRatio
- const r = Math.max(0, Math.min(0.49, insetRatio))
- // compute centroid (average)
- let cx = 0
- let cy = 0
- outer.forEach(p => {
- cx += p[0]
- cy += p[1]
- })
- cx = cx / outer.length
- cy = cy / outer.length
- // for each corner, move it toward centroid by ratio r
- const inner: Array<LngLat> = outer.map((p): LngLat => {
- const dx = p[0] - cx
- const dy = p[1] - cy
- return [cx + dx * (1 - r), cy + dy * (1 - r)]
- })
- return inner
- }
|