2019-07-19 19:33:27 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <emscripten/bind.h>
|
|
|
|
#include <emscripten/val.h>
|
2019-07-20 10:45:41 +02:00
|
|
|
#include "../psimpl_v7_src/psimpl.h"
|
2019-07-19 19:33:27 +02:00
|
|
|
|
|
|
|
using namespace emscripten;
|
|
|
|
|
|
|
|
val nth_point(uintptr_t ptr, int length, int n) {
|
|
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
|
|
double* end = begin + length;
|
|
|
|
std::vector<double> resultCoords;
|
|
|
|
psimpl::simplify_nth_point<2>(begin, end, n, std::back_inserter(resultCoords));
|
|
|
|
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
val radial_distance(uintptr_t ptr, int length, double tol) {
|
|
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
|
|
double* end = begin + length;
|
|
|
|
std::vector<double> resultCoords;
|
|
|
|
psimpl::simplify_radial_distance<2>(begin, end, tol, std::back_inserter(resultCoords));
|
|
|
|
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
|
|
|
|
}
|
|
|
|
|
2019-07-21 12:50:30 +02:00
|
|
|
val perpendicular_distance(uintptr_t ptr, int length, double tol, unsigned repeat) {
|
2019-07-19 19:33:27 +02:00
|
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
|
|
double* end = begin + length;
|
|
|
|
std::vector<double> resultCoords;
|
2019-07-21 12:50:30 +02:00
|
|
|
psimpl::simplify_perpendicular_distance<2>(begin, end, tol, repeat, std::back_inserter(resultCoords));
|
2019-07-19 19:33:27 +02:00
|
|
|
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
val reumann_witkam(uintptr_t ptr, int length, double tol) {
|
|
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
|
|
double* end = begin + length;
|
|
|
|
std::vector<double> resultCoords;
|
|
|
|
psimpl::simplify_reumann_witkam<2>(begin, end, tol, std::back_inserter(resultCoords));
|
|
|
|
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
val opheim(uintptr_t ptr, int length, double minTol, double maxTol) {
|
|
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
|
|
double* end = begin + length;
|
|
|
|
std::vector<double> resultCoords;
|
|
|
|
psimpl::simplify_opheim<2>(begin, end, minTol, maxTol, std::back_inserter(resultCoords));
|
|
|
|
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
val lang(uintptr_t ptr, int length, double tol, unsigned look_ahead) {
|
|
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
|
|
double* end = begin + length;
|
|
|
|
std::vector<double> resultCoords;
|
|
|
|
psimpl::simplify_lang<2>(begin, end, tol, look_ahead, std::back_inserter(resultCoords));
|
|
|
|
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
val douglas_peucker(uintptr_t ptr, int length, double tol) {
|
|
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
|
|
double* end = begin + length;
|
|
|
|
std::vector<double> resultCoords;
|
|
|
|
psimpl::simplify_douglas_peucker<2>(begin, end, tol, std::back_inserter(resultCoords));
|
|
|
|
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
val douglas_peucker_n(uintptr_t ptr, int length, unsigned count) {
|
|
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
|
|
double* end = begin + length;
|
|
|
|
std::vector<double> resultCoords;
|
|
|
|
psimpl::simplify_douglas_peucker_n<2>(begin, end, count, std::back_inserter(resultCoords));
|
|
|
|
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
EMSCRIPTEN_BINDINGS(my_module) {
|
|
|
|
function("nth_point", &nth_point);
|
|
|
|
function("radial_distance", &radial_distance);
|
|
|
|
function("perpendicular_distance", &perpendicular_distance);
|
|
|
|
function("reumann_witkam", &reumann_witkam);
|
|
|
|
function("opheim", &opheim);
|
|
|
|
function("lang", &lang);
|
|
|
|
function("douglas_peucker", &douglas_peucker);
|
|
|
|
function("douglas_peucker_n", &douglas_peucker_n);
|
|
|
|
register_vector<double>("vector<double>");
|
|
|
|
}
|