From bafb339c09b132422c0e0a9d4013102b34cbc922 Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 3 Sep 2021 06:23:40 +0300 Subject: [PATCH] MergeMetaTriangles: epsilon compare st, improves merging imprecise sts, e.g. for nonplanar surfaces after q3map_tcgen or just brush face texture projection --- libs/math/vector.h | 19 +++++++++++++++++++ tools/quake3/q3map2/surface_meta.cpp | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libs/math/vector.h b/libs/math/vector.h index b7f5a410..91cadb0d 100644 --- a/libs/math/vector.h +++ b/libs/math/vector.h @@ -123,6 +123,25 @@ inline Element float_mod( const Element& self, const ModulusElement& modulus ){ } +template +inline bool vector2_equal( const BasicVector2& self, const BasicVector2& other ){ + return self.x() == other.x() && self.y() == other.y(); +} +template +inline bool operator==( const BasicVector2& self, const BasicVector2& other ){ + return vector2_equal( self, other ); +} +template +inline bool operator!=( const BasicVector2& self, const BasicVector2& other ){ + return !vector2_equal( self, other ); +} + +template +inline bool vector2_equal_epsilon( const BasicVector2& self, const BasicVector2& other, Epsilon epsilon ){ + return float_equal_epsilon( self.x(), other.x(), epsilon ) + && float_equal_epsilon( self.y(), other.y(), epsilon ); +} + template inline BasicVector2 vector2_added( const BasicVector2& self, const BasicVector2& other ){ return BasicVector2( diff --git a/tools/quake3/q3map2/surface_meta.cpp b/tools/quake3/q3map2/surface_meta.cpp index a023121e..527e5c66 100644 --- a/tools/quake3/q3map2/surface_meta.cpp +++ b/tools/quake3/q3map2/surface_meta.cpp @@ -1297,7 +1297,7 @@ int AddMetaVertToSurface( mapDrawSurface_t *ds, const bspDrawVert_t& dv1, const ( *coincident )++; /* compare texture coordinates and color */ - if ( dv1.st[ 0 ] != dv2.st[ 0 ] || dv1.st[ 1 ] != dv2.st[ 1 ] ) { + if ( !vector2_equal_epsilon( dv1.st, dv2.st, 1e-4f ) ) { continue; } if ( dv1.color[ 0 ].alpha() != dv2.color[ 0 ].alpha() ) {