PenroseTiling.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * PenroseTiling.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../GameConstants.h"
  12. #include "../CRandomGenerator.h"
  13. #include <boost/geometry.hpp>
  14. #include <boost/geometry/geometries/point_xy.hpp>
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. using namespace boost::geometry;
  17. typedef std::array<uint32_t, 3> TIndices;
  18. const float PI_CONSTANT = 3.141592f;
  19. class Point2D : public model::d2::point_xy<float>
  20. {
  21. public:
  22. using point_xy::point_xy;
  23. Point2D operator * (float scale) const;
  24. Point2D operator + (const Point2D& other) const;
  25. Point2D rotated(float radians) const;
  26. bool operator < (const Point2D& other) const;
  27. };
  28. Point2D rotatePoint(const Point2D& point, double radians, const Point2D& origin);
  29. class Triangle
  30. {
  31. public:
  32. ~Triangle();
  33. const bool tiling;
  34. TIndices indices;
  35. std::vector<Triangle *> subTriangles;
  36. Triangle(bool t_123, const TIndices & inds);
  37. };
  38. class PenroseTiling
  39. {
  40. public:
  41. const float PHI = 1.0 / ((1.0 + std::sqrt(5.0)) / 2);
  42. const uint32_t POLY = 10; // Number of symmetries?
  43. const float BASE_SIZE = 1.25f;
  44. const uint32_t DEPTH = 7; //Recursion depth
  45. const bool P2 = false; // Tiling type
  46. std::set<Point2D> generatePenroseTiling(size_t numZones, CRandomGenerator * rand);
  47. private:
  48. void split(Triangle& p, std::vector<Point2D>& points, std::array<std::vector<uint32_t>, 5>& indices, uint32_t depth);
  49. };
  50. VCMI_LIB_NAMESPACE_END