PenroseTiling.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <boost/geometry.hpp>
  13. #include <boost/geometry/geometries/point_xy.hpp>
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. namespace vstd
  16. {
  17. class RNG;
  18. }
  19. using namespace boost::geometry;
  20. typedef std::array<uint32_t, 3> TIndices;
  21. const float PI_CONSTANT = 3.141592f;
  22. class Point2D : public model::d2::point_xy<float>
  23. {
  24. public:
  25. using point_xy::point_xy;
  26. Point2D operator * (float scale) const;
  27. Point2D operator / (float scale) const;
  28. Point2D operator + (const Point2D& other) const;
  29. Point2D operator - (const Point2D& other) const;
  30. Point2D rotated(float radians) const;
  31. bool operator < (const Point2D& other) const;
  32. bool operator == (const Point2D& other) const;
  33. std::string toString() const;
  34. };
  35. Point2D rotatePoint(const Point2D& point, double radians, const Point2D& origin);
  36. class Triangle
  37. {
  38. public:
  39. ~Triangle();
  40. const bool tiling;
  41. TIndices indices;
  42. std::vector<Triangle *> subTriangles;
  43. Triangle(bool t_123, const TIndices & inds);
  44. };
  45. class PenroseTiling
  46. {
  47. public:
  48. const float PHI = 1.0 / ((1.0 + std::sqrt(5.0)) / 2);
  49. const uint32_t POLY = 10; // Number of symmetries?
  50. const float BASE_SIZE = 1.25f;
  51. const uint32_t DEPTH = 8; //Recursion depth
  52. const bool P2 = false; // Tiling type
  53. std::set<Point2D> generatePenroseTiling(size_t numZones, vstd::RNG * rand);
  54. private:
  55. void split(Triangle& p, std::vector<Point2D>& points, std::array<std::vector<uint32_t>, 5>& indices, uint32_t depth);
  56. };
  57. VCMI_LIB_NAMESPACE_END