1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
// Copyright (c) 1997 Philip A. Hardin (pahardin@cs.utexas.edu)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License v2 or later.
#ifndef RECT3D_h
#define RECT3D_h
#include "general.h"
#include "pt3d.h"
/************************************************************************/
/* pnt = N-dimensional point type which delimits the bounds of the rect
pnts = container of pts
*/
template <class pnt, class pnts>
struct rect {
pnt low,
high;
bool Contains(const pnt& p) const
{return p.IsBetween(low,high);};
bool ContainsInclusively(const pnt& p) const
{return p.IsBetweenInclusively(low,high);};
bool ContainsExclusively(const pnt& p) const
{return p.IsBetweenExclusively(low,high);};
// Center used to return "const pnt& "
pnt Center() const
{return (low+high)/2;};
void MakeBoundingBox(const pnts& pts, double & farthestDist) {
double d;
farthestDist= 0;
if (pts.Num()==0) {
low= pnt(0,0,0);
high= pnt(0,0,0);
return;
}
low= pts[0];
high= pts[0];
forii(pts.Num()) {
d= (double) pts[i].Dist();
if (d >farthestDist)
farthestDist= d;
low.SetMin(pts[i]);
high.SetMax(pts[i]);
}
};
};
typedef rect<pt3d,table<pt3d> > rect3d;
#endif
|