Skip to content

Commit 2a6523f

Browse files
committed
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeode into fix/small-set-at
2 parents 94768e3 + 5c1c5fd commit 2a6523f

File tree

7 files changed

+476
-0
lines changed

7 files changed

+476
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2019 - 2025 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
#pragma once
24+
25+
#include <geode/basic/pimpl.hpp>
26+
27+
#include <geode/geometry/common.hpp>
28+
29+
namespace geode
30+
{
31+
FORWARD_DECLARATION_DIMENSION_CLASS( Frame );
32+
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
33+
FORWARD_DECLARATION_DIMENSION_CLASS( Vector );
34+
} // namespace geode
35+
36+
namespace geode
37+
{
38+
template < index_t dimension >
39+
class FrameTransform
40+
{
41+
public:
42+
FrameTransform(
43+
const Frame< dimension >& from, const Frame< dimension >& to );
44+
virtual ~FrameTransform();
45+
46+
[[nodiscard]] virtual local_index_t direction(
47+
local_index_t index ) const;
48+
49+
[[nodiscard]] virtual signed_index_t orientation(
50+
local_index_t index ) const;
51+
52+
[[nodiscard]] virtual Frame< dimension > apply(
53+
const Frame< dimension >& frame ) const;
54+
55+
[[nodiscard]] virtual Vector< dimension > apply(
56+
const Vector< dimension >& vector ) const;
57+
58+
[[nodiscard]] virtual Point< dimension > apply(
59+
const Point< dimension >& point ) const;
60+
61+
private:
62+
IMPLEMENTATION_MEMBER( impl_ );
63+
};
64+
ALIAS_2D_AND_3D( FrameTransform );
65+
} // namespace geode
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2019 - 2025 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
#pragma once
24+
25+
#include <geode/basic/pimpl.hpp>
26+
27+
#include <geode/geometry/common.hpp>
28+
#include <geode/geometry/frame_transform.hpp>
29+
30+
namespace geode
31+
{
32+
FORWARD_DECLARATION_DIMENSION_CLASS( Frame );
33+
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
34+
FORWARD_DECLARATION_DIMENSION_CLASS( Vector );
35+
} // namespace geode
36+
37+
namespace geode
38+
{
39+
template < index_t dimension >
40+
class NormalFrameTransform : public FrameTransform< dimension >
41+
{
42+
public:
43+
NormalFrameTransform(
44+
const Frame< dimension >& from, const Frame< dimension >& to );
45+
~NormalFrameTransform();
46+
47+
[[nodiscard]] Frame< dimension > apply(
48+
const Frame< dimension >& frame ) const final;
49+
50+
[[nodiscard]] Vector< dimension > apply(
51+
const Vector< dimension >& vector ) const final;
52+
53+
[[nodiscard]] Point< dimension > apply(
54+
const Point< dimension >& point ) const final;
55+
56+
private:
57+
IMPLEMENTATION_MEMBER( impl_ );
58+
};
59+
ALIAS_2D_AND_3D( NormalFrameTransform );
60+
} // namespace geode

