save out to file
diff --git a/.gitignore b/.gitignore
index 378b516..3ffa6f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,4 +11,4 @@
 build
 includes
 .DS_Store
-test-files/out.json
\ No newline at end of file
+out
\ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 80ee88b..295383a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -47,62 +47,85 @@
         // Points points = {.x_vector = x_vector, .y_vector = y_vector};
         return coords;
     }
+
+    const char* serialize_to_json(Delaunator &delaunator) {
+        rapidjson::StringBuffer sb;
+        rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
+        writer.StartObject();
+            writer.String("type"); writer.String("FeatureCollection");
+            writer.String("crs");
+                writer.StartObject();
+                    writer.String("type"); writer.String("name");
+                    writer.String("properties");
+                        writer.StartObject();
+                            writer.String("name"); writer.String("urn:ogc:def:crs:EPSG::900913");
+                        writer.EndObject();
+                writer.EndObject();
+            writer.String("features");
+                writer.StartArray();
+                    for(long int i = 0; i < delaunator.triangles.size(); i+=3) {
+                        writer.StartObject();
+                            writer.String("type"); writer.String("Feature");
+                            writer.String("properties"); writer.StartObject(); writer.EndObject();
+                            writer.String("geometry");
+                                writer.StartObject();
+                                    writer.String("type"); writer.String("Polygon");
+                                    writer.String("coordinates");
+                                        writer.StartArray();
+                                        writer.StartArray();
+                                            writer.StartArray();
+                                                writer.Uint(delaunator.coords[2 * delaunator.triangles[i]]);
+                                                writer.Uint(delaunator.coords[2 * delaunator.triangles[i] + 1]);
+                                            writer.EndArray();
+                                            writer.StartArray();
+                                                writer.Uint(delaunator.coords[2 * delaunator.triangles[i + 1]]);
+                                                writer.Uint(delaunator.coords[2 * delaunator.triangles[i + 1] + 1]);
+                                            writer.EndArray();
+                                            writer.StartArray();
+                                                writer.Uint(delaunator.coords[2 * delaunator.triangles[i + 2]]);
+                                                writer.Uint(delaunator.coords[2 * delaunator.triangles[i + 2] + 1]);
+                                            writer.EndArray();
+                                            writer.StartArray();
+                                                writer.Uint(delaunator.coords[2 * delaunator.triangles[i]]);
+                                                writer.Uint(delaunator.coords[2 * delaunator.triangles[i] + 1]);
+                                            writer.EndArray();
+                                        writer.EndArray();
+                                        writer.EndArray();
+                                writer.EndObject();
+                        writer.EndObject();
+                    }
+                writer.EndArray();
+        writer.EndObject();
+        return sb.GetString();
+    }
 }
 
 
 int main(int, char* argv[]) {
     const char* filename = argv[1];
+    const char* output = argv[2];
     string json = read_file(filename);
     const vector<double> coords = get_geo_json_points(json);
     Delaunator delaunator(coords);
-    rapidjson::StringBuffer sb;
-    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
-    writer.StartObject();
-        writer.String("type"); writer.String("FeatureCollection");
-        writer.String("crs");
-            writer.StartObject();
-                writer.String("type"); writer.String("name");
-                writer.String("properties");
-                    writer.StartObject();
-                        writer.String("name"); writer.String("urn:ogc:def:crs:EPSG::900913");
-                    writer.EndObject();
-            writer.EndObject();
-        writer.String("features");
-            writer.StartArray();
-                for(long int i = 0; i < delaunator.triangles.size(); i+=3) {
-                    writer.StartObject();
-                        writer.String("type"); writer.String("Feature");
-                        writer.String("properties"); writer.StartObject(); writer.EndObject();
-                        writer.String("geometry");
-                            writer.StartObject();
-                                writer.String("type"); writer.String("Polygon");
-                                writer.String("coordinates");
-                                    writer.StartArray();
-                                    writer.StartArray();
-                                        writer.StartArray();
-                                            writer.Uint(delaunator.coords[2 * delaunator.triangles[i]]);
-                                            writer.Uint(delaunator.coords[2 * delaunator.triangles[i] + 1]);
-                                        writer.EndArray();
-                                        writer.StartArray();
-                                            writer.Uint(delaunator.coords[2 * delaunator.triangles[i + 1]]);
-                                            writer.Uint(delaunator.coords[2 * delaunator.triangles[i + 1] + 1]);
-                                        writer.EndArray();
-                                        writer.StartArray();
-                                            writer.Uint(delaunator.coords[2 * delaunator.triangles[i + 2]]);
-                                            writer.Uint(delaunator.coords[2 * delaunator.triangles[i + 2] + 1]);
-                                        writer.EndArray();
-                                        writer.StartArray();
-                                            writer.Uint(delaunator.coords[2 * delaunator.triangles[i]]);
-                                            writer.Uint(delaunator.coords[2 * delaunator.triangles[i] + 1]);
-                                        writer.EndArray();
-                                    writer.EndArray();
-                                    writer.EndArray();
-                            writer.EndObject();
-                    writer.EndObject();
-                }
-            writer.EndArray();
-    writer.EndObject();
-    puts(sb.GetString());
+    const char* out_json = serialize_to_json(delaunator);
+
+    if (output) {
+        printf("Writing to file %s", output);
+        ofstream stream;
+        stream.open(output);
+        stream << out_json;
+        stream.close();
+        // cout << output << endl;
+    } else {
+        puts(out_json);
+    }
+
+    // cout << output << endl;
+    // if (sizeof(argv) > 2) {
+    //     puts("ouput to file");
+    // } else {
+    //     puts(out_json);
+    // }
     return 0;
     // cout << delaunator.triangles << endl;
 }
