Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision renaming #1008

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bindings/c/include/manifold/manifoldc.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ ManifoldManifold *manifold_level_set(void *mem,
double (*sdf)(double, double, double,
void *),
ManifoldBox *bounds, double edge_length,
double level, double precision, void *ctx);
double level, double tolerance, void *ctx);
ManifoldManifold *manifold_level_set_seq(
void *mem, double (*sdf)(double, double, double, void *),
ManifoldBox *bounds, double edge_length, double level, double precision,
ManifoldBox *bounds, double edge_length, double level, double tolerance,
void *ctx);

// Manifold Vectors
Expand Down Expand Up @@ -142,8 +142,8 @@ ManifoldManifold *manifold_smooth_out(void *mem, ManifoldManifold *m,
ManifoldManifold *manifold_refine(void *mem, ManifoldManifold *m, int refine);
ManifoldManifold *manifold_refine_to_length(void *mem, ManifoldManifold *m,
double length);
ManifoldManifold *manifold_refine_to_precision(void *mem, ManifoldManifold *m,
double precision);
ManifoldManifold *manifold_refine_to_tolerance(void *mem, ManifoldManifold *m,
double tolerance);

// Manifold Shapes / Constructors

Expand Down Expand Up @@ -180,7 +180,7 @@ size_t manifold_num_vert(ManifoldManifold *m);
size_t manifold_num_edge(ManifoldManifold *m);
size_t manifold_num_tri(ManifoldManifold *m);
ManifoldBox *manifold_bounding_box(void *mem, ManifoldManifold *m);
double manifold_precision(ManifoldManifold *m);
double manifold_epsilon(ManifoldManifold *m);
int manifold_genus(ManifoldManifold *m);
ManifoldProperties manifold_get_properties(ManifoldManifold *m);
int manifold_get_circular_segments(double radius);
Expand Down
22 changes: 10 additions & 12 deletions bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace manifold;
namespace {
ManifoldManifold *level_set(
void *mem, double (*sdf_context)(double, double, double, void *),
ManifoldBox *bounds, double edge_length, double level, double precision,
ManifoldBox *bounds, double edge_length, double level, double tolerance,
bool seq, void *ctx) {
// Bind function with context argument to one without
using namespace std::placeholders;
Expand All @@ -37,7 +37,7 @@ ManifoldManifold *level_set(
return (sdf(v.x, v.y, v.z));
};
return to_c(new (mem) Manifold(Manifold::LevelSet(
fun, *from_c(bounds), edge_length, level, precision, !seq)));
fun, *from_c(bounds), edge_length, level, tolerance, !seq)));
}
} // namespace

