Skip to content

Commit

Permalink
Exp: Add RTree index for polygon (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringsaturn committed Jun 22, 2023
1 parent f950ef3 commit c690361
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 123 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "geometry-rs"
version = "0.1.2"
version = "0.2.0"
edition = "2021"
license-file = "LICENSE"
description = "geometry utils"
Expand All @@ -15,6 +15,7 @@ keywords = ["geometry"]
[dependencies]

float_next_after = "1.0.0"
rtree_rs = "0.1.4"

[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
Expand Down
52 changes: 4 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,10 @@
Rewrite parts of [tidwall/geometry](https://github.com/tidwall/geometry) to Rust
for [ringsaturn/tzf-rs](https://github.com/ringsaturn/tzf-rs).

```toml
[dependencies]
geometry-rs = "0.1.2"
```bash
cargo add geometry-rs
```

```rust
use std::vec;
## TODO

use geometry_rs;

fn main() {
let poly = geometry_rs::Polygon::new(
vec![
geometry_rs::Point {
x: 90.48826291293898,
y: 45.951129815858565,
},
geometry_rs::Point {
x: 90.48826291293898,
y: 27.99437617512571,
},
geometry_rs::Point {
x: 122.83201291294,
y: 27.99437617512571,
},
geometry_rs::Point {
x: 122.83201291294,
y: 45.951129815858565,
},
geometry_rs::Point {
x: 90.48826291293898,
y: 45.951129815858565,
},
],
vec![],
);

let p_out = geometry_rs::Point {
x: 130.74216916294148,
y: 37.649011392900306,
};

print!("{:?}\n", poly.contains_point(p_out));

let p_in = geometry_rs::Point {
x: 99.9804504129416,
y: 39.70716466970461,
};
print!("{:?}\n", poly.contains_point(p_in));
}
```
- [ ] Use compressed data of RTree index, since too many memory costs.
1 change: 1 addition & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod benches_polygon {
},
],
vec![],
false,
);
return poly;
}
Expand Down
24 changes: 23 additions & 1 deletion benches/bench_az.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ mod benches_az_polygon {
extern crate test;
use test::Bencher;

// test data copy from https://github.com/unitedstates/districts/blob/gh-pages/states/AZ/shape.geojson
/* Test data copy from https://github.com/unitedstates/districts/blob/gh-pages/states/AZ/shape.geojson
Python code to generate the data:
```python
import json
TPL = """geometry_rs::Point {x: {lng}, y: {lat}},"""
with open("./az.geojson") as f:
data = json.loads(f.read())
coordinates = data["coordinates"][0][0]
# print(len(coordinates))
gens = []
for coord in coordinates:
# gens.append(TPL.format(lng=coord[0], lat=coord[1]))
gens.append(TPL.replace("{lng}", str(coord[0])).replace("{lat}", str(coord[1])))
gen_text = "\n".join(gens)
print(gen_text)
```
*/

fn load_poly() -> geometry_rs::Polygon{
let poly = geometry_rs::Polygon::new(
vec![
Expand Down Expand Up @@ -1594,6 +1615,7 @@ mod benches_az_polygon {

],
vec![],
true,
);
return poly;
}
Expand Down
44 changes: 0 additions & 44 deletions examples/demo.rs

This file was deleted.

0 comments on commit c690361

Please sign in to comment.