mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-21 07:41:09 -06:00
Implement lower_bound() and upper_bound() methods for ZTable
This commit is contained in:
parent
e29aca3553
commit
b1147861dd
3 changed files with 43 additions and 4 deletions
|
@ -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__
|
||||
|
|
|
@ -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
|
||||
|
||||
%}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue