From 6af9b48bdad3807edb621e85f924420a1b11db59 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Mon, 6 Jan 2025 18:05:13 +0100 Subject: [PATCH] fix range index, Index-operators --- libsrc/meshing/meshtype.hpp | 30 ++++++++++++++++++++---------- libsrc/meshing/topology.cpp | 3 +-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 422d8416..7826be20 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -182,7 +182,15 @@ namespace netgen TIndex operator-- (int) { TIndex hi(*this); i--; return hi; } TIndex & operator++ () { i++; return static_cast(*this); } TIndex & operator-- () { i--; return static_cast(*this); } - constexpr TIndex operator+= (T add) { i += add; return TIndex{*this}; } + constexpr TIndex operator+= (int add) { i += add; return TIndex{*this}; } + constexpr TIndex operator+= (size_t add) { i += add; return TIndex{*this}; } + constexpr TIndex operator-= (int add) { i -= add; return TIndex{*this}; } + constexpr TIndex operator-= (size_t add) { i -= add; return TIndex{*this}; } + + auto operator- (Index i2) const { return i-i2.i; } + + // bool operator== (Index i2) const { return i==i2.i; } + // bool operator!= (Index i2) const { return i!=i2.i; } void Invalidate() { i = long(TIndex::BASE)-1; } bool IsValid() const { return i+1 != TIndex::BASE; } // operator bool() const { return IsValid(); } @@ -192,17 +200,19 @@ namespace netgen template - constexpr auto operator+ (Index ind, int i) { return TIndex(ind.i+i); } + constexpr auto operator+ (Index ind, int i) { TIndex res(ind); res += i; return res; } + template + constexpr auto operator+ (Index ind, size_t i) { TIndex res(ind); res += i; return res; } template - constexpr TIndex operator+ (Index pi, size_t i) { return TIndex(pi.i+i); } + constexpr TIndex operator+ (int i, Index ind) { TIndex res(ind); res += i; return res; } template - constexpr TIndex operator+ (int i, Index pi) { return TIndex(pi.i+i); } + inline TIndex operator+ (size_t i, Index ind) { TIndex res(ind); res += i; return res; } + template - inline TIndex operator+ (size_t i, Index pi) { return TIndex(pi.i+i); } - template - constexpr inline auto operator- (Index pi, int i) -> TIndex { return TIndex(pi.i-i); } - template - constexpr inline auto operator- (Index pa, Index pb) { return pa.i-pb.i; } + constexpr inline auto operator- (Index ind, int i) { TIndex res(ind); res -= i; return res; } + // template + // constexpr inline auto operator- (Index pa, Index pb) { return pa.i-pb.i; } + template inline bool operator< (Index a, Index b) { return a-b < 0; } template @@ -211,11 +221,11 @@ namespace netgen inline bool operator>= (Index a, Index b) { return a-b >= 0; } template inline bool operator<= (Index a, Index b) { return a-b <= 0; } + template inline bool operator== (Index a, Index b) { return a.i == b.i; } template inline bool operator!= (Index a, Index b) { return a.i != b.i; } - class PointIndex : public Index diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index bb1d209b..ff104cf3 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -2403,8 +2403,7 @@ namespace netgen return; } } - - SurfaceElementIndex surfel = GetFace2SurfaceElement(fnr); + SurfaceElementIndex surfel = GetFace2SurfaceElement(fnr-1); if (!surfel.IsValid()) { // GetSurfaceElementEdges (surfel, fedges);