PenroseTiling.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. std::string toString() const;
  28. };
  29. Point2D rotatePoint(const Point2D& point, double radians, const Point2D& origin);
  30. class Triangle
  31. {
  32. public:
  33. ~Triangle();
  34. const bool tiling;
  35. TIndices indices;
  36. std::vector<Triangle *> subTriangles;
  37. Triangle(bool t_123, const TIndices & inds);
  38. };
  39. class PenroseTiling
  40. {
  41. public:
  42. const float PHI = 1.0 / ((1.0 + std::sqrt(5.0)) / 2);
  43. const uint32_t POLY = 10; // Number of symmetries?
  44. const float BASE_SIZE = 1.25f;
  45. const uint32_t DEPTH = 7; //Recursion depth
  46. const bool P2 = false; // Tiling type
  47. std::set<Point2D> generatePenroseTiling(size_t numZones, CRandomGenerator * rand);
  48. private:
  49. void split(Triangle& p, std::vector<Point2D>& points, std::array<std::vector<uint32_t>, 5>& indices, uint32_t depth);
  50. };
  51. VCMI_LIB_NAMESPACE_END