Files
TeslaRel410/CODE/RP/MUNGA/RECT2D.CPP
T
CydandClaude Fable 5 fdd9ac9d97 Initial import: Tesla Release 4.10 (Tesla:BattleTech & Tesla:Red Planet)
Archival snapshot of the Virtual World Entertainment Tesla cockpit
software, 1994-1996: MUNGA engine and L4 pod layer source (Borland
C++ 5.0), BT/RP game code, and game content (models, audio, maps,
gauges, Division renderer data). Includes third-party libraries:
Division dVS/DPL graphics, HMI SOS audio, WATTCP networking.

Files are preserved byte-for-byte (.gitattributes disables all
line-ending conversion). README.md documents the layout, target
hardware, and toolchain.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 13:21:58 -05:00

163 lines
3.8 KiB
C++

//===========================================================================//
// File: rect2d.cc //
// Project: MUNGA Brick: Math Library //
// Contents: Implementation details for vector classes //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- ---------------------------------------------------------- //
// 2/01/95 CPB Initial coding (copied from vector3d.cc) //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc. //
// All Rights reserved worldwide //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
//===========================================================================//
#include <munga.hpp>
#pragma hdrstop
#if !defined(RECT2D_HPP)
# include <rect2d.hpp>
#endif
//
//------------------------------------------------------------------------
// Creators
//------------------------------------------------------------------------
//
Rectangle2D::Rectangle2D()
{
MakeEmpty(); // uninitialized rectangles should be "empty"
}
Rectangle2D::Rectangle2D(
Vector2DOf<int> bl,
Vector2DOf<int> tr
)
{
bottomLeft = bl;
topRight = tr;
}
Rectangle2D::Rectangle2D(
int x1, int y1, int x2, int y2
)
{
bottomLeft.x = x1;
bottomLeft.y = y1;
topRight.x = x2;
topRight.y = y2;
}
//
//------------------------------------------------------------------------
// Union (returns bounding rectangle)
//------------------------------------------------------------------------
//
void
Rectangle2D::Union(
const Rectangle2D& r1,
const Rectangle2D& r2
)
{
Check(this);
Check(&r1);
Check(&r2);
if (r1.IsEmpty())
{
if (r2.IsEmpty())
{
MakeEmpty();
}
else
{
bottomLeft = r2.bottomLeft;
topRight = r2.topRight;
}
}
else
{
if (r2.IsEmpty())
{
bottomLeft = r1.bottomLeft;
topRight = r1.topRight;
}
else
{
bottomLeft.x = Min(r1.bottomLeft.x, r2.bottomLeft.x);
bottomLeft.y = Min(r1.bottomLeft.y, r2.bottomLeft.y);
topRight.x = Max(r1.topRight.x, r2.topRight.x);
topRight.y = Max(r1.topRight.y, r2.topRight.y);
}
}
}
//
//------------------------------------------------------------------------
// Intersection (returns overlapping section)
//------------------------------------------------------------------------
//
void
Rectangle2D::Intersection(
const Rectangle2D& r1,
const Rectangle2D& r2
)
{
Check(this);
Check(&r1);
Check(&r2);
if (r1.IsEmpty())
{
MakeEmpty();
}
else
{
if (r2.IsEmpty())
{
MakeEmpty();
}
else
{
bottomLeft.x = Max(r1.bottomLeft.x, r2.bottomLeft.x);
bottomLeft.y = Max(r1.bottomLeft.y, r2.bottomLeft.y);
topRight.x = Min(r1.topRight.x, r2.topRight.x);
topRight.y = Min(r1.topRight.y, r2.topRight.y);
}
}
}
//
//------------------------------------------------------------------------
// Output stream operator
//------------------------------------------------------------------------
//
ostream&
operator<<(
ostream& Stream,
const Rectangle2D& r
)
{
Check(&r);
return Stream << '(' << r.bottomLeft << ',' << r.topRight << ')';
}
//
//------------------------------------------------------------------------
// TestInstance
//------------------------------------------------------------------------
//
Logical
Rectangle2D::TestInstance() const
{
return True;
}
#if defined(TEST_CLASS)
# include "rect2d.tcp"
#endif