QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RTriangle.h
Go to the documentation of this file.
1 
20 #ifndef RTRIANGLE_H
21 #define RTRIANGLE_H
22 
23 #include "../core_global.h"
24 
25 #include "RExplodable.h"
26 #include "RShape.h"
27 #include "RVector.h"
28 #include "RLine.h"
29 
30 class RBox;
31 
32 #ifndef RDEFAULT_MIN1
33 #define RDEFAULT_MIN1 -1
34 #endif
35 
36 
47 public:
48  RTriangle();
49  RTriangle(const RVector& p1, const RVector& p2, const RVector& p3);
50  virtual ~RTriangle();
51 
52  virtual RTriangle* clone() const {
53  return new RTriangle(*this);
54  }
55 
56  virtual void to2D();
57 
58 
59  static RTriangle createArrow(const RVector& position, double direction, double size);
60 
61  virtual RBox getBoundingBox() const;
62  virtual double getLength() const;
63  RVector getCorner(int i) const;
64  void setCorner(int i, const RVector& p);
65 
66  virtual QList<RVector> getEndPoints() const;
67  virtual QList<RVector> getMiddlePoints() const;
68  virtual QList<RVector> getCenterPoints() const;
69  virtual QList<RVector> getPointsWithDistanceToEnd(
70  double distance, RS::From from = RS::FromAny) const;
71 
72  double getDistanceTo(const RVector& point, bool limited = true) const;
73  virtual RVector getVectorTo(const RVector& point, bool limited = true) const;
74  //virtual RVector getVectorTo(const RLine& line, bool limited = true) const;
75 
76  virtual RVector getNormal() const;
77 
78 // virtual bool intersectsWith(const RShape& other, bool limited) const;
79 
80 // virtual QList<RVector> getIntersectionPoints(const RShape& other,
81 // bool limited) const;
82 
83  bool isPointInTriangle(const RVector& p, bool treatAsQuadrant = false) const;
84  bool isPointInQuadrant(const RVector& p) const;
85 
86  double getD() const;
87 
88  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
89 
90  virtual bool move(const RVector& offset) {
91  corner[0].move(offset);
92  corner[1].move(offset);
93  corner[2].move(offset);
94  return true;
95  }
96  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
97  corner[0].rotate(rotation, center);
98  corner[1].rotate(rotation, center);
99  corner[2].rotate(rotation, center);
100  return true;
101  }
102  virtual bool scale(const RVector& scaleFactors, const RVector& center =
103  RVector()) {
104  corner[0].scale(scaleFactors, center);
105  corner[1].scale(scaleFactors, center);
106  corner[2].scale(scaleFactors, center);
107  return true;
108  }
109  virtual bool mirror(const RLine& axis) {
110  corner[0].mirror(axis);
111  corner[1].mirror(axis);
112  corner[2].mirror(axis);
113  return true;
114  }
115  virtual bool flipHorizontal() {
116  corner[0].flipHorizontal();
117  corner[1].flipHorizontal();
118  corner[2].flipHorizontal();
119  return true;
120  }
121  virtual bool flipVertical() {
122  corner[0].flipVertical();
123  corner[1].flipVertical();
124  corner[2].flipVertical();
125  return true;
126  }
127 
128  QSharedPointer<RShape> getTransformed(const QTransform& transform) const {
129  return QSharedPointer<RShape>(
130  new RTriangle(
131  corner[0].getTransformed2d(transform),
132  corner[1].getTransformed2d(transform),
133  corner[2].getTransformed2d(transform)
134  )
135  );
136  }
137 
138 protected:
139  virtual void print(QDebug dbg) const;
140 
141 public:
142  RVector corner[3];
143 };
144 
145 Q_DECLARE_METATYPE(QList<RTriangle>)
149 Q_DECLARE_METATYPE(QSharedPointer<RTriangle>)
150 Q_DECLARE_METATYPE(QSharedPointer<RTriangle>*)
151 
152 #endif