2011-09-18 17:28:12 +00:00
|
|
|
package Slic3r::Geometry;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2011-10-07 19:19:18 +00:00
|
|
|
require Exporter;
|
|
|
|
our @ISA = qw(Exporter);
|
2017-07-19 08:45:39 +00:00
|
|
|
|
|
|
|
# Exported by this module. The last section starting with convex_hull is exported by Geometry.xsp
|
2011-10-07 19:19:18 +00:00
|
|
|
our @EXPORT_OK = qw(
|
2017-07-19 08:45:39 +00:00
|
|
|
PI epsilon
|
|
|
|
|
|
|
|
scale
|
|
|
|
unscale
|
|
|
|
scaled_epsilon
|
|
|
|
size_2D
|
|
|
|
|
|
|
|
X Y Z
|
|
|
|
convex_hull
|
|
|
|
chained_path_from
|
|
|
|
deg2rad
|
|
|
|
rad2deg
|
2011-10-07 19:19:18 +00:00
|
|
|
);
|
|
|
|
|
2011-09-26 13:51:22 +00:00
|
|
|
use constant PI => 4 * atan2(1, 1);
|
2011-09-18 17:28:12 +00:00
|
|
|
use constant A => 0;
|
|
|
|
use constant B => 1;
|
2011-11-13 17:14:02 +00:00
|
|
|
use constant X1 => 0;
|
|
|
|
use constant Y1 => 1;
|
|
|
|
use constant X2 => 2;
|
|
|
|
use constant Y2 => 3;
|
2011-09-18 17:28:12 +00:00
|
|
|
|
2012-02-25 16:16:55 +00:00
|
|
|
sub epsilon () { 1E-4 }
|
2012-09-12 13:19:47 +00:00
|
|
|
sub scaled_epsilon () { epsilon / &Slic3r::SCALING_FACTOR }
|
2011-10-07 17:07:57 +00:00
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub scale ($) { $_[0] / &Slic3r::SCALING_FACTOR }
|
|
|
|
sub unscale ($) { $_[0] * &Slic3r::SCALING_FACTOR }
|
2011-11-27 10:40:03 +00:00
|
|
|
|
2011-10-06 09:55:26 +00:00
|
|
|
# 2D
|
|
|
|
sub bounding_box {
|
|
|
|
my ($points) = @_;
|
2013-09-06 14:46:28 +00:00
|
|
|
|
2013-08-26 21:27:51 +00:00
|
|
|
my @x = map $_->x, @$points;
|
|
|
|
my @y = map $_->y, @$points; #,,
|
|
|
|
my @bb = (undef, undef, undef, undef);
|
|
|
|
for (0..$#x) {
|
|
|
|
$bb[X1] = $x[$_] if !defined $bb[X1] || $x[$_] < $bb[X1];
|
|
|
|
$bb[X2] = $x[$_] if !defined $bb[X2] || $x[$_] > $bb[X2];
|
|
|
|
$bb[Y1] = $y[$_] if !defined $bb[Y1] || $y[$_] < $bb[Y1];
|
|
|
|
$bb[Y2] = $y[$_] if !defined $bb[Y2] || $y[$_] > $bb[Y2];
|
2012-02-25 16:16:55 +00:00
|
|
|
}
|
2011-10-06 09:55:26 +00:00
|
|
|
|
2013-08-26 21:27:51 +00:00
|
|
|
return @bb[X1,Y1,X2,Y2];
|
2011-10-06 09:55:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-14 08:25:20 +00:00
|
|
|
# used by ExPolygon::size
|
2012-11-19 16:39:16 +00:00
|
|
|
sub size_2D {
|
|
|
|
my @bounding_box = bounding_box(@_);
|
|
|
|
return (
|
|
|
|
($bounding_box[X2] - $bounding_box[X1]),
|
|
|
|
($bounding_box[Y2] - $bounding_box[Y1]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
1;
|