@@ -256,26 +256,32 @@ Delaunator::Delaunator(std::vector<double> const& in_coords)
256256 }
257257 }
258258
259+ const double i0x = coords[2 * i0];
260+ const double i0y = coords[2 * i0 + 1 ];
261+
259262 min_dist = std::numeric_limits<double >::max ();
260263
261264 // find the point closest to the seed
262265 for (std::size_t i = 0 ; i < n; i++) {
263266 if (i == i0) continue ;
264- const double d = dist (coords[ 2 * i0], coords[ 2 * i0 + 1 ] , coords[2 * i], coords[2 * i + 1 ]);
267+ const double d = dist (i0x, i0y , coords[2 * i], coords[2 * i + 1 ]);
265268 if (d < min_dist && d > 0.0 ) {
266269 i1 = i;
267270 min_dist = d;
268271 }
269272 }
270273
274+ double i1x = coords[2 * i1];
275+ double i1y = coords[2 * i1 + 1 ];
276+
271277 double min_radius = std::numeric_limits<double >::max ();
272278
273279 // find the third point which forms the smallest circumcircle with the first two
274280 for (std::size_t i = 0 ; i < n; i++) {
275281 if (i == i0 || i == i1) continue ;
276282
277283 const double r = circumradius (
278- coords[ 2 * i0], coords[ 2 * i0 + 1 ], coords[ 2 * i1], coords[ 2 * i1 + 1 ] , coords[2 * i], coords[2 * i + 1 ]);
284+ i0x, i0y, i1x, i1y , coords[2 * i], coords[2 * i + 1 ]);
279285
280286 if (r < min_radius) {
281287 i2 = i;
@@ -287,23 +293,15 @@ Delaunator::Delaunator(std::vector<double> const& in_coords)
287293 throw std::runtime_error (" not triangulation" );
288294 }
289295
290- if (orient (
291- coords[2 * i0], coords[2 * i0 + 1 ], //
292- coords[2 * i1],
293- coords[2 * i1 + 1 ], //
294- coords[2 * i2],
295- coords[2 * i2 + 1 ]) //
296- ) {
296+ double i2x = coords[2 * i2];
297+ double i2y = coords[2 * i2 + 1 ];
298+
299+ if (orient (i0x, i0y, i1x, i1y, i2x, i2y)) {
297300 std::swap (i1, i2);
301+ std::swap (i1x, i2x);
302+ std::swap (i1y, i2y);
298303 }
299304
300- const double i0x = coords[2 * i0];
301- const double i0y = coords[2 * i0 + 1 ];
302- const double i1x = coords[2 * i1];
303- const double i1y = coords[2 * i1 + 1 ];
304- const double i2x = coords[2 * i2];
305- const double i2y = coords[2 * i2 + 1 ];
306-
307305 std::tie (m_center_x, m_center_y) = circumcenter (i0x, i0y, i1x, i1y, i2x, i2y);
308306
309307 // sort the points by distance from the seed triangle circumcenter
0 commit comments