MeshLib C++ Docs
Loading...
Searching...
No Matches
MRUnorientedTriangle.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRId.h"
4#include <cassert>
5#include <cstdint>
6#include <utility>
7
8namespace MR
9{
12
13
17{
19
21 bool * outFlipped = nullptr )
22 : verts( inVs )
23 {
24 bool flipped = false;
25 auto checkSwap = [this, &flipped]( int i, int j )
26 {
27 assert( i < j );
28 assert( verts[i] != verts[j] );
29 if ( verts[i] > verts[j] )
30 {
31 flipped = !flipped;
32 std::swap( verts[i], verts[j] );
33 }
34 };
35 checkSwap( 0, 1 );
36 checkSwap( 0, 2 );
37 checkSwap( 1, 2 );
38 if ( outFlipped )
39 *outFlipped = flipped;
40 }
41
43 ThreeVertIds getFlipped() const { return { verts[0], verts[2], verts[1] }; }
44
45 operator ThreeVertIds &() { return verts; }
46 operator const ThreeVertIds &() const { return verts; }
47
48 VertId &operator[]( std::size_t i ) { return verts[i]; }
49 const VertId &operator[]( std::size_t i ) const { return verts[i]; }
50
51 friend bool operator==( const UnorientedTriangle& a, const UnorientedTriangle& b ) = default;
52};
53
54}
55
56namespace std
57{
58
59template <>
60struct hash<MR::UnorientedTriangle>
61{
62 size_t operator() ( const MR::UnorientedTriangle& triplet ) const noexcept
63 {
66 const auto a = std::uint32_t( triplet.verts[0] );
67 const auto b = std::uint32_t( triplet.verts[1] );
68 const auto c = std::uint32_t( triplet.verts[2] );
69 if constexpr ( sizeof( size_t ) >= 8 )
70 {
72 return size_t( a ^ ( std::uint64_t( b ) << 21 ) ^ ( std::uint64_t( c ) << 42 ) );
73 }
74 else
75 {
77 return size_t( 0xea87bb09u * a + 0xd8306b31u * b + c );
78 }
79 }
80};
81
82}
const VertId & operator[](std::size_t i) const
Definition MRUnorientedTriangle.h:49
VertId & operator[](std::size_t i)
Definition MRUnorientedTriangle.h:48
friend bool operator==(const UnorientedTriangle &a, const UnorientedTriangle &b)=default
ThreeVertIds verts
Definition MRUnorientedTriangle.h:18
ThreeVertIds getFlipped() const
returns this triangle with the opposite orientation
Definition MRUnorientedTriangle.h:43
UnorientedTriangle(const ThreeVertIds &inVs, bool *outFlipped=nullptr)
Definition MRUnorientedTriangle.h:20
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
three vertex ids describing a triangle with the corners in vertices given by their ids
Definition MRId.h:203
Definition MRUnorientedTriangle.h:17