src/geode/geometry/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ add_geode_library(
4242
"distance.cpp"
4343
"dynamic_nn_search.cpp"
4444
"frame.cpp"
45+
"frame_transform.cpp"
4546
"information.cpp"
4647
"intersection.cpp"
4748
"intersection_detection.cpp"
4849
"mensuration.cpp"
4950
"nn_search.cpp"
51+
"normal_frame_transform.cpp"
5052
"perpendicular.cpp"
5153
"points_sort.cpp"
5254
"position.cpp"
@@ -77,11 +79,13 @@ add_geode_library(
7779
"distance.hpp"
7880
"dynamic_nn_search.hpp"
7981
"frame.hpp"
82+
"frame_transform.hpp"
8083
"information.hpp"
8184
"intersection.hpp"
8285
"intersection_detection.hpp"
8386
"mensuration.hpp"
8487
"nn_search.hpp"
88+
"normal_frame_transform.hpp"
8589
"perpendicular.hpp"
8690
"point.hpp"
8791
"points_sort.hpp"
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright (c) 2019 - 2025 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#include <geode/geometry/frame_transform.hpp>
25+
26+
#include <geode/basic/logger.hpp>
27+
#include <geode/basic/pimpl_impl.hpp>
28+
29+
#include <geode/geometry/frame.hpp>
30+
#include <geode/geometry/vector.hpp>
31+
32+
namespace geode
33+
{
34+
template < index_t dimension >
35+
class FrameTransform< dimension >::Impl
36+
{
37+
public:
38+
Impl( const Frame< dimension >& from, const Frame< dimension >& to )
39+
{
40+
for( const auto d_from : LRange{ dimension } )
41+
{
42+
const auto from_vector = from.direction( d_from ).normalize();
43+
double max_dot{ 0 };
44+
for( const auto d_to : LRange{ dimension } )
45+
{
46+
const auto to_vector = to.direction( d_to ).normalize();
47+
const auto dot = from_vector.dot( to_vector );
48+
const auto abs_dot = std::fabs( dot );
49+
if( abs_dot > max_dot )
50+
{
51+
directions_[d_from] = d_to;
52+
max_dot = abs_dot;
53+
orientations_[d_from] = dot > 0 ? 1 : -1;
54+
}
55+
}
56+
}
57+
}
58+
59+
local_index_t direction( local_index_t index ) const
60+
{
61+
return directions_[index];
62+
}
63+
64+
signed_index_t orientation( local_index_t index ) const
65+
{
66+
return orientations_[index];
67+
}
68+
69+
Frame< dimension > apply( const Frame< dimension >& frame ) const
70+
{
71+
Frame< dimension > result;
72+
for( const auto d : LRange{ dimension } )
73+
{
74+
result.set_direction(
75+
direction( d ), frame.direction( d ) * orientation( d ) );
76+
}
77+
return result;
78+
}
79+
80+
Point< dimension > apply( const Point< dimension >& point ) const
81+
{
82+
Point< dimension > result;
83+
for( const auto d : LRange{ dimension } )
84+
{
85+
result.set_value(
86+
d, orientations_[d] * point.value( directions_[d] ) );
87+
}
88+
return result;
89+
}
90+
91+
Vector< dimension > apply( const Vector< dimension >& vector ) const
92+
{
93+
Vector< dimension > result;
94+
for( const auto d : LRange{ dimension } )
95+
{
96+
result.set_value(
97+
d, orientations_[d] * vector.value( directions_[d] ) );
98+
}
99+
return result;
100+
}
101+
102+
private:
103+
std::array< local_index_t, dimension > directions_;
104+
std::array< signed_index_t, dimension > orientations_;
105+
};
106+
107+
template < index_t dimension >
108+
FrameTransform< dimension >::FrameTransform(
109+
const Frame< dimension >& from, const Frame< dimension >& to )
110+
: impl_{ from, to }
111+
{
112+
}
113+
114+
template < index_t dimension >
115+
FrameTransform< dimension >::~FrameTransform() = default;
116+
117+
template < index_t dimension >
118+
local_index_t FrameTransform< dimension >::direction(
119+
local_index_t index ) const
120+
{
121+
return impl_->direction( index );
122+
}
123+
124+
template < index_t dimension >
125+
signed_index_t FrameTransform< dimension >::orientation(
126+
local_index_t index ) const
127+
{
128+
return impl_->orientation( index );
129+
}
130+
131+
template < index_t dimension >
132+
Frame< dimension > FrameTransform< dimension >::apply(
133+
const Frame< dimension >& frame ) const
134+
{
135+
return impl_->apply( frame );
136+
}
137+
138+
template < index_t dimension >
139+
Vector< dimension > FrameTransform< dimension >::apply(
140+
const Vector< dimension >& vector ) const
141+
{
142+
return impl_->apply( vector );
143+
}
144+
145+
template < index_t dimension >
146+
Point< dimension > FrameTransform< dimension >::apply(
147+
const Point< dimension >& point ) const
148+
{
149+
return impl_->apply( point );
150+
}
151+
template class opengeode_geometry_api FrameTransform< 2 >;
152+
template class opengeode_geometry_api FrameTransform< 3 >;
153+
} // namespace geode

0 commit comments

Comments
 (0)