mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-09 14:55:08 -06:00
Ported nearest_point() and nearest_point_index()
This commit is contained in:
parent
f1e9216c70
commit
b11b595c97
18 changed files with 79 additions and 69 deletions
|
@ -1,4 +1,5 @@
|
|||
#include "Point.hpp"
|
||||
#include <math.h>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -31,6 +32,38 @@ Point::coincides_with(const Point* point) const
|
|||
return this->x == point->x && this->y == point->y;
|
||||
}
|
||||
|
||||
int
|
||||
Point::nearest_point_index(const Points points) const
|
||||
{
|
||||
int idx = -1;
|
||||
long distance = -1;
|
||||
|
||||
for (Points::const_iterator it = points.begin(); it != points.end(); ++it) {
|
||||
/* If the X distance of the candidate is > than the total distance of the
|
||||
best previous candidate, we know we don't want it */
|
||||
long d = pow(this->x - (*it).x, 2);
|
||||
if (distance != -1 && d > distance) continue;
|
||||
|
||||
/* If the Y distance of the candidate is > than the total distance of the
|
||||
best previous candidate, we know we don't want it */
|
||||
d += pow(this->y - (*it).y, 2);
|
||||
if (distance != -1 && d > distance) continue;
|
||||
|
||||
idx = it - points.begin();
|
||||
distance = d;
|
||||
|
||||
if (distance < EPSILON) break;
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
Point*
|
||||
Point::nearest_point(Points points) const
|
||||
{
|
||||
return &(points.at(this->nearest_point_index(points)));
|
||||
}
|
||||
|
||||
SV*
|
||||
Point::to_SV_pureperl() {
|
||||
AV* av = newAV();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue