points.py 557 B

123456789101112131415161718192021
  1. # Copyright (c) 2019 Manfred Moitzi
  2. # License: MIT License
  3. from typing import TYPE_CHECKING, Iterable
  4. from ezdxf.math.vector import Vector
  5. if TYPE_CHECKING:
  6. from ezdxf.eztypes import Vertex
  7. def closest_point(base: 'Vertex', points: Iterable['Vertex']) -> Vector:
  8. base = Vector(base)
  9. min_dist = None
  10. found = None
  11. for point in points:
  12. p = Vector(point)
  13. dist = (base - p).magnitude
  14. if (min_dist is None) or (dist < min_dist):
  15. min_dist = dist
  16. found = p
  17. return found