Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions scripts/mrbind/extra_headers/instantiate_templates.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#ifdef MR_PARSING_FOR_PB11_BINDINGS
#ifdef MR_PARSING_FOR_ANY_BINDINGS

#include "MRMesh/MRDistanceMap.h"
#include "MRMesh/MRMesh.h"
Expand All @@ -20,31 +20,41 @@ namespace MR

#define VEC3(T, isFloatingPoint) \
template struct Vector3<T>; \
template T distanceSq( const Vector3<T> & a, const Vector3<T> & b ); \
INST_IF(isFloatingPoint)( \
template T distance( const Vector3<T> & a, const Vector3<T> & b ); \
) \
template Vector3<T> cross( const Vector3<T> & a, const Vector3<T> & b ); \
template T dot( const Vector3<T> & a, const Vector3<T> & b ); \
template T sqr( const Vector3<T> & a ); \
template T mixed( const Vector3<T> & a, const Vector3<T> & b, const Vector3<T> & c ); \
template Vector3<T> mult( const Vector3<T>& a, const Vector3<T>& b ); \
template Vector3<T> div( const Vector3<T>& a, const Vector3<T>& b ); \
template T angle( const Vector3<T> & a, const Vector3<T> & b ); \
INST_IF(isFloatingPoint)( \
template Vector3<T> unitVector3( T azimuth, T altitude ); \
)

#define VEC2(T) \
#define VEC2(T, isFloatingPoint) \
template struct Vector2<T>; \
template T distanceSq( const Vector2<T> & a, const Vector2<T> & b ); \
INST_IF(isFloatingPoint)( \
template T distance( const Vector2<T> & a, const Vector2<T> & b ); \
) \
template T cross( const Vector2<T> & a, const Vector2<T> & b ); \
template T dot( const Vector2<T> & a, const Vector2<T> & b ); \
template T sqr( const Vector2<T> & a ); \
template Vector2<T> mult( const Vector2<T>& a, const Vector2<T>& b ); \
template Vector2<T> div( const Vector2<T>& a, const Vector2<T>& b ); \
template T angle( const Vector2<T> & a, const Vector2<T> & b );

VEC3(float, 1)
VEC3(double, 1)
VEC3(int, 0)

VEC2(float)
VEC2(double)
VEC2(int)
VEC2(float, 1)
VEC2(double, 1)
VEC2(int, 0)

#undef VEC3
#undef VEC2
Expand Down
12 changes: 6 additions & 6 deletions source/MRMesh/MRBitSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@ template <typename I>

/// iterator to enumerate all indices with set bits in BitSet class or its derivatives
template <typename T>
class MR_BIND_IGNORE SetBitIteratorT
class MR_BIND_IGNORE_PY SetBitIteratorT
{
public:
using IndexType = typename T::IndexType;

using iterator_category = std::forward_iterator_tag;
using value_type = IndexType;
using difference_type = std::ptrdiff_t;
using reference = const IndexType; ///< intentionally not a reference
using reference = IndexType; ///< intentionally not a reference
using pointer = const IndexType *;

/// constructs end iterator
Expand Down Expand Up @@ -377,16 +377,16 @@ class MR_BIND_IGNORE SetBitIteratorT
};


[[nodiscard]] MR_BIND_IGNORE inline auto begin( const BitSet & a )
[[nodiscard]] MR_BIND_IGNORE_PY inline auto begin( const BitSet & a )
{ return SetBitIteratorT<BitSet>(a); }
[[nodiscard]] MR_BIND_IGNORE inline auto end( const BitSet & )
[[nodiscard]] MR_BIND_IGNORE_PY inline auto end( const BitSet & )
{ return SetBitIteratorT<BitSet>(); }

template <typename I>
[[nodiscard]] MR_BIND_IGNORE inline auto begin( const TypedBitSet<I> & a )
[[nodiscard]] MR_BIND_IGNORE_PY inline auto begin( const TypedBitSet<I> & a )
{ return SetBitIteratorT<TypedBitSet<I>>(a); }
template <typename I>
[[nodiscard]] MR_BIND_IGNORE inline auto end( const TypedBitSet<I> & )
[[nodiscard]] MR_BIND_IGNORE_PY inline auto end( const TypedBitSet<I> & )
{ return SetBitIteratorT<TypedBitSet<I>>(); }

/// creates a Vector where for each set bit of input bitset its sequential number starting from 0 is returned; and -1 for reset bits
Expand Down
2 changes: 1 addition & 1 deletion source/MRMesh/MRBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Buffer

void clear() { data_.reset(); capacity_ = {}; size_ = {}; }

