Skip to content

Commit 2cdbe3e

Browse files
Add some missing functions to C and C# bindings.
1 parent 44cdaee commit 2cdbe3e

File tree

8 files changed

+49
-31
lines changed

8 files changed

+49
-31
lines changed

scripts/mrbind/extra_headers/instantiate_templates.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#ifdef MR_PARSING_FOR_PB11_BINDINGS
3+
#ifdef MR_PARSING_FOR_ANY_BINDINGS
44

55
#include "MRMesh/MRDistanceMap.h"
66
#include "MRMesh/MRMesh.h"
@@ -20,31 +20,41 @@ namespace MR
2020

2121
#define VEC3(T, isFloatingPoint) \
2222
template struct Vector3<T>; \
23+
template T distanceSq( const Vector3<T> & a, const Vector3<T> & b ); \
24+
INST_IF(isFloatingPoint)( \
25+
template T distance( const Vector3<T> & a, const Vector3<T> & b ); \
26+
) \
2327
template Vector3<T> cross( const Vector3<T> & a, const Vector3<T> & b ); \
2428
template T dot( const Vector3<T> & a, const Vector3<T> & b ); \
2529
template T sqr( const Vector3<T> & a ); \
2630
template T mixed( const Vector3<T> & a, const Vector3<T> & b, const Vector3<T> & c ); \
2731
template Vector3<T> mult( const Vector3<T>& a, const Vector3<T>& b ); \
32+
template Vector3<T> div( const Vector3<T>& a, const Vector3<T>& b ); \
2833
template T angle( const Vector3<T> & a, const Vector3<T> & b ); \
2934
INST_IF(isFloatingPoint)( \
3035
template Vector3<T> unitVector3( T azimuth, T altitude ); \
3136
)
3237

33-
#define VEC2(T) \
38+
#define VEC2(T, isFloatingPoint) \
3439
template struct Vector2<T>; \
40+
template T distanceSq( const Vector2<T> & a, const Vector2<T> & b ); \
41+
INST_IF(isFloatingPoint)( \
42+
template T distance( const Vector2<T> & a, const Vector2<T> & b ); \
43+
) \
3544
template T cross( const Vector2<T> & a, const Vector2<T> & b ); \
3645
template T dot( const Vector2<T> & a, const Vector2<T> & b ); \
3746
template T sqr( const Vector2<T> & a ); \
3847
template Vector2<T> mult( const Vector2<T>& a, const Vector2<T>& b ); \
48+
template Vector2<T> div( const Vector2<T>& a, const Vector2<T>& b ); \
3949
template T angle( const Vector2<T> & a, const Vector2<T> & b );
4050

4151
VEC3(float, 1)
4252
VEC3(double, 1)
4353
VEC3(int, 0)
4454

45-
VEC2(float)
46-
VEC2(double)
47-
VEC2(int)
55+
VEC2(float, 1)
56+
VEC2(double, 1)
57+
VEC2(int, 0)
4858

4959
#undef VEC3
5060
#undef VEC2

source/MRMesh/MRBitSet.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ template <typename I>
336336

337337
/// iterator to enumerate all indices with set bits in BitSet class or its derivatives
338338
template <typename T>
339-
class MR_BIND_IGNORE SetBitIteratorT
339+
class MR_BIND_IGNORE_PY SetBitIteratorT
340340
{
341341
public:
342342
using IndexType = typename T::IndexType;
343343

344344
using iterator_category = std::forward_iterator_tag;
345345
using value_type = IndexType;
346346
using difference_type = std::ptrdiff_t;
347-
using reference = const IndexType; ///< intentionally not a reference
347+
using reference = IndexType; ///< intentionally not a reference
348348
using pointer = const IndexType *;
349349

350350
/// constructs end iterator
@@ -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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,17 @@ inline Vector2<T> Vector2<T>::furthestBasisVector() const MR_REQUIRES_IF_SUPPORT
202202
}
203203

204204

205-
// We don't need to bind those functions themselves. This doesn't prevent `__iter__` from being generated for the type.
205+
// We don't need to bind those functions in Python, because this doesn't prevent `__iter__` from being generated for the type.
206206

207207
template <typename T>
208-
MR_BIND_IGNORE inline auto begin( const Vector2<T> & v ) { return &v[0]; }
208+
MR_BIND_IGNORE_PY inline auto begin( const Vector2<T> & v ) { return &v[0]; }
209209
template <typename T>
210-
MR_BIND_IGNORE inline auto begin( Vector2<T> & v ) { return &v[0]; }
210+
MR_BIND_IGNORE_PY inline auto begin( Vector2<T> & v ) { return &v[0]; }
211211

