-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangle.h
48 lines (40 loc) · 1.61 KB
/
triangle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef TRIANGLE_H
#define TRIANGLE_H
#include <utility>
#include <list>
#include <memory>
#include <QPolygonF>
#include <QVector2D>
static inline QPointF getVector(QPointF &from, QPointF &to, double length)
{
return (QVector2D(to - from).normalized()*length).toPointF();
}
class Triangle
{
enum {SommetA = 0, SommetB = 1, SommetC = 2};
public:
Triangle(bool acute, QPointF A, QPointF B, QPointF C, int acute_pattern = 0, int obtuse_pattern = 0, bool acute_double_cut = true, bool obtuse_double_cut = false);
Triangle(bool acute, QPolygonF triangle, int acute_pattern = 0, int obtuse_pattern = 0, bool acute_double_cut = true, bool obtuse_double_cut = false);
void invert();
double getBaseLength();
std::pair<Triangle, Triangle> cut();
void generate();
std::list<std::pair<QPolygonF, bool>> getTriangles(unsigned int level);
private:
struct Properties
{
Properties(int acute_pattern = 0, int obtuse_pattern = 0, bool acute_double_cut = true, bool obtuse_double_cut = false) :
acute_pattern_(acute_pattern), obtuse_pattern_(obtuse_pattern), acute_double_cut_(acute_double_cut), obtuse_double_cut_(obtuse_double_cut) {}
int acute_pattern_;
int obtuse_pattern_;
bool acute_double_cut_;
bool obtuse_double_cut_;
};
Triangle(bool acute, QPointF A, QPointF B, QPointF C, std::shared_ptr<Properties> properties);
Triangle(bool acute, QPolygonF, std::shared_ptr<Properties> properties);
bool acute_;
QPolygonF triangle_;
std::vector<Triangle> sub_triangles_;
std::shared_ptr<Properties> properties_;
};
#endif // TRIANGLE_H