home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / graphics / graphtal.lha / Graphtal / BoundingBox.C < prev    next >
C/C++ Source or Header  |  1992-11-17  |  2KB  |  63 lines

  1. /*
  2.  * BoundingBox.C - methods for class BoundingBox.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  *                     University of Berne, Switzerland
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified, and redistributed
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * You may not distribute this software, in whole or in part, as part of
  12.  * any commercial product without the express consent of the authors.
  13.  *
  14.  * There is no warranty or other guarantee of fitness of this software
  15.  * for any purpose.  It is provided solely "as is".
  16.  *
  17.  */
  18.  
  19. #include <values.h>
  20. #include "BoundingBox.h"
  21. #include "TransMatrix.h"
  22.  
  23. //___________________________________________________________ BoundingBox
  24.  
  25. BoundingBox::BoundingBox()
  26. : vmin(MAXDOUBLE, MAXDOUBLE, MAXDOUBLE), vmax(-MAXDOUBLE, -MAXDOUBLE, -MAXDOUBLE)
  27. {}
  28.  
  29. BoundingBox BoundingBox::transform(const TransMatrix& tmat) const
  30. {
  31.   BoundingBox retval;
  32.   
  33.   retval.expand(Vector(vmin[0], vmin[1], vmin[2])*tmat);
  34.   retval.expand(Vector(vmax[0], vmin[1], vmin[2])*tmat); 
  35.   retval.expand(Vector(vmax[0], vmax[1], vmin[2])*tmat); 
  36.   retval.expand(Vector(vmin[0], vmax[1], vmin[2])*tmat); 
  37.   retval.expand(Vector(vmin[0], vmin[1], vmax[2])*tmat); 
  38.   retval.expand(Vector(vmax[0], vmin[1], vmax[2])*tmat); 
  39.   retval.expand(Vector(vmax[0], vmax[1], vmax[2])*tmat); 
  40.   retval.expand(Vector(vmin[0], vmax[1], vmax[2])*tmat);
  41.  
  42.   return retval;
  43. }
  44.  
  45. void BoundingBox::expand(const Vector& v)
  46. {
  47.   if (v[0] < vmin[0]) vmin[0] = v[0]; if (v[0] > vmax[0]) vmax[0] = v[0];
  48.   if (v[1] < vmin[1]) vmin[1] = v[1]; if (v[1] > vmax[1]) vmax[1] = v[1];
  49.   if (v[2] < vmin[2]) vmin[2] = v[2]; if (v[2] > vmax[2]) vmax[2] = v[2];
  50. }
  51.  
  52. void BoundingBox::expand(const BoundingBox& b)
  53. {
  54.   expand(b.vmin);
  55.   expand(b.vmax);
  56. }
  57.  
  58. ostream& operator<<(ostream& os, const BoundingBox& b)
  59. {
  60.   return os << "{ min" << b.vmin << ", max" << b.vmax << " }";
  61. }
  62.  
  63.