Use a more robust parallelism detection
This commit is contained in:
parent
fce669dea0
commit
0a88492fdc
@ -247,7 +247,7 @@ sub unsupported_edges {
|
|||||||
|
|
||||||
# split into individual segments and filter out edges parallel to the bridging angle
|
# split into individual segments and filter out edges parallel to the bridging angle
|
||||||
@$unsupported = map $_->as_polyline,
|
@$unsupported = map $_->as_polyline,
|
||||||
grep { abs($_->direction - $angle) < epsilon }
|
grep $_->parallel_to($angle),
|
||||||
map @{$_->lines},
|
map @{$_->lines},
|
||||||
@$unsupported;
|
@$unsupported;
|
||||||
|
|
||||||
|
@ -111,6 +111,17 @@ Line::direction() const
|
|||||||
: atan2;
|
: atan2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Line::parallel_to(double angle) const {
|
||||||
|
double diff = abs(this->direction() - angle);
|
||||||
|
return (diff < EPSILON) || (abs(diff - PI) < EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Line::parallel_to(const Line &line) const {
|
||||||
|
return this->parallel_to(line.direction());
|
||||||
|
}
|
||||||
|
|
||||||
Vector
|
Vector
|
||||||
Line::vector() const
|
Line::vector() const
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,8 @@ class Line
|
|||||||
Point point_at(double distance) const;
|
Point point_at(double distance) const;
|
||||||
bool coincides_with(const Line &line) const;
|
bool coincides_with(const Line &line) const;
|
||||||
double distance_to(const Point &point) const;
|
double distance_to(const Point &point) const;
|
||||||
|
bool parallel_to(double angle) const;
|
||||||
|
bool parallel_to(const Line &line) const;
|
||||||
double atan2_() const;
|
double atan2_() const;
|
||||||
double direction() const;
|
double direction() const;
|
||||||
Vector vector() const;
|
Vector vector() const;
|
||||||
|
@ -4,7 +4,10 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 6;
|
use Test::More tests => 34;
|
||||||
|
|
||||||
|
use constant PI => 4 * atan2(1, 1);
|
||||||
|
use constant EPSILON => 1E-4;
|
||||||
|
|
||||||
my $points = [
|
my $points = [
|
||||||
[100, 100],
|
[100, 100],
|
||||||
@ -37,4 +40,28 @@ isa_ok $line->[0], 'Slic3r::Point::Ref', 'line point is blessed';
|
|||||||
], 'translate';
|
], 'translate';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach my $base_angle (0, PI/4, PI/2, PI) {
|
||||||
|
my $line = Slic3r::Line->new([0,0], [100,0]);
|
||||||
|
$line->rotate($base_angle, [0,0]);
|
||||||
|
ok $line->parallel_to_line($line->clone), 'line is parallel to self';
|
||||||
|
ok $line->parallel_to($line->direction), 'line is parallel to its direction';
|
||||||
|
ok $line->parallel_to($line->direction + PI), 'line is parallel to its direction + PI';
|
||||||
|
ok $line->parallel_to($line->direction - PI), 'line is parallel to its direction - PI';
|
||||||
|
{
|
||||||
|
my $line2 = $line->clone;
|
||||||
|
$line2->reverse;
|
||||||
|
ok $line->parallel_to_line($line2), 'line is parallel to its opposite';
|
||||||
|
}
|
||||||
|
{
|
||||||
|
my $line2 = $line->clone;
|
||||||
|
$line2->rotate(+EPSILON/2, [0,0]);
|
||||||
|
ok $line->parallel_to_line($line2), 'line is parallel within epsilon';
|
||||||
|
}
|
||||||
|
{
|
||||||
|
my $line2 = $line->clone;
|
||||||
|
$line2->rotate(-EPSILON/2, [0,0]);
|
||||||
|
ok $line->parallel_to_line($line2), 'line is parallel within epsilon';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
double length();
|
double length();
|
||||||
double atan2_();
|
double atan2_();
|
||||||
double direction();
|
double direction();
|
||||||
|
bool parallel_to(double angle);
|
||||||
|
bool parallel_to_line(Line* line)
|
||||||
|
%code{% RETVAL = THIS->parallel_to(*line); %};
|
||||||
Point* midpoint();
|
Point* midpoint();
|
||||||
Clone<Point> point_at(double distance);
|
Clone<Point> point_at(double distance);
|
||||||
Polyline* as_polyline()
|
Polyline* as_polyline()
|
||||||
|
Loading…
Reference in New Issue
Block a user