shape.hpp 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // shape.hpp
  3. // math
  4. //
  5. // Created by Sam Jaffe on 7/5/16.
  6. //
  7. #pragma once
  8. #include "vector/vector.hpp"
  9. #include "math_fwd.hpp"
  10. namespace math { namespace dim2 {
  11. using point = vec2;
  12. struct line {
  13. float length() const;
  14. float slope() const;
  15. point first, second;
  16. };
  17. struct circle {
  18. point center;
  19. float radius;
  20. };
  21. struct triangle {
  22. point a, b, c;
  23. };
  24. struct quad {
  25. point ll, lr, ur, ul;
  26. };
  27. struct rectangle {
  28. operator quad() const;
  29. point origin, size;
  30. };
  31. struct square {
  32. operator rectangle() const;
  33. operator quad() const;
  34. point origin;
  35. float size;
  36. };
  37. }}
  38. namespace math { namespace shapes {
  39. std::vector<dim2::line> segments(dim2::quad const & shape);
  40. }}
  41. namespace math { namespace lines {
  42. bool parallel(dim2::line const & lhs, dim2::line const & rhs);
  43. dim2::point intersection(dim2::line const & lhs, dim2::line const & rhs);
  44. dim2::line orthogonal(dim2::line const & from, dim2::point const & to);
  45. }}