@@ -34,13 +34,26 @@ LengthDbl irregular::norm(
3434 return std::sqrt (vector.x * vector.x + vector.y * vector.y );
3535}
3636
37+ LengthDbl irregular::squared_norm (
38+ const Point& vector)
39+ {
40+ return vector.x * vector.x + vector.y * vector.y ;
41+ }
42+
3743LengthDbl irregular::distance (
3844 const Point& point_1,
3945 const Point& point_2)
4046{
4147 return norm (point_2 - point_1);
4248}
4349
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+
4457LengthDbl irregular::dot_product (
4558 const Point& vector_1,
4659 const Point& vector_2)
@@ -102,6 +115,20 @@ Point Point::rotate_radians(
102115 return point_out;
103116}
104117
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+
105132Point Point::axial_symmetry_identity_line () const
106133{
107134 Point point_out;
@@ -145,6 +172,21 @@ Angle irregular::angle_radian(
145172 return a;
146173}
147174
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+
148190// //////////////////////////////////////////////////////////////////////////////
149191// /////////////////////////////// ShapeElement /////////////////////////////////
150192// //////////////////////////////////////////////////////////////////////////////
@@ -336,13 +378,9 @@ std::vector<ShapeElement> irregular::approximate_circular_arc_by_line_segments(
336378 Angle angle_cur = (angle * (line_segment_id + 1 )) / (number_of_line_segments - 1 );
337379 if (!circular_arc.anticlockwise )
338380 angle_cur *= -1 ;
339- Point point_circle;
340- point_circle.x = circular_arc.center .x
341- + std::cos (angle_cur) * (circular_arc.start .x - circular_arc.center .x )
342- - std::sin (angle_cur) * (circular_arc.start .y - circular_arc.center .y );
343- point_circle.y = circular_arc.center .y
344- + std::sin (angle_cur) * (circular_arc.start .x - circular_arc.center .x )
345- + std::cos (angle_cur) * (circular_arc.start .y - circular_arc.center .y );
381+ Point point_circle = circular_arc.start .rotate_radians (
382+ circular_arc.center ,
383+ angle_cur);
346384 Point point_cur;
347385 if ((outer && !circular_arc.anticlockwise ) || (!outer && circular_arc.anticlockwise )) {
348386 point_cur = point_circle;
0 commit comments