mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 00:01:09 -06:00
Ported point_along_segment(), Polyline::length(), Polyline::clip_end() to XS
This commit is contained in:
parent
26a18a2a52
commit
29b83517cb
12 changed files with 64 additions and 57 deletions
|
@ -42,6 +42,18 @@ Line::midpoint() const
|
|||
return new Point ((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0);
|
||||
}
|
||||
|
||||
Point*
|
||||
Line::point_at(double distance) const
|
||||
{
|
||||
double len = this->length();
|
||||
Point* p = new Point(this->a);
|
||||
if (this->a.x != this->b.x)
|
||||
p->x = this->a.x + (this->b.x - this->a.x) * distance / len;
|
||||
if (this->a.y != this->b.y)
|
||||
p->y = this->a.y + (this->b.y - this->a.y) * distance / len;
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
void
|
||||
Line::from_SV(SV* line_sv)
|
||||
|
|
|
@ -19,6 +19,7 @@ class Line
|
|||
void reverse();
|
||||
double length() const;
|
||||
Point* midpoint() const;
|
||||
Point* point_at(double distance) const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
void from_SV(SV* line_sv);
|
||||
|
|
|
@ -38,6 +38,17 @@ MultiPoint::first_point() const
|
|||
return new Point(this->points.front());
|
||||
}
|
||||
|
||||
double
|
||||
MultiPoint::length() const
|
||||
{
|
||||
Lines lines = this->lines();
|
||||
double len = 0;
|
||||
for (Lines::iterator it = lines.begin(); it != lines.end(); ++it) {
|
||||
len += it->length();
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
void
|
||||
MultiPoint::from_SV(SV* poly_sv)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef slic3r_MultiPoint_hpp_
|
||||
#define slic3r_MultiPoint_hpp_
|
||||
|
||||
#include "Line.hpp"
|
||||
#include "Point.hpp"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
@ -17,6 +18,8 @@ class MultiPoint
|
|||
void reverse();
|
||||
Point* first_point() const;
|
||||
virtual Point* last_point() const = 0;
|
||||
virtual Lines lines() const = 0;
|
||||
double length() const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
void from_SV(SV* poly_sv);
|
||||
|
|
|
@ -19,6 +19,27 @@ Polyline::lines() const
|
|||
return lines;
|
||||
}
|
||||
|
||||
// removes the given distance from the end of the polyline
|
||||
void
|
||||
Polyline::clip_end(double distance)
|
||||
{
|
||||
while (distance > 0) {
|
||||
Point last_point = *this->last_point();
|
||||
this->points.pop_back();
|
||||
if (this->points.empty()) break;
|
||||
|
||||
double last_segment_length = last_point.distance_to(this->last_point());
|
||||
if (last_segment_length <= distance) {
|
||||
distance -= last_segment_length;
|
||||
continue;
|
||||
}
|
||||
|
||||
Line segment(last_point, *this->last_point());
|
||||
this->points.push_back(*segment.point_at(distance));
|
||||
distance = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV*
|
||||
Polyline::to_SV_ref()
|
||||
|
|
|
@ -10,6 +10,7 @@ class Polyline : public MultiPoint {
|
|||
public:
|
||||
Point* last_point() const;
|
||||
Lines lines() const;
|
||||
void clip_end(double distance);
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue