Skip to content

Commit 68951b6

Browse files
Expose some forgotten functions to the bindings.
1 parent 44cdaee commit 68951b6

File tree

6 files changed

+165
-205
lines changed

6 files changed

+165
-205
lines changed

source/MRMesh/MRBitSet.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,16 @@ class MR_BIND_IGNORE SetBitIteratorT
377377
};
378378

379379

380-
[[nodiscard]] MR_BIND_IGNORE inline auto begin( const BitSet & a )
380+
[[nodiscard]] MR_BIND_IGNORE_PY inline auto begin( const BitSet & a )
381381
{ return SetBitIteratorT<BitSet>(a); }
382-
[[nodiscard]] MR_BIND_IGNORE inline auto end( const BitSet & )
382+
[[nodiscard]] MR_BIND_IGNORE_PY inline auto end( const BitSet & )
383383
{ return SetBitIteratorT<BitSet>(); }
384384

385385
template <typename I>
386-
[[nodiscard]] MR_BIND_IGNORE inline auto begin( const TypedBitSet<I> & a )
386+
[[nodiscard]] MR_BIND_IGNORE_PY inline auto begin( const TypedBitSet<I> & a )
387387
{ return SetBitIteratorT<TypedBitSet<I>>(a); }
388388
template <typename I>
389-
[[nodiscard]] MR_BIND_IGNORE inline auto end( const TypedBitSet<I> & )
389+
[[nodiscard]] MR_BIND_IGNORE_PY inline auto end( const TypedBitSet<I> & )
390390
{ return SetBitIteratorT<TypedBitSet<I>>(); }
391391

392392
/// creates a Vector where for each set bit of input bitset its sequential number starting from 0 is returned; and -1 for reset bits

source/MRMesh/MRVector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,19 @@ class Vector
163163
};
164164

165165
template <typename T, typename I>
166-
[[nodiscard]] MR_BIND_IGNORE inline auto begin( const Vector<T, I> & a )
166+
[[nodiscard]] MR_BIND_IGNORE_PY inline auto begin( const Vector<T, I> & a )
167167
{ return a.vec_.begin(); }
168168

169169
template <typename T, typename I>
170-
[[nodiscard]] MR_BIND_IGNORE inline auto begin( Vector<T, I> & a )
170+
[[nodiscard]] MR_BIND_IGNORE_PY inline auto begin( Vector<T, I> & a )
171171
{ return a.vec_.begin(); }
172172

173173
template <typename T, typename I>
174-
[[nodiscard]] MR_BIND_IGNORE inline auto end( const Vector<T, I> & a )
174+
[[nodiscard]] MR_BIND_IGNORE_PY inline auto end( const Vector<T, I> & a )
175175
{ return a.vec_.end(); }
176176

177177
template <typename T, typename I>
178-
[[nodiscard]] MR_BIND_IGNORE inline auto end( Vector<T, I> & a )
178+
[[nodiscard]] MR_BIND_IGNORE_PY inline auto end( Vector<T, I> & a )
179179
{ return a.vec_.end(); }
180180

181181
/// given some std::vector and a key, returns the value associated with the key, or default value if key is invalid or outside the std::vector

source/MRMesh/MRVector2.h

Lines changed: 52 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -127,68 +127,67 @@ struct Vector2
127127
{
128128
return s >> vec.x >> vec.y;
129129
}
130-
};
131130

132-
/// \related Vector2
133-
/// \{
134131

135-
/// squared distance between two points, which is faster to compute than just distance
136-
template <typename T>
137-
inline T distanceSq( const Vector2<T> & a, const Vector2<T> & b )
138-
{
139-
return ( a - b ).lengthSq();
140-
}
132+
/// squared distance between two points, which is faster to compute than just distance
133+
[[nodiscard]] T distanceSq( const Vector2& a, const Vector2& b )
134+
{
135+
return ( a - b ).lengthSq();
136+
}
141137

