mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-30 16:42:43 +00:00
Ported get_layer_range() to C
This commit is contained in:
49
xs/xsp/Object.xsp
Normal file
49
xs/xsp/Object.xsp
Normal file
@@ -0,0 +1,49 @@
|
||||
%module{Slic3r::XS};
|
||||
%package{Slic3r::Object::XS};
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
%{
|
||||
PROTOTYPES: DISABLE
|
||||
|
||||
std::vector<unsigned int>
|
||||
get_layer_range(z_array, min_z, max_z)
|
||||
std::vector<unsigned int>* z_array;
|
||||
unsigned int min_z;
|
||||
unsigned int max_z;
|
||||
CODE:
|
||||
RETVAL.resize(2);
|
||||
|
||||
unsigned int bottom = 0;
|
||||
unsigned int top = z_array->size()-1;
|
||||
while (1) {
|
||||
unsigned int mid = bottom + floor((top - bottom)/2.0);
|
||||
if (mid == top || mid == bottom) {
|
||||
RETVAL[0] = mid;
|
||||
break;
|
||||
}
|
||||
if ((*z_array)[mid] > min_z) {
|
||||
top = mid;
|
||||
} else {
|
||||
bottom = mid;
|
||||
}
|
||||
}
|
||||
top = z_array->size()-1;
|
||||
while (1) {
|
||||
unsigned int mid = bottom + ceil((top - bottom)/2.0);
|
||||
if (mid == top || mid == bottom) {
|
||||
RETVAL[1] = mid;
|
||||
break;
|
||||
}
|
||||
if ((*z_array)[mid] < max_z) {
|
||||
bottom = mid;
|
||||
} else {
|
||||
top = mid;
|
||||
}
|
||||
}
|
||||
delete z_array;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
%}
|
||||
Reference in New Issue
Block a user