-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bundle clipper for pt-in-poly for #12
- Loading branch information
Showing
8 changed files
with
5,115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Generated by cpp11: do not edit by hand | ||
|
||
cpp_index_sort <- function (index0) { | ||
.Call (`_utaengine_cpp_index_sort`, index0) | ||
cpp_pip <- function(layer, xy) { | ||
.Call(`_utaengine_cpp_pip`, layer, xy) | ||
} | ||
|
||
cpp_index_sort <- function(index0) { | ||
.Call(`_utaengine_cpp_index_sort`, index0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "clipper-cpp11.h" | ||
|
||
// clipper only works with integers, so double values have to be multiplied by | ||
// this amount before converting to int: | ||
const long long mult = 1e6; | ||
|
||
//' rcpp_pip | ||
//' | ||
//' polys List of polygons for which to extract membership | ||
//' @noRd | ||
writable::integers cpp_pip( | ||
const list polys, | ||
const list xy) | ||
{ | ||
const doubles x = xy ["x"]; | ||
const doubles y = xy ["y"]; | ||
const int n = x.size (); | ||
|
||
writable::integers res (n); | ||
std::fill (res.begin (), res.end (), -1L); | ||
for (int i = 0; i < polys.size (); i++) | ||
{ | ||
doubles pi = polys [i]; | ||
const int nrow = pi.size () / 2; | ||
|
||
ClipperLib::Path path; | ||
for (size_t j = 0; j < nrow; j++) | ||
{ | ||
path << ClipperLib::IntPoint (round (pi [j] * mult), | ||
round (pi [nrow + j] * mult)); | ||
} | ||
|
||
for (size_t j = 0; j < n; j++) | ||
{ | ||
const ClipperLib::IntPoint pj = | ||
ClipperLib::IntPoint (round (x [j] * mult), | ||
round (y [j] * mult)); | ||
int pip = ClipperLib::PointInPolygon (pj, path); | ||
if (pip != 0) res [j] = i; | ||
} | ||
|
||
const double progress = 100 * i / polys.size (); | ||
std::cout << "\r" << i << " / " << polys.size () << ": " << | ||
progress << "%"; | ||
std::cout.flush (); | ||
check_user_interrupt (); | ||
} | ||
std::cout << "\r" << polys.size () << " / " << polys.size () << | ||
": 100%" << std::endl; | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <iostream>> // std::cout | ||
|
||
#include "clipper.h" | ||
#include "cpp11.hpp" | ||
#include <cpp11/protect.hpp> | ||
|
||
using namespace cpp11; | ||
|
||
[[cpp11::register]] | ||
writable::integers cpp_pip( | ||
const list layer, | ||
const list xy); |
Oops, something went wrong.