Skip to content

Commit 8142715

Browse files
feat(tile): resolve clippy & update crates
1 parent ecca724 commit 8142715

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ repository = "https://github.com/chargetrip/supercluster-rust"
1313

1414
[dependencies]
1515
geojson = "0.24.1"
16-
serde_json = "1.0.113"
16+
serde_json = "1.0.120"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A very fast Rust crate for geospatial point clustering.
44

5-
This crate is deeply inspired by Mapbox's supercluster [JS package](https://www.npmjs.com/package/supercluster) and [blog post](https://www.mapbox.com/blog/supercluster/).
5+
This crate is inspired by Mapbox's supercluster [JS package](https://www.npmjs.com/package/supercluster) and [blog post](https://www.mapbox.com/blog/supercluster/).
66

77
## Reference implementation
88

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.79.0"
3+
components = ["clippy", "rustfmt"]

src/lib.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod kdbush;
55
use geojson::{feature::Id, Feature, FeatureCollection, Geometry, JsonObject, Value::Point};
66
use kdbush::KDBush;
77
use serde_json::json;
8-
use std::f64::{consts::PI, INFINITY};
8+
use std::f64::consts::PI;
99

1010
/// An offset index used to access the zoom level value associated with a cluster in the data arrays.
1111
const OFFSET_ZOOM: usize = 2;
@@ -123,7 +123,7 @@ impl Supercluster {
123123
data.push(lat_y(coordinates[1]));
124124

125125
// The last zoom the point was processed at
126-
data.push(INFINITY);
126+
data.push(f64::INFINITY);
127127

128128
// Index of the source feature in the original input array
129129
data.push(i as f64);
@@ -162,13 +162,13 @@ impl Supercluster {
162162
/// A vector of GeoJSON features representing the clusters within the specified bounding box and zoom level.
163163
pub fn get_clusters(&self, bbox: [f64; 4], zoom: u8) -> Vec<Feature> {
164164
let mut min_lng = ((((bbox[0] + 180.0) % 360.0) + 360.0) % 360.0) - 180.0;
165-
let min_lat = f64::max(-90.0, f64::min(90.0, bbox[1]));
165+
let min_lat = bbox[1].clamp(-90.0, 90.0);
166166
let mut max_lng = if bbox[2] == 180.0 {
167167
180.0
168168
} else {
169169
((((bbox[2] + 180.0) % 360.0) + 360.0) % 360.0) - 180.0
170170
};
171-
let max_lat = f64::max(-90.0, f64::min(90.0, bbox[3]));
171+
let max_lat = bbox[3].clamp(-90.0, 90.0);
172172

173173
if bbox[2] - bbox[0] >= 360.0 {
174174
min_lng = -180.0;
@@ -610,7 +610,7 @@ impl Supercluster {
610610

611611
next_data.push(wx / num_points);
612612
next_data.push(wy / num_points);
613-
next_data.push(INFINITY);
613+
next_data.push(f64::INFINITY);
614614
next_data.push(id as f64);
615615
next_data.push(-1.0);
616616
next_data.push(num_points);
@@ -755,13 +755,7 @@ fn lat_y(lat: f64) -> f64 {
755755
let sin = lat.to_radians().sin();
756756
let y = 0.5 - (0.25 * ((1.0 + sin) / (1.0 - sin)).ln()) / PI;
757757

758-
if y < 0.0 {
759-
0.0
760-
} else if y > 1.0 {
761-
1.0
762-
} else {
763-
y
764-
}
758+
y.clamp(0.0, 1.0)
765759
}
766760

767761
/// Convert spherical mercator to longitude.

0 commit comments

Comments
 (0)