Skip to content

Commit 172d648

Browse files
Merge pull request #1024 from Geode-solutions/feat_new_functions_Vector_Point
feat(Geometry): Adding project_point function to Point class and least_meaningful_axis function to Vector class.
2 parents 6500528 + f7d5240 commit 172d648

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

bindings/python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
5-
# pip-compile bindings/python/requirements.in
5+
# pip-compile --pre bindings/python/requirements.in
66
#

include/geode/geometry/point.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,26 @@ namespace geode
174174
return oss.str();
175175
}
176176

177+
[[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+
}
196+
177197
private:
178198
friend class bitsery::Access;
179199
template < typename Archive >

include/geode/geometry/vector.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,38 @@ namespace geode
130130
this->value( 0 ) * other.value( 1 )
131131
- this->value( 1 ) * other.value( 0 ) } };
132132
}
133+
134+
[[nodiscard]] geode::local_index_t most_meaningful_axis() const
135+
{
136+
geode::local_index_t axis{ 0 };
137+
double max{ 0 };
138+
for( const auto i : LRange{ dimension } )
139+
{
140+
const auto val = std::fabs( this->value( i ) );
141+
if( val > max )
142+
{
143+
max = val;
144+
axis = i;
145+
}
146+
}
147+
return axis;
148+
}
149+
150+
[[nodiscard]] geode::local_index_t least_meaningful_axis() const
151+
{
152+
geode::local_index_t axis{ 0 };
153+
auto min = std::numeric_limits< double >::max();
154+
for( const auto i : LRange{ dimension } )
155+
{
156+
const auto val = std::fabs( this->value( i ) );
157+
if( val < min )
158+
{
159+
min = val;
160+
axis = i;
161+
}
162+
}
163+
return axis;
164+
}
133165
};
134166
ALIAS_1D_AND_2D_AND_3D( Vector );
135167

0 commit comments

Comments
 (0)