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