212212
template <typename T>
213-
MR_BIND_IGNORE inline auto end( const Vector2<T> & v ) { return &v[2]; }
213+
MR_BIND_IGNORE_PY inline auto end( const Vector2<T> & v ) { return &v[2]; }
214214
template <typename T>
215-
MR_BIND_IGNORE inline auto end( Vector2<T> & v ) { return &v[2]; }
215+
MR_BIND_IGNORE_PY inline auto end( Vector2<T> & v ) { return &v[2]; }
216216

217217
/// \}
218218

source/MRMesh/MRVector3.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,17 @@ Vector3<T> unitVector3( T azimuth, T altitude )
258258
}
259259

260260

261-
// We don't need to bind those functions themselves. This doesn't prevent `__iter__` from being generated for the type.
261+
// We don't need to bind those functions in Python, because this doesn't prevent `__iter__` from being generated for the type.
262262

263263
template <typename T>
264-
MR_BIND_IGNORE inline auto begin( const Vector3<T> & v ) { return &v[0]; }
264+
MR_BIND_IGNORE_PY inline auto begin( const Vector3<T> & v ) { return &v[0]; }
265265
template <typename T>
266-
MR_BIND_IGNORE inline auto begin( Vector3<T> & v ) { return &v[0]; }
266+
MR_BIND_IGNORE_PY inline auto begin( Vector3<T> & v ) { return &v[0]; }
267267

268268
template <typename T>
269-
MR_BIND_IGNORE inline auto end( const Vector3<T> & v ) { return &v[3]; }
269+
MR_BIND_IGNORE_PY inline auto end( const Vector3<T> & v ) { return &v[3]; }
270270
template <typename T>
271-
MR_BIND_IGNORE inline auto end( Vector3<T> & v ) { return &v[3]; }
271+
MR_BIND_IGNORE_PY inline auto end( Vector3<T> & v ) { return &v[3]; }
272272

273273
/// \}
274274

source/MRMesh/MRVector4.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,17 @@ inline Vector4<T> div( const Vector4<T>& a, const Vector4<T>& b )
169169
}
170170

171171

172-
// We don't need to bind those functions themselves. This doesn't prevent `__iter__` from being generated for the type.
172+
// We don't need to bind those functions in Python, because this doesn't prevent `__iter__` from being generated for the type.
173173

174174
template <typename T>
175-
MR_BIND_IGNORE auto begin( const Vector4<T> & v ) { return &v[0]; }
175+
MR_BIND_IGNORE_PY auto begin( const Vector4<T> & v ) { return &v[0]; }
176176
template <typename T>
177-
MR_BIND_IGNORE auto begin( Vector4<T> & v ) { return &v[0]; }
177+
MR_BIND_IGNORE_PY auto begin( Vector4<T> & v ) { return &v[0]; }
178178

179179
template <typename T>
180-
MR_BIND_IGNORE auto end( const Vector4<T> & v ) { return &v[4]; }
180+
MR_BIND_IGNORE_PY auto end( const Vector4<T> & v ) { return &v[4]; }
181181
template <typename T>
182-
MR_BIND_IGNORE auto end( Vector4<T> & v ) { return &v[4]; }
182+
MR_BIND_IGNORE_PY auto end( Vector4<T> & v ) { return &v[4]; }
183183

184184
/// \}
185185

source/MRPch/MRBindingMacros.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@
2020
// Mark a declaration with this to avoid generating a binding for it.
2121
#define MR_BIND_IGNORE __attribute__((__annotate__("mrbind::ignore")))
2222

23+
// Same, but specific to Python.
24+
#ifdef MR_PARSING_FOR_PB11_BINDINGS
25+
#define MR_BIND_IGNORE_PY MR_BIND_IGNORE
26+
#else
27+
#define MR_BIND_IGNORE_PY
28+
#endif
29+
2330
// This is a specialized replacement for `MR_CANONICAL_TYPEDEFS()`, to be used on full template specializations, where that macro doesn't work.
2431
#define MR_BIND_PREFERRED_NAME(...) __attribute__((__annotate__(DETAIL_MR_BIND_PREFERRED_NAME(mrbind::preferred_name=__VA_ARGS__))))
2532
#define DETAIL_MR_BIND_PREFERRED_NAME(...) #__VA_ARGS__
2633

2734
#else
2835
#define MR_BIND_TEMPLATE(...)
2936
#define MR_BIND_IGNORE
37+
#define MR_BIND_IGNORE_PY
3038
#define MR_BIND_PREFERRED_NAME(...)
3139
#endif
3240

0 commit comments

Comments
 (0)