Skip to content

Commit f2929c6

Browse files
committed
fix(Vector): Added Vector to genericable and interpolable attributes.
1 parent 81900f2 commit f2929c6

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

include/geode/geometry/point.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ namespace geode
230230
{
231231
return true;
232232
}
233-
static local_index_t nb_items()
234233

234+
static local_index_t nb_items()
235235
{
236236
return dimension;
237237
}
@@ -245,7 +245,7 @@ namespace geode
245245
explicit OpenGeodePointException(
246246
Point< dimension > point_in, const Args &...message )
247247
: OpenGeodeException{ absl::StrCat(
248-
message..., " at ", point_in.string() ) },
248+
message..., " at ", point_in.string() ) },
249249
point{ std::move( point_in ) }
250250
{
251251
}

include/geode/geometry/vector.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,51 @@ namespace geode
132132
}
133133
};
134134
ALIAS_1D_AND_2D_AND_3D( Vector );
135+
136+
template < index_t dimension >
137+
struct AttributeLinearInterpolationImpl< Vector< dimension > >
138+
{
139+
template < template < typename > class Attribute >
140+
static Vector< dimension > compute(
141+
const AttributeLinearInterpolation &interpolator,
142+
const Attribute< Vector< dimension > > &attribute )
143+
{
144+
Vector< dimension > result;
145+
for( const auto i : Indices{ interpolator.indices_ } )
146+
{
147+
result = result
148+
+ attribute.value( interpolator.indices_[i] )
149+
* interpolator.lambdas_[i];
150+
}
151+
return result;
152+
}
153+
};
154+
155+
template < index_t dimension >
156+
struct GenericAttributeConversion< Vector< dimension > >
157+
{
158+
static float converted_value( const Vector< dimension > &vector )
159+
{
160+
return converted_item_value( vector, 0 );
161+
}
162+
163+
static float converted_item_value(
164+
const Vector< dimension > &vector, local_index_t item )
165+
{
166+
OPENGEODE_ASSERT( item < nb_items(),
167+
"[GenericAttributeConversion] Accessing "
168+
"incorrect item value" );
169+
return static_cast< float >( vector.value( item ) );
170+
}
171+
172+
static bool is_genericable()
173+
{
174+
return true;
175+
}
176+
177+
static local_index_t nb_items()
178+
{
179+
return dimension;
180+
}
181+
};
135182
} // namespace geode

0 commit comments

Comments
 (0)