Files
firestorm/Gameleap/code/mw4/Libraries/stuff/Point3D_Test.cpp
T
Cyd 2b8ca921cb Initial full mirror of c:\VWE (source + assets + toolchain + outputs) via Git LFS
Complete disaster-recovery snapshot: engine/game source, game data assets,
VC6 toolchain + DX SDKs, build outputs, deployed game, and _UNUSED archive.
Large binaries in Git LFS; text preserved byte-for-byte (core.autocrlf=false,
no eol attributes). See RECOVERY.md for the one-clone rebuild procedure.
2026-06-24 21:28:16 -05:00

142 lines
3.9 KiB
C++

//===========================================================================//
// File: point.tst //
// Project: MUNGA Brick: Math Library //
// Contents: test code for point class //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- ---------------------------------------------------------- //
// 11/19/94 JMA Initial coding. //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc. //
// All Rights reserved worldwide //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
//===========================================================================//
#include "StuffHeaders.hpp"
//
//###########################################################################
//###########################################################################
//
bool
Point3D::TestClass()
{
SPEW((GROUP_STUFF_TEST, "Starting Point3D test...\n"));
const Point3D
a(Identity);
Point3D
b;
const Point3D
c(1.0f,2.0f,3.0f);
Point3D
d(2.0f,3.0f,1.0f);
Verify(!a.x && !a.y && !a.z);
#if 0
Verify(c.x == 1.0f && c.y == 2.0f && c.z == 3.0f);
Verify(c[2] == c.z);
Verify(a[1] == a.y);
#endif
Verify(Small_Enough(a));
// Verify(!a);
b = c;
#if 0
Verify(b.x == c.x && b.y == c.y && b.z == c.z);
#endif
Verify(Close_Enough(b,c));
Verify(b == c);
Verify(a != b);
b.Negate(c);
Verify(b == Point3D(-c.x,-c.y,-c.z));
b.Add(c,d);
Verify(b == Point3D(c.x+d.x,c.y+d.y,c.z+d.z));
b = c;
b += d;
Verify(b == Point3D(c.x+d.x,c.y+d.y,c.z+d.z));
b.Subtract(d,c);
Verify(b == Point3D(d.x-c.x,d.y-c.y,d.z-c.z));
b = d;
b -= c;
Verify(b == Point3D(d.x-c.x,d.y-c.y,d.z-c.z));
Scalar f = c*d;
#if 0
Verify(f == c.x*d.x + c.y*d.y + c.z*d.z);
#endif
b.Cross(c,d);
Verify(b == Point3D(c.y*d.z-c.z*d.y,c.z*d.x-c.x*d.z,c.x*d.y-c.y*d.x));
f = 2.0f;
b.Multiply(c,f);
Verify(b == Point3D(f*c.x,f*c.y,f*c.z));
b = c;
b *= f;
Verify(b == Point3D(f*c.x,f*c.y,f*c.z));
b.Multiply(c,d);
Verify(b == Point3D(c.x*d.x,c.y*d.y,c.z*d.z));
b = c;
b *= d;
Verify(b == Point3D(c.x*d.x,c.y*d.y,c.z*d.z));
b.Divide(c,f);
Verify(b == Point3D(c.x/f,c.y/f,c.z/f));
b = c;
b /= f;
Verify(b == Point3D(c.x/f,c.y/f,c.z/f));
b.Divide(c,d);
Verify(b == Point3D(c.x/d.x,c.y/d.y,c.z/d.z));
b = c;
b /= d;
Verify(b == Point3D(c.x/d.x,c.y/d.y,c.z/d.z));
AffineMatrix4D
m;
EulerAngles
r(Pi_Over_4,0.0f,0.0f);
m.BuildRotation(r);
m.BuildTranslation(c);
b = m;
Verify(b == c);
b.Multiply(c,m);
Verify(b == Point3D(c.x+m(3,0),c.y*m(1,1)+c.z*m(2,1)+m(3,1),c.y*m(1,2)+c.z*m(2,2)+m(3,2)));
b = c;
b *= m;
Verify(b == Point3D(c.x+m(3,0),c.y*m(1,1)+c.z*m(2,1)+m(3,1),c.y*m(1,2)+c.z*m(2,2)+m(3,2)));
Verify(!a.GetLengthSquared());
f = c.GetLengthSquared();
Verify(f == c.x*c.x + c.y*c.y + c.z*c.z);
f = c.GetLength();
Verify(Close_Enough(f,Sqrt(c.x*c.x + c.y*c.y + c.z*c.z)));
b.Normalize(c);
Verify(b == Point3D(c.x/f, c.y/f, c.z/f));
b.Combine(c,2.0f,d,2.0f);
Verify(b == Point3D(2.0f*(c.x+d.x),2.0f*(c.y+d.y),2.0f*(c.z+d.z)));
b.Lerp(c,d,0.5f);
Verify(b == Point3D(0.5f*(c.x+d.x),0.5f*(c.y+d.y),0.5f*(c.z+d.z)));
Vector4D v(2.0f,4.0f,6.0f,2.0f);
b = v;
Verify(b == Point3D(v.x/v.w, v.y/v.w, v.z/v.w));
Origin3D t;
t.linearPosition = Point3D(2.0f,3.0f,4.0f);
t.angularPosition = EulerAngles(0.0f,0.0f,0.0f);
b = t;
Verify(b == Point3D(t.linearPosition.x,t.linearPosition.y,t.linearPosition.z));
return true;
}