Skip to content

Commit b133771

Browse files
committed
Update changelog and readme
1 parent 6b96a50 commit b133771

File tree

3 files changed

+97
-26
lines changed

3 files changed

+97
-26
lines changed

CHANGELOG.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
## Changelog
22

3-
### Current master (unreleased)
3+
### 0.7.0 (2022-09-23)
4+
5+
- Make geojson optional, use geo-types for geometry representation
6+
(thanks to @michaelkirk, see #5 and #6 for details).
47

58
- Add `x_origin`, `y_origin`, `x_step` and `y_step`
69
attributes to `ContourBuilder` struct. They can be set using the *builder pattern*, before calling
710
the `contours` method.
811

912
- Create this changelog and complete it retroactively.
1013

11-
### 0.6.0
14+
### 0.6.0 (2022-09-15)
1215

1316
- Bump maximum supported geojson version to 0.24.
1417

15-
### 0.5.0
18+
### 0.5.0 (2022-06-25)
1619

1720
- Bump maximum supported geojson version to 0.23.
1821

19-
### 0.4.0
22+
### 0.4.0 (2021-02-09)
2023

2124
- Bump maximum supported geojson version to 0.22.
2225

23-
### 0.3.0
26+
### 0.3.0 (2020-12-08)
2427

2528
- Support a range of geojson crate versions instead of a specific one.
2629

27-
### 0.2.0
30+
### 0.2.0 (2020-07-25)
2831

2932
- Modernize error handling.
3033
- Bump supported geojson version to 0.19.
3134

32-
### 0.1.0
35+
### 0.1.0 (2019-01-21)
3336

3437
- First version

README.md

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
[![Docs.rs version](https://docs.rs/contour/badge.svg)](https://docs.rs/contour/)
66

77
Computes *isorings* and __*contour polygons*__ by applying [marching squares](https://en.wikipedia.org/wiki/Marching_squares) to a rectangular array of numeric values.
8-
Outputs ring coordinates or polygons contours as a `Vec` of [GeoJSON](https://github.com/georust/rust-geojson) [Feature](https://docs.rs/geojson/latest/geojson/struct.Feature.html)s.
8+
Outputs ring coordinates or polygons contours (represented using geo-types [MultiPolygon](https://docs.rs/geo-types/latest/geo_types/geometry/struct.MultiPolygon.html)s).
9+
The generated contours can also easily be serialised to GeoJSON.
10+
911
*Note : This is a port of [d3-contour](https://github.com/d3/d3-contour).*
1012

1113
<div style="text-align:center"><a href="https://mthh.github.io/wasm_demo_contour/"><img src ="https://raw.githubusercontent.com/mthh/contour-rs/master/illustration.png" /></a></div><br>
@@ -16,7 +18,7 @@ Add this to your `Cargo.toml`:
1618

1719
```toml
1820
[dependencies]
19-
contour = "0.6.0"
21+
contour = "0.7.0"
2022
```
2123

2224
and this to your crate root:
@@ -27,11 +29,13 @@ extern crate contour;
2729

2830
The API exposes:
2931
- a `contour_rings` function, which computes isorings coordinates for one threshold value (*returns a `Vec` of rings coordinates*).
30-
- a `ContourBuilder` struct, which computes isorings coordinates for a `Vec` of threshold values and transform them in `MultiPolygon`s (*returns a `Vec` of GeoJSON Features*).
32+
- a `ContourBuilder` struct, which computes isorings coordinates for a `Vec` of threshold values and transform them in `Contour`s (a type containing the threshold value and the geometry as a MultiPolygon, easily serializable to GeoJSON).
3133

3234

3335
### Example:
3436

37+
**Without defining origin and step:**
38+
3539
```rust
3640
let c = ContourBuilder::new(10, 10, false); // x dim., y dim., smoothing
3741
let res = c.contours(&vec![
@@ -47,24 +51,89 @@ let res = c.contours(&vec![
4751
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
4852
], &[0.5])?; // values, thresholds
4953
```
54+
55+
**With origin and step**
56+
57+
```rust
58+
let c = ContourBuilder::new(10, 10, true) // x dim., y dim., smoothing
59+
.x_step(2) // The horizontal coordinate for the origin of the grid.
60+
.y_step(2) // The vertical coordinate for the origin of the grid.
61+
.x_origin(100) // The horizontal step for the grid
62+
.y_origin(200); // The vertical step for the grid
63+
64+
let res = c.contours(&[
65+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
66+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
67+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
68+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
69+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
70+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
71+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
72+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
73+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
74+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
75+
], &[0.5]).unwrap(); // values, thresholds
76+
77+
```
78+
79+
**Using the `geojson` feature**
80+
81+
The `geojson` feature is not enabled by default, so you need to specify it in your `Cargo.toml`:
82+
83+
```toml
84+
[dependencies]
85+
contour = { version = "0.7.0", features = ["geojson"] }
86+
```
87+
88+
```rust
89+
let c = ContourBuilder::new(10, 10, true) // x dim., y dim., smoothing
90+
.x_step(2) // The horizontal coordinate for the origin of the grid.
91+
.y_step(2) // The vertical coordinate for the origin of the grid.
92+
.x_origin(100) // The horizontal step for the grid
93+
.y_origin(200); // The vertical step for the grid
94+
95+
let res = c.contours(&[
96+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
97+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
98+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
99+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
100+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
101+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
102+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
103+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
104+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
105+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
106+
], &[0.5]).unwrap(); // values, thresholds
107+
println!("{:?}", res[0].to_geojson()); // prints the GeoJSON representation of the first contour
108+
```
109+
110+
```rust
50111
__*Output:*__
51112
```rust
52-
[Feature {
53-
bbox: None,
54-
geometry: Some(Geometry {
113+
Feature {
55114
bbox: None,
56-
value: MultiPolygon([[[
57-
[6., 7.5], [6., 6.5], [6., 5.5], [6., 4.5],
58-
[6., 3.5], [5.5, 3.], [4.5, 3.], [3.5, 3.],
59-
[3., 3.5], [3., 4.5], [3., 5.5], [3., 6.5],
60-
[3., 7.5], [3.5, 8.], [4.5, 8.], [5.5, 8.],
61-
[6., 7.5]]]]),
62-
foreign_members: None
115+
geometry: Some(Geometry {
116+
bbox: None,
117+
value: MultiPolygon([
118+
[[
119+
[110.0, 215.0], [110.0, 213.0], [110.0, 211.0], [110.0, 209.0],
120+
[110.0, 207.0], [109.0, 206.0], [107.0, 206.0], [106.0, 207.0],
121+
[106.0, 209.0], [106.0, 211.0], [106.0, 213.0], [106.0, 215.0],
122+
[107.0, 216.0], [109.0, 216.0], [110.0, 215.0]
123+
]],
124+
[[
125+
[114.0, 215.0], [114.0, 213.0], [114.0, 211.0], [114.0, 209.0],
126+
[114.0, 207.0], [113.0, 206.0], [112.0, 207.0], [112.0, 209.0],
127+
[112.0, 211.0], [112.0, 213.0], [112.0, 215.0], [113.0, 216.0],
128+
[114.0, 215.0]
129+
]]
130+
]),
131+
foreign_members: None
63132
}),
64-
id: None,
65-
properties: Some({"value": Number(0.5)}),
66-
foreign_members: None
67-
}]
133+
id: None,
134+
properties: Some({"threshold": Number(0.5)}),
135+
foreign_members: None
136+
}
68137
```
69138

70139
### Demo

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,9 @@ mod tests {
458458
#[cfg(feature = "geojson")]
459459
#[test]
460460
fn test_simple_polygon_no_smoothing_geojson() {
461-
use super::*;
462461
let c = ContourBuilder::new(10, 10, false);
463462
#[rustfmt::skip]
464-
let res = c.contours(&[
463+
let res = c.contours(&[
465464
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
466465
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
467466
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,

0 commit comments

Comments
 (0)