Skip to content

Commit c40f19c

Browse files
committed
Add geom asciiart command
1 parent 5d6613f commit c40f19c

File tree

5 files changed

+415
-1
lines changed

5 files changed

+415
-1
lines changed
Lines changed: 349 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,349 @@
1+
package org.geometrycommands;
2+
3+
import com.vividsolutions.jts.geom.Geometry;
4+
import org.geometrycommands.AsciiArtCommand.AsciiArtOptions;
5+
6+
import java.io.Reader;
7+
import java.io.Writer;
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
/**
14+
* Get the Geometry as WKT ASCII Art
15+
* @author Jared Erickson
16+
*/
17+
public class AsciiArtCommand extends GeometryCommand<AsciiArtOptions> {
18+
19+
/**
20+
* Get the Command's name
21+
* @return The Command's name
22+
*/
23+
@Override
24+
public String getName() {
25+
return "asciiart";
26+
}
27+
28+
/**
29+
* Get the description of what the Command does
30+
* @return The description of what the Command does
31+
*/
32+
@Override
33+
public String getDescription() {
34+
return "Get the Geometry as WKT ASCII Art";
35+
}
36+
37+
38+
/**
39+
* Get a new GeometryOptions
40+
*
41+
* @return A new GeometryOptions
42+
*/
43+
@Override
44+
public AsciiArtOptions getOptions() {
45+
return new AsciiArtOptions();
46+
}
47+
48+
/**
49+
* Process the input Geometry
50+
* @param geometry The input Geometry
51+
* @param options The GeometryOptions
52+
* @param reader The java.io.Reader
53+
* @param writer The java.io.Writer
54+
* @throws Exception if an error occurs
55+
*/
56+
@Override
57+
protected void processGeometry(Geometry geometry, AsciiArtOptions options, Reader reader, Writer writer) throws Exception {
58+
String wkt = geometry.toText();
59+
List<String[]> letters = new ArrayList<String[]>();
60+
char[] chars = wkt.toCharArray();
61+
for (int i = 0; i < chars.length; i++) {
62+
char c = chars[i];
63+
String[] characters = art.get(String.valueOf(c));
64+
if (characters != null) {
65+
letters.add(characters);
66+
}
67+
}
68+
String NEW_LINE = System.getProperty("line.separator");
69+
for (int i = 0; i < 5; i++) {
70+
for (String[] lines : letters) {
71+
writer.write(lines[i]);
72+
}
73+
writer.write(NEW_LINE);
74+
}
75+
}
76+
77+
/**
78+
* The AsciiArtOptions
79+
*/
80+
public static class AsciiArtOptions extends GeometryOptions {
81+
}
82+
83+
private static String[] zero = new String[]{
84+
" ___ ",
85+
" / _ \\ ",
86+
"| | | |",
87+
"| |_| |",
88+
" \\___/ ",
89+
};
90+
91+
private static String[] one = new String[]{
92+
" _ ",
93+
"/ |",
94+
"| |",
95+
"| |",
96+
"|_|"
97+
};
98+
private static String[] two = new String[]{
99+
" ____ ",
100+
"|___ \\ ",
101+
" __) |",
102+
" / __/ ",
103+
"|_____|"
104+
};
105+
106+
private static String[] three = new String[]{
107+
" _____ ",
108+
"|___ / ",
109+
" |_ \\ ",
110+
" ___) |",
111+
"|____/ "
112+
};
113+
114+
private static String[] four = new String[]{
115+
" _ _ ",
116+
"| || | ",
117+
"| || |_ ",
118+
"|__ _|",
119+
" |_| "
120+
};
121+
122+
private static String[] five = new String[]{
123+
" ____ ",
124+
"| ___| ",
125+
"|___ \\ ",
126+
" ___) |",
127+
"|____/ "
128+
};
129+
130+
private static String[] six = new String[]{
131+
" __ ",
132+
" / /_ ",
133+
"| '_ \\ ",
134+
"| (_) |",
135+
" \\___/ "
136+
};
137+
138+
private static String[] seven = new String[]{
139+
" _____ ",
140+
" |___ |",
141+
" / / ",
142+
" / / ",
143+
" /_/ "
144+
};
145+
146+
private static String[] eight = new String[]{
147+
" ___ ",
148+
" ( _ ) ",
149+
" / _ \\ ",
150+
"| (_) |",
151+
" \\___/ "
152+
};
153+
154+
private static String[] nine = new String[]{
155+
" ___ ",
156+
" / _ \\ ",
157+
"| (_) |",
158+
" \\__, |",
159+
" /_/ "
160+
};
161+
162+
private static String[] p = new String[]{
163+
" ____ ",
164+
"| _ \\ ",
165+
"| |_) |",
166+
"| __/ ",
167+
"|_| ",
168+
};
169+
170+
private static String[] o = new String[]{
171+
" ___ ",
172+
" / _ \\ ",
173+
"| | | |",
174+
"| |_| |",
175+
" \\___/ "
176+
};
177+
178+
179+
private static String[] i = new String[]{
180+
" ___ ",
181+
"|_ _|",
182+
" | | ",
183+
" | | ",
184+
"|___|"
185+
};
186+
187+
private static String[] n = new String[]{
188+
" _ _ ",
189+
"| \\ | |",
190+
"| \\| |",
191+
"| |\\ |",
192+
"|_| \\_|"
193+
194+
};
195+
196+
private static String[] t = new String[]{
197+
" _____ ",
198+
"|_ _|",
199+
" | | ",
200+
" | | ",
201+
" |_| "
202+
};
203+
204+
private static String[] l = new String[]{
205+
" _ ",
206+
"| | ",
207+
"| | ",
208+
"| |___ ",
209+
"|_____|"
210+
};
211+
212+
private static String[] e = new String[]{
213+
" _____ ",
214+
"| ____|",
215+
"| _| ",
216+
"| |___ ",
217+
"|_____|"
218+
};
219+
220+
private static String[] g = new String[]{
221+
" ____ ",
222+
" / ___|",
223+
"| | _ ",
224+
"| |_| |",
225+
" \\____|"
226+
};
227+
228+
private static String[] r = new String[]{
229+
" ____ ",
230+
"| _ \\ ",
231+
"| |_) |",
232+
"| _ < ",
233+
"|_| \\_\\"
234+
};
235+
236+
private static String[] s = new String[]{
237+
" ____ ",
238+
"/ ___| ",
239+
"\\___ \\ ",
240+
" ___) |",
241+
"|____/ ",
242+
};
243+
244+
private static String[] y = new String[]{
245+
"__ __",
246+
"\\ \\ / /",
247+
" \\ V / ",
248+
" | | ",
249+
" |_| ",
250+
};
251+
252+
private static String[] m = new String[]{
253+
" __ __ ",
254+
"| \\/ |",
255+
"| |\\/| |",
256+
"| | | |",
257+
"|_| |_|",
258+
};
259+
260+
private static String[] u = new String[]{
261+
" _ _ ",
262+
"| | | |",
263+
"| | | |",
264+
"| |_| |",
265+
" \\___/ "
266+
};
267+
268+
private static String[] c = new String[]{
269+
" ____ ",
270+
" / ___|",
271+
"| | ",
272+
"| |___ ",
273+
" \\____|"
274+
};
275+
276+
private static String[] space = new String[]{
277+
" ",
278+
" ",
279+
" ",
280+
" ",
281+
" "
282+
};
283+
284+
private static String[] leftparan = new String[]{
285+
" __",
286+
" / /",
287+
"| | ",
288+
"| | ",
289+
" \\_\\"
290+
};
291+
292+
private static String[] rightparan = new String[]{
293+
"__ ",
294+
"\\ \\ ",
295+
" | |",
296+
" | |",
297+
"/_/ "
298+
};
299+
300+
private static String[] comma = new String[]{
301+
" ",
302+
" ",
303+
" _ ",
304+
"( )",
305+
"|/ "
306+
};
307+
308+
private static String[] period = new String[]{
309+
" ",
310+
" ",
311+
" ",
312+
" _ ",
313+
"(_)"
314+
};
315+
316+
private static Map<String, String[]> art = new HashMap<String, String[]>();
317+
318+
static {
319+
art.put("0", zero);
320+
art.put("1", one);
321+
art.put("2", two);
322+
art.put("3", three);
323+
art.put("4", four);
324+
art.put("5", five);
325+
art.put("6", six);
326+
art.put("7", seven);
327+
art.put("8", eight);
328+
art.put("9", nine);
329+
art.put(",", comma);
330+
art.put(".", period);
331+
art.put(" ", space);
332+
art.put("P", p);
333+
art.put("O", o);
334+
art.put("I", i);
335+
art.put("N", n);
336+
art.put("T", t);
337+
art.put("L", l);
338+
art.put("E", e);
339+
art.put("S", s);
340+
art.put("R", r);
341+
art.put("G", g);
342+
art.put("Y", y);
343+
art.put("M", m);
344+
art.put("U", u);
345+
art.put("C", c);
346+
art.put("(", leftparan);
347+
art.put(")", rightparan);
348+
}
349+
}

