huiZiArea.ts 1.1 KB

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