1 // $Id$
2 //
3 // Test Suite for C-API GEOSGetCentroid
4 
5 #include <tut/tut.hpp>
6 // geos
7 #include <geos_c.h>
8 // std
9 #include <cstdarg>
10 #include <cstdio>
11 #include <cstdlib>
12 #include <cstring>
13 
14 namespace tut {
15 //
16 // Test Group
17 //
18 
19 // Common data used in test cases.
20 struct test_capimaximuminscribedcircle_data {
21     GEOSGeometry* geom1_;
22     GEOSGeometry* geom2_;
23     GEOSWKTWriter* wktw_;
24     char* wkt_;
25     double area_;
26 
27     static void
noticetut::test_capimaximuminscribedcircle_data28     notice(const char* fmt, ...)
29     {
30         std::fprintf(stdout, "NOTICE: ");
31 
32         va_list ap;
33         va_start(ap, fmt);
34         std::vfprintf(stdout, fmt, ap);
35         va_end(ap);
36 
37         std::fprintf(stdout, "\n");
38     }
39 
test_capimaximuminscribedcircle_datatut::test_capimaximuminscribedcircle_data40     test_capimaximuminscribedcircle_data()
41         : geom1_(nullptr), geom2_(nullptr), wkt_(nullptr)
42     {
43         initGEOS(notice, notice);
44         wktw_ = GEOSWKTWriter_create();
45         GEOSWKTWriter_setTrim(wktw_, 1);
46         GEOSWKTWriter_setRoundingPrecision(wktw_, 8);
47     }
48 
~test_capimaximuminscribedcircle_datatut::test_capimaximuminscribedcircle_data49     ~test_capimaximuminscribedcircle_data()
50     {
51         GEOSGeom_destroy(geom1_);
52         GEOSGeom_destroy(geom2_);
53         GEOSWKTWriter_destroy(wktw_);
54         GEOSFree(wkt_);
55         geom1_ = nullptr;
56         geom2_ = nullptr;
57         wkt_ = nullptr;
58         finishGEOS();
59     }
60 
61 };
62 
63 typedef test_group<test_capimaximuminscribedcircle_data> group;
64 typedef group::object object;
65 
66 group test_capimaximuminscribedcircle_group("capi::GEOSMaximumInscribedCircle");
67 
68 //
69 // Test Cases
70 //
71 
72 // Single point
73 template<>
74 template<>
test()75 void object::test<1>
76 ()
77 {
78     geom1_ = GEOSGeomFromWKT("POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200))");
79     ensure(nullptr != geom1_);
80     geom2_ = GEOSMaximumInscribedCircle(geom1_, 0.001);
81     ensure(nullptr != geom2_);
82 
83     wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
84 
85     ensure_equals(std::string(wkt_), std::string("LINESTRING (150 150, 150 200)"));
86 }
87 
88 // Single point
89 template<>
90 template<>
test()91 void object::test<2>
92 ()
93 {
94     geom1_ = GEOSGeomFromWKT("MULTIPOINT ((100 100), (100 200), (200 200), (200 100))");
95     ensure(nullptr != geom1_);
96     geom2_ = GEOSLargestEmptyCircle(geom1_, nullptr, 0.001);
97     ensure(nullptr != geom2_);
98 
99     wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
100 
101     ensure_equals(std::string(wkt_), std::string("LINESTRING (150 150, 100 100)"));
102 }
103 
104 
105 } // namespace tut
106 
107