We're going to turn ascii art versions of polygons into their equivalent GeoJSON.
The ASCII shape language
The input ASCII language only has 3 possible characters:
*signifies a vertex
-signifies a horizontal line
|signifies a vertical line
* will never be directly adjacent to another
* (but may be diagonal to one). A
* shall have exactly two lines adjacent to it, either a
- to the left or right of it, or a
| to the top or bottom. There will never be a
| to the left or right of a
*, and consequently, never a
- directly above or below a
*. It is possible to have a vertex along a line, e.g.
Each input only contains one "ring". There are no multi-part polygons, or polygons with holes.
The input is minimal. For example, there are no extra leading or trailing blank lines or trailing white spaces.
For example, some valid shapes are:
*--* | | *--* *--* | | | *--* | | *-----* *--* | | *-* | | *-* | | *--*
The coordinate language
The above shapes shall be converted into their equivalent coordinates. The top left corner of the ASCII art is
(0,0). The first coordinate is the x-axis.
For example, the 3 shapes above would turn into the following coordinates:
[[0,0],[3,0],[3,2],[0,2],[0,0]] [[0,0],[3,0],[3,2],[6,2],[6,4],[0,4],[0,0]] [[2,0],[5,0],[5,3],[3,3],[3,5],[0,5],[0,2],[2,2],[2,0]]
Note that other representations are possible too, depending on which coordinate you start with. Continuing with GeoJSON convention, the coordinate ring shall be clockwise.
Take your input via any of the standard methods. The input may be:
- A string containing only the characters
- or an array of strings where each string represents a line.
Output shall be via any standard format. The output shall be an
n-by-2 dimensional JSON array. Any amount and type of whitespace is allowed in the resulting JSON.
This is code-golf, so fewest bytes wins.