mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-30 04:02:52 -06:00
[refactor] Move remaining utility functions into sla_test_utils
This commit is contained in:
parent
4bc4e347fb
commit
7f476f38b9
3 changed files with 175 additions and 167 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
// Debug
|
||||
#include <fstream>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "libslic3r/libslic3r.h"
|
||||
#include "libslic3r/Format/OBJ.hpp"
|
||||
|
|
@ -109,4 +110,78 @@ inline void test_support_model_collision(
|
|||
test_support_model_collision(obj_filename, input_supportcfg, hcfg, {});
|
||||
}
|
||||
|
||||
// Test pair hash for 'nums' random number pairs.
|
||||
template <class I, class II> void test_pairhash()
|
||||
{
|
||||
const constexpr size_t nums = 1000;
|
||||
I A[nums] = {0}, B[nums] = {0};
|
||||
std::unordered_set<I> CH;
|
||||
std::unordered_map<II, std::pair<I, I>> ints;
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
const I Ibits = int(sizeof(I) * CHAR_BIT);
|
||||
const II IIbits = int(sizeof(II) * CHAR_BIT);
|
||||
|
||||
int bits = IIbits / 2 < Ibits ? Ibits / 2 : Ibits;
|
||||
if (std::is_signed<I>::value) bits -= 1;
|
||||
const I Imin = 0;
|
||||
const I Imax = I(std::pow(2., bits) - 1);
|
||||
|
||||
std::uniform_int_distribution<I> dis(Imin, Imax);
|
||||
|
||||
for (size_t i = 0; i < nums;) {
|
||||
I a = dis(gen);
|
||||
if (CH.find(a) == CH.end()) { CH.insert(a); A[i] = a; ++i; }
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nums;) {
|
||||
I b = dis(gen);
|
||||
if (CH.find(b) == CH.end()) { CH.insert(b); B[i] = b; ++i; }
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nums; ++i) {
|
||||
I a = A[i], b = B[i];
|
||||
|
||||
REQUIRE(a != b);
|
||||
|
||||
II hash_ab = sla::pairhash<I, II>(a, b);
|
||||
II hash_ba = sla::pairhash<I, II>(b, a);
|
||||
REQUIRE(hash_ab == hash_ba);
|
||||
|
||||
auto it = ints.find(hash_ab);
|
||||
|
||||
if (it != ints.end()) {
|
||||
REQUIRE((
|
||||
(it->second.first == a && it->second.second == b) ||
|
||||
(it->second.first == b && it->second.second == a)
|
||||
));
|
||||
} else
|
||||
ints[hash_ab] = std::make_pair(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
// SLA Raster test utils:
|
||||
|
||||
using TPixel = uint8_t;
|
||||
static constexpr const TPixel FullWhite = 255;
|
||||
static constexpr const TPixel FullBlack = 0;
|
||||
|
||||
template <class A, int N> constexpr int arraysize(const A (&)[N]) { return N; }
|
||||
|
||||
void check_raster_transformations(sla::Raster::Orientation o,
|
||||
sla::Raster::TMirroring mirroring);
|
||||
|
||||
ExPolygon square_with_hole(double v);
|
||||
|
||||
inline double pixel_area(TPixel px, const sla::Raster::PixelDim &pxdim)
|
||||
{
|
||||
return (pxdim.h_mm * pxdim.w_mm) * px * 1. / (FullWhite - FullBlack);
|
||||
}
|
||||
|
||||
double raster_white_area(const sla::Raster &raster);
|
||||
|
||||
double predict_error(const ExPolygon &p, const sla::Raster::PixelDim &pd);
|
||||
|
||||
#endif // SLA_TEST_UTILS_HPP
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue