83 lines
3.4 KiB
C++
83 lines
3.4 KiB
C++
#include <stdio.h>
|
|
#include <emscripten/bind.h>
|
|
#include <emscripten/val.h>
|
|
#include "../psimpl_v7_src/psimpl.h"
|
|
|
|
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]));
|
|
}
|
|
|
|
val perpendicular_distance(uintptr_t ptr, int length, double tol, unsigned repeat) {
|
|
double* begin = reinterpret_cast<double*>(ptr);
|
|
double* end = begin + length;
|
|
std::vector<double> resultCoords;
|
|
psimpl::simplify_perpendicular_distance<2>(begin, end, tol, repeat, std::back_inserter(resultCoords));
|
|
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>");
|
|
}
|