Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2013-07-20 23:19:59 +0400
committerAlessandro Ranellucci <aar@cpan.org>2013-07-20 23:19:59 +0400
commitb1147861ddcc2f3e06790a2e4d08b243f49f5777 (patch)
tree073959bcd3b31ae27a377122d8cde2e84edf98d2 /xs
parente29aca35539ee7a85eb02b95e22a07f0834ec5fc (diff)
Implement lower_bound() and upper_bound() methods for ZTable
Diffstat (limited to 'xs')
-rw-r--r--xs/t/02_object.t15
-rw-r--r--xs/xsp/Object.xsp20
2 files changed, 34 insertions, 1 deletions
diff --git a/xs/t/02_object.t b/xs/t/02_object.t
index 4ceddeda3..53a6f869b 100644
--- a/xs/t/02_object.t
+++ b/xs/t/02_object.t
@@ -4,9 +4,22 @@ use strict;
use warnings;
use Slic3r::XS;
-use Test::More tests => 1;
+use Test::More tests => 10;
my $table = Slic3r::Object::XS::ZTable->new([ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]);
+is_deeply $table->get_range(31, 61), [2, 6], 'get_layer_range';
is_deeply $table->get_range(39, 69), [2, 6], 'get_layer_range';
+is_deeply $table->get_range(30, 60), [2, 5], 'get_layer_range';
+
+# upper_bound points to the first element that is greater than argument
+is $table->upper_bound(30), 3, 'upper_bound';
+is $table->upper_bound(31), 3, 'upper_bound';
+is $table->upper_bound(39), 3, 'upper_bound';
+is $table->upper_bound(39, 4), 4, 'upper_bound with offset';
+
+# lower_bound points to the first element that is not less than argument
+is $table->lower_bound(31), 3, 'lower_bound';
+is $table->lower_bound(39), 3, 'lower_bound';
+is $table->lower_bound(40), 3, 'lower_bound';
__END__
diff --git a/xs/xsp/Object.xsp b/xs/xsp/Object.xsp
index 2f8a0601e..9e800cdf8 100644
--- a/xs/xsp/Object.xsp
+++ b/xs/xsp/Object.xsp
@@ -8,6 +8,7 @@
%name{Slic3r::Object::XS::ZTable} class ZTable {
ZTable(std::vector<unsigned int>* z_array);
+ ~ZTable();
%{
std::vector<unsigned int>
@@ -47,6 +48,25 @@ get_range(THIS, min_z, max_z)
}
OUTPUT:
RETVAL
+
+unsigned int
+ZTable::lower_bound(z, offset = 0)
+ unsigned int z
+ unsigned int offset
+ CODE:
+ RETVAL = std::lower_bound(THIS->z.begin() + offset, THIS->z.end(), z) - THIS->z.begin();
+ OUTPUT:
+ RETVAL
+
+unsigned int
+ZTable::upper_bound(z, offset = 0)
+ unsigned int z
+ unsigned int offset
+ CODE:
+ RETVAL = std::upper_bound(THIS->z.begin() + offset, THIS->z.end(), z) - THIS->z.begin();
+ OUTPUT:
+ RETVAL
+
%}
};