-
Notifications
You must be signed in to change notification settings - Fork 0
/
bounds_curve.cpp
80 lines (60 loc) · 1.81 KB
/
bounds_curve.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "bounds_curve.h"
#include <curve_line.h>
#include <curve_figure.h>
namespace cppgef
{
BoundsCurve::BoundsCurve()
{
}
BoundsCurve::~BoundsCurve()
{
}
void BoundsCurve::setBounds(shared_ptr<ModelElementBase> element, const Rectangle& bounds)
{
shared_ptr< CurveLine > curve_element = dynamic_pointer_cast< CurveLine >(element);
if (curve_element)
{
Point start_pt;
Point end_pt;
Point start_ctrl_pt;
Point end_ctrl_pt;
computePoints (bounds, start_pt, end_pt, start_ctrl_pt, end_ctrl_pt);
curve_element->setStartPoint (start_pt);
curve_element->setEndPoint (end_pt);
curve_element->setStartControlPoint (start_ctrl_pt);
curve_element->setEndControlPoint (end_ctrl_pt);
}
}
void BoundsCurve::setBounds(shared_ptr<Figure> figure, const Rectangle& bounds)
{
shared_ptr< CurveFigure > curve_figure = dynamic_pointer_cast< CurveFigure >(figure);
if (curve_figure)
{
Point start_pt;
Point end_pt;
Point start_ctrl_pt;
Point end_ctrl_pt;
computePoints (bounds, start_pt, end_pt, start_ctrl_pt, end_ctrl_pt);
curve_figure->setStartPoint (start_pt);
curve_figure->setEndPoint (end_pt);
curve_figure->setStartControlPoint (start_ctrl_pt);
curve_figure->setEndControlPoint (end_ctrl_pt);
}
}
void BoundsCurve::computePoints(const Rectangle& bounds, Point& start_point, Point& end_point, Point& start_control_point, Point& end_control_point)
{
start_point = bounds.getLocation();
end_point = start_point;
end_point.moveRel (bounds.getSize());
int dx = 0;
if (bounds.getSize().getWidth() != 0)
dx = bounds.getSize().getWidth() / 2;
int dy = 0;
if (bounds.getSize().getHeight() != 0)
dy = bounds.getSize().getHeight() / 2;
start_control_point = start_point;
start_control_point.moveRel (0, dy);
end_control_point = end_point;
end_control_point.moveRel (-dx, 0);
}
}