diff --git a/doc/images/drawarrow.png b/doc/images/drawarrow.png new file mode 100644 index 0000000..4f60478 Binary files /dev/null and b/doc/images/drawarrow.png differ diff --git a/doc/manual.rst b/doc/manual.rst index 4474ed2..a0c0896 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -286,6 +286,7 @@ Drawing figures on the map * ``--drawpoint ", "`` : Draw a point (single pixel) on the map * ``--drawline " "`` : Draw a line on the map + * ``--drawarrow " "`` : Draw an arrow on the map * ``--drawcircle " "`` : Draw a circle on the map * ``--drawellipse " "`` : Draw an ellipse on the map * ``--drawrectangle " "`` : Draw a rectangle on the map @@ -295,6 +296,7 @@ Drawing figures on the map * ``--drawmappoint ", "`` : Draw a point (single pixel) on the map * ``--drawmapline " "`` : Draw a line on the map + * ``--drawmaparrow " "`` : Draw an arrow on the map * ``--drawmapcircle " "`` : Draw a circle on the map * ``--drawmapellipse " "`` : Draw an ellipse on the map * ``--drawmaprectangle " "`` : Draw a rectangle on the map @@ -522,6 +524,7 @@ Detailed Description of Options * circle * ellipse (which is a synonym for circle) * line + * arrow * point (which uses simple coordinates (x,y) instead of a geometry) * rectangle * text (which uses simple coordinates (x,y) instead of a geometry) @@ -609,6 +612,16 @@ Detailed Description of Options .. image:: images/drawline.png +``--draw[map]arrow " "`` +......................................... + Draw an arrow on the map, with the given geometry and color. + + See `--draw[map]
`_ for details. + + An example arrow: + + .. image:: images/drawarrow.png + ``--draw[map]point ", "`` ...................................... Draw a point on the map, at the given location, using the given color. diff --git a/mapper.cpp b/mapper.cpp index 0386aa5..d643b0b 100644 --- a/mapper.cpp +++ b/mapper.cpp @@ -48,6 +48,7 @@ using namespace std; #define DRAW_ARROW_LENGTH 10 #define DRAW_ARROW_ANGLE 30 + // Will be replaced with the actual name and location of the executable (if found) string executableName = "minetestmapper"; string executablePath; // ONLY for use on windows @@ -130,6 +131,8 @@ void usage() " --draw[map]circle \" color\"\n" " --draw[map]ellipse \" color\"\n" " --draw[map]rectangle \" color\"\n" + " --draw[map]arrow \", , color\"\n" + " --draw[map]arrow \", [np] color\"\n" " --draw[map]text \", color text\"\n" " --noshading\n" " --min-y \n" @@ -436,6 +439,16 @@ static void convertDimensionToCornerCoordinates(NodeCoord &coord1, NodeCoord &co } } +static void convertCornerToDimensionCoordinates(NodeCoord &coord1, NodeCoord &coord2, NodeCoord &dimensions, int n) +{ + for (int i = 0; i < n; i++) { + if (coord2.dimension[i] < coord1.dimension[i]) + dimensions.dimension[i] = coord2.dimension[i] - coord1.dimension[i] - 1; + else + dimensions.dimension[i] = coord2.dimension[i] - coord1.dimension[i] + 1; + } +} + static void convertPolarToCartesianCoordinates(NodeCoord &coord1, NodeCoord &coord2, double angle, double length) { angle *= M_PI / 180; @@ -696,12 +709,14 @@ int main(int argc, char *argv[]) {"drawcircle", required_argument, 0, OPT_DRAW_OBJECT}, {"drawellipse", required_argument, 0, OPT_DRAW_OBJECT}, {"drawrectangle", required_argument, 0, OPT_DRAW_OBJECT}, + {"drawarrow", required_argument, 0, OPT_DRAW_OBJECT}, {"drawtext", required_argument, 0, OPT_DRAW_OBJECT}, {"drawmappoint", required_argument, 0, OPT_DRAW_OBJECT}, {"drawmapline", required_argument, 0, OPT_DRAW_OBJECT}, {"drawmapcircle", required_argument, 0, OPT_DRAW_OBJECT}, {"drawmapellipse", required_argument, 0, OPT_DRAW_OBJECT}, {"drawmaprectangle", required_argument, 0, OPT_DRAW_OBJECT}, + {"drawmaparrow", required_argument, 0, OPT_DRAW_OBJECT}, {"drawmaptext", required_argument, 0, OPT_DRAW_OBJECT}, {"noshading", no_argument, 0, 'H'}, {"geometry", required_argument, 0, 'g'}, @@ -1282,6 +1297,9 @@ int main(int argc, char *argv[]) case 'c' : drawObject.type = TileGenerator::DrawObject::Ellipse; break; + case 'a' : + drawObject.type = TileGenerator::DrawObject::Line; + break; case 't' : drawObject.type = TileGenerator::DrawObject::Text; break; @@ -1372,6 +1390,31 @@ int main(int argc, char *argv[]) } generator.drawObject(drawObject); + if (object == 'a') { + if (drawObject.haveCenter) { + std::cerr << "Arrow cannot use a centered dimension." + << " Specify at least one corner." << std::endl; + exit(1); + } + bool useDimensions = drawObject.haveDimensions; + + if (drawObject.haveDimensions) + convertDimensionToCornerCoordinates(drawObject.corner1, drawObject.corner2, drawObject.dimensions, 2); + double angle, length; + convertCartesianToPolarCoordinates(drawObject.corner1, drawObject.corner2, angle, length); + convertPolarToCartesianCoordinates(drawObject.corner1, drawObject.corner2, angle + DRAW_ARROW_ANGLE, DRAW_ARROW_LENGTH); + if (useDimensions) { + convertCornerToDimensionCoordinates(drawObject.corner1, drawObject.corner2, drawObject.dimensions, 2); + drawObject.haveDimensions = useDimensions; + } + generator.drawObject(drawObject); + convertPolarToCartesianCoordinates(drawObject.corner1, drawObject.corner2, angle - DRAW_ARROW_ANGLE, DRAW_ARROW_LENGTH); + if (useDimensions) { + convertCornerToDimensionCoordinates(drawObject.corner1, drawObject.corner2, drawObject.dimensions, 2); + drawObject.haveDimensions = useDimensions; + } + generator.drawObject(drawObject); + } } break; case 'd':