MCPcopy Create free account
hub / github.com/JACoders/OpenJK / CM_ValidateFacet

Function CM_ValidateFacet

code/qcommon/cm_patch.cpp:786–831  ·  view source on GitHub ↗

================== CM_ValidateFacet If the facet isn't bounded by its borders, we screwed up. ================== */

Source from the content-addressed store, hash-verified

784==================
785*/
786static qboolean CM_ValidateFacet( facet_t *facet ) {
787 float plane[4];
788 int j;
789 winding_t *w;
790 vec3_t bounds[2];
791
792 if ( facet->surfacePlane == -1 ) {
793 return qfalse;
794 }
795
796 VectorCopy4( planes[ facet->surfacePlane ].plane, plane );
797 w = BaseWindingForPlane( plane, plane[3] );
798 for ( j = 0 ; j < facet->numBorders && w ; j++ ) {
799 if ( facet->borderPlanes[j] == -1 ) {
800 FreeWinding(w);
801 return qfalse;
802 }
803 VectorCopy4( planes[ facet->borderPlanes[j] ].plane, plane );
804 if ( !facet->borderInward[j] ) {
805 VectorSubtract( vec3_origin, plane, plane );
806 plane[3] = -plane[3];
807 }
808 ChopWindingInPlace( &w, plane, plane[3], 0.1f );
809 }
810
811 if ( !w ) {
812 return qfalse; // winding was completely chopped away
813 }
814
815 // see if the facet is unreasonably large
816 WindingBounds( w, bounds[0], bounds[1] );
817 FreeWinding( w );
818
819 for ( j = 0 ; j < 3 ; j++ ) {
820 if ( bounds[1][j] - bounds[0][j] > MAX_MAP_BOUNDS ) {
821 return qfalse; // we must be missing a plane
822 }
823 if ( bounds[0][j] >= MAX_MAP_BOUNDS ) {
824 return qfalse;
825 }
826 if ( bounds[1][j] <= -MAX_MAP_BOUNDS ) {
827 return qfalse;
828 }
829 }
830 return qtrue; // winding is fine
831}
832
833/*
834==================

Callers 1

CM_PatchCollideFromGridFunction · 0.70

Calls 6

VectorCopy4Function · 0.85
VectorSubtractFunction · 0.85
BaseWindingForPlaneFunction · 0.70
FreeWindingFunction · 0.70
ChopWindingInPlaceFunction · 0.70
WindingBoundsFunction · 0.70

Tested by

no test coverage detected