[Cmap-cvs] mp2mp mp_parser.cpp,1.10,1.11 mp_parser.h,1.9,1.10 parserImpl.cpp,1.6,1.7
Status: Beta
Brought to you by:
dyp
From: Denis P. <dy...@us...> - 2005-09-24 16:01:22
|
Update of /cvsroot/cmap/mp2mp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6998 Modified Files: mp_parser.cpp mp_parser.h parserImpl.cpp Log Message: Add height and width Index: parserImpl.cpp =================================================================== RCS file: /cvsroot/cmap/mp2mp/parserImpl.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- parserImpl.cpp 23 Sep 2005 05:10:39 -0000 1.6 +++ parserImpl.cpp 24 Sep 2005 16:01:11 -0000 1.7 @@ -25,6 +25,28 @@ }; }; +class WidthExpr : public IntRVar { +public: + virtual ~WidthExpr() { + } + + virtual int getValue(const void *obj, const ObjectProp &op, int numArray) { + const mp::Rgn *rgn = (const mp::Rgn *)obj; + return rgn->getWidth() * 1e3; + }; +}; + +class HeightExpr : public IntRVar { +public: + virtual ~HeightExpr() { + } + + virtual int getValue(const void *obj, const ObjectProp &op, int numArray) { + const mp::Rgn *rgn = (const mp::Rgn *)obj; + return rgn->getHeight() * 1e3; + }; +}; + ConfigParserImpl::ConfigParserImpl(Tokenizer &_t) : ConfigParser(_t) { } @@ -33,6 +55,10 @@ return new AreaExpr; if (varName == "length") return new LengthExpr; + if (varName == "width") + return new WidthExpr; + if (varName == "height") + return new HeightExpr; return ConfigParser::parseIntRVar(varName); } Index: mp_parser.cpp =================================================================== RCS file: /cvsroot/cmap/mp2mp/mp_parser.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- mp_parser.cpp 23 Sep 2005 05:10:39 -0000 1.10 +++ mp_parser.cpp 24 Sep 2005 16:01:11 -0000 1.11 @@ -72,10 +72,14 @@ break; case kind::Line: fprintf(f, "; LENGTH=%d\n", (int)(getLength() * 1.e3)); + fprintf(f, "; WIDTH=%d\n", (int)(getWidth() * 1.e3)); + fprintf(f, "; HEIGHT=%d\n", (int)(getHeight() * 1.e3)); fprintf(f, "[POLYLINE]\n"); break; case kind::Polygon: fprintf(f, "; AREA=%d\n", (int)(getArea() * 1.e6)); + fprintf(f, "; WIDTH=%d\n", (int)(getWidth() * 1.e3)); + fprintf(f, "; HEIGHT=%d\n", (int)(getHeight() * 1.e3)); fprintf(f, "[POLYGON]\n"); break; }; @@ -186,6 +190,38 @@ return fLength; } +inline double max(const double x1, const double x2) { + return x1 > x2 ? x1 : x2; +} + +inline double min(const double x1, const double x2) { + return x1 < x2 ? x1 : x2; +} + +double Rgn::getHeight() const { + const size_t cElements = elements.size(); + if (cElements == 0) + return 0; + double fMaxHeight = elements[0].getHeight(); + for (size_t cElement = 1; cElement < cElements; ++ cElement) { + const Element &element = elements[cElement]; + fMaxHeight = max(fMaxHeight, element.getHeight()); + } + return fMaxHeight; +} + +double Rgn::getWidth() const { + const size_t cElements = elements.size(); + if (cElements == 0) + return 0; + double fMaxWidth = elements[0].getWidth(); + for (size_t cElement = 1; cElement < cElements; ++ cElement) { + const Element &element = elements[cElement]; + fMaxWidth = max(fMaxWidth, element.getWidth()); + } + return fMaxWidth; +} + bool Rgn::isHoleOfAny(const Element &_element) { const size_t cElements = elements.size(); for (size_t cElement = 0; cElement < cElements; ++ cElement) { @@ -384,6 +420,41 @@ return fLength; } +double Element::getHeight() const { + const size_t cPoints = points.size (); + if (cPoints <= 1) + return 0; + + double fMinY = 360; + double fMaxY = -360; + + for (size_t cPoint = 0; cPoint < cPoints; ++ cPoint) { + const point_t & p = points [cPoint]; + + fMinY = min(p.y, fMinY); + fMaxY = max(p.y, fMaxY); + } + + return fMaxY - fMinY; +} + +double Element::getWidth() const { + const size_t cPoints = points.size (); + if (cPoints <= 1) + return 0; + + double fMinX = 360; + double fMaxX = -360; + for (size_t cPoint = 0; cPoint < cPoints; ++ cPoint) { + const point_t & p = points [cPoint]; + + fMinX = min(p.x, fMinX); + fMaxX = max(p.x, fMaxX); + } + + return fMaxX - fMinX; +} + void point_t::print(FILE *f, bool is6Digits) { if (is6Digits) fprintf(f, "(%.6f,%.6f)", y, x); Index: mp_parser.h =================================================================== RCS file: /cvsroot/cmap/mp2mp/mp_parser.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- mp_parser.h 23 Sep 2005 05:10:39 -0000 1.9 +++ mp_parser.h 24 Sep 2005 16:01:11 -0000 1.10 @@ -34,6 +34,8 @@ void print(FILE *f, const ObjectProp &op, bool is6Digit, unsigned int level); double getArea() const; double getLength() const; + double getHeight() const; + double getWidth() const; bool isHoleOf(const Element &_outer) const; }; @@ -89,6 +91,8 @@ void print(FILE *f, const ObjectProp &op, bool is6Digit); double getArea() const; double getLength() const; + double getHeight() const; + double getWidth() const; bool isHoleOfAny(const Element &_element); void refreshInners(); }; |