common.cpp 665 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // common.cpp
  3. // math
  4. //
  5. // Created by Sam Jaffe on 8/20/16.
  6. //
  7. #include "common.hpp"
  8. #include "angle.hpp"
  9. #include "math_fwd.hpp"
  10. #include "shape.hpp"
  11. #include "vector.hpp"
  12. namespace math {
  13. vec2 rotate(vec2 const & c, vec2 const & p, radian r) {
  14. vec2 trans = p - c;
  15. vec2 vcos = trans * static_cast<float>(cos(r));
  16. vec2 vsin = trans * static_cast<float>(sin(r));
  17. return {{
  18. vcos[0] - vsin[1] + c[0],
  19. vsin[0] - vcos[1] + c[1]
  20. }};
  21. }
  22. quad rotate(vec2 const & c, quad const & q, radian r) {
  23. return {
  24. rotate(c, q.ll, r),
  25. rotate(c, q.lr, r),
  26. rotate(c, q.ur, r),
  27. rotate(c, q.ul, r)
  28. };
  29. }
  30. }