2013-07-16 19:04:14 +00:00
|
|
|
#include "Line.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
void
|
|
|
|
Line::scale(double factor)
|
|
|
|
{
|
|
|
|
this->a.scale(factor);
|
|
|
|
this->b.scale(factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Line::translate(double x, double y)
|
|
|
|
{
|
|
|
|
this->a.translate(x, y);
|
|
|
|
this->b.translate(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Line::rotate(double angle, Point* center)
|
|
|
|
{
|
|
|
|
this->a.rotate(angle, center);
|
|
|
|
this->b.rotate(angle, center);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Line::reverse()
|
|
|
|
{
|
|
|
|
std::swap(this->a, this->b);
|
|
|
|
}
|
|
|
|
|
2013-08-28 18:32:25 +00:00
|
|
|
double
|
|
|
|
Line::length() const
|
|
|
|
{
|
|
|
|
return this->a.distance_to(&(this->b));
|
|
|
|
}
|
|
|
|
|
2013-08-28 23:36:42 +00:00
|
|
|
Point*
|
|
|
|
Line::midpoint() const
|
|
|
|
{
|
|
|
|
return new Point ((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0);
|
|
|
|
}
|
|
|
|
|
2013-10-27 21:57:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-06 18:38:10 +00:00
|
|
|
bool
|
|
|
|
Line::coincides_with(const Line* line) const
|
|
|
|
{
|
|
|
|
return this->a.coincides_with(&line->a) && this->b.coincides_with(&line->b);
|
|
|
|
}
|
|
|
|
|
2013-11-06 22:08:03 +00:00
|
|
|
double
|
|
|
|
Line::distance_to(const Point* point) const
|
|
|
|
{
|
|
|
|
return point->distance_to(this);
|
|
|
|
}
|
|
|
|
|
2013-09-13 12:48:40 +00:00
|
|
|
#ifdef SLIC3RXS
|
2013-07-16 19:04:14 +00:00
|
|
|
void
|
|
|
|
Line::from_SV(SV* line_sv)
|
|
|
|
{
|
|
|
|
AV* line_av = (AV*)SvRV(line_sv);
|
|
|
|
this->a.from_SV_check(*av_fetch(line_av, 0, 0));
|
|
|
|
this->b.from_SV_check(*av_fetch(line_av, 1, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Line::from_SV_check(SV* line_sv)
|
|
|
|
{
|
|
|
|
if (sv_isobject(line_sv) && (SvTYPE(SvRV(line_sv)) == SVt_PVMG)) {
|
|
|
|
*this = *(Line*)SvIV((SV*)SvRV( line_sv ));
|
|
|
|
} else {
|
|
|
|
this->from_SV(line_sv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SV*
|
2013-09-09 20:27:58 +00:00
|
|
|
Line::to_AV() {
|
2013-07-16 19:04:14 +00:00
|
|
|
AV* av = newAV();
|
|
|
|
av_extend(av, 1);
|
|
|
|
|
|
|
|
SV* sv = newSV(0);
|
2013-09-02 18:22:20 +00:00
|
|
|
sv_setref_pv( sv, "Slic3r::Point::Ref", &(this->a) );
|
2013-07-16 19:04:14 +00:00
|
|
|
av_store(av, 0, sv);
|
|
|
|
|
|
|
|
sv = newSV(0);
|
2013-09-02 18:22:20 +00:00
|
|
|
sv_setref_pv( sv, "Slic3r::Point::Ref", &(this->b) );
|
2013-07-16 19:04:14 +00:00
|
|
|
av_store(av, 1, sv);
|
|
|
|
|
|
|
|
return newRV_noinc((SV*)av);
|
|
|
|
}
|
|
|
|
|
|
|
|
SV*
|
|
|
|
Line::to_SV_ref() {
|
2013-09-02 18:22:20 +00:00
|
|
|
SV* sv = newSV(0);
|
|
|
|
sv_setref_pv( sv, "Slic3r::Line::Ref", this );
|
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
SV*
|
2013-09-03 17:26:58 +00:00
|
|
|
Line::to_SV_clone_ref() const {
|
2013-07-16 19:04:14 +00:00
|
|
|
SV* sv = newSV(0);
|
|
|
|
sv_setref_pv( sv, "Slic3r::Line", new Line(*this) );
|
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
SV*
|
2013-09-03 17:26:58 +00:00
|
|
|
Line::to_SV_pureperl() const {
|
2013-07-16 19:04:14 +00:00
|
|
|
AV* av = newAV();
|
|
|
|
av_extend(av, 1);
|
|
|
|
av_store(av, 0, this->a.to_SV_pureperl());
|
|
|
|
av_store(av, 1, this->b.to_SV_pureperl());
|
|
|
|
return newRV_noinc((SV*)av);
|
|
|
|
}
|
2013-09-13 12:48:40 +00:00
|
|
|
#endif
|
2013-07-16 19:04:14 +00:00
|
|
|
|
|
|
|
}
|