2424#pragma once
2525
2626#include < array>
27- #include < limits>
28- #include < sstream>
29-
30- #include < absl/hash/hash.h>
31-
32- #include < bitsery/bitsery.h>
3327
3428#include < geode/basic/attribute_utils.hpp>
3529#include < geode/basic/range.hpp>
3630
37- #include < geode/geometry/bitsery_archive.hpp>
3831#include < geode/geometry/common.hpp>
39- #include < geode/geometry/detail/point_operators.hpp>
4032
4133namespace geode
4234{
@@ -47,163 +39,49 @@ namespace geode
4739 class Point
4840 {
4941 public:
50- Point ()
51- {
52- values_.fill ( 0 );
53- }
42+ Point ();
5443
55- explicit Point ( std::array< double , dimension > values )
56- : values_( std::move( values ) )
57- {
58- }
44+ explicit Point ( std::array< double , dimension > values );
5945
60- [[nodiscard]] double value ( local_index_t index ) const
61- {
62- return values_[index];
63- }
46+ [[nodiscard]] double value ( local_index_t index ) const ;
6447
65- void set_value ( local_index_t index, double coordinate )
66- {
67- values_[index] = coordinate;
68- }
48+ void set_value ( local_index_t index, double coordinate );
6949
70- [[nodiscard]] bool operator ==( const Point &other ) const
71- {
72- for ( const auto i : LRange{ dimension } )
73- {
74- if ( value ( i ) != other.value ( i ) )
75- {
76- return false ;
77- }
78- }
79- return true ;
80- }
50+ [[nodiscard]] bool operator ==( const Point &other ) const ;
8151
82- [[nodiscard]] bool operator !=( const Point &other ) const
83- {
84- return !( *this == other );
85- }
52+ [[nodiscard]] bool operator !=( const Point &other ) const ;
8653
87- [[nodiscard]] bool operator <( const Point &other ) const
88- {
89- for ( const auto i : LRange{ dimension } )
90- {
91- if ( value ( i ) < other.value ( i ) )
92- {
93- return true ;
94- }
95- if ( value ( i ) > other.value ( i ) )
96- {
97- return false ;
98- }
99- }
100- return false ;
101- }
54+ [[nodiscard]] bool operator <( const Point &other ) const ;
10255
103- [[nodiscard]] bool operator <=( const Point &other ) const
104- {
105- return operator <( other ) || operator ==( other );
106- }
56+ [[nodiscard]] bool operator <=( const Point &other ) const ;
10757
108- [[nodiscard]] Point operator *( double multiplier ) const
109- {
110- return detail::coords_multiply ( *this , multiplier );
111- }
58+ [[nodiscard]] Point operator *( double multiplier ) const ;
11259
113- [[nodiscard]] Point operator /( double divider ) const
114- {
115- return detail::coords_divide ( *this , divider );
116- }
60+ [[nodiscard]] Point operator /( double divider ) const ;
11761
118- [[nodiscard]] Point operator +( const Point &other ) const
119- {
120- return detail::coords_add ( *this , other );
121- }
62+ [[nodiscard]] Point operator +( const Point &other ) const ;
12263
123- [[nodiscard]] Point operator -( const Point &other ) const
124- {
125- return detail::coords_substract ( *this , other );
126- }
64+ [[nodiscard]] Point operator -( const Point &other ) const ;
12765
128- void operator *=( double multiplier )
129- {
130- detail::coords_multiply_equal ( *this , multiplier );
131- }
66+ void operator *=( double multiplier );
13267
133- void operator /=( double divider )
134- {
135- detail::coords_divide_equal ( *this , divider );
136- }
68+ void operator /=( double divider );
13769
138- void operator +=( const Point &other )
139- {
140- detail::coords_add_equal ( *this , other );
141- }
70+ void operator +=( const Point &other );
14271
143- void operator -=( const Point &other )
144- {
145- detail::coords_substract_equal ( *this , other );
146- }
72+ void operator -=( const Point &other );
14773
148- [[nodiscard]] bool inexact_equal ( const Point &other ) const
149- {
150- double square_length{ 0 };
151- static constexpr auto SQR_EPSILON = GLOBAL_EPSILON * GLOBAL_EPSILON;
152- for ( const auto i : LRange{ dimension } )
153- {
154- const double diff{ other.value ( i ) - this ->value ( i ) };
155- square_length += diff * diff;
156- if ( square_length > SQR_EPSILON )
157- {
158- return false ;
159- }
160- }
161- return true ;
162- }
74+ [[nodiscard]] bool inexact_equal ( const Point &other ) const ;
16375
164- [[nodiscard]] std::string string () const
165- {
166- std::ostringstream oss;
167- oss.precision ( std::numeric_limits< double >::digits10 );
168- const auto *sep = " " ;
169- for ( const auto i : LRange{ dimension } )
170- {
171- oss << sep << value ( i );
172- sep = " " ;
173- }
174- return oss.str ();
175- }
76+ [[nodiscard]] std::string string () const ;
17677
17778 [[nodiscard]] Point< dimension - 1 > project_point (
178- geode::local_index_t axis_to_remove ) const
179- {
180- OPENGEODE_ASSERT ( axis_to_remove < dimension && axis_to_remove >= 0 ,
181- " [Point] Invalid axis to remove" );
182- OPENGEODE_ASSERT (
183- dimension > 1 , " [Point] Invalid dimension to reduce" );
184- Point< dimension - 1 > projected_point;
185- geode::index_t dim{ 0 };
186- for ( const auto i : LRange{ dimension } )
187- {
188- if ( i != axis_to_remove )
189- {
190- projected_point.set_value ( dim, this ->value ( i ) );
191- dim++;
192- }
193- }
194- return projected_point;
195- }
79+ geode::local_index_t axis_to_remove ) const ;
19680
19781 private:
19882 friend class bitsery ::Access;
19983 template < typename Archive >
200- void serialize ( Archive &archive )
201- {
202- archive.ext ( *this ,
203- Growable< Archive, Point >{ { []( Archive &a, Point &point ) {
204- a.container8b ( point.values_ );
205- } } } );
206- }
84+ void serialize ( Archive &archive );
20785
20886 private:
20987 std::array< double , dimension > values_;
@@ -309,32 +187,20 @@ namespace geode
309187namespace std
310188{
311189 template <>
312- struct hash < geode::Point1D >
190+ struct opengeode_geometry_api hash< geode::Point1D >
313191 {
314- size_t operator ()( const geode::Point1D &point ) const
315- {
316- return absl::Hash< double >()( point.value ( 0 ) );
317- }
192+ size_t operator ()( const geode::Point1D &point ) const ;
318193 };
319194
320195 template <>
321- struct hash < geode::Point2D >
196+ struct opengeode_geometry_api hash< geode::Point2D >
322197 {
323- size_t operator ()( const geode::Point2D &point ) const
324- {
325- return absl::Hash< double >()( point.value ( 0 ) )
326- ^ absl::Hash< double >()( point.value ( 1 ) );
327- }
198+ size_t operator ()( const geode::Point2D &point ) const ;
328199 };
329200
330201 template <>
331- struct hash < geode::Point3D >
202+ struct opengeode_geometry_api hash< geode::Point3D >
332203 {
333- size_t operator ()( const geode::Point3D &point ) const
334- {
335- return absl::Hash< double >()( point.value ( 0 ) )
336- ^ absl::Hash< double >()( point.value ( 1 ) )
337- ^ absl::Hash< double >()( point.value ( 2 ) );
338- }
204+ size_t operator ()( const geode::Point3D &point ) const ;
339205 };
340206} // namespace std
0 commit comments