@@ -176,12 +176,18 @@ class rational_number : public bigrational
176
176
{
177
177
return (0.0 );
178
178
}
179
-
179
+ // std::cout << i << std::endl;
180
180
// from integer range [-2^26, 2^26]^3 to normalized range [-1, 1]^3
181
+ MCUT_ASSERT (i <= rational_number (1 << 26 ));
181
182
const auto n = i / rational_number (1 << 26 );
183
+ // std::cout << n.get_dec_str() << std::endl;
184
+ // auto nv = n.get_d();
182
185
// from normalized range [-1, 1]^3 to actual/user coord value
183
186
const auto d = n * rational_number (m);
184
187
const double result = d.get_d (); // NOTE: truncated
188
+
189
+ MCUT_ASSERT (result <= m);
190
+
185
191
return result;
186
192
}
187
193
};
@@ -531,6 +537,7 @@ T square_root(const T& number, double multiplier = 1)
531
537
#else
532
538
const double dequantized = scalar_t::dequantize (
533
539
number, multiplier); // to native user coordinates/from rational coordinates
540
+
534
541
const double sqrt_val = std::sqrt (dequantized);
535
542
const scalar_t quantized =
536
543
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)
597
604
return vec3_<T>(max (a.x (), b.x ()), max (a.y (), b.y ()), max (a.z (), b.z ()));
598
605
}
599
606
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
+ }
601
614
602
615
template <typename vector_type>
603
616
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)
647
660
{
648
661
return dot_product (v, v);
649
662
}
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
+ }
650
682
683
+ #else
651
684
template <typename vector_type>
652
685
typename vector_type::element_type length (const vector_type& v, double multiplier = 1.0 )
653
686
{
654
687
return square_root (squared_length (v), multiplier);
655
688
}
689
+ #endif
656
690
657
691
template <typename vector_type>
658
- vector_type normalize (const vector_type& v)
692
+ vector_type normalize (const vector_type& v, double multiplier = 1.0 )
659
693
{
660
- return v / length (v);
694
+ return v / length (v, multiplier );
661
695
}
662
696
663
697
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,
667
701
// Compute a polygon's plane coefficients (i.e. normal and d parameters).
668
702
// The computed normal is not normalized. This function returns the largest component of the normal.
669
703
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);
671
707
672
708
// Compute the intersection point between a line (not a segment) and a plane defined by a polygon.
673
709
//
@@ -712,7 +748,9 @@ char compute_segment_plane_intersection(vec3& p, const vec3& normal, const scala
712
748
// '1': The segment intersects the plane, and none of {p, q, r} hold.
713
749
char compute_segment_plane_intersection_type (const vec3& q, const vec3& r,
714
750
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);
716
754
717
755
// Test if a point 'q' (in 2D) lies inside or outside a given polygon (count the number ray crossings).
718
756
//
@@ -721,7 +759,8 @@ char compute_segment_plane_intersection_type(const vec3& q, const vec3& r,
721
759
// 'o': q is strictly exterior (outside).
722
760
// 'e': q is on an edge, but not an endpoint.
723
761
// '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);
725
764
726
765
// Test if a point 'q' (in 3D) lies inside or outside a given polygon (count the number ray crossings).
727
766
//
@@ -731,14 +770,17 @@ char compute_point_in_polygon_test(const vec2& q, const std::vector<vec2>& polyg
731
770
// 'e': q is on an edge, but not an endpoint.
732
771
// 'v': q is a vertex.
733
772
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 );
735
774
736
775
// project a 3d polygon to 3d by eliminating the largest component of its normal
737
776
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);
739
780
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);
742
784
743
785
bool coplaner (const vec3& pa, const vec3& pb, const vec3& pc,
744
786
const vec3& pd);
0 commit comments