Skip to content

Commit

Permalink
Remove GetProperties() (#1022)
Browse files Browse the repository at this point in the history
* organize member docs

* remove GetProperties

* updated WASM bindings
  • Loading branch information
elalish authored Nov 5, 2024
1 parent 8e9bdb2 commit 82140d3
Show file tree
Hide file tree
Showing 28 changed files with 336 additions and 403 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ EXTRACT_PACKAGE = NO
# included in the documentation.
# The default value is: NO.

EXTRACT_STATIC = NO
EXTRACT_STATIC = YES

# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
# locally in source files will be included in the documentation. If set to NO,
Expand Down
4 changes: 0 additions & 4 deletions bindings/c/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ ManifoldVec3 to_c(vec3 v) { return {v.x, v.y, v.z}; }

ManifoldIVec3 to_c(ivec3 v) { return {v.x, v.y, v.z}; }

ManifoldProperties to_c(manifold::Properties p) {
return {p.surfaceArea, p.volume};
}

const manifold::Manifold *from_c(ManifoldManifold *m) {
return reinterpret_cast<manifold::Manifold const *>(m);
}
Expand Down
1 change: 0 additions & 1 deletion bindings/c/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ ManifoldError to_c(manifold::Manifold::Error error);
ManifoldVec2 to_c(vec2 v);
ManifoldVec3 to_c(vec3 v);
ManifoldIVec3 to_c(ivec3 v);
ManifoldProperties to_c(manifold::Properties p);

const manifold::Manifold *from_c(ManifoldManifold *m);
ManifoldVec *from_c(ManifoldManifoldVec *ms);
Expand Down
3 changes: 2 additions & 1 deletion bindings/c/include/manifold/manifoldc.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ size_t manifold_num_tri(ManifoldManifold *m);
ManifoldBox *manifold_bounding_box(void *mem, ManifoldManifold *m);
double manifold_epsilon(ManifoldManifold *m);
int manifold_genus(ManifoldManifold *m);
ManifoldProperties manifold_get_properties(ManifoldManifold *m);
double manifold_surface_area(ManifoldManifold *m);
double manifold_volume(ManifoldManifold *m);
int manifold_get_circular_segments(double radius);
int manifold_original_id(ManifoldManifold *m);
uint32_t manifold_reserve_ids(uint32_t n);
Expand Down
5 changes: 3 additions & 2 deletions bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,10 @@ size_t manifold_num_edge(ManifoldManifold *m) { return from_c(m)->NumEdge(); }
size_t manifold_num_tri(ManifoldManifold *m) { return from_c(m)->NumTri(); }
int manifold_genus(ManifoldManifold *m) { return from_c(m)->Genus(); }

ManifoldProperties manifold_get_properties(ManifoldManifold *m) {
return to_c(from_c(m)->GetProperties());
double manifold_surface_area(ManifoldManifold *m) {
return from_c(m)->SurfaceArea();
}
double manifold_volume(ManifoldManifold *m) { return from_c(m)->Volume(); }

ManifoldBox *manifold_bounding_box(void *mem, ManifoldManifold *m) {
auto box = from_c(m)->BoundingBox();
Expand Down
5 changes: 2 additions & 3 deletions bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,12 @@ NB_MODULE(manifold3d, m) {
.def("num_prop_vert", &Manifold::NumPropVert, manifold__num_prop_vert)
.def("genus", &Manifold::Genus, manifold__genus)
.def(
"volume",
[](const Manifold &self) { return self.GetProperties().volume; },
"volume", [](const Manifold &self) { return self.Volume(); },
"Get the volume of the manifold\n This is clamped to zero for a "
"given face if they are within the Epsilon().")
.def(
"surface_area",
[](const Manifold &self) { return self.GetProperties().surfaceArea; },
[](const Manifold &self) { return self.SurfaceArea(); },
"Get the surface area of the manifold\n This is clamped to zero for "
"a given face if they are within the Epsilon().")
.def("original_id", &Manifold::OriginalID, manifold__original_id)
Expand Down
7 changes: 2 additions & 5 deletions bindings/wasm/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ EMSCRIPTEN_BINDINGS(whatever) {
.field("halfedge", &Smoothness::halfedge)
.field("smoothness", &Smoothness::smoothness);

value_object<Properties>("properties")
.field("surfaceArea", &Properties::surfaceArea)
.field("volume", &Properties::volume);

register_vector<ivec3>("Vector_ivec3");
register_vector<vec3>("Vector_vec3");
register_vector<vec2>("Vector_vec2");
Expand Down Expand Up @@ -163,7 +159,8 @@ EMSCRIPTEN_BINDINGS(whatever) {
.function("_boundingBox", &Manifold::BoundingBox)
.function("tolerance", &Manifold::GetTolerance)
.function("genus", &Manifold::Genus)
.function("getProperties", &Manifold::GetProperties)
.function("volume", &Manifold::Volume)
.function("surfaceArea", &Manifold::SurfaceArea)
.function("minGap", &Manifold::MinGap)
.function("calculateCurvature", &Manifold::CalculateCurvature)
.function("_CalculateNormals", &Manifold::CalculateNormals)
Expand Down
5 changes: 3 additions & 2 deletions bindings/wasm/examples/worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ async function runExample(name: string) {
}
const {mesh} = readMesh(docMesh)!;
const manifold = new module.Manifold(mesh as Mesh);
const prop = manifold.getProperties();
const volume = manifold.volume();
const surfaceArea = manifold.surfaceArea();
const genus = manifold.genus();
manifold.delete();
return {...prop, genus};
return {volume, surfaceArea, genus};
}
assert.ok(false);
}
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 @@ -522,7 +522,7 @@ function addMesh(
}
log(`Bounding Box: X = ${size[0].toLocaleString()} mm, Y = ${
size[1].toLocaleString()} mm, Z = ${size[2].toLocaleString()} mm`);
const volume = Math.round(manifold.getProperties().volume / 10);
const volume = Math.round(manifold.volume() / 10);
log(`Genus: ${manifold.genus().toLocaleString()}, Volume: ${
(volume / 100).toLocaleString()} cm^3`);

Expand Down
13 changes: 7 additions & 6 deletions bindings/wasm/manifold-encapsulated-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {Box, FillRule, JoinType, Mat3, Mat4, Polygons, Properties, Rect, SealedFloat32Array, SealedUint32Array, SimplePolygon, Smoothness, Vec2, Vec3} from './manifold-global-types';
import {Box, FillRule, JoinType, Mat3, Mat4, Polygons, Rect, SealedFloat32Array, SealedUint32Array, SimplePolygon, Smoothness, Vec2, Vec3} from './manifold-global-types';

/**
* Triangulates a set of /epsilon-valid polygons.
Expand Down Expand Up @@ -946,13 +946,14 @@ export class Manifold {
genus(): number;

/**
* Returns the surface area and volume of the manifold. These properties are
* clamped to zero for a given face if they are within the Precision(). This
* means degenerate manifolds can by identified by testing these properties as
* == 0.
* Returns the surface area of the manifold.
*/
getProperties(): Properties;
surfaceArea(): number;

/**
* Returns the volume of the manifold.
*/
volume(): number;

/**
* Returns the minimum gap between two manifolds. Returns a float between
Expand Down
4 changes: 0 additions & 4 deletions bindings/wasm/manifold-global-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,5 @@ export type Smoothness = {
halfedge: number,
smoothness: number
};
export type Properties = {
surfaceArea: number,
volume: number
};
export type FillRule = 'EvenOdd'|'NonZero'|'Positive'|'Negative'
export type JoinType = 'Square'|'Round'|'Miter'
5 changes: 2 additions & 3 deletions extras/convert_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ int main(int argc, char** argv) {
const std::vector<Manifold> parts = manifold.Decompose();
std::cout << parts.size() << " objects:" << std::endl;
for (const Manifold& part : parts) {
auto prop = part.GetProperties();
std::cout << part.NumVert() << " vertices, " << part.NumTri()
<< " triangles, volume = " << prop.volume
<< ", surface area = " << prop.surfaceArea << std::endl;
<< " triangles, volume = " << part.Volume()
<< ", surface area = " << part.SurfaceArea() << std::endl;
}

if (argc == 3) {
Expand Down
20 changes: 9 additions & 11 deletions include/manifold/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ constexpr double kHalfPi = 1.57079632679489661923132169163975144;
/**
* Convert degrees to radians.
*
* @param x Angle in degrees.
* @param a Angle in degrees.
*/
constexpr double radians(double a) { return a * kPi / 180; }

/**
* Convert radians to degrees.
*
* @param x Angle in radians.
* @param a Angle in radians.
*/
constexpr double degrees(double a) { return a * 180 / kPi; }

Expand All @@ -71,7 +71,7 @@ constexpr double degrees(double a) { return a * 180 / kPi; }
*
* @param edge0 Specifies the value of the lower edge of the Hermite function.
* @param edge1 Specifies the value of the upper edge of the Hermite function.
* @param x Specifies the source value for interpolation.
* @param a Specifies the source value for interpolation.
*/
constexpr double smoothstep(double edge0, double edge1, double a) {
const double x = la::clamp((a - edge0) / (edge1 - edge0), 0, 1);
Expand Down Expand Up @@ -144,12 +144,8 @@ struct Smoothness {
};

/**
* Geometric properties of the manifold, created with Manifold.GetProperties().
* @brief Axis-aligned 3D box, primarily for bounding.
*/
struct Properties {
double surfaceArea, volume;
};

struct Box {
vec3 min = vec3(std::numeric_limits<double>::infinity());
vec3 max = vec3(-std::numeric_limits<double>::infinity());
Expand Down Expand Up @@ -298,7 +294,7 @@ struct Box {
};

/**
* Axis-aligned rectangular bounds.
* @brief Axis-aligned 2D box, primarily for bounding.
*/
struct Rect {
vec2 min = vec2(std::numeric_limits<double>::infinity());
Expand Down Expand Up @@ -471,8 +467,10 @@ constexpr int DEFAULT_SEGMENTS = 0;
constexpr double DEFAULT_ANGLE = 10.0;
constexpr double DEFAULT_LENGTH = 1.0;
/**
* These static properties control how circular shapes are quantized by
* default on construction. If circularSegments is specified, it takes
* @brief These static properties control how circular shapes are quantized by
* default on construction.
*
* If circularSegments is specified, it takes
* precedence. If it is zero, then instead the minimum is used of the segments
* calculated based on edge length and angle, rounded up to the nearest
* multiple of four. To get numbers not divisible by four, circularSegments
Expand Down
95 changes: 47 additions & 48 deletions include/manifold/cross_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@ namespace manifold {
struct PathImpl;

/**
* Two-dimensional cross sections guaranteed to be without self-intersections,
* or overlaps between polygons (from construction onwards). This class makes
* use of the [Clipper2](http://www.angusj.com/clipper2/Docs/Overview.htm)
* library for polygon clipping (boolean) and offsetting operations.
* @brief Two-dimensional cross sections guaranteed to be without
* self-intersections, or overlaps between polygons (from construction onwards).
* This class makes use of the
* [Clipper2](http://www.angusj.com/clipper2/Docs/Overview.htm) library for
* polygon clipping (boolean) and offsetting operations.
*/
class CrossSection {
public:
/** @name Creation
* Constructors
/** @name Basics
* Copy / move / assignment
*/
///@{

CrossSection();
~CrossSection();

CrossSection(const CrossSection& other);
CrossSection& operator=(const CrossSection& other);
CrossSection(CrossSection&&) noexcept;
CrossSection& operator=(CrossSection&&) noexcept;
///@}

// Adapted from Clipper2 docs:
// http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/FillRule.htm
Expand All @@ -69,11 +70,46 @@ class CrossSection {
Negative ///< Only sub-regions with winding counts < 0 are filled.
};

// Adapted from Clipper2 docs:
// http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/JoinType.htm
// (Copyright © 2010-2023 Angus Johnson)
/**
* Specifies the treatment of path/contour joins (corners) when offseting
* CrossSections. See the [Clipper2
* doc](http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/JoinType.htm)
* for illustrations.
*/
enum class JoinType {
Square, /*!< Squaring is applied uniformly at all joins where the internal
join angle is less that 90 degrees. The squared edge will be at
exactly the offset distance from the join vertex. */
Round, /*!< Rounding is applied to all joins that have convex external
angles, and it maintains the exact offset distance from the join
vertex. */
Miter /*!< There's a necessary limit to mitered joins (to avoid narrow
angled joins producing excessively long and narrow
[spikes](http://www.angusj.com/clipper2/Docs/Units/Clipper.Offset/Classes/ClipperOffset/Properties/MiterLimit.htm)).
So where mitered joins would exceed a given maximum miter distance
(relative to the offset distance), these are 'squared' instead. */
};

/** @name Input & Output
*/
///@{
CrossSection(const SimplePolygon& contour,
FillRule fillrule = FillRule::Positive);
CrossSection(const Polygons& contours,
FillRule fillrule = FillRule::Positive);
CrossSection(const Rect& rect);
Polygons ToPolygons() const;
///@}

/** @name Constructors
* Topological ops and primitives
*/
///@{
std::vector<CrossSection> Decompose() const;
static CrossSection Compose(std::vector<CrossSection>&);
static CrossSection Square(const vec2 dims, bool center = false);
static CrossSection Circle(double radius, int circularSegments = 0);
///@}
Expand All @@ -82,14 +118,14 @@ class CrossSection {
* Details of the cross-section
*/
///@{
double Area() const;
bool IsEmpty() const;
int NumVert() const;
int NumContour() const;
bool IsEmpty() const;
Rect Bounds() const;
double Area() const;
///@}

/** @name Modification
/** @name Transformation
*/
///@{
CrossSection Translate(const vec2 v) const;
Expand All @@ -100,30 +136,6 @@ class CrossSection {
CrossSection Warp(std::function<void(vec2&)> warpFunc) const;
CrossSection WarpBatch(std::function<void(VecView<vec2>)> warpFunc) const;
CrossSection Simplify(double epsilon = 1e-6) const;

// Adapted from Clipper2 docs:
// http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/JoinType.htm
// (Copyright © 2010-2023 Angus Johnson)
/**
* Specifies the treatment of path/contour joins (corners) when offseting
* CrossSections. See the [Clipper2
* doc](http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/JoinType.htm)
* for illustrations.
*/
enum class JoinType {
Square, /*!< Squaring is applied uniformly at all joins where the internal
join angle is less that 90 degrees. The squared edge will be at
exactly the offset distance from the join vertex. */
Round, /*!< Rounding is applied to all joins that have convex external
angles, and it maintains the exact offset distance from the join
vertex. */
Miter /*!< There's a necessary limit to mitered joins (to avoid narrow
angled joins producing excessively long and narrow
[spikes](http://www.angusj.com/clipper2/Docs/Units/Clipper.Offset/Classes/ClipperOffset/Properties/MiterLimit.htm)).
So where mitered joins would exceed a given maximum miter distance
(relative to the offset distance), these are 'squared' instead. */
};

CrossSection Offset(double delta, JoinType jt, double miter_limit = 2.0,
int circularSegments = 0) const;
///@}
Expand All @@ -143,27 +155,14 @@ class CrossSection {
CrossSection& operator^=(const CrossSection&);
///@}

/** @name Topological
*/
///@{
static CrossSection Compose(std::vector<CrossSection>&);
std::vector<CrossSection> Decompose() const;
///@}

/** @name Convex Hulling
/** @name Convex Hull
*/
///@{
CrossSection Hull() const;
static CrossSection Hull(const std::vector<CrossSection>& crossSections);
static CrossSection Hull(const SimplePolygon pts);
static CrossSection Hull(const Polygons polys);
///@}
///
/** @name Conversion
*/
///@{
Polygons ToPolygons() const;
///@}

private:
mutable std::shared_ptr<const PathImpl> paths_;
Expand Down
Loading

0 comments on commit 82140d3

Please sign in to comment.