Expand Down Expand Up @@ -265,16 +265,16 @@ ManifoldManifold *manifold_warp(void *mem, ManifoldManifold *m,

ManifoldManifold *manifold_level_set(
void *mem, double (*sdf)(double, double, double, void *),
ManifoldBox *bounds, double edge_length, double level, double precision,
ManifoldBox *bounds, double edge_length, double level, double tolerance,
void *ctx) {
return level_set(mem, sdf, bounds, edge_length, level, precision, false, ctx);
return level_set(mem, sdf, bounds, edge_length, level, tolerance, false, ctx);
}

ManifoldManifold *manifold_level_set_seq(
void *mem, double (*sdf)(double, double, double, void *),
ManifoldBox *bounds, double edge_length, double level, double precision,
ManifoldBox *bounds, double edge_length, double level, double tolerance,
void *ctx) {
return level_set(mem, sdf, bounds, edge_length, level, precision, true, ctx);
return level_set(mem, sdf, bounds, edge_length, level, tolerance, true, ctx);
}

ManifoldManifold *manifold_smooth_by_normals(void *mem, ManifoldManifold *m,
Expand All @@ -301,9 +301,9 @@ ManifoldManifold *manifold_refine_to_length(void *mem, ManifoldManifold *m,
return to_c(new (mem) Manifold(refined));
}

ManifoldManifold *manifold_refine_to_precision(void *mem, ManifoldManifold *m,
double precision) {
auto refined = from_c(m)->RefineToPrecision(precision);
ManifoldManifold *manifold_refine_to_tolerance(void *mem, ManifoldManifold *m,
double tolerance) {
auto refined = from_c(m)->RefineToTolerance(tolerance);
return to_c(new (mem) Manifold(refined));
}

Expand Down Expand Up @@ -524,9 +524,7 @@ ManifoldBox *manifold_bounding_box(void *mem, ManifoldManifold *m) {
return to_c(new (mem) Box(box));
}

double manifold_precision(ManifoldManifold *m) {
return from_c(m)->GetEpsilon();
}
double manifold_epsilon(ManifoldManifold *m) { return from_c(m)->GetEpsilon(); }

uint32_t manifold_reserve_ids(uint32_t n) { return Manifold::ReserveIDs(n); }

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/all_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def all_manifold():
c = m.project()
m = m.refine(2)
m = m.refine_to_length(0.1)
m = m.refine_to_precision(0.01)
m = m.refine_to_tolerance(0.01)
m = m.smooth_out()
i = Manifold.reserve_ids(1)
m = m.scale((1, 2, 3))
Expand Down
16 changes: 8 additions & 8 deletions bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ NB_MODULE(manifold3d, m) {
.def("refine", &Manifold::Refine, nb::arg("n"), manifold__refine__n)
.def("refine_to_length", &Manifold::RefineToLength, nb::arg("length"),
manifold__refine_to_length__length)
.def("refine_to_precision", &Manifold::RefineToPrecision,
nb::arg("precision"), manifold__refine_to_precision__precision)
.def("refine_to_tolerance", &Manifold::RefineToTolerance,
nb::arg("tolerance"), manifold__refine_to_tolerance__tolerance)
.def("to_mesh", &Manifold::GetMeshGL,
nb::arg("normal_idx") = std::make_tuple(0, 0, 0),
manifold__get_mesh_gl__normal_idx)
Expand Down Expand Up @@ -437,7 +437,7 @@ NB_MODULE(manifold3d, m) {
"level_set",
[](const std::function<double(double, double, double)> &f,
std::vector<double> bounds, double edgeLength, double level = 0.0,
double precision = -1) {
double tolerance = -1) {
// Same format as Manifold.bounding_box
Box bound = {vec3(bounds[0], bounds[1], bounds[2]),
vec3(bounds[3], bounds[4], bounds[5])};
Expand All @@ -446,11 +446,11 @@ NB_MODULE(manifold3d, m) {
return f(v.x, v.y, v.z);
};
return Manifold::LevelSet(cppToPython, bound, edgeLength, level,
precision, false);
tolerance, false);
},
nb::arg("f"), nb::arg("bounds"), nb::arg("edgeLength"),
nb::arg("level") = 0.0, nb::arg("precision") = -1,
manifold__level_set__sdf__bounds__edge_length__level__precision__can_parallel)
nb::arg("level") = 0.0, nb::arg("tolerance") = -1,
manifold__level_set__sdf__bounds__edge_length__level__tolerance__can_parallel)
.def_static(
"cylinder", &Manifold::Cylinder, nb::arg("height"),
nb::arg("radius_low"), nb::arg("radius_high") = -1.0f,
Expand Down Expand Up @@ -484,7 +484,7 @@ NB_MODULE(manifold3d, m) {
nb::ndarray<uint32_t, nb::shape<-1>, nb::c_contig>> &faceID,
const std::optional<nb::ndarray<float, nb::shape<-1, 3, 4>,
nb::c_contig>> &halfedgeTangent,
float precision) {
float tolerance) {
new (self) MeshGL();
MeshGL &out = *self;
out.numProp = vertProp.shape(1);
Expand Down Expand Up @@ -529,7 +529,7 @@ NB_MODULE(manifold3d, m) {
nb::arg("run_original_id") = nb::none(),
nb::arg("run_transform") = nb::none(),
nb::arg("face_id") = nb::none(),
nb::arg("halfedge_tangent") = nb::none(), nb::arg("precision") = 0)
nb::arg("halfedge_tangent") = nb::none(), nb::arg("tolerance") = 0)
.def_prop_ro(
"vert_properties",
[](const MeshGL &self) {
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ EMSCRIPTEN_BINDINGS(whatever) {
.function("_GetMeshJS", &js::GetMeshJS)
.function("refine", &Manifold::Refine)
.function("refineToLength", &Manifold::RefineToLength)
.function("refineToPrecision", &Manifold::RefineToPrecision)
.function("refineToTolerance", &Manifold::RefineToTolerance)
.function("smoothByNormals", &Manifold::SmoothByNormals)
.function("_SmoothOut", &Manifold::SmoothOut)
.function("_Warp", &man_js::Warp)
Expand Down
8 changes: 4 additions & 4 deletions bindings/wasm/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ Module.setup = function() {
Module.Manifold.intersection = manifoldBatchbool('Intersection');

Module.Manifold.levelSet = function(
sdf, bounds, edgeLength, level = 0, precision = -1) {
sdf, bounds, edgeLength, level = 0, tolerance = -1) {
const bounds2 = {
min: {x: bounds.min[0], y: bounds.min[1], z: bounds.min[2]},
max: {x: bounds.max[0], y: bounds.max[1], z: bounds.max[2]},
Expand All @@ -653,7 +653,7 @@ Module.setup = function() {
return sdf(vert);
}, 'di');
const out =
Module._LevelSet(wasmFuncPtr, bounds2, edgeLength, level, precision);
Module._LevelSet(wasmFuncPtr, bounds2, edgeLength, level, tolerance);
removeFunction(wasmFuncPtr);
return out;
};
Expand Down Expand Up @@ -697,10 +697,10 @@ Module.setup = function() {

// Top-level functions

Module.triangulate = function(polygons, precision = -1) {
Module.triangulate = function(polygons, epsilon = -1) {
const polygonsVec = polygons2vec(polygons);
const result = fromVec(
Module._Triangulate(polygonsVec, precision), (x) => [x[0], x[1], x[2]]);
Module._Triangulate(polygonsVec, epsilon), (x) => [x[0], x[1], x[2]]);
disposePolygons(polygonsVec);
return result;
};
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const manifoldMemberFunctions = [
'smoothOut',
'refine',
'refineToLength',
'refineToPrecision',
'refineToTolerance',
'setProperties',
'asOriginal',
'trimByPlane',
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ Manifold SetProperties(Manifold& manifold, int numProp, uintptr_t funcPtr) {
}

Manifold LevelSet(uintptr_t funcPtr, Box bounds, double edgeLength,
double level, double precision) {
double level, double tolerance) {
double (*f)(const vec3&) = reinterpret_cast<double (*)(const vec3&)>(funcPtr);
return Manifold::LevelSet(f, bounds, edgeLength, level, precision);
return Manifold::LevelSet(f, bounds, edgeLength, level, tolerance);
}

std::vector<Manifold> Split(Manifold& a, Manifold& b) {
Expand Down
24 changes: 12 additions & 12 deletions bindings/wasm/manifold-encapsulated-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {Box, FillRule, JoinType, Mat3, Mat4, Polygons, Properties, Rect, SealedF
*
* @param polygons The set of polygons, wound CCW and representing multiple
* polygons and/or holes.
* @param precision The value of epsilon, bounding the uncertainty of the input
* @param epsilon The value of epsilon, bounding the uncertainty of the input
* @return The triangles, referencing the original polygon points in order.
*/
export function triangulate(polygons: Polygons, precision?: number): Vec3[];
export function triangulate(polygons: Polygons, epsilon?: number): Vec3[];

/**
* Sets an angle constraint the default number of circular segments for the
Expand Down Expand Up @@ -569,14 +569,14 @@ export class Manifold {
* performance.
* @param level You can inset your Mesh by using a positive value, or outset
* it with a negative value.
* @param precision Ensure each vertex is within this distance of the true
* @param tolerance Ensure each vertex is within this distance of the true
* surface. Defaults to -1, which will return the interpolated
* crossing-point based on the two nearest grid points. Small positive values
* will require more sdf evaluations per output vertex.
*/
static levelSet(
sdf: (point: Vec3) => number, bounds: Box, edgeLength: number,
level?: number, precision?: number): Manifold;
level?: number, tolerance?: number): Manifold;

// Transformations

Expand Down Expand Up @@ -697,17 +697,17 @@ export class Manifold {

/**
* Increase the density of the mesh by splitting each edge into pieces such
* that any point on the resulting triangles is roughly within precision of
* that any point on the resulting triangles is roughly within tolerance of
* the smoothly curved surface defined by the tangent vectors. This means
* tightly curving regions will be divided more finely than smoother regions.
* If halfedgeTangents are not present, the result will simply be a copy of
* the original. Quads will ignore their interior triangle bisector.
*
* @param precision The desired maximum distance between the faceted mesh
* @param tolerance The desired maximum distance between the faceted mesh
* produced and the exact smoothly curving surface. All vertices are exactly
* on the surface, within rounding error.
*/
refineToPrecision(precision: number): Manifold;
refineToTolerance(tolerance: number): Manifold;

/**
* Create a new copy of this manifold with updated vertex properties by
Expand Down Expand Up @@ -929,14 +929,14 @@ export class Manifold {
boundingBox(): Box;

/**
* Returns the precision of this Manifold's vertices, which tracks the
* Returns the tolerance of this Manifold's vertices, which tracks the
* approximate rounding error over all the transforms and operations that have
* led to this state. Any triangles that are colinear within this precision
* led to this state. Any triangles that are colinear within this tolerance
* are considered degenerate and removed. This is the value of &epsilon;
* defining
* [&epsilon;-valid](https://github.com/elalish/manifold/wiki/Manifold-Library#definition-of-%CE%B5-valid).
*/
precision(): number;
tolerance(): number;

/**
* The genus is a topological property of the manifold, representing the
Expand Down Expand Up @@ -1137,8 +1137,8 @@ export class Mesh {
* Updates the mergeFromVert and mergeToVert vectors in order to create a
* manifold solid. If the MeshGL is already manifold, no change will occur and
* the function will return false. Otherwise, this will merge verts along open
* edges within precision (the maximum of the MeshGL precision and the
* baseline bounding-box precision), keeping any from the existing merge
* edges within tolerance (the maximum of the MeshGL tolerance and the
* baseline bounding-box tolerance), keeping any from the existing merge
* vectors.
*
* There is no guarantee the result will be manifold - this is a best-effort
Expand Down
4 changes: 2 additions & 2 deletions extras/minimize_testcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ inline bool intersect(vec2 p0, vec2 p1, vec2 q0, vec2 q1, double precision) {
//
// note that this does not correspond to a fixed angle,
// but seems to work well enough
if (rxs < kTolerance && rxs > -kTolerance) {
if (rxs < kPrecision && rxs > -kPrecision) {
return false;
}
double u = cross(q0 - p0, r) / rxs;
Expand Down Expand Up @@ -373,7 +373,7 @@ int main(int argc, char **argv) {
bound = la::max(bound, la::abs(pt.y));
}
}
precision = bound * kTolerance;
precision = bound * kPrecision;
}

std::cout << "------------" << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions include/manifold/manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ struct MeshGLP {
/// Mesh.triVerts[tri][i] along the CCW edge. If empty, mesh is faceted.
std::vector<Precision> halfedgeTangent;
/// Tolerance for mesh simplification.
/// When creating a Manifold, the precision used will be the maximum
/// of this and a baseline precision from the size of the bounding box. Any
/// When creating a Manifold, the tolerance used will be the maximum
/// of this and a baseline tolerance from the size of the bounding box. Any
/// edge shorter than tolerance may be collapsed.
/// Tolerance may be enlarged when floating point error accumulates.
Precision tolerance = 0;
Expand Down Expand Up @@ -192,7 +192,7 @@ class Manifold {
double revolveDegrees = 360.0f);
static Manifold LevelSet(std::function<double(vec3)> sdf, Box bounds,
double edgeLength, double level = 0,
double precision = -1, bool canParallel = true);
double tolerance = -1, bool canParallel = true);
///@}

/** @name Topological
Expand Down Expand Up @@ -266,7 +266,7 @@ class Manifold {
Manifold SmoothOut(double minSharpAngle = 60, double minSmoothness = 0) const;
Manifold Refine(int) const;
Manifold RefineToLength(double) const;
Manifold RefineToPrecision(double) const;
Manifold RefineToTolerance(double) const;
Manifold SetTolerance(double) const;
///@}

Expand Down Expand Up @@ -363,7 +363,7 @@ inline std::string ToString(const Manifold::Error& error) {
case Manifold::Error::InvalidConstruction:
return "Invalid Construction";
default:
return "Unkown Error";
return "Unknown Error";
};
}

Expand Down
4 changes: 2 additions & 2 deletions include/manifold/polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ using SimplePolygonIdx = std::vector<PolyVert>;
using PolygonsIdx = std::vector<SimplePolygonIdx>;

std::vector<ivec3> TriangulateIdx(const PolygonsIdx &polys,
double precision = -1);
double epsilon = -1);
/** @} */

/** @ingroup Connections
* @{
*/
std::vector<ivec3> Triangulate(const Polygons &polygons, double precision = -1);
std::vector<ivec3> Triangulate(const Polygons &polygons, double epsilon = -1);

ExecutionParams &PolygonParams();
/** @} */
Expand Down
4 changes: 2 additions & 2 deletions src/csg_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Manifold::Impl CsgLeafNode::Compose(
node->pImpl_->bBox_.Transform(node->transform_).Scale();
double nodeEpsilon = node->pImpl_->epsilon_;
nodeEpsilon *= std::max(1.0, nodeNewScale / nodeOldScale);
nodeEpsilon = std::max(nodeEpsilon, kTolerance * nodeNewScale);
nodeEpsilon = std::max(nodeEpsilon, kPrecision * nodeNewScale);
if (!std::isfinite(nodeEpsilon)) nodeEpsilon = -1;
epsilon = std::max(epsilon, nodeEpsilon);
tolerance = std::max(tolerance, node->pImpl_->tolerance_);
Expand Down Expand Up @@ -323,7 +323,7 @@ Manifold::Impl CsgLeafNode::Compose(
}
}

// required to remove parts that are smaller than the precision
// required to remove parts that are smaller than the tolerance
combined.SimplifyTopology();
combined.Finish();
combined.IncrementMeshIDs();
Expand Down
Loading
Loading