Skip to content

Commit f2a045b

Browse files
committed
successful run of helloworld (with heap corruption)
1 parent b2a8f8e commit f2a045b

File tree

12 files changed

+1553
-942
lines changed

12 files changed

+1553
-942
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ endif()
134134

135135

136136
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
137-
list(APPEND compilation_flags -Wall -Wextra)
137+
list(APPEND compilation_flags -Wall -Wextra -frounding-math)
138138
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
139139
list(APPEND compilation_flags w3 -diag-disable:remark)
140140
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
141-
list(APPEND compilation_flags /W4 /wd26812 /bigobj)
141+
list(APPEND compilation_flags /W4 /wd26812 /bigobj /fp:strict)
142142
list(APPEND preprocessor_defs -D_CRT_SECURE_NO_WARNINGS)
143143
endif()
144144

include/mcut/internal/frontend.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ struct connected_component_t {
267267
bool face_adjacent_faces_size_cache_initialized = false;
268268
#endif // #if defined(MCUT_WITH_COMPUTE_HELPER_THREADPOOL)
269269
// non-zero if origin source and cut-mesh where perturbed
270-
vec3 perturbation_vector = vec3(0.0);
270+
vec3_<double> perturbation_vector = vec3_<double>(0.0);
271271
//
272272
// An array storing the lists of vertices that define seams/intersection
273273
// contours along the cut path of a CC. We need this cache because it will be

include/mcut/internal/kernel.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,13 @@ struct input_t {
163163
bool keep_fragments_sealed_inside = false;
164164
bool keep_fragments_sealed_outside = false;
165165
// bool include_fragment_sealed_partial = false; // See: variable above "keep_partially_sealed_connected_components"
166-
//bool keep_fragments_sealed_inside_exhaustive = false; // TODO remove
167-
//bool keep_fragments_sealed_outside_exhaustive = false; // TODO remove
166+
// bool keep_fragments_sealed_inside_exhaustive = false; // TODO remove
167+
// bool keep_fragments_sealed_outside_exhaustive = false; // TODO remove
168168
// NOTE TO SELF: if the user simply wants patches, then kernel should not have to proceed to stitching!!!
169169

170170
bool src_mesh_is_watertight = false;
171171
bool cut_mesh_is_watertight = false;
172+
double multiplier = 1.;
172173
};
173174

174175
struct output_mesh_data_maps_t {

include/mcut/internal/math.h

+53-11
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,18 @@ class rational_number : public bigrational
176176
{
177177
return (0.0);
178178
}
179-
179+
//std::cout << i << std::endl;
180180
// from integer range [-2^26, 2^26]^3 to normalized range [-1, 1]^3
181+
MCUT_ASSERT(i <= rational_number(1 << 26));
181182
const auto n = i / rational_number(1 << 26);
183+
//std::cout << n.get_dec_str() << std::endl;
184+
//auto nv = n.get_d();
182185
// from normalized range [-1, 1]^3 to actual/user coord value
183186
const auto d = n * rational_number(m);
184187
const double result = d.get_d(); // NOTE: truncated
188+
189+
MCUT_ASSERT(result <= m);
190+
185191
return result;
186192
}
187193
};
@@ -531,6 +537,7 @@ T square_root(const T& number, double multiplier = 1)
531537
#else
532538
const double dequantized = scalar_t::dequantize(
533539
number, multiplier); // to native user coordinates/from rational coordinates
540+
534541
const double sqrt_val = std::sqrt(dequantized);
535542
const scalar_t quantized =
536543
scalar_t::quantize(sqrt_val, multiplier); // to rational coordinates
@@ -597,7 +604,13 @@ vec3_<T> compwise_max(const vec3_<T>& a, const vec3_<T>& b)
597604
return vec3_<T>(max(a.x(), b.x()), max(a.y(), b.y()), max(a.z(), b.z()));
598605
}
599606

600-
extern vec3 cross_product(const vec3& a, const vec3& b);
607+
template <typename vector_type>
608+
typename vector_type cross_product(const vector_type& a, const vector_type& b)
609+
{
610+
return vector_type( a.y() * b.z() - a.z() * b.y(),
611+
a.z() * b.x() - a.x() * b.z(),
612+
a.x() * b.y() - a.y() * b.x());
613+
}
601614

