[geos-devel] Current project status
Norman Vine
nhv at cape.com
Mon Nov 25 00:48:48 EST 2002
Yury A. Bychkov writes:
>
> Sure. I agree. After I'll finish modifying the code for CoordinateList and
> Coordinate I'll inline as much of it as possible.
Yup, no point in doing to early
FYI -
I have been using this to keep from filling
up the code with strings when inlining
class CoordinateList : public CoordinateListInterface {
public:
enum {
BOUNDS_ERROR,
RETRIEVE_ERROR,
CHANGE_ERROR,
REMOVE_ERROR
};
Coordinate& getAt(int pos){
if (pos < 0 || pos>vect->size()-1)
throw err_msg[BOUNDS_ERROR] ;
current=pos;
return (*vect)[current];
}
private:
.....
static char *err_msg[4];
}
then in Coordinate.cpp
char *CoordinateList::err_msg[] = {
"CoordinateList exception: out of bounds\n",
"CoordinateList exception: can't retrieve element\n",
"CoordinateList exception: can't change element\n",
"CoordinateList exception: can't remove element\n"
};
These are some helper functions that let me
pass iterating over a CoordinateList into
the class that seems to help too
ie things like
bool Geometry::hasNullElements(CoordinateList list){
return list.hasNullElement();
}
bool CoordinateList::hasNullElement()
{
int size = vect->size();
for (int i=0; i<size; i++) {
// I think this is true NHV
if ((*vect)[i].x == DoubleNotANumber) {
return true;
}
}
return false;
}
bool CoordinateList::hasElement(Coordinate pt)
{
int size = vect->size();
for (int i = 0; i<size; i++) {
if ((*vect)[i] == pt) {
return true;
}
}
return false;
}
int CoordinateList::indexOfMaxY()
{
int index = 0;
int size = vect->size();
double tmp = (*vect)[0].y;
for (int i=1; i<size; i++) {
if ((*vect)[i].y > tmp) {
tmp = (*vect)[i].y;
index = i;
}
}
return index;
}
int CoordinateList::indexOfMinY()
{
int index = 0;
int size = vect->size();
double tmp = (*vect)[0].y;
for (int i=1; i<size; i++) {
if ((*vect)[i].y < tmp) {
tmp = (*vect)[i].y;
index = i;
}
}
return index;
}
int CoordinateList::indexOfMaxX()
{
int index = 0;
int size = vect->size();
double tmp = (*vect)[0].x;
for (int i=1; i<size; i++) {
if ((*vect)[i].x > tmp) {
tmp = (*vect)[i].x;
index = i;
}
}
return index;
}
int CoordinateList::indexOfMinX()
{
int index = 0;
int size = vect->size();
double tmp = (*vect)[0].x;
for (int i=1; i<size; i++) {
if ((*vect)[i].x < tmp) {
tmp = (*vect)[i].x;
index = i;
}
}
return index;
}
void CoordinateList::getMinMax2D( double *minx, double *maxx, double *miny, double *maxy )
{
double xmin = (*vect)[0].x;
double ymin = (*vect)[0].y;
double xmax = (*vect)[0].x;
double ymax = (*vect)[0].y;
int size = vect->size();
for (int i=1; i<size; i++) {
xmin = min(xmin, (*vect)[i].x); //min
xmax = max(xmax, (*vect)[i].x);
ymin = min(ymin, (*vect)[i].y);
ymax = max(ymax, (*vect)[i].y);
}
*minx = xmin;
*maxx = xmax;
*miny = ymin;
*maxy = ymax;
}
bool CoordinateList::equalsExact(CoordinateList *other )
{
int size = vect->size();
if( size != other->getSize() )
return false;
for (int i = 0; i < size; i++) {
if (!((*vect)[i] == other->getAt(i)))
return false;
}
return true;
}
More information about the geos-devel
mailing list