feat: establish reproducible FreeCAD web compatibility baseline
This commit is contained in:
25
native/camotics-wasm/build.sh
Executable file
25
native/camotics-wasm/build.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
|
||||
source_root="$repo_root/CAMotics/src"
|
||||
output_dir="$repo_root/public/vendor/camotics"
|
||||
|
||||
test -f "$source_root/camotics/sim/ConicSweep.cpp"
|
||||
test -f "$source_root/camotics/sim/SpheroidSweep.cpp"
|
||||
command -v em++ >/dev/null
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
em++ \
|
||||
"$repo_root/native/camotics-wasm/camotics_sweep.cpp" \
|
||||
"$source_root/camotics/sim/Sweep.cpp" \
|
||||
"$source_root/camotics/sim/ConicSweep.cpp" \
|
||||
"$source_root/camotics/sim/SpheroidSweep.cpp" \
|
||||
-I"$repo_root/native/camotics-wasm/include" \
|
||||
-I"$source_root" \
|
||||
-std=c++17 -O3 -flto -fno-exceptions \
|
||||
-sSTANDALONE_WASM=1 \
|
||||
-sERROR_ON_UNDEFINED_SYMBOLS=1 \
|
||||
-sEXPORTED_FUNCTIONS='["_camotics_sweep_abi_version","_camotics_conic_depth","_camotics_spheroid_depth","_camotics_conic_bbox_count"]' \
|
||||
-Wl,--no-entry \
|
||||
-o "$output_dir/camotics-sweep.wasm"
|
||||
44
native/camotics-wasm/camotics_sweep.cpp
Normal file
44
native/camotics-wasm/camotics_sweep.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <camotics/sim/ConicSweep.h>
|
||||
#include <camotics/sim/SpheroidSweep.h>
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using CAMotics::ConicSweep;
|
||||
using CAMotics::SpheroidSweep;
|
||||
using cb::Rectangle3D;
|
||||
using cb::Vector3D;
|
||||
|
||||
extern "C" {
|
||||
EMSCRIPTEN_KEEPALIVE int camotics_sweep_abi_version() {return 1;}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE double camotics_conic_depth(
|
||||
double length, double topRadius, double bottomRadius,
|
||||
double ax, double ay, double az,
|
||||
double bx, double by, double bz,
|
||||
double px, double py, double pz) {
|
||||
return ConicSweep(length, topRadius, bottomRadius).depth(
|
||||
Vector3D(ax, ay, az), Vector3D(bx, by, bz), Vector3D(px, py, pz));
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE double camotics_spheroid_depth(
|
||||
double radius, double length,
|
||||
double ax, double ay, double az,
|
||||
double bx, double by, double bz,
|
||||
double px, double py, double pz) {
|
||||
return SpheroidSweep(radius, length).depth(
|
||||
Vector3D(ax, ay, az), Vector3D(bx, by, bz), Vector3D(px, py, pz));
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE int camotics_conic_bbox_count(
|
||||
double length, double topRadius, double bottomRadius,
|
||||
double ax, double ay, double az,
|
||||
double bx, double by, double bz,
|
||||
double tolerance) {
|
||||
std::vector<Rectangle3D> bounds;
|
||||
ConicSweep(length, topRadius, bottomRadius).getBBoxes(
|
||||
Vector3D(ax, ay, az), Vector3D(bx, by, bz), bounds, tolerance);
|
||||
return bounds.size();
|
||||
}
|
||||
}
|
||||
56
native/camotics-wasm/include/cbang/geom/Rectangle.h
Normal file
56
native/camotics-wasm/include/cbang/geom/Rectangle.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace cb {
|
||||
class Vector3D {
|
||||
double values[3];
|
||||
|
||||
public:
|
||||
Vector3D(double value = 0) : values{value, value, value} {}
|
||||
Vector3D(double x, double y, double z) : values{x, y, z} {}
|
||||
|
||||
double &operator[](unsigned index) {return values[index];}
|
||||
double operator[](unsigned index) const {return values[index];}
|
||||
double x() const {return values[0];}
|
||||
double y() const {return values[1];}
|
||||
double z() const {return values[2];}
|
||||
|
||||
Vector3D operator+(const Vector3D &other) const {
|
||||
return Vector3D(x() + other.x(), y() + other.y(), z() + other.z());
|
||||
}
|
||||
Vector3D operator-(const Vector3D &other) const {
|
||||
return Vector3D(x() - other.x(), y() - other.y(), z() - other.z());
|
||||
}
|
||||
Vector3D operator*(double scalar) const {
|
||||
return Vector3D(x() * scalar, y() * scalar, z() * scalar);
|
||||
}
|
||||
Vector3D &operator*=(const Vector3D &other) {
|
||||
values[0] *= other.x();
|
||||
values[1] *= other.y();
|
||||
values[2] *= other.z();
|
||||
return *this;
|
||||
}
|
||||
double dot(const Vector3D &other) const {
|
||||
return x() * other.x() + y() * other.y() + z() * other.z();
|
||||
}
|
||||
double distance(const Vector3D &other) const {
|
||||
const Vector3D delta = *this - other;
|
||||
return std::sqrt(delta.dot(delta));
|
||||
}
|
||||
};
|
||||
|
||||
class Rectangle3D {
|
||||
Vector3D minimum;
|
||||
Vector3D maximum;
|
||||
|
||||
public:
|
||||
Rectangle3D() = default;
|
||||
Rectangle3D(const Vector3D &minimum, const Vector3D &maximum) :
|
||||
minimum(minimum), maximum(maximum) {}
|
||||
|
||||
const Vector3D &getMin() const {return minimum;}
|
||||
const Vector3D &getMax() const {return maximum;}
|
||||
};
|
||||
}
|
||||
1
native/camotics-wasm/include/cbang/log/Logger.h
Normal file
1
native/camotics-wasm/include/cbang/log/Logger.h
Normal file
@@ -0,0 +1 @@
|
||||
#pragma once
|
||||
3
native/camotics-wasm/include/gcode/Move.h
Normal file
3
native/camotics-wasm/include/gcode/Move.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
namespace GCode {class Move;}
|
||||
Reference in New Issue
Block a user