diff --git a/test-files/map-25p-epsg-3857.geojson b/test-files/map-25p-epsg-3857.geojson
new file mode 100644
index 0000000..afb7cca
--- /dev/null
+++ b/test-files/map-25p-epsg-3857.geojson
@@ -0,0 +1,32 @@
+{
+"type": "FeatureCollection",
+"name": "map-25p",
+"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::3857" } },
+"features": [
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1464686.336000547511503, 6917398.185751880519092 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1479667.993544442113489, 6923360.273958121426404 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1487617.444486100459471, 6904556.76499997638166 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1524612.966176125919446, 6893702.70698347967118 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1522472.729384140809998, 6916328.067355887033045 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1506573.827500824118033, 6909448.734810220077634 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1486088.703920396743342, 6888963.61122979503125 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1500917.487407721113414, 6881931.404627557843924 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1469731.179867369355634, 6898900.424906868487597 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1502751.976086565293372, 6896913.062171457335353 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1484101.34118498233147, 6877498.056987018324435 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1463310.469491414260119, 6878568.175383010879159 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1511771.545424216194078, 6883613.019249833188951 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1489910.555334655800834, 6869395.731988795101643 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1495261.147314618108794, 6909601.608866788446903 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1465756.454396540066227, 6868937.109819080680609 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1505656.583161402028054, 6871077.346611065790057 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1501223.235520861810073, 6924277.518297546543181 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1516204.893064756412059, 6908072.868301087059081 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1460252.988360007293522, 6894161.329153183847666 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1476916.260526175843552, 6867255.495196804404259 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1497095.635993462288752, 6865115.25840481929481 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1512841.663820208515972, 6919691.296600436791778 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1496484.139767180895433, 6907767.120187944732606 ] } },
+{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ 1476610.512413035146892, 6920914.289053001441061 ] } }
+]
+}
diff --git a/test-files/map-25p.geojson b/test-files/map-25p.geojson
new file mode 100644
index 0000000..bc18398
--- /dev/null
+++ b/test-files/map-25p.geojson
@@ -0,0 +1,280 @@
+{
+  "type": "FeatureCollection",
+  "features": [
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.157501220703125,
+          52.64389671230341
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.292083740234375,
+          52.67638208083924
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.363494873046875,
+          52.573846203920276
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.695831298828125,
+          52.51454943590012
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.676605224609375,
+          52.638063449400555
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.533782958984375,
+          52.60054532499603
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.349761962890623,
+          52.48863417058138
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.48297119140625,
+          52.4501511030057
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.20281982421875,
+          52.54295506642127
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.49945068359375,
+          52.53209625938427
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.3319091796875,
+          52.42587274336118
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.145141601562498,
+          52.431734261871235
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.580474853515625,
+          52.45935663683681
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.38409423828125,
+          52.38146737790348
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.432159423828125,
+          52.60137941045533
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.1671142578125,
+          52.37895253000267
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.525543212890625,
+          52.39068726147953
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.4857177734375,
+          52.68137768713742
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.62030029296875,
+          52.59303784115741
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.11767578125,
+          52.51705655410402
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.267364501953125,
+          52.369730195560706
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.448638916015625,
+          52.357989893633615
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.590087890625,
+          52.65639394198803
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.443145751953125,
+          52.59136933670434
+        ]
+      }
+    },
+    {
+      "type": "Feature",
+      "properties": {},
+      "geometry": {
+        "type": "Point",
+        "coordinates": [
+          13.264617919921875,
+          52.66305767075935
+        ]
+      }
+    }
+  ]
+}
\ No newline at end of file