class Spatialindex < Formula desc "General framework for developing spatial indices" homepage "https://libspatialindex.org/" url "https://github.com/libspatialindex/libspatialindex/releases/download/1.9.3/spatialindex-src-1.9.3.tar.bz2" sha256 "4a529431cfa80443ab4dcd45a4b25aebbabe1c0ce2fa1665039c80e999dcc50a" bottle do cellar :any sha256 "fbcbfaf6510137f3168a0dc57cbac8c8b1435094b1ede9d35a30fa6ccaea28f4" => :catalina sha256 "a5cbdfb3acddb053e596fc56e7653559581923e48ed6815503fffc47c7a16660" => :mojave sha256 "cace27981cc1e5143a48e8b700d6823dff9d8049140683e0e536c476894ede91" => :high_sierra end depends_on "cmake" => :build def install ENV.cxx11 mkdir "build" do system "cmake", "..", *std_cmake_args system "make", "install" end end test do # write out a small program which inserts a fixed box into an rtree # and verifies that it can query it (testpath/"test.cpp").write <<~EOS #include using namespace std; using namespace SpatialIndex; class MyVisitor : public IVisitor { public: vector matches; void visitNode(const INode& n) {} void visitData(const IData& d) { matches.push_back(d.getIdentifier()); } void visitData(std::vector& v) {} }; int main(int argc, char** argv) { IStorageManager* memory = StorageManager::createNewMemoryStorageManager(); id_type indexIdentifier; RTree::RTreeVariant variant = RTree::RV_RSTAR; ISpatialIndex* tree = RTree::createNewRTree( *memory, 0.5, 100, 10, 2, variant, indexIdentifier ); /* insert a box from (0, 5) to (0, 10) */ double plow[2] = { 0.0, 0.0 }; double phigh[2] = { 5.0, 10.0 }; Region r = Region(plow, phigh, 2); std::string data = "a value"; id_type id = 1; tree->insertData(data.size() + 1, reinterpret_cast(data.c_str()), r, id); /* ensure that (2, 2) is in that box */ double qplow[2] = { 2.0, 2.0 }; double qphigh[2] = { 2.0, 2.0 }; Region qr = Region(qplow, qphigh, 2); MyVisitor q_vis; tree->intersectsWithQuery(qr, q_vis); return (q_vis.matches.size() == 1) ? 0 : 1; } EOS system ENV.cxx, "-std=c++11", "test.cpp", "-L#{lib}", "-lspatialindex", "-o", "test" system "./test" end end