void resize( size_t newSize )
void resize( size_t newSize )
{
if ( size_.val == newSize )
return;
Expand Down
8 changes: 4 additions & 4 deletions source/MRMesh/MRVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,19 @@ class Vector
};

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

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

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

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

/// 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
Expand Down
10 changes: 5 additions & 5 deletions source/MRMesh/MRVector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ inline Vector2<T> Vector2<T>::furthestBasisVector() const MR_REQUIRES_IF_SUPPORT
}


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

template <typename T>
MR_BIND_IGNORE inline auto begin( const Vector2<T> & v ) { return &v[0]; }
MR_BIND_IGNORE_PY inline auto begin( const Vector2<T> & v ) { return &v[0]; }
template <typename T>
MR_BIND_IGNORE inline auto begin( Vector2<T> & v ) { return &v[0]; }
MR_BIND_IGNORE_PY inline auto begin( Vector2<T> & v ) { return &v[0]; }

template <typename T>
MR_BIND_IGNORE inline auto end( const Vector2<T> & v ) { return &v[2]; }
MR_BIND_IGNORE_PY inline auto end( const Vector2<T> & v ) { return &v[2]; }
template <typename T>
MR_BIND_IGNORE inline auto end( Vector2<T> & v ) { return &v[2]; }
MR_BIND_IGNORE_PY inline auto end( Vector2<T> & v ) { return &v[2]; }

/// \}

Expand Down
10 changes: 5 additions & 5 deletions source/MRMesh/MRVector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@ Vector3<T> unitVector3( T azimuth, T altitude )
}


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

template <typename T>
MR_BIND_IGNORE inline auto begin( const Vector3<T> & v ) { return &v[0]; }
MR_BIND_IGNORE_PY inline auto begin( const Vector3<T> & v ) { return &v[0]; }
template <typename T>
MR_BIND_IGNORE inline auto begin( Vector3<T> & v ) { return &v[0]; }
MR_BIND_IGNORE_PY inline auto begin( Vector3<T> & v ) { return &v[0]; }

template <typename T>
MR_BIND_IGNORE inline auto end( const Vector3<T> & v ) { return &v[3]; }
MR_BIND_IGNORE_PY inline auto end( const Vector3<T> & v ) { return &v[3]; }
template <typename T>
MR_BIND_IGNORE inline auto end( Vector3<T> & v ) { return &v[3]; }
MR_BIND_IGNORE_PY inline auto end( Vector3<T> & v ) { return &v[3]; }

/// \}

Expand Down
10 changes: 5 additions & 5 deletions source/MRMesh/MRVector4.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ inline Vector4<T> div( const Vector4<T>& a, const Vector4<T>& b )
}


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

template <typename T>
MR_BIND_IGNORE auto begin( const Vector4<T> & v ) { return &v[0]; }
MR_BIND_IGNORE_PY auto begin( const Vector4<T> & v ) { return &v[0]; }
template <typename T>
MR_BIND_IGNORE auto begin( Vector4<T> & v ) { return &v[0]; }
MR_BIND_IGNORE_PY auto begin( Vector4<T> & v ) { return &v[0]; }

template <typename T>
MR_BIND_IGNORE auto end( const Vector4<T> & v ) { return &v[4]; }
MR_BIND_IGNORE_PY auto end( const Vector4<T> & v ) { return &v[4]; }
template <typename T>
MR_BIND_IGNORE auto end( Vector4<T> & v ) { return &v[4]; }
MR_BIND_IGNORE_PY auto end( Vector4<T> & v ) { return &v[4]; }

/// \}

Expand Down
8 changes: 8 additions & 0 deletions source/MRPch/MRBindingMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@
// Mark a declaration with this to avoid generating a binding for it.
#define MR_BIND_IGNORE __attribute__((__annotate__("mrbind::ignore")))

// Same, but specific to Python.
#ifdef MR_PARSING_FOR_PB11_BINDINGS
#define MR_BIND_IGNORE_PY MR_BIND_IGNORE
#else
#define MR_BIND_IGNORE_PY
#endif

// This is a specialized replacement for `MR_CANONICAL_TYPEDEFS()`, to be used on full template specializations, where that macro doesn't work.
#define MR_BIND_PREFERRED_NAME(...) __attribute__((__annotate__(DETAIL_MR_BIND_PREFERRED_NAME(mrbind::preferred_name=__VA_ARGS__))))
#define DETAIL_MR_BIND_PREFERRED_NAME(...) #__VA_ARGS__

#else
#define MR_BIND_TEMPLATE(...)
#define MR_BIND_IGNORE
#define MR_BIND_IGNORE_PY
#define MR_BIND_PREFERRED_NAME(...)
#endif

Expand Down
Loading