polygon.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * polygon.h
  3. * Copyright (C) Andrew Tridgell 2011
  4. *
  5. * This file is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This file is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include "vector2.h"
  20. template <typename T>
  21. bool Polygon_outside(const Vector2<T> &P, const Vector2<T> *V, unsigned n) WARN_IF_UNUSED;
  22. template <typename T>
  23. bool Polygon_complete(const Vector2<T> *V, unsigned n) WARN_IF_UNUSED;
  24. /*
  25. determine if the polygon of N verticies defined by points V is
  26. intersected by a line from point p1 to point p2
  27. intersection argument returns the intersection closest to p1
  28. */
  29. bool Polygon_intersects(const Vector2f *V, unsigned N, const Vector2f &p1, const Vector2f &p2, Vector2f &intersection) WARN_IF_UNUSED;
  30. /*
  31. return the closest distance that a line from p1 to p2 comes to an
  32. edge of closed polygon V, defined by N points
  33. negative numbers indicate the line cross into the polygon with the negative size being the distance from p2 to the intersection point closest to p1
  34. */
  35. float Polygon_closest_distance_line(const Vector2f *V, unsigned N, const Vector2f &p1, const Vector2f &p2);
  36. /*
  37. return the closest distance that a point p comes to an edge of
  38. closed polygon V, defined by N points
  39. */
  40. float Polygon_closest_distance_point(const Vector2f *V, unsigned N, const Vector2f &p);