src/main/resources/META-INF/services/org.geometrycommands.Command

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ org.geometrycommands.AngleCommand
33
org.geometrycommands.ArcCommand
44
org.geometrycommands.ArcPolygonCommand
55
org.geometrycommands.AreaCommand
6+
org.geometrycommands.AsciiArtCommand
67
org.geometrycommands.BoundaryCommand
78
org.geometrycommands.BufferCommand
89
org.geometrycommands.CentroidCommand

src/man/geom-asciiart.1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.TH "geom-asciiart" "1" "4 May 2012" "version 0.1"
2+
.SH NAME
3+
geom asciiart
4+
.SH DESCRIPTION
5+
Get the Geometry as WKT ASCII Art
6+
.SH USAGE
7+
geom asciiart -g "POINT (10 10)"
8+
.SH OPTIONS
9+
-g --geometry: The input geometry
10+
.PP
11+
--help : Print help message
12+
.PP

src/shell/geom_bash_comp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _geom()
55
local line=${COMP_LINE}
66
COMPREPLY=()
77
if [[ "$line" == *"geom " ]]; then
8-
COMPREPLY=($(compgen -W 'angle arc arcpoly area boundary buffer centroid closelinestring combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify difference dimension disjoint distance distanceline draw drawbase64 dump ellipse endpoint envelope equals fromwkb get grid hausdorffdistance interiorpoint interpolatepoint intersection intersects isccw isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linemerge list locatepoint mincircle minclearance mindiameter minrect narrow nearestpoints node normalize octagonalenvelope overlaps placepoint pointatangle polygonize project random randomwalk rectangle reduceprecision reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar slice snap split spoke squircle startpoint subline supercircle symdifference text touches towkb translate type union voronoi within' -- $cur))
8+
COMPREPLY=($(compgen -W 'angle arc arcpoly area asciiart boundary buffer centroid closelinestring combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify difference dimension disjoint distance distanceline draw drawbase64 dump ellipse endpoint envelope equals fromwkb get grid hausdorffdistance interiorpoint interpolatepoint intersection intersects isccw isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linemerge list locatepoint mincircle minclearance mindiameter minrect narrow nearestpoints node normalize octagonalenvelope overlaps placepoint pointatangle polygonize project random randomwalk rectangle reduceprecision reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar slice snap split spoke squircle startpoint subline supercircle symdifference text touches towkb translate type union voronoi within' -- $cur))
99
elif [[ "$line" == *"geom angle "* ]]; then
1010
COMPREPLY=($(compgen -W '--help -g --geometry -o --otherGeometry -t --type' -- $cur))
1111
elif [[ "$line" == *"geom arc "* ]]; then
@@ -14,6 +14,8 @@ _geom()
1414
COMPREPLY=($(compgen -W '--help -a --startAngle -c --center -d --degrees -e --angleExtent -g --geometry -h --height -p --numberOfPoints -r --rotation -w --width' -- $cur))
1515
elif [[ "$line" == *"geom area "* ]]; then
1616
COMPREPLY=($(compgen -W '--help -g --geometry' -- $cur))
17+
elif [[ "$line" == *"geom asciiart "* ]]; then
18+
COMPREPLY=($(compgen -W '--help -g --geometry' -- $cur))
1719
elif [[ "$line" == *"geom boundary "* ]]; then
1820
COMPREPLY=($(compgen -W '--help -g --geometry' -- $cur))
1921
elif [[ "$line" == *"geom buffer "* ]]; then
@@ -212,6 +214,9 @@ _geom()
212214
if [[ "area" == "$nm"* ]]; then
213215
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'area'))
214216
fi
217+
if [[ "asciiart" == "$nm"* ]]; then
218+
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'asciiart'))
219+
fi
215220
if [[ "boundary" == "$nm"* ]]; then
216221
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'boundary'))
217222
fi

0 commit comments

Comments
 (0)