diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2011-11-13 21:14:02 +0400 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2011-11-13 21:14:02 +0400 |
commit | 038caddcdae26a44bb0b68c952570319cd0ab42c (patch) | |
tree | 8cac8bb3336223d24bb931b376f0e1b1f5b52010 /lib/Slic3r/Geometry.pm | |
parent | 041e9877a3838e8441618901dc20e89311de428c (diff) |
New fill types (hilbertcurve, archimedeanchords, octagramspiral) and ability to use different patterns for solid layers. #20
Diffstat (limited to 'lib/Slic3r/Geometry.pm')
-rw-r--r-- | lib/Slic3r/Geometry.pm | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index 39fdc0937..98ad804e2 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -5,7 +5,7 @@ use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( - PI X Y Z A B epsilon slope line_atan lines_parallel three_points_aligned + PI X Y Z A B X1 Y1 X2 Y2 epsilon slope line_atan lines_parallel line_point_belongs_to_segment points_coincide distance_between_points line_length midpoint point_in_polygon point_in_segment segment_in_segment point_is_on_left_of_segment polyline_lines polygon_lines nearest_point @@ -14,7 +14,7 @@ our @EXPORT_OK = qw( rotate_points move_points remove_coinciding_points clip_segment_polygon sum_vectors multiply_vector subtract_vectors dot perp polygon_points_visibility line_intersection bounding_box bounding_box_intersect - clip_segment_complex_polygon longest_segment angle3points + longest_segment angle3points three_points_aligned polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges shortest_path collinear @@ -29,6 +29,10 @@ use constant B => 1; use constant X => 0; use constant Y => 1; use constant Z => 2; +use constant X1 => 0; +use constant Y1 => 1; +use constant X2 => 2; +use constant Y2 => 3; our $parallel_degrees_limit = abs(deg2rad(3)); our $epsilon = 1E-4; @@ -110,6 +114,7 @@ sub midpoint { return [ ($line->[B][X] + $line->[A][X]) / 2, ($line->[B][Y] + $line->[A][Y]) / 2 ]; } +# this will check whether a point is in a polygon regardless of polygon orientation sub point_in_polygon { my ($point, $polygon) = @_; @@ -311,7 +316,7 @@ sub rotate_points { sub move_points { my ($shift, @points) = @_; - return map [ $shift->[X] + $_->[X], $shift->[Y] + $_->[Y] ], @points; + return map Slic3r::Point->new($shift->[X] + $_->[X], $shift->[Y] + $_->[Y]), @points; } # preserves order @@ -558,32 +563,6 @@ sub bounding_box_intersect { return 1; } -sub clip_segment_complex_polygon { - my ($line, $polygons) = @_; - - my @intersections = grep $_, map line_intersection($line, $_, 1), - map polygon_lines($_), @$polygons or return (); - - # this is not very elegant, however it works - @intersections = sort { sprintf("%020f,%020f", @$a) cmp sprintf("%020f,%020f", @$b) } @intersections; - - shift(@intersections) if !grep(point_in_polygon($intersections[0], $_), @$polygons) - && !grep(polygon_segment_having_point($_, $intersections[0]), @$polygons); - - # defensive programming - ###die "Invalid intersections" if @intersections % 2 != 0; - - my @lines = (); - while (@intersections) { - # skip tangent points - my @points = map shift @intersections, 1..2; - next if !$points[1]; - next if points_coincide(@points); - push @lines, [ @points ]; - } - return [@lines]; -} - sub angle3points { my ($p1, $p2, $p3) = @_; # p1 is the center |