PenroseTiling.h 1.6 KB

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