@@ -34,13 +34,26 @@ LengthDbl irregular::norm(
34
34
return std::sqrt (vector.x * vector.x + vector.y * vector.y );
35
35
}
36
36
37
+ LengthDbl irregular::squared_norm (
38
+ const Point & vector)
39
+ {
40
+ return vector.x * vector.x + vector.y * vector.y ;
41
+ }
42
+
37
43
LengthDbl irregular::distance (
38
44
const Point & point_1,
39
45
const Point & point_2)
40
46
{
41
47
return norm (point_2 - point_1);
42
48
}
43
49
50
+ LengthDbl irregular::squared_distance (
51
+ const Point & point_1,
52
+ const Point & point_2)
53
+ {
54
+ return squared_norm (point_2 - point_1);
55
+ }
56
+
44
57
LengthDbl irregular::dot_product (
45
58
const Point & vector_1,
46
59
const Point & vector_2)
@@ -102,6 +115,20 @@ Point Point::rotate_radians(
102
115
return point_out;
103
116
}
104
117
118
+ Point Point::rotate_radians (
119
+ const Point & center,
120
+ Angle angle) const
121
+ {
122
+ Point point_out;
123
+ point_out.x = center.x
124
+ + std::cos (angle) * (this ->x - center.x )
125
+ - std::sin (angle) * (this ->y - center.y );
126
+ point_out.y = center.y
127
+ + std::sin (angle) * (this ->x - center.x )
128
+ + std::cos (angle) * (this ->y - center.y );
129
+ return point_out;
130
+ }
131
+
105
132
Point Point::axial_symmetry_identity_line () const
106
133
{
107
134
Point point_out;
@@ -145,6 +172,21 @@ Angle irregular::angle_radian(
145
172
return a;
146
173
}
147
174
175
+ int irregular::counter_clockwise (
176
+ const Point & point_1,
177
+ const Point & point_2,
178
+ const Point & point_3)
179
+ {
180
+ AreaDbl area = (point_2.x - point_1.x ) * (point_3.y - point_1.y )
181
+ - (point_2.y - point_1.y ) * (point_3.x - point_1.x );
182
+ if (strictly_greater (area, 0 )) {
183
+ return -1 ;
184
+ } else if (strictly_lesser (area, 0 )) {
185
+ return 1 ;
186
+ }
187
+ return 0 ;
188
+ }
189
+
148
190
// //////////////////////////////////////////////////////////////////////////////
149
191
// /////////////////////////////// ShapeElement /////////////////////////////////
150
192
// //////////////////////////////////////////////////////////////////////////////
@@ -398,13 +440,9 @@ std::vector<ShapeElement> irregular::approximate_circular_arc_by_line_segments(
398
440
Angle angle_cur = (angle * (line_segment_id + 1 )) / (number_of_line_segments - 1 );
399
441
if (!circular_arc.anticlockwise )
400
442
angle_cur *= -1 ;
401
- Point point_circle;
402
- point_circle.x = circular_arc.center .x
403
- + std::cos (angle_cur) * (circular_arc.start .x - circular_arc.center .x )
404
- - std::sin (angle_cur) * (circular_arc.start .y - circular_arc.center .y );
405
- point_circle.y = circular_arc.center .y
406
- + std::sin (angle_cur) * (circular_arc.start .x - circular_arc.center .x )
407
- + std::cos (angle_cur) * (circular_arc.start .y - circular_arc.center .y );
443
+ Point point_circle = circular_arc.start .rotate_radians (
444
+ circular_arc.center ,
445
+ angle_cur);
408
446
Point point_cur;
409
447
if ((outer && !circular_arc.anticlockwise ) || (!outer && circular_arc.anticlockwise )) {
410
448
point_cur = point_circle;
0 commit comments