1 package org.djutils.draw;
2
3 import java.util.Locale;
4
5 import org.djutils.draw.line.LineSegment2d;
6 import org.djutils.draw.line.LineSegment3d;
7 import org.djutils.draw.line.PolyLine2d;
8 import org.djutils.draw.line.PolyLine3d;
9 import org.djutils.draw.line.Polygon2d;
10 import org.djutils.draw.line.Polygon3d;
11
12
13
14
15
16
17
18
19
20
21
22
23
24 public final class Export
25 {
26
27
28
29 private Export()
30 {
31
32 }
33
34
35
36
37
38
39
40 public static String toPlot(final LineSegment2d lineSegment)
41 {
42 return String.format(Locale.US, "M%.3f,%.3fL%.3f,%.3f\n", lineSegment.startX, lineSegment.startY, lineSegment.endX,
43 lineSegment.endY);
44 }
45
46
47
48
49
50
51
52 public static String toPlot(final PolyLine2d polyLine)
53 {
54 StringBuffer result = new StringBuffer();
55 for (int i = 0; i < polyLine.size(); i++)
56 {
57 result.append(String.format(Locale.US, "%s%.3f,%.3f", 0 == result.length() ? "M" : " L", polyLine.getX(i),
58 polyLine.getY(i)));
59 }
60 result.append("\n");
61 return result.toString();
62 }
63
64
65
66
67
68
69
70 public static String toPlot(final Polygon2d polygon)
71 {
72 StringBuffer result = new StringBuffer();
73 for (int i = 0; i < polygon.size(); i++)
74 {
75 result.append(String.format(Locale.US, "%s%.3f,%.3f", 0 == result.length() ? "M" : " L", polygon.getX(i),
76 polygon.getY(i)));
77 }
78 result.append(String.format(Locale.US, " L%.3f,%.3f", polygon.getX(0), polygon.getY(0)));
79 result.append("\n");
80 return result.toString();
81 }
82
83
84
85
86
87
88
89 public static String toTsv(final LineSegment2d lineSegment)
90 {
91 return lineSegment.startX + "\t" + lineSegment.startY + "\n" + lineSegment.endX + "\t" + lineSegment.endY + "\n";
92 }
93
94
95
96
97
98
99
100 public static String toTsv(final PolyLine2d polyLine)
101 {
102 StringBuffer s = new StringBuffer();
103 for (int i = 0; i < polyLine.size(); i++)
104 {
105 s.append(polyLine.getX(i) + "\t" + polyLine.getY(i) + "\n");
106 }
107 return s.toString();
108 }
109
110
111
112
113
114
115
116 public static String toTsv(final Polygon2d polygon)
117 {
118 StringBuffer s = new StringBuffer();
119 for (int i = 0; i < polygon.size(); i++)
120 {
121 s.append(polygon.getX(i) + "\t" + polygon.getY(i) + "\n");
122 }
123 s.append(polygon.getX(0) + "\t" + polygon.getY(0) + "\n");
124 return s.toString();
125 }
126
127
128
129
130
131
132
133 public static String toTsv(final LineSegment3d lineSegment)
134 {
135 return lineSegment.startX + "\t" + lineSegment.startY + "\t" + lineSegment.startZ + "\n" + lineSegment.endX + "\t"
136 + lineSegment.endY + "\t" + lineSegment.endZ + "\n";
137 }
138
139
140
141
142
143
144
145 public static String toTsv(final PolyLine3d polyline)
146 {
147 StringBuffer s = new StringBuffer();
148 for (int i = 0; i < polyline.size(); i++)
149 {
150 s.append(polyline.getX(i) + "\t" + polyline.getY(i) + "\t" + polyline.getZ(i) + "\n");
151 }
152 return s.toString();
153 }
154
155
156
157
158
159
160
161 public static String toTsv(final Polygon3d polygon)
162 {
163 StringBuffer s = new StringBuffer();
164 for (int i = 0; i < polygon.size(); i++)
165 {
166 s.append(polygon.getX(i) + "\t" + polygon.getY(i) + "\t" + polygon.getZ(i) + "\n");
167 }
168 s.append(polygon.getX(0) + "\t" + polygon.getY(0) + "\t" + polygon.getZ(0) + "\n");
169 return s.toString();
170 }
171
172 }