Fixed everything in the XS port
This commit is contained in:
parent
49040db9a3
commit
443d4e52cb
@ -60,11 +60,6 @@ sub offset_ex {
|
||||
return Slic3r::Geometry::Clipper::offset_ex(\@$self, @_);
|
||||
}
|
||||
|
||||
sub safety_offset {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::Clipper::safety_offset_ex(\@$self, @_);
|
||||
}
|
||||
|
||||
sub noncollapsing_offset_ex {
|
||||
my $self = shift;
|
||||
my ($distance, @params) = @_;
|
||||
|
@ -956,7 +956,7 @@ sub repaint {
|
||||
@{$parent->{object_previews}} = ();
|
||||
for my $obj_idx (0 .. $#{$parent->{objects}}) {
|
||||
my $object = $parent->{objects}[$obj_idx];
|
||||
next unless defined $object->thumbnail && @{$object->thumbnail};
|
||||
next unless defined $object->thumbnail;
|
||||
for my $instance_idx (0 .. $#{$object->instances}) {
|
||||
my $instance = $object->instances->[$instance_idx];
|
||||
|
||||
@ -973,7 +973,7 @@ sub repaint {
|
||||
} else {
|
||||
$dc->SetBrush($parent->{objects_brush});
|
||||
}
|
||||
$dc->DrawPolygon($parent->_y($_), 0, 0) for map $_->contour, @{ $parent->{object_previews}->[-1][2] };
|
||||
$dc->DrawPolygon($parent->_y($_), 0, 0) for map $_->contour->pp, @{ $parent->{object_previews}->[-1][2] };
|
||||
|
||||
# if sequential printing is enabled and we have more than one object
|
||||
if ($parent->{config}->complete_objects && (map @{$_->instances}, @{$parent->{objects}}) > 1) {
|
||||
@ -988,7 +988,7 @@ sub repaint {
|
||||
|
||||
# draw skirt
|
||||
if (@{$parent->{object_previews}} && $parent->{config}->skirts) {
|
||||
my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @{$_->contour}, map @{$_->[2]}, @{$parent->{object_previews}} ])});
|
||||
my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @{$_->contour->pp}, map @{$_->[2]}, @{$parent->{object_previews}} ])});
|
||||
($convex_hull) = @{offset([$convex_hull], $parent->{config}->skirt_distance * $parent->{scaling_factor}, 100, JT_ROUND)};
|
||||
$dc->SetPen($parent->{skirt_pen});
|
||||
$dc->SetBrush($parent->{transparent_brush});
|
||||
@ -1003,7 +1003,7 @@ sub mouse_event {
|
||||
my $parent = $self->GetParent;
|
||||
|
||||
my $point = $event->GetPosition;
|
||||
my $pos = $parent->_y([[$point->x, $point->y]])->[0]; #]]
|
||||
my $pos = Slic3r::Point->new(map @$_, map @$_, $parent->_y([[$point->x, $point->y]])); #]]
|
||||
if ($event->ButtonDown(&Wx::wxMOUSE_BTN_LEFT)) {
|
||||
$parent->{selected_objects} = [];
|
||||
$parent->{list}->Select($parent->{list}->GetFirstSelected, 0);
|
||||
|
@ -4,7 +4,7 @@ use warnings;
|
||||
|
||||
require Exporter;
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT_OK = qw(safety_offset safety_offset_ex offset offset_ex collapse_ex
|
||||
our @EXPORT_OK = qw(offset offset_ex
|
||||
diff_ex diff union_ex intersection_ex xor_ex PFT_EVENODD JT_MITER JT_ROUND
|
||||
JT_SQUARE is_counter_clockwise union_pt offset2 offset2_ex traverse_pt
|
||||
intersection union);
|
||||
@ -13,31 +13,20 @@ use Math::Clipper 1.22 qw(:cliptypes :polyfilltypes :jointypes is_counter_clockw
|
||||
use Slic3r::Geometry qw(scale);
|
||||
our $clipper = Math::Clipper->new;
|
||||
|
||||
sub safety_offset {
|
||||
sub _safety_offset {
|
||||
my ($polygons, $factor) = @_;
|
||||
return [ map Slic3r::Polygon->new(@$_),
|
||||
@{Math::Clipper::int_offset(_convert($polygons), $factor // (scale 1e-05), 100000, JT_MITER, 2)} ];
|
||||
}
|
||||
|
||||
sub safety_offset_ex {
|
||||
my ($polygons, $factor) = @_;
|
||||
return map Slic3r::ExPolygon->new($_->{outer}, @{$_->{holes}}),
|
||||
@{Math::Clipper::ex_int_offset(_convert($polygons), $factor // (scale 1e-05), 100000, JT_MITER, 2)};
|
||||
}
|
||||
|
||||
sub union_pt {
|
||||
my ($polygons, $jointype, $safety_offset) = @_;
|
||||
$jointype = PFT_NONZERO unless defined $jointype;
|
||||
$clipper->clear;
|
||||
$clipper->add_subject_polygons($safety_offset ? _convert(safety_offset($polygons)) : _convert($polygons));
|
||||
$clipper->add_subject_polygons($safety_offset ? _convert(_safety_offset($polygons)) : _convert($polygons));
|
||||
return $clipper->pt_execute(CT_UNION, $jointype, $jointype);
|
||||
}
|
||||
|
||||
sub collapse_ex {
|
||||
my ($polygons, $width) = @_;
|
||||
return offset2_ex($polygons, -$width/2, +$width/2);
|
||||
}
|
||||
|
||||
sub traverse_pt {
|
||||
my ($polynodes) = @_;
|
||||
|
||||
|
@ -4,7 +4,7 @@ use Moo;
|
||||
use List::Util qw(sum first);
|
||||
use Slic3r::ExtrusionPath ':roles';
|
||||
use Slic3r::Geometry qw(PI A B scale chained_path_items points_coincide);
|
||||
use Slic3r::Geometry::Clipper qw(safety_offset union_ex diff_ex intersection_ex
|
||||
use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex
|
||||
offset offset2 offset2_ex PFT_EVENODD union_pt traverse_pt diff intersection
|
||||
union diff);
|
||||
use Slic3r::Surface ':types';
|
||||
|
@ -565,7 +565,7 @@ sub horizontal_projection {
|
||||
$_->make_counter_clockwise for @f; # do this after scaling, as winding order might change while doing that
|
||||
|
||||
# the offset factor was tuned using groovemount.stl
|
||||
return union_ex([ offset(\@f, Slic3r::Geometry::scale 0.01) ], 1);
|
||||
return union_ex(offset(\@f, Slic3r::Geometry::scale 0.01), 1);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -194,7 +194,7 @@ offset2_ex(Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const float d
|
||||
|
||||
template <class T>
|
||||
void _clipper_do(const ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
Slic3r::Polygons &clip, T &retval, const bool safety_offset)
|
||||
Slic3r::Polygons &clip, T &retval, const bool safety_offset_)
|
||||
{
|
||||
// read input
|
||||
ClipperLib::Polygons* input_subject = new ClipperLib::Polygons();
|
||||
@ -203,11 +203,11 @@ void _clipper_do(const ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
Slic3rPolygons_to_ClipperPolygons(clip, *input_clip);
|
||||
|
||||
// perform safety offset
|
||||
if (safety_offset) {
|
||||
if (safety_offset_) {
|
||||
if (clipType == ClipperLib::ctUnion) {
|
||||
// SafetyOffset(*input_subject);
|
||||
safety_offset(input_subject);
|
||||
} else {
|
||||
// SafetyOffset(*input_clip);
|
||||
safety_offset(input_clip);
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,11 +226,11 @@ void _clipper_do(const ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
}
|
||||
|
||||
void _clipper(ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset)
|
||||
Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset_)
|
||||
{
|
||||
// perform operation
|
||||
ClipperLib::Polygons* output = new ClipperLib::Polygons();
|
||||
_clipper_do<ClipperLib::Polygons>(clipType, subject, clip, *output, safety_offset);
|
||||
_clipper_do<ClipperLib::Polygons>(clipType, subject, clip, *output, safety_offset_);
|
||||
|
||||
// convert into Polygons
|
||||
ClipperPolygons_to_Slic3rPolygons(*output, retval);
|
||||
@ -238,11 +238,11 @@ void _clipper(ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
}
|
||||
|
||||
void _clipper(ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
Slic3r::Polygons &clip, Slic3r::ExPolygons &retval, bool safety_offset)
|
||||
Slic3r::Polygons &clip, Slic3r::ExPolygons &retval, bool safety_offset_)
|
||||
{
|
||||
// perform operation
|
||||
ClipperLib::PolyTree* polytree = new ClipperLib::PolyTree();
|
||||
_clipper_do<ClipperLib::PolyTree>(clipType, subject, clip, *polytree, safety_offset);
|
||||
_clipper_do<ClipperLib::PolyTree>(clipType, subject, clip, *polytree, safety_offset_);
|
||||
|
||||
// convert into ExPolygons
|
||||
PolyTreeToExPolygons(*polytree, retval);
|
||||
@ -250,35 +250,35 @@ void _clipper(ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void diff(Slic3r::Polygons &subject, Slic3r::Polygons &clip, T &retval, bool safety_offset)
|
||||
void diff(Slic3r::Polygons &subject, Slic3r::Polygons &clip, T &retval, bool safety_offset_)
|
||||
{
|
||||
_clipper(ClipperLib::ctDifference, subject, clip, retval, safety_offset);
|
||||
_clipper(ClipperLib::ctDifference, subject, clip, retval, safety_offset_);
|
||||
}
|
||||
template void diff<Slic3r::ExPolygons>(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::ExPolygons &retval, bool safety_offset);
|
||||
template void diff<Slic3r::Polygons>(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset);
|
||||
template void diff<Slic3r::ExPolygons>(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::ExPolygons &retval, bool safety_offset_);
|
||||
template void diff<Slic3r::Polygons>(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset_);
|
||||
|
||||
template <class T>
|
||||
void intersection(Slic3r::Polygons &subject, Slic3r::Polygons &clip, T &retval, bool safety_offset)
|
||||
void intersection(Slic3r::Polygons &subject, Slic3r::Polygons &clip, T &retval, bool safety_offset_)
|
||||
{
|
||||
_clipper(ClipperLib::ctIntersection, subject, clip, retval, safety_offset);
|
||||
_clipper(ClipperLib::ctIntersection, subject, clip, retval, safety_offset_);
|
||||
}
|
||||
template void intersection<Slic3r::ExPolygons>(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::ExPolygons &retval, bool safety_offset);
|
||||
template void intersection<Slic3r::Polygons>(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset);
|
||||
template void intersection<Slic3r::ExPolygons>(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::ExPolygons &retval, bool safety_offset_);
|
||||
template void intersection<Slic3r::Polygons>(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset_);
|
||||
|
||||
void xor_ex(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::ExPolygons &retval,
|
||||
bool safety_offset)
|
||||
bool safety_offset_)
|
||||
{
|
||||
_clipper(ClipperLib::ctXor, subject, clip, retval, safety_offset);
|
||||
_clipper(ClipperLib::ctXor, subject, clip, retval, safety_offset_);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void union_(Slic3r::Polygons &subject, T &retval, bool safety_offset)
|
||||
void union_(Slic3r::Polygons &subject, T &retval, bool safety_offset_)
|
||||
{
|
||||
Slic3r::Polygons p;
|
||||
_clipper(ClipperLib::ctUnion, subject, p, retval, safety_offset);
|
||||
_clipper(ClipperLib::ctUnion, subject, p, retval, safety_offset_);
|
||||
}
|
||||
template void union_<Slic3r::ExPolygons>(Slic3r::Polygons &subject, Slic3r::ExPolygons &retval, bool safety_offset);
|
||||
template void union_<Slic3r::Polygons>(Slic3r::Polygons &subject, Slic3r::Polygons &retval, bool safety_offset);
|
||||
template void union_<Slic3r::ExPolygons>(Slic3r::Polygons &subject, Slic3r::ExPolygons &retval, bool safety_offset_);
|
||||
template void union_<Slic3r::Polygons>(Slic3r::Polygons &subject, Slic3r::Polygons &retval, bool safety_offset_);
|
||||
|
||||
void simplify_polygons(Slic3r::Polygons &subject, Slic3r::Polygons &retval)
|
||||
{
|
||||
@ -295,4 +295,21 @@ void simplify_polygons(Slic3r::Polygons &subject, Slic3r::Polygons &retval)
|
||||
delete output;
|
||||
}
|
||||
|
||||
void safety_offset(ClipperLib::Polygons* &subject)
|
||||
{
|
||||
// scale input
|
||||
scaleClipperPolygons(*subject, CLIPPER_OFFSET_SCALE);
|
||||
|
||||
// perform offset (delta = scale 1e-05)
|
||||
ClipperLib::Polygons* retval = new ClipperLib::Polygons();
|
||||
ClipperLib::OffsetPolygons(*subject, *retval, 10.0 * CLIPPER_OFFSET_SCALE, ClipperLib::jtMiter, 2);
|
||||
|
||||
// unscale output
|
||||
scaleClipperPolygons(*retval, 1.0/CLIPPER_OFFSET_SCALE);
|
||||
|
||||
// delete original data and switch pointer
|
||||
delete subject;
|
||||
subject = retval;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
#define CLIPPER_OFFSET_SCALE 100000.0
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// legacy code from Clipper documentation
|
||||
@ -45,26 +46,28 @@ void offset2_ex(Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const fl
|
||||
|
||||
template <class T>
|
||||
void _clipper_do(ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
Slic3r::Polygons &clip, T &retval, bool safety_offset);
|
||||
Slic3r::Polygons &clip, T &retval, bool safety_offset_);
|
||||
void _clipper(ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset);
|
||||
Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset_);
|
||||
void _clipper(ClipperLib::ClipType clipType, Slic3r::Polygons &subject,
|
||||
Slic3r::Polygons &clip, Slic3r::ExPolygons &retval, bool safety_offset);
|
||||
Slic3r::Polygons &clip, Slic3r::ExPolygons &retval, bool safety_offset_);
|
||||
|
||||
template <class T>
|
||||
void diff(Slic3r::Polygons &subject, Slic3r::Polygons &clip, T &retval, bool safety_offset);
|
||||
void diff(Slic3r::Polygons &subject, Slic3r::Polygons &clip, T &retval, bool safety_offset_);
|
||||
|
||||
template <class T>
|
||||
void intersection(Slic3r::Polygons &subject, Slic3r::Polygons &clip, T &retval, bool safety_offset);
|
||||
void intersection(Slic3r::Polygons &subject, Slic3r::Polygons &clip, T &retval, bool safety_offset_);
|
||||
|
||||
void xor_ex(Slic3r::Polygons &subject, Slic3r::Polygons &clip, Slic3r::ExPolygons &retval,
|
||||
bool safety_offset = false);
|
||||
bool safety_offset_ = false);
|
||||
|
||||
template <class T>
|
||||
void union_(Slic3r::Polygons &subject, T &retval, bool safety_offset = false);
|
||||
void union_(Slic3r::Polygons &subject, T &retval, bool safety_offset_ = false);
|
||||
|
||||
void simplify_polygons(Slic3r::Polygons &subject, Slic3r::Polygons &retval);
|
||||
|
||||
void safety_offset(ClipperLib::Polygons* &subject);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -11,7 +11,7 @@
|
||||
%{
|
||||
|
||||
Polygons
|
||||
offset(polygons, delta, scale = 100000, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||
offset(polygons, delta, scale = CLIPPER_OFFSET_SCALE, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||
Polygons polygons
|
||||
const float delta
|
||||
double scale
|
||||
@ -23,7 +23,7 @@ offset(polygons, delta, scale = 100000, joinType = ClipperLib::jtMiter, miterLim
|
||||
RETVAL
|
||||
|
||||
ExPolygons
|
||||
offset_ex(polygons, delta, scale = 100000, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||
offset_ex(polygons, delta, scale = CLIPPER_OFFSET_SCALE, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||
Polygons polygons
|
||||
const float delta
|
||||
double scale
|
||||
@ -35,7 +35,7 @@ offset_ex(polygons, delta, scale = 100000, joinType = ClipperLib::jtMiter, miter
|
||||
RETVAL
|
||||
|
||||
Polygons
|
||||
offset2(polygons, delta1, delta2, scale = 100000, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||
offset2(polygons, delta1, delta2, scale = CLIPPER_OFFSET_SCALE, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||
Polygons polygons
|
||||
const float delta1
|
||||
const float delta2
|
||||
@ -48,7 +48,7 @@ offset2(polygons, delta1, delta2, scale = 100000, joinType = ClipperLib::jtMiter
|
||||
RETVAL
|
||||
|
||||
ExPolygons
|
||||
offset2_ex(polygons, delta1, delta2, scale = 100000, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||
offset2_ex(polygons, delta1, delta2, scale = CLIPPER_OFFSET_SCALE, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||
Polygons polygons
|
||||
const float delta1
|
||||
const float delta2
|
||||
|
Loading…
Reference in New Issue
Block a user