602615
template <typename vector_type>
603616
typename vector_type::element_type dot_product(const vector_type& a, const vector_type& b)
@@ -647,17 +660,38 @@ typename vector_type::element_type squared_length(const vector_type& v)
647660
{
648661
return dot_product(v, v);
649662
}
663+
# if MCUT_WITH_ARBITRARY_PRECISION_NUMBERS
664+
template <typename vector_type>
665+
typename vector_type::element_type length(const vector_type& v, double multiplier = 1.0)
666+
{
667+
MCUT_ASSERT(false);
668+
return vector_type::element_type(); // no-op
669+
}
670+
template <>
671+
inline scalar_t length(const vec3_<scalar_t>& v, double multiplier)
672+
{
673+
return std::sqrt(squared_length(v).get_d());
674+
//square_root(squared_length(v).get_d(), multiplier);
675+
}
676+
677+
template <>
678+
inline double length(const vec3_<double>& v, double multiplier)
679+
{
680+
return square_root(squared_length(v), multiplier);
681+
}
650682

683+
#else
651684
template <typename vector_type>
652685
typename vector_type::element_type length(const vector_type& v, double multiplier = 1.0)
653686
{
654687
return square_root(squared_length(v), multiplier);
655688
}
689+
#endif
656690

657691
template <typename vector_type>
658-
vector_type normalize(const vector_type& v)
692+
vector_type normalize(const vector_type& v, double multiplier = 1.0)
659693
{
660-
return v / length(v);
694+
return v / length(v, multiplier);
661695
}
662696

663697
scalar_t orient2d(const vec2& pa, const vec2& pb, const vec2& pc);
@@ -667,7 +701,9 @@ scalar_t orient3d(const vec3& pa, const vec3& pb, const vec3& pc,
667701
// Compute a polygon's plane coefficients (i.e. normal and d parameters).
668702
// The computed normal is not normalized. This function returns the largest component of the normal.
669703
int compute_polygon_plane_coefficients(vec3& normal, scalar_t& d_coeff,
670-
const vec3* polygon_vertices, const int polygon_vertex_count);
704+
const vec3* polygon_vertices,
705+
const int polygon_vertex_count,
706+
const double multiplier);
671707

672708
// Compute the intersection point between a line (not a segment) and a plane defined by a polygon.
673709
//
@@ -712,7 +748,9 @@ char compute_segment_plane_intersection(vec3& p, const vec3& normal, const scala
712748
// '1': The segment intersects the plane, and none of {p, q, r} hold.
713749
char compute_segment_plane_intersection_type(const vec3& q, const vec3& r,
714750
const std::vector<vec3>& polygon_vertices,
715-
const vec3& polygon_normal, const int polygon_normal_largest_component);
751+
const vec3& polygon_normal,
752+
const int polygon_normal_largest_component,
753+
const double multiplier);
716754

717755
// Test if a point 'q' (in 2D) lies inside or outside a given polygon (count the number ray crossings).
718756
//
@@ -721,7 +759,8 @@ char compute_segment_plane_intersection_type(const vec3& q, const vec3& r,
721759
// 'o': q is strictly exterior (outside).
722760
// 'e': q is on an edge, but not an endpoint.
723761
// 'v': q is a vertex.
724-
char compute_point_in_polygon_test(const vec2& q, const std::vector<vec2>& polygon_vertices);
762+
char compute_point_in_polygon_test(const vec2& q,
763+
const std::vector<vec2>& polygon_vertices);
725764

726765
// Test if a point 'q' (in 3D) lies inside or outside a given polygon (count the number ray crossings).
727766
//
@@ -731,14 +770,17 @@ char compute_point_in_polygon_test(const vec2& q, const std::vector<vec2>& polyg
731770
// 'e': q is on an edge, but not an endpoint.
732771
// 'v': q is a vertex.
733772
char compute_point_in_polygon_test(const vec3& p, const std::vector<vec3>& polygon_vertices,
734-
const vec3& polygon_normal, const int polygon_normal_largest_component);
773+
const vec3& polygon_normal, const int polygon_normal_largest_component, const double multiplier);
735774

736775
// project a 3d polygon to 3d by eliminating the largest component of its normal
737776
void project_to_2d(std::vector<vec2>& out, const std::vector<vec3>& polygon_vertices,
738-
const vec3& polygon_normal, const int polygon_normal_largest_component);
777+
const vec3& polygon_normal,
778+
const int polygon_normal_largest_component,
779+
const double multiplier);
739780

740-
void project_to_2d(std::vector<vec2>& out, const std::vector<vec3>& polygon_vertices,
741-
const vec3& polygon_normal);
781+
//void project_to_2d(std::vector<vec2>& out, const std::vector<vec3>& polygon_vertices,
782+
// const vec3& polygon_normal,
783+
// const double multiplier);
742784

743785
bool coplaner(const vec3& pa, const vec3& pb, const vec3& pc,
744786
const vec3& pd);

0 commit comments

Comments
 (0)