142-
/// distance between two points, better use distanceSq for higher performance
143-
template <typename T>
144-
inline T distance( const Vector2<T> & a, const Vector2<T> & b )
145-
{
146-
return ( a - b ).length();
147-
}
138+
/// distance between two points, better use distanceSq for higher performance
139+
[[nodiscard]] T distance( const Vector2& a, const Vector2& b ) MR_REQUIRES_IF_SUPPORTED( std::floating_point<T> )
140+
{
141+
return ( a - b ).length();
142+
}
148143

149-
/// cross product
150-
template <typename T>
151-
inline T cross( const Vector2<T> & a, const Vector2<T> & b )
152-
{
153-
return a.x * b.y - a.y * b.x;
154-
}
144+
/// cross product
145+
[[nodiscard]] T cross( const Vector2& a, const Vector2& b )
146+
{
147+
return a.x * b.y - a.y * b.x;
148+
}
155149

156-
/// dot product
157-
template <typename T>
158-
inline auto dot( const Vector2<T> & a, const Vector2<T> & b ) -> decltype( a.x * b.x )
159-
{
160-
return a.x * b.x + a.y * b.y;
161-
}
150+
/// dot product
151+
[[nodiscard]] auto dot( const Vector2& a, const Vector2& b ) -> decltype( a.x * b.x )
152+
{
153+
return a.x * b.x + a.y * b.y;
154+
}
162155

163-
/// squared length
164-
template <typename T>
165-
inline T sqr( const Vector2<T> & a )
166-
{
167-
return a.lengthSq();
168-
}
156+
/// squared length
157+
[[nodiscard]] T sqr( const Vector2& a )
158+
{
159+
return a.lengthSq();
160+
}
169161

170-
/// per component multiplication
171-
template <typename T>
172-
inline Vector2<T> mult( const Vector2<T>& a, const Vector2<T>& b )
173-
{
174-
return { a.x * b.x,a.y * b.y };
175-
}
162+
/// per component multiplication
163+
[[nodiscard]] Vector2 mult( const Vector2& a, const Vector2& b )
164+
{
165+
return { a.x * b.x,a.y * b.y };
166+
}
176167

177-
/// per component division
178-
template <typename T>
179-
inline Vector2<T> div( const Vector2<T>& a, const Vector2<T>& b )
180-
{
181-
return { a.x / b.x, a.y / b.y };
182-
}
168+
/// per component division
169+
[[nodiscard]] Vector2 div( const Vector2& a, const Vector2& b )
170+
{
171+
return { a.x / b.x, a.y / b.y };
172+
}
173+
174+
/// angle in radians between two vectors
175+
[[nodiscard]] T angle( const Vector2& a, const Vector2& b ) MR_REQUIRES_IF_SUPPORTED( std::floating_point<T> )
176+
{
177+
return std::atan2( std::abs( cross( a, b ) ), dot( a, b ) );
178+
// this version is slower and less precise
179+
//return std::acos( std::clamp( dot( a.normalized(), b.normalized() ), T(-1), T(1) ) );
180+
}
183181

184-
/// angle in radians between two vectors
185-
template <typename T>
186-
inline T angle( const Vector2<T> & a, const Vector2<T> & b )
187-
{
188-
return std::atan2( std::abs( cross( a, b ) ), dot( a, b ) );
189-
// this version is slower and less precise
190-
//return std::acos( std::clamp( dot( a.normalized(), b.normalized() ), T(-1), T(1) ) );
191-
}
182+
183+
// Those don't need Python bindings, the `__iter__` generation works even if they are ignored.
184+
185+
MR_BIND_IGNORE_PY auto begin( const Vector2<T>& v ) { return &v[0]; }
186+
MR_BIND_IGNORE_PY auto begin( Vector2<T>& v ) { return &v[0]; }
187+
188+
MR_BIND_IGNORE_PY auto end( const Vector2<T>& v ) { return &v[2]; }
189+
MR_BIND_IGNORE_PY auto end( Vector2<T>& v ) { return &v[2]; }
190+
};
192191

