////////////////////////////////////////////////////////////
//
//  ENVIRON.CPP - Environment Class
//
//  Version:    1.03A
//
//  History:    96/02/29 - Created.
//              96/04/01 - Version 1.03A release.
//
//  Compilers:  Microsoft Visual C/C++ Professional V1.5
//              Borland C++ Version 4.5
//
//  Author:     Ian Ashdown, P.Eng.
//              byHeart Software Limited
//              620 Ballantree Road
//              West Vancouver, B.C.
//              Canada V7S 1W3
//              Tel. (604) 922-6148
//              Fax. (604) 987-7621
//
//  Copyright 1994-1996 byHeart Software Limited
//
//  The following source code has been derived from:
//
//    Ashdown, I. 1994. Radiosity: A Programmer's
//    Perspective. New York, NY: John Wiley & Sons.
//
//  It may be freely copied, redistributed, and/or modified
//  for personal use ONLY, as long as the copyright notice
//  is included with all source code files.
//
////////////////////////////////////////////////////////////

#include "environ.h"

// Calculate environment extents
void Environ::CalcExtents()
{
  double vx, vy, vz;    // Vertex co-ordinates
  Instance *pinst;      // Instance pointer

  // Initialize extents
  max_x = max_y = max_z = -MAX_VALUE;
  min_x = min_y = min_z = MAX_VALUE;

  // Walk the instance list
  pinst = pinsthd;
  while (pinst != NULL)
  {
    // Get vertex co-ordinates
    pinst->CalcExtents();

    vx = pinst->GetMin_X();
    vy = pinst->GetMin_Y();
    vz = pinst->GetMin_Z();

    // Update x-axis extents
    if (vx < min_x)
        min_x = vx;
    if (vy < min_y)
        min_y = vy;
    if (vz < min_z)
        min_z = vz;

    vx = pinst->GetMax_X();
    vy = pinst->GetMax_Y();
    vz = pinst->GetMax_Z();

    // Update x-axis extents
    if (vx > max_x)
        max_x = vx;
    if (vy > max_y)
        max_y = vy;
    if (vz > max_z)
        max_z = vz;

    pinst = pinst->GetNext();
  }
}
