2013-06-23 13:33:07 +00:00
|
|
|
%module{Slic3r::XS};
|
|
|
|
|
2013-06-23 15:07:12 +00:00
|
|
|
%{
|
|
|
|
#include <myinit.h>
|
2013-07-06 13:26:32 +00:00
|
|
|
#include "ZTable.hpp"
|
2013-06-23 13:33:07 +00:00
|
|
|
#include <vector>
|
2013-07-23 09:36:18 +00:00
|
|
|
#include <algorithm>
|
2013-06-23 15:07:12 +00:00
|
|
|
%}
|
2013-06-23 13:33:07 +00:00
|
|
|
|
2013-06-23 15:07:12 +00:00
|
|
|
%name{Slic3r::Object::XS::ZTable} class ZTable {
|
|
|
|
ZTable(std::vector<unsigned int>* z_array);
|
2013-07-20 19:19:59 +00:00
|
|
|
~ZTable();
|
2013-06-23 13:33:07 +00:00
|
|
|
|
2013-06-23 15:07:12 +00:00
|
|
|
%{
|
2013-06-23 13:33:07 +00:00
|
|
|
std::vector<unsigned int>
|
2013-06-23 15:07:12 +00:00
|
|
|
get_range(THIS, min_z, max_z)
|
|
|
|
ZTable* THIS;
|
2013-06-23 13:33:07 +00:00
|
|
|
unsigned int min_z;
|
|
|
|
unsigned int max_z;
|
|
|
|
CODE:
|
|
|
|
RETVAL.resize(2);
|
|
|
|
|
|
|
|
unsigned int bottom = 0;
|
2013-06-23 15:07:12 +00:00
|
|
|
unsigned int top = THIS->z.size()-1;
|
2013-06-23 13:33:07 +00:00
|
|
|
while (1) {
|
|
|
|
unsigned int mid = bottom + floor((top - bottom)/2.0);
|
|
|
|
if (mid == top || mid == bottom) {
|
|
|
|
RETVAL[0] = mid;
|
|
|
|
break;
|
|
|
|
}
|
2013-06-23 15:07:12 +00:00
|
|
|
if (THIS->z[mid] > min_z) {
|
2013-06-23 13:33:07 +00:00
|
|
|
top = mid;
|
|
|
|
} else {
|
|
|
|
bottom = mid;
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 15:07:12 +00:00
|
|
|
top = THIS->z.size()-1;
|
2013-06-23 13:33:07 +00:00
|
|
|
while (1) {
|
|
|
|
unsigned int mid = bottom + ceil((top - bottom)/2.0);
|
|
|
|
if (mid == top || mid == bottom) {
|
|
|
|
RETVAL[1] = mid;
|
|
|
|
break;
|
|
|
|
}
|
2013-06-23 15:07:12 +00:00
|
|
|
if (THIS->z[mid] < max_z) {
|
2013-06-23 13:33:07 +00:00
|
|
|
bottom = mid;
|
|
|
|
} else {
|
|
|
|
top = mid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OUTPUT:
|
|
|
|
RETVAL
|
2013-07-20 19:19:59 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-06-23 15:07:12 +00:00
|
|
|
%}
|
2013-06-23 13:33:07 +00:00
|
|
|
|
2013-06-23 15:07:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
%package{Slic3r::Object::XS};
|
|
|
|
|
|
|
|
%{
|
|
|
|
#include <myinit.h>
|
|
|
|
#include <vector>
|
2013-06-23 13:33:07 +00:00
|
|
|
%}
|