use MinMax functions instead of raw math

This commit is contained in:
Garux 2021-03-03 07:01:28 +03:00
parent f9a424b6c8
commit 39f5a2d060
5 changed files with 27 additions and 44 deletions

View File

@ -819,6 +819,7 @@ winding_t *ChopWinding( winding_t *in, const Plane3f& plane ){
}
inline const MinMax c_worldMinmax( Vector3().set( MIN_WORLD_COORD ), Vector3().set( MAX_WORLD_COORD ) );
/*
=================
CheckWinding
@ -827,7 +828,7 @@ winding_t *ChopWinding( winding_t *in, const Plane3f& plane ){
*/
void CheckWinding( winding_t *w ){
int i, j;
float d, edgedist;
float edgedist;
Vector3 dir, edgenormal;
float area;
@ -846,16 +847,14 @@ void CheckWinding( winding_t *w ){
{
const Vector3& p1 = w->p[i];
for ( j = 0 ; j < 3 ; j++ )
if ( p1[j] > MAX_WORLD_COORD || p1[j] < MIN_WORLD_COORD ) {
Error( "CheckFace: MAX_WORLD_COORD exceeded: %f",p1[j] );
}
if ( !c_worldMinmax.test( p1 ) ) {
Error( "CheckFace: MAX_WORLD_COORD exceeded: ( %f %f %f )", p1[0], p1[1], p1[2] );
}
j = ( i + 1 == w->numpoints )? 0 : i + 1;
// check the point is on the face plane
d = plane3_distance_to_point( faceplane, p1 );
if ( d < -ON_EPSILON || d > ON_EPSILON ) {
if ( fabs( plane3_distance_to_point( faceplane, p1 ) ) > ON_EPSILON ) {
Error( "CheckWinding: point off plane" );
}
@ -876,8 +875,7 @@ void CheckWinding( winding_t *w ){
if ( j == i ) {
continue;
}
d = vector3_dot( w->p[j], edgenormal );
if ( d > edgedist ) {
if ( vector3_dot( w->p[j], edgenormal ) > edgedist ) {
Error( "CheckWinding: non-convex" );
}
}

View File

@ -57,6 +57,7 @@ struct MinMax___
extend( other.mins );
extend( other.maxs );
}
// true, if point is within the bounds
template<typename U>
bool test( const BasicVector3<U>& point ) const {
return point.x() >= mins.x() && point.y() >= mins.y() && point.z() >= mins.z()
@ -68,6 +69,12 @@ struct MinMax___
return other.maxs.x() >= mins.x() && other.maxs.y() >= mins.y() && other.maxs.z() >= mins.z()
&& other.mins.x() <= maxs.x() && other.mins.y() <= maxs.y() && other.mins.z() <= maxs.z();
}
// true, if other is completely enclosed by this
template<typename U>
bool surrounds( const MinMax___<U>& other ) const {
return other.mins.x() >= mins.x() && other.mins.y() >= mins.y() && other.mins.z() >= mins.z()
&& other.maxs.x() <= maxs.x() && other.maxs.y() <= maxs.y() && other.maxs.z() <= maxs.z();
}
BasicVector3<T> origin() const {
return ( mins + maxs ) * 0.5;
}

View File

@ -175,29 +175,18 @@ brush_t *CopyBrush( const brush_t *brush ){
*/
bool BoundBrush( brush_t *brush ){
int i, j;
winding_t *w;
brush->minmax.clear();
for ( i = 0; i < brush->numsides; i++ )
for ( int i = 0; i < brush->numsides; i++ )
{
w = brush->sides[ i ].winding;
const winding_t *w = brush->sides[ i ].winding;
if ( w == NULL ) {
continue;
}
for ( j = 0; j < w->numpoints; j++ )
for ( int j = 0; j < w->numpoints; j++ )
brush->minmax.extend( w->p[ j ] );
}
for ( i = 0; i < 3; i++ )
{
if ( brush->minmax.mins[ i ] < MIN_WORLD_COORD || brush->minmax.maxs[ i ] > MAX_WORLD_COORD || brush->minmax.mins[i] >= brush->minmax.maxs[ i ] ) {
return false;
}
}
return true;
return brush->minmax.valid() && c_worldMinmax.surrounds( brush->minmax );
}
@ -823,15 +812,9 @@ bool WindingIsTiny( winding_t *w ){
================
*/
bool WindingIsHuge( winding_t *w ){
int i, j;
for ( i = 0 ; i < w->numpoints ; i++ )
{
for ( j = 0 ; j < 3 ; j++ )
if ( w->p[i][j] <= MIN_WORLD_COORD || w->p[i][j] >= MAX_WORLD_COORD ) {
return true;
}
}
for ( int i = 0; i < w->numpoints; i++ )
if ( !c_worldMinmax.test( w->p[i] ) )
return true;
return false;
}

View File

@ -478,10 +478,8 @@ void CalcNodeBounds( node_t *node ){
==================
*/
void MakeTreePortals_r( node_t *node ){
int i;
CalcNodeBounds( node );
if ( node->minmax.mins[0] >= node->minmax.maxs[0] ) {
if ( !node->minmax.valid() ) {
Sys_Warning( "node without a volume\n"
"node has %d tiny portals\n"
"node reference point %1.2f %1.2f %1.2f\n",
@ -491,14 +489,9 @@ void MakeTreePortals_r( node_t *node ){
node->referencepoint[2] );
}
for ( i = 0 ; i < 3 ; i++ )
{
if ( node->minmax.mins[i] < MIN_WORLD_COORD || node->minmax.maxs[i] > MAX_WORLD_COORD ) {
if ( node->portals && node->portals->winding ) {
xml_Winding( "WARNING: Node With Unbounded Volume", node->portals->winding->p, node->portals->winding->numpoints, false );
}
break;
if ( !c_worldMinmax.surrounds( node->minmax ) ) {
if ( node->portals && node->portals->winding ) {
xml_Winding( "WARNING: Node With Unbounded Volume", node->portals->winding->p, node->portals->winding->numpoints, false );
}
}
if ( node->planenum == PLANENUM_LEAF ) {

View File

@ -2128,6 +2128,8 @@ Q_EXTERN int allocatedmapplanes Q_ASSIGN( 0 );
Q_EXTERN int numMapPatches;
Q_EXTERN MinMax g_mapMinmax;
inline const MinMax c_worldMinmax( Vector3().set( MIN_WORLD_COORD ), Vector3().set( MAX_WORLD_COORD ) );
Q_EXTERN int defaultFogNum Q_ASSIGN( -1 ); /* ydnar: cleaner fog handling */
Q_EXTERN int numMapFogs Q_ASSIGN( 0 );
Q_EXTERN fog_t mapFogs[ MAX_MAP_FOGS ];