mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-18 19:12:17 +00:00
Ported point_line_distance() and removed same_point()
This commit is contained in:
@@ -60,6 +60,12 @@ Line::coincides_with(const Line* line) const
|
||||
return this->a.coincides_with(&line->a) && this->b.coincides_with(&line->b);
|
||||
}
|
||||
|
||||
double
|
||||
Line::distance_to(const Point* point) const
|
||||
{
|
||||
return point->distance_to(this);
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
void
|
||||
Line::from_SV(SV* line_sv)
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Line;
|
||||
|
||||
class Line
|
||||
{
|
||||
public:
|
||||
@@ -21,6 +23,7 @@ class Line
|
||||
Point* midpoint() const;
|
||||
Point* point_at(double distance) const;
|
||||
bool coincides_with(const Line* line) const;
|
||||
double distance_to(const Point* point) const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
void from_SV(SV* line_sv);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Point.hpp"
|
||||
#include "Line.hpp"
|
||||
#include <math.h>
|
||||
|
||||
namespace Slic3r {
|
||||
@@ -72,6 +73,17 @@ Point::distance_to(const Point* point) const
|
||||
return sqrt(dx*dx + dy*dy);
|
||||
}
|
||||
|
||||
double
|
||||
Point::distance_to(const Line* line) const
|
||||
{
|
||||
if (line->a.coincides_with(&line->b)) return this->distance_to(&line->a);
|
||||
|
||||
double n = (line->b.x - line->a.x) * (line->a.y - this->y)
|
||||
- (line->a.x - this->x) * (line->b.y - line->a.y);
|
||||
|
||||
return abs(n) / line->length();
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV*
|
||||
Point::to_SV_ref() {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Line;
|
||||
class Point;
|
||||
typedef std::vector<Point> Points;
|
||||
|
||||
@@ -23,6 +24,7 @@ class Point
|
||||
int nearest_point_index(const Points points) const;
|
||||
Point* nearest_point(Points points) const;
|
||||
double distance_to(const Point* point) const;
|
||||
double distance_to(const Line* line) const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
void from_SV(SV* point_sv);
|
||||
|
||||
Reference in New Issue
Block a user