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

fixed properties #1051

Merged
merged 4 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions include/manifold/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,16 @@ struct ExecutionParams {
bool cleanupTriangles = true;
};
/** @} */

#ifdef MANIFOLD_DEBUG
inline std::ostream& operator<<(std::ostream& stream, const Box& box) {
return stream << "min: " << box.min << ", "
<< "max: " << box.max;
}

inline std::ostream& operator<<(std::ostream& stream, const Rect& box) {
return stream << "min: " << box.min << ", "
<< "max: " << box.max;
}
#endif
} // namespace manifold
69 changes: 55 additions & 14 deletions include/manifold/linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
#include <iosfwd> // For forward definitions of std::ostream
#include <type_traits> // For std::enable_if, std::is_same, std::declval

#ifdef MANIFOLD_DEBUG
#include <iomanip>
#include <iostream>
#endif

// In Visual Studio 2015, `constexpr` applied to a member function implies
// `const`, which causes ambiguous overload resolution
#if defined(_MSC_VER) && (_MSC_VER <= 1900)
Expand Down Expand Up @@ -466,8 +471,8 @@ struct select {
};
struct lerp {
template <class A, class B, class C>
constexpr auto operator()(A a, B b,
C c) const -> decltype(a * (1 - c) + b * c) {
constexpr auto operator()(A a, B b, C c) const
-> decltype(a * (1 - c) + b * c) {
return a * (1 - c) + b * c;
}
};
Expand Down Expand Up @@ -1311,33 +1316,33 @@ constexpr typename detail::any_compare<A, B>::type compare(const A &a,
return detail::any_compare<A, B>()(a, b);
}
template <class A, class B>
constexpr auto operator==(const A &a,
const B &b) -> decltype(compare(a, b) == 0) {
constexpr auto operator==(const A &a, const B &b)
-> decltype(compare(a, b) == 0) {
return compare(a, b) == 0;
}
template <class A, class B>
constexpr auto operator!=(const A &a,
const B &b) -> decltype(compare(a, b) != 0) {
constexpr auto operator!=(const A &a, const B &b)
-> decltype(compare(a, b) != 0) {
return compare(a, b) != 0;
}
template <class A, class B>
constexpr auto operator<(const A &a,
const B &b) -> decltype(compare(a, b) < 0) {
constexpr auto operator<(const A &a, const B &b)
-> decltype(compare(a, b) < 0) {
return compare(a, b) < 0;
}
template <class A, class B>
constexpr auto operator>(const A &a,
const B &b) -> decltype(compare(a, b) > 0) {
constexpr auto operator>(const A &a, const B &b)
-> decltype(compare(a, b) > 0) {
return compare(a, b) > 0;
}
template <class A, class B>
constexpr auto operator<=(const A &a,
const B &b) -> decltype(compare(a, b) <= 0) {
constexpr auto operator<=(const A &a, const B &b)
-> decltype(compare(a, b) <= 0) {
return compare(a, b) <= 0;
}
template <class A, class B>
constexpr auto operator>=(const A &a,
const B &b) -> decltype(compare(a, b) >= 0) {
constexpr auto operator>=(const A &a, const B &b)
-> decltype(compare(a, b) >= 0) {
return compare(a, b) >= 0;
}
/** @} */
Expand Down Expand Up @@ -2360,6 +2365,42 @@ struct converter<std::array<T, 4>, vec<T, 4>> {
}
};
/** @} */

#ifdef MANIFOLD_DEBUG
template <class T>
std::ostream &operator<<(std::ostream &out, const vec<T, 1> &v) {
return out << '{' << v[0] << '}';
}
template <class T>
std::ostream &operator<<(std::ostream &out, const vec<T, 2> &v) {
return out << '{' << v[0] << ',' << v[1] << '}';
}
template <class T>
std::ostream &operator<<(std::ostream &out, const vec<T, 3> &v) {
return out << '{' << v[0] << ',' << v[1] << ',' << v[2] << '}';
}
template <class T>
std::ostream &operator<<(std::ostream &out, const vec<T, 4> &v) {
return out << '{' << v[0] << ',' << v[1] << ',' << v[2] << ',' << v[3] << '}';
}

template <class T, int M>
std::ostream &operator<<(std::ostream &out, const mat<T, M, 1> &m) {
return out << '{' << m[0] << '}';
}
template <class T, int M>
std::ostream &operator<<(std::ostream &out, const mat<T, M, 2> &m) {
return out << '{' << m[0] << ',' << m[1] << '}';
}
template <class T, int M>
std::ostream &operator<<(std::ostream &out, const mat<T, M, 3> &m) {
return out << '{' << m[0] << ',' << m[1] << ',' << m[2] << '}';
}
template <class T, int M>
std::ostream &operator<<(std::ostream &out, const mat<T, M, 4> &m) {
return out << '{' << m[0] << ',' << m[1] << ',' << m[2] << ',' << m[3] << '}';
}
#endif
} // namespace linalg

namespace std {
Expand Down
2 changes: 1 addition & 1 deletion src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct UpdateProperties {
auto old = std::atomic_exchange(
reinterpret_cast<std::atomic<uint8_t>*>(&counters[propVert]),
static_cast<uint8_t>(1));
if (old == 1) return;
if (old == 1) continue;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the actual one-line fix for the bug.


for (int p = 0; p < oldNumProp; ++p) {
properties[numProp * propVert + p] =
Expand Down
47 changes: 0 additions & 47 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#ifdef MANIFOLD_DEBUG
#include <chrono>
#include <iomanip>
#include <iostream>
#endif

#include "./vec.h"
Expand Down Expand Up @@ -231,51 +229,6 @@ inline mat4 Mat4(mat3x4 a) {
inline mat3 Mat3(mat2x3 a) { return mat3({a[0], 0}, {a[1], 0}, {a[2], 1}); }

#ifdef MANIFOLD_DEBUG

template <class T>
std::ostream& operator<<(std::ostream& out, const la::vec<T, 1>& v) {
return out << '{' << v[0] << '}';
}
template <class T>
std::ostream& operator<<(std::ostream& out, const la::vec<T, 2>& v) {
return out << '{' << v[0] << ',' << v[1] << '}';
}
template <class T>
std::ostream& operator<<(std::ostream& out, const la::vec<T, 3>& v) {
return out << '{' << v[0] << ',' << v[1] << ',' << v[2] << '}';
}
template <class T>
std::ostream& operator<<(std::ostream& out, const la::vec<T, 4>& v) {
return out << '{' << v[0] << ',' << v[1] << ',' << v[2] << ',' << v[3] << '}';
}

template <class T, int M>
std::ostream& operator<<(std::ostream& out, const la::mat<T, M, 1>& m) {
return out << '{' << m[0] << '}';
}
template <class T, int M>
std::ostream& operator<<(std::ostream& out, const la::mat<T, M, 2>& m) {
return out << '{' << m[0] << ',' << m[1] << '}';
}
template <class T, int M>
std::ostream& operator<<(std::ostream& out, const la::mat<T, M, 3>& m) {
return out << '{' << m[0] << ',' << m[1] << ',' << m[2] << '}';
}
template <class T, int M>
std::ostream& operator<<(std::ostream& out, const la::mat<T, M, 4>& m) {
return out << '{' << m[0] << ',' << m[1] << ',' << m[2] << ',' << m[3] << '}';
}

inline std::ostream& operator<<(std::ostream& stream, const Box& box) {
return stream << "min: " << box.min << ", "
<< "max: " << box.max;
}

inline std::ostream& operator<<(std::ostream& stream, const Rect& box) {
return stream << "min: " << box.min << ", "
<< "max: " << box.max;
}

/**
* Print the contents of this vector to standard output. Only exists if compiled
* with MANIFOLD_DEBUG flag.
Expand Down
1 change: 1 addition & 0 deletions test/samples_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ TEST(Samples, Scallop) {
3, colorCurvature);
EXPECT_NEAR(scallop.Volume(), 39.9, 0.1);
EXPECT_NEAR(scallop.SurfaceArea(), 79.3, 0.1);
EXPECT_EQ(scallop.NumVert(), scallop.NumPropVert());
CheckGL(scallop);

#ifdef MANIFOLD_EXPORT
Expand Down
4 changes: 2 additions & 2 deletions test/smooth_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ TEST(Smooth, TruncatedCone) {
Manifold smooth = cone.SmoothOut().RefineToLength(0.5).CalculateNormals(0);
EXPECT_NEAR(smooth.Volume(), 1158.61, 0.01);
EXPECT_NEAR(smooth.SurfaceArea(), 768.12, 0.01);
MeshGL out = smooth.GetMeshGL();
CheckGL(out);
CheckGL(smooth, false);

Manifold smooth1 = cone.SmoothOut(180, 1).RefineToLength(0.5);
Manifold smooth2 = cone.SmoothOut(180, 0).RefineToLength(0.5);
EXPECT_NEAR(smooth2.Volume(), smooth1.Volume(), 0.01);
EXPECT_NEAR(smooth2.SurfaceArea(), smooth1.SurfaceArea(), 0.01);

#ifdef MANIFOLD_EXPORT
MeshGL out = smooth.GetMeshGL();
ExportOptions options2;
options2.faceted = false;
options2.mat.normalIdx = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void RelatedGL(const Manifold& out, const std::vector<MeshGL>& originals,
void ExpectMeshes(const Manifold& manifold,
const std::vector<MeshSize>& meshSize);
void CheckStrictly(const Manifold& manifold);
void CheckGL(const Manifold& manifold);
void CheckGL(const Manifold& manifold, bool noMerge = true);
#ifdef MANIFOLD_EXPORT
Manifold ReadMesh(const std::string& filename);
#endif
Expand Down
3 changes: 2 additions & 1 deletion test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,10 @@ void CheckStrictly(const Manifold& manifold) {
EXPECT_EQ(manifold.NumDegenerateTris(), 0);
}

void CheckGL(const Manifold& manifold) {
void CheckGL(const Manifold& manifold, bool noMerge) {
ASSERT_FALSE(manifold.IsEmpty());
const MeshGL meshGL = manifold.GetMeshGL();
if (noMerge) EXPECT_EQ(manifold.NumVert(), meshGL.NumVert());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this test to catch the regression.

EXPECT_EQ(meshGL.mergeFromVert.size(), meshGL.mergeToVert.size());
EXPECT_EQ(meshGL.mergeFromVert.size(), meshGL.NumVert() - manifold.NumVert());
EXPECT_EQ(meshGL.runIndex.size(), meshGL.runOriginalID.size() + 1);
Expand Down
Loading