Skip to content

Commit 7a7cb9c

Browse files
committed
more
1 parent 6bbf2f0 commit 7a7cb9c

File tree

16 files changed

+621
-328
lines changed

16 files changed

+621
-328
lines changed

include/geode/geometry/point.hpp

Lines changed: 26 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,11 @@
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

4133
namespace 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
309187
namespace 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

include/geode/geometry/vector.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <geode/basic/range.hpp>
2727

2828
#include <geode/geometry/common.hpp>
29+
#include <geode/geometry/detail/point_operators.hpp>
2930
#include <geode/geometry/point.hpp>
3031

3132
namespace geode

include/geode/image/core/greyscale_color.hpp

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,76 +23,39 @@
2323

2424
#pragma once
2525

26-
#include <absl/hash/hash.h>
27-
2826
#include <geode/basic/attribute_utils.hpp>
29-
#include <geode/basic/bitsery_archive.hpp>
3027
#include <geode/basic/range.hpp>
3128

3229
#include <geode/image/common.hpp>
3330

3431
namespace geode
3532
{
36-
/*!
37-
* Description of a color in grey scale
38-
*/
39-
class GreyscaleColor
33+
class opengeode_image_api GreyscaleColor
4034
{
4135
public:
42-
GreyscaleColor()
43-
{
44-
value_ = 0;
45-
}
36+
GreyscaleColor();
4637

47-
explicit GreyscaleColor( local_index_t value ) : value_( value ) {}
38+
explicit GreyscaleColor( local_index_t value );
4839

49-
[[nodiscard]] local_index_t value() const
50-
{
51-
return value_;
52-
}
40+
[[nodiscard]] local_index_t value() const;
5341

54-
void set_value( local_index_t greyscale )
55-
{
56-
value_ = greyscale;
57-
}
42+
void set_value( local_index_t greyscale );
5843

59-
[[nodiscard]] bool operator==( const GreyscaleColor &other ) const
60-
{
61-
return value() == other.value();
62-
}
44+
[[nodiscard]] bool operator==( const GreyscaleColor &other ) const;
6345

64-
[[nodiscard]] bool operator!=( const GreyscaleColor &other ) const
65-
{
66-
return value() != other.value();
67-
}
46+
[[nodiscard]] bool operator!=( const GreyscaleColor &other ) const;
6847

6948
[[nodiscard]] GreyscaleColor operator+(
70-
const GreyscaleColor &other ) const
71-
{
72-
return GreyscaleColor{ static_cast< geode::local_index_t >(
73-
value() / 2 + other.value() / 2 ) };
74-
}
49+
const GreyscaleColor &other ) const;
7550

76-
void operator+=( const GreyscaleColor &other )
77-
{
78-
set_value( ( value() + other.value() ) / 2 );
79-
}
51+
void operator+=( const GreyscaleColor &other );
8052

81-
[[nodiscard]] std::string string() const
82-
{
83-
return absl::StrCat( value_ );
84-
}
53+
[[nodiscard]] std::string string() const;
8554

8655
private:
8756
friend class bitsery::Access;
8857
template < typename Archive >
89-
void serialize( Archive &archive )
90-
{
91-
archive.ext( *this, Growable< Archive, GreyscaleColor >{
92-
{ []( Archive &a, GreyscaleColor &color ) {
93-
a.value1b( color.value_ );
94-
} } } );
95-
}
58+
void serialize( Archive &archive );
9659

9760
private:
9861
local_index_t value_;
@@ -161,11 +124,8 @@ namespace geode
161124
namespace std
162125
{
163126
template <>
164-
struct hash< geode::GreyscaleColor >
127+
struct opengeode_image_api hash< geode::GreyscaleColor >
165128
{
166-
size_t operator()( const geode::GreyscaleColor &color ) const
167-
{
168-
return absl::Hash< geode::local_index_t >()( color.value() );
169-
}
129+
size_t operator()( const geode::GreyscaleColor &color ) const;
170130
};
171131
} // namespace std

0 commit comments

Comments
 (0)