经典numerical receip 配套代码
源代码在线查看: pointbox.h
template struct Point {
Doub x[DIM];
Point(const Point &p) {
for (Int i=0; i }
Point& operator= (const Point &p) {
for (Int i=0; i return *this;
}
bool operator== (const Point &p) const {
for (Int i=0; i return true;
}
Point(Doub x0 = 0.0, Doub x1 = 0.0, Doub x2 = 0.0) {
x[0] = x0;
if (DIM > 1) x[1] = x1;
if (DIM > 2) x[2] = x2;
if (DIM > 3) throw("Point not implemented for DIM > 3");
}
};
template struct Box {
Point lo, hi;
Box() {}
Box(const Point &mylo, const Point &myhi) : lo(mylo), hi(myhi) {}
};
template Doub dist(const Point &p, const Point &q) {
Doub dd = 0.0;
for (Int j=0; j return sqrt(dd);
}
template Doub dist(const Box &b, const Point &p) {
Doub dd = 0;
for (Int i=0; i if (p.x[i] if (p.x[i]>b.hi.x[i]) dd += SQR(p.x[i]-b.hi.x[i]);
}
return sqrt(dd);
}