6 #include "../core/log.h" 8 #include <QPainterPath> 12 virtual void render()
override {
13 if (controlPoints().empty()) {
17 shape = std::make_shared<QPainterPath>();
18 shape->addPolygon(QPolygonF(QRectF(-10, -2, 20, 4))
19 .united(QPolygonF(QRectF(-2, -10, 4, 20))));
20 shape->translate(controlPoints().front().x(),
21 controlPoints().front().y());
29 virtual void render()
override {
30 if (controlPoints().size() < 2) {
34 shape = std::make_shared<QPainterPath>();
36 std::min(controlPoints().at(0).x(), controlPoints().at(1).x());
38 std::max(controlPoints().at(0).x(), controlPoints().at(1).x());
40 std::min(controlPoints().at(0).y(), controlPoints().at(1).y());
42 std::max(controlPoints().at(0).y(), controlPoints().at(1).y());
43 shape->addRect(left, top, right - left, bottom - top);
51 virtual void render()
override {
52 shape = std::make_shared<QPainterPath>();
53 QVector<QPointF> points;
54 if (!controlPoints().empty()) {
55 for (
auto &p : controlPoints()) {
56 points.push_back(QPointF(p.x(), p.y()));
59 auto p = controlPoints().front();
60 points.push_back(QPointF(p.x(), p.y()));
63 shape->addPolygon(points);
64 complete = ((controlPoints().size() > 3) &&
65 (controlPoints().front() == controlPoints().back()));
71 virtual void render()
override {
72 shape = std::make_shared<QPainterPath>();
73 QVector<QPointF> points;
74 if (!controlPoints().empty()) {
75 for (
auto &p : controlPoints()) {
76 points.push_back(QPointF(p.x(), p.y()));
79 auto p = controlPoints().front();
80 points.push_back(QPointF(p.x(), p.y()));
83 shape->addPolygon(points);
84 complete = (controlPoints().size() >= 3);
90 virtual void render()
override {
91 shape = std::make_shared<QPainterPath>();
92 QVector<QPointF> points;
93 if (!controlPoints().empty()) {
94 for (
auto &p : controlPoints()) {
95 points.push_back(QPointF(p.x(), p.y()));
98 auto p = controlPoints().front();
99 points.push_back(QPointF(p.x(), p.y()));
102 shape->addPolygon(points);
103 complete = (controlPoints().size() >= 4);
109 virtual void render()
override {
110 if (controlPoints().size() < 2) {
114 shape = std::make_shared<QPainterPath>();
115 double cx = controlPoints().at(0).x();
116 double cy = controlPoints().at(0).y();
117 double r = (controlPoints().at(0) - controlPoints().at(1)).norm();
118 shape->addEllipse(cx - r, cy - r, 2 * r, 2 * r);
126 virtual void render()
override {
127 if (controlPoints().size() < 2) {
131 shape = std::make_shared<QPainterPath>();
132 double cx = (controlPoints().at(0).x() + controlPoints().at(1).x()) * 0.5;
133 double cy = (controlPoints().at(0).y() + controlPoints().at(1).y()) * 0.5;
134 double r = (controlPoints().at(0) - controlPoints().at(1)).norm() * 0.5;
135 shape->addEllipse(cx - r, cy - r, 2 * r, 2 * r);
143 virtual void render()
override {
144 if (controlPoints().size() < 2) {
148 shape = std::make_shared<QPainterPath>();
150 std::min(controlPoints().at(0).x(), controlPoints().at(1).x());
152 std::max(controlPoints().at(0).x(), controlPoints().at(1).x());
154 std::min(controlPoints().at(0).y(), controlPoints().at(1).y());
156 std::max(controlPoints().at(0).y(), controlPoints().at(1).y());
157 shape->addEllipse(left, top, right - left, bottom - top);
165 virtual void constrain()
override {
166 if (controlPoints().size() == 3) {
167 double r = (controlPoints().at(0) - controlPoints().at(2)).norm();
168 auto d = (controlPoints().at(0) - controlPoints().at(1)).normalized();
169 controlPoints().at(2) +=
170 d * d.dot(controlPoints().at(0) - controlPoints().at(2));
171 controlPoints().at(2) =
172 controlPoints().at(0) +
173 (controlPoints().at(2) - controlPoints().at(0)).normalized() * r;
176 virtual void render()
override {
177 if (controlPoints().size() < 2) {
180 }
else if (controlPoints().size() == 2) {
181 shape = std::make_shared<QPainterPath>();
182 double cx = controlPoints().at(0).x();
183 double cy = controlPoints().at(0).y();
184 double r = (controlPoints().at(0) - controlPoints().at(1)).norm();
185 shape->addEllipse(cx - r, cy - r, 2 * r, 2 * r);
188 shape = std::make_shared<QPainterPath>();
189 double width = (controlPoints().at(0) - controlPoints().at(1)).norm() * 2;
190 auto d = (controlPoints().at(0) - controlPoints().at(1)).normalized();
192 std::abs(Eigen::Vector2d(-d.y(), d.x())
193 .dot(controlPoints().at(0) - controlPoints().at(2))) *
195 shape->addEllipse(-width * 0.5, -height * 0.5, width, height);
196 QTransform transform;
197 transform.translate(controlPoints().at(0).x(), controlPoints().at(0).y());
199 std::atan2(controlPoints().at(0).y() - controlPoints().at(1).y(),
200 controlPoints().at(0).x() - controlPoints().at(1).x()) *
202 *shape = transform.map(*shape);