Fixed minor regression

This commit is contained in:
Alessandro Ranellucci 2014-11-04 21:07:18 +01:00
parent d452a16ba8
commit a4eef93950
4 changed files with 9 additions and 6 deletions

View file

@ -209,7 +209,7 @@ ConfigBase::set(t_config_option_key opt_key, SV* value) {
optv->values.push_back(std::string(SvPV_nolen(*elem), SvCUR(*elem))); optv->values.push_back(std::string(SvPV_nolen(*elem), SvCUR(*elem)));
} }
} else if (ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt)) { } else if (ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt)) {
return optv->point.from_SV(value); return optv->point.from_SV_check(value);
} else if (ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt)) { } else if (ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt)) {
std::vector<Pointf> values; std::vector<Pointf> values;
AV* av = (AV*)SvRV(value); AV* av = (AV*)SvRV(value);
@ -217,7 +217,7 @@ ConfigBase::set(t_config_option_key opt_key, SV* value) {
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
SV** elem = av_fetch(av, i, 0); SV** elem = av_fetch(av, i, 0);
Pointf point; Pointf point;
if (elem == NULL || !point.from_SV(*elem)) return false; if (elem == NULL || !point.from_SV_check(*elem)) return false;
values.push_back(point); values.push_back(point);
} }
optv->values = values; optv->values = values;

View file

@ -306,15 +306,16 @@ Pointf::from_SV(SV* point_sv)
return true; return true;
} }
void bool
Pointf::from_SV_check(SV* point_sv) Pointf::from_SV_check(SV* point_sv)
{ {
if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) { if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) {
if (!sv_isa(point_sv, perl_class_name(this)) && !sv_isa(point_sv, perl_class_name_ref(this))) if (!sv_isa(point_sv, perl_class_name(this)) && !sv_isa(point_sv, perl_class_name_ref(this)))
CONFESS("Not a valid %s object (got %s)", perl_class_name(this), HvNAME(SvSTASH(SvRV(point_sv)))); CONFESS("Not a valid %s object (got %s)", perl_class_name(this), HvNAME(SvSTASH(SvRV(point_sv))));
*this = *(Pointf*)SvIV((SV*)SvRV( point_sv )); *this = *(Pointf*)SvIV((SV*)SvRV( point_sv ));
return true;
} else { } else {
this->from_SV(point_sv); return this->from_SV(point_sv);
} }
} }
#endif #endif

View file

@ -75,7 +75,7 @@ class Pointf
#ifdef SLIC3RXS #ifdef SLIC3RXS
bool from_SV(SV* point_sv); bool from_SV(SV* point_sv);
void from_SV_check(SV* point_sv); bool from_SV_check(SV* point_sv);
SV* to_SV_pureperl() const; SV* to_SV_pureperl() const;
#endif #endif
}; };

View file

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use Slic3r::XS; use Slic3r::XS;
use Test::More tests => 105; use Test::More tests => 107;
foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) { foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) {
$config->set('layer_height', 0.3); $config->set('layer_height', 0.3);
@ -60,6 +60,8 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) {
$config->set('extruder_offset', [[10,20],[30,45]]); $config->set('extruder_offset', [[10,20],[30,45]]);
is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[10,20],[30,45]], 'set/get points'; is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[10,20],[30,45]], 'set/get points';
$config->set('extruder_offset', [Slic3r::Pointf->new(10,20),Slic3r::Pointf->new(30,45)]);
is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[10,20],[30,45]], 'set/get points';
is $config->serialize('extruder_offset'), '10x20,30x45', 'serialize points'; is $config->serialize('extruder_offset'), '10x20,30x45', 'serialize points';
$config->set_deserialize('extruder_offset', '20x10'); $config->set_deserialize('extruder_offset', '20x10');
is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[20,10]], 'deserialize points'; is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[20,10]], 'deserialize points';