PenroseTiling.h 1.7 KB

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