193192
template <typename T>
194193
inline Vector2<T> Vector2<T>::furthestBasisVector() const MR_REQUIRES_IF_SUPPORTED( !std::is_same_v<T, bool> )
@@ -201,21 +200,6 @@ inline Vector2<T> Vector2<T>::furthestBasisVector() const MR_REQUIRES_IF_SUPPORT
201200
return Vector2( 0, 1 );
202201
}
203202

204-
205-
// We don't need to bind those functions themselves. This doesn't prevent `__iter__` from being generated for the type.
206-
207-
template <typename T>
208-
MR_BIND_IGNORE inline auto begin( const Vector2<T> & v ) { return &v[0]; }
209-
template <typename T>
210-
MR_BIND_IGNORE inline auto begin( Vector2<T> & v ) { return &v[0]; }
211-
212-
template <typename T>
213-
MR_BIND_IGNORE inline auto end( const Vector2<T> & v ) { return &v[2]; }
214-
template <typename T>
215-
MR_BIND_IGNORE inline auto end( Vector2<T> & v ) { return &v[2]; }
216-
217-
/// \}
218-
219203
#ifdef _MSC_VER
220204
#pragma warning(pop)
221205
#endif

source/MRMesh/MRVector3.h

Lines changed: 61 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -146,82 +146,79 @@ struct Vector3
146146
{
147147
return s >> vec.x >> vec.y >> vec.z;
148148
}
149-
};
150149

151-
/// \related Vector3
152-
/// \{
153150

151+
/// squared distance between two points, which is faster to compute than just distance
152+
[[nodiscard]] friend T distanceSq( const Vector3& a, const Vector3& b )
153+
{
154+
return ( a - b ).lengthSq();
155+
}
154156

155-
/// squared distance between two points, which is faster to compute than just distance
156-
template <typename T>
157-
inline T distanceSq( const Vector3<T> & a, const Vector3<T> & b )
158-
{
159-
return ( a - b ).lengthSq();
160-
}
157+
/// distance between two points, better use distanceSq for higher performance
158+
[[nodiscard]] friend T distance( const Vector3& a, const Vector3& b ) MR_REQUIRES_IF_SUPPORTED( std::floating_point<T> )
159+
{
160+
return ( a - b ).length();
161+
}
161162

162-
/// distance between two points, better use distanceSq for higher performance
163-
template <typename T>
164-
inline T distance( const Vector3<T> & a, const Vector3<T> & b )
165-
{
166-
return ( a - b ).length();
167-
}
163+
/// cross product
164+
[[nodiscard]] friend Vector3 cross( const Vector3& a, const Vector3& b )
165+
{
166+
return {
167+
a.y * b.z - a.z * b.y,
168+
a.z * b.x - a.x * b.z,
169+
a.x * b.y - a.y * b.x
170+
};
171+
}
168172

169-
/// cross product
170-
template <typename T>
171-
inline Vector3<T> cross( const Vector3<T> & a, const Vector3<T> & b )
172-
{
173-
return {
174-
a.y * b.z - a.z * b.y,
175-
a.z * b.x - a.x * b.z,
176-
a.x * b.y - a.y * b.x
177-
};
178-
}
173+
/// dot product
174+
[[nodiscard]] friend auto dot( const Vector3& a, const Vector3& b ) -> decltype( a.x * b.x )
175+
{
176+
return a.x * b.x + a.y * b.y + a.z * b.z;
177+
}
179178

180-
/// dot product
181-
template <typename T>
182-
inline auto dot( const Vector3<T> & a, const Vector3<T> & b ) -> decltype( a.x * b.x )
183-
{
184-
return a.x * b.x + a.y * b.y + a.z * b.z;
185-
}
179+
/// squared length
180+
[[nodiscard]] friend T sqr( const Vector3& a )
181+
{
182+
return a.lengthSq();
183+
}
186184

187-
/// squared length
188-
template <typename T>
189-
inline T sqr( const Vector3<T> & a )
190-
{
191-
return a.lengthSq();
192-
}
185+
/// mixed product
186+
[[nodiscard]] friend T mixed( const Vector3& a, const Vector3& b, const Vector3& c )
187+
{
188+
return dot( a, cross( b, c ) );
189+
}
193190

194-
/// mixed product
195-
template <typename T>
196-
inline T mixed( const Vector3<T> & a, const Vector3<T> & b, const Vector3<T> & c )
197-
{
198-
return dot( a, cross( b, c ) );
199-
}
191+
/// per component multiplication
192+
[[nodiscard]] friend Vector3 mult( const Vector3& a, const Vector3& b )
193+
{
194+
return { a.x * b.x, a.y * b.y, a.z * b.z };
195+
}
200196

201-
/// per component multiplication
202-
template <typename T>
203-
inline Vector3<T> mult( const Vector3<T>& a, const Vector3<T>& b )
204-
{
205-
return { a.x * b.x,a.y * b.y,a.z * b.z };
206-
}
197+
/// per component division
198+
[[nodiscard]] friend Vector3 div( const Vector3& a, const Vector3& b )
199+
{
200+
return { a.x / b.x, a.y / b.y, a.z / b.z };
201+
}
207202

208-
/// per component division
209-
template <typename T>
210-
inline Vector3<T> div( const Vector3<T>& a, const Vector3<T>& b )
211-
{
212-
return { a.x / b.x, a.y / b.y, a.z / b.z };
213-
}
214203

204+
/// computes minimal angle in [0,pi] between two vectors;
205+
/// the function is symmetric: angle( a, b ) == angle( b, a )
206+
[[nodiscard]] friend T angle( const Vector3& a, const Vector3& b ) MR_REQUIRES_IF_SUPPORTED( std::floating_point<T> )
207+
{
208+
return std::atan2( cross( a, b ).length(), dot( a, b ) );
209+
// this version is slower and less precise
210+
//return std::acos( std::clamp( dot( a.normalized(), b.normalized() ), T(-1), T(1) ) );
211+
}
215212

216-
/// computes minimal angle in [0,pi] between two vectors;
217-
/// the function is symmetric: angle( a, b ) == angle( b, a )
218-
template <typename T>
219-
inline T angle( const Vector3<T> & a, const Vector3<T> & b )
220-
{
221-
return std::atan2( cross( a, b ).length(), dot( a, b ) );
222-
// this version is slower and less precise
223-
//return std::acos( std::clamp( dot( a.normalized(), b.normalized() ), T(-1), T(1) ) );
224-
}
213+
214+
// Those don't need Python bindings, the `__iter__` generation works even if they are ignored.
215+
216+
MR_BIND_IGNORE_PY friend auto begin( const Vector3& v ) { return &v[0]; }
217+
MR_BIND_IGNORE_PY friend auto begin( Vector3& v ) { return &v[0]; }
218+
219+
MR_BIND_IGNORE_PY friend auto end( const Vector3& v ) { return &v[3]; }
220+
MR_BIND_IGNORE_PY friend auto end( Vector3& v ) { return &v[3]; }
221+
};
225222

226223
template <typename T>
227224
inline Vector3<T> Vector3<T>::furthestBasisVector() const MR_REQUIRES_IF_SUPPORTED( !std::is_same_v<T, bool> )
@@ -257,21 +254,6 @@ Vector3<T> unitVector3( T azimuth, T altitude )
257254
};
258255
}
259256

260-
261-
// We don't need to bind those functions themselves. This doesn't prevent `__iter__` from being generated for the type.
262-
263-
template <typename T>
264-
MR_BIND_IGNORE inline auto begin( const Vector3<T> & v ) { return &v[0]; }
265-
template <typename T>
266-
MR_BIND_IGNORE inline auto begin( Vector3<T> & v ) { return &v[0]; }
267-
268-
template <typename T>
269-
MR_BIND_IGNORE inline auto end( const Vector3<T> & v ) { return &v[3]; }
270-
template <typename T>
271-
MR_BIND_IGNORE inline auto end( Vector3<T> & v ) { return &v[3]; }
272-
273-
/// \}
274-
275257
#ifdef _MSC_VER
276258
#pragma warning(pop)
277259
#endif

0 commit comments

Comments
 (0)