Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat long strings to avoid rustfmt bugs. #580

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nusamai-citygml/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@

pub fn skip_current_element(&mut self) -> Result<(), ParseError> {
let Some(start) = &self.state.current_start else {
panic!("skip_current_element() must be called immediately after encountering a new starting tag.");
panic!(
"skip_current_element() must be called immediately after encountering a new \
starting tag."
);

Check warning on line 259 in nusamai-citygml/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

nusamai-citygml/src/parser.rs#L256-L259

Added lines #L256 - L259 were not covered by tests
};
self.reader
.read_to_end_into(start.name(), &mut self.state.buf1)?;
Expand Down
5 changes: 4 additions & 1 deletion nusamai-gltf/examples/make_gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ fn main() -> io::Result<()> {
byte_length,
..Default::default()
};
buffer.uri = "data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=".to_string().into();
buffer.uri = "data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/\
AAAAAAAAAAAAAAAAAACAPwAAAAA="
.to_string()
.into();

let buffer_view1 = BufferView {
name: None,
Expand Down
38 changes: 24 additions & 14 deletions nusamai-gpkg/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ impl GpkgHandler {
pub async fn gpkg_geometry_columns(
&self,
) -> Result<Vec<(String, String, String, i32, i8, i8)>, GpkgError> {
let result = sqlx::query("SELECT table_name, column_name, geometry_type_name, srs_id, z, m FROM gpkg_geometry_columns;")
.fetch_all(&self.pool)
.await?;
let result = sqlx::query(
"SELECT table_name, column_name, geometry_type_name, srs_id, z, m FROM \
gpkg_geometry_columns;",
)
.fetch_all(&self.pool)
.await?;

let rows = result
.iter()
Expand Down Expand Up @@ -213,7 +216,8 @@ impl<'c> GpkgTransaction<'c> {

// Add the table to `gpkg_contents`
sqlx::query(
"INSERT INTO gpkg_contents (table_name, data_type, identifier, srs_id) VALUES (?, ?, ?, ?);",
"INSERT INTO gpkg_contents (table_name, data_type, identifier, srs_id) VALUES (?, ?, \
?, ?);",
)
.bind(table_info.name.as_str())
.bind(if table_info.has_geometry {
Expand All @@ -229,13 +233,17 @@ impl<'c> GpkgTransaction<'c> {
// Add the table to `gpkg_geometry_columns`
if table_info.has_geometry {
sqlx::query(
"INSERT INTO gpkg_geometry_columns (table_name, column_name, geometry_type_name, srs_id, z, m) VALUES (?, ?, ?, ?, ?, ?);"
).bind(table_info.name.as_str())
"INSERT INTO gpkg_geometry_columns (table_name, column_name, geometry_type_name, \
srs_id, z, m) VALUES (?, ?, ?, ?, ?, ?);",
)
.bind(table_info.name.as_str())
.bind("geometry")
.bind("MULTIPOLYGON") // Fixed for now - TODO: Change according to the data
.bind(srs_id)
.bind(1)
.bind(0).execute(&mut *executor).await?;
.bind(0)
.execute(&mut *executor)
.await?;
}

// TODO: add MIME type to `gpkg_data_columns`
Expand Down Expand Up @@ -319,13 +327,15 @@ impl<'c> GpkgTransaction<'c> {
(min_x, min_y, max_x, max_y): (f64, f64, f64, f64),
) -> Result<(), GpkgError> {
let executor = self.tx.acquire().await.unwrap();
let query = sqlx::query("UPDATE gpkg_contents SET min_x = ?, min_y = ?, max_x = ?, max_y = ? WHERE table_name = ?;"
)
.bind(min_x)
.bind(min_y)
.bind(max_x)
.bind(max_y)
.bind(table_name);
let query = sqlx::query(
"UPDATE gpkg_contents SET min_x = ?, min_y = ?, max_x = ?, max_y = ? WHERE table_name \
= ?;",
)
.bind(min_x)
.bind(min_y)
.bind(max_x)
.bind(max_y)
.bind(table_name);
query.execute(&mut *executor).await?;
Ok(())
}
Expand Down
4 changes: 1 addition & 3 deletions nusamai-kml/src/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::{collections::HashMap, vec};

use flatgeom::{Coord, MultiPoint, MultiPoint3, MultiPolygon, MultiPolygon3, Polygon, Polygon3};
use kml::types::{
AltitudeMode, Coord as KmlCoord, Geometry, LinearRing, MultiGeometry, Point,
Polygon as KmlPolygon,
};
use flatgeom::{
Coord, MultiPoint, MultiPoint3, MultiPolygon, MultiPolygon3, Polygon, Polygon3,
};

pub fn multipolygon_to_kml(mpoly: &MultiPolygon3) -> Vec<KmlPolygon> {
multipolygon_to_kml_with_mapping(mpoly, |c| c)
Expand Down
2 changes: 1 addition & 1 deletion nusamai-plateau/src/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use std::hash::{Hash, Hasher};

use flatgeom::LineString2;
use hashbrown::HashMap;
use nusamai_citygml::{appearance::TextureAssociation, Color, LocalId, SurfaceSpan};
use flatgeom::LineString2;
use url::Url;

use crate::models::appearance::{self, ParameterizedTexture, SurfaceDataProperty, X3DMaterial};
Expand Down
69 changes: 48 additions & 21 deletions nusamai/src/sink/cesiumtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,30 @@
let zxy = tile_id_conv.id_to_zxy(tile_id);
let (tile_zoom, tile_x, tile_y) = zxy;
let (min_lat, max_lat) = tiling::y_slice_range(tile_zoom, tile_y);
let (min_lng, max_lng) = tiling::x_slice_range(tile_zoom, tile_x as i32, tiling::x_step(tile_zoom, tile_y));
let (min_lng, max_lng) = tiling::x_slice_range(
tile_zoom,
tile_x as i32,
tiling::x_step(tile_zoom, tile_y),
);

// Use the tile center as the translation of the glTF mesh
let translation = {
let (tx, ty, tz) = geodetic_to_geocentric(&ellipsoid, (min_lng + max_lng) / 2.0, (min_lat + max_lat) / 2.0, 0.);
let (tx, ty, tz) = geodetic_to_geocentric(
&ellipsoid,
(min_lng + max_lng) / 2.0,
(min_lat + max_lat) / 2.0,
0.,
);
// z-up to y-up
let [tx, ty, tz] = [tx, tz, -ty];
// double-precision to single-precision
[(tx as f32) as f64, (ty as f32) as f64, (tz as f32) as f64]
};

let geom_error = tiling::geometric_error(tile_zoom, tile_y);
feedback.info(
format!(
"tile: z={tile_zoom}, x={tile_x}, y={tile_y} (lng: [{min_lng} => {max_lng}], lat: [{min_lat} => {max_lat}) geometricError: {geom_error}"
feedback.info(format!(
"tile: z={tile_zoom}, x={tile_x}, y={tile_y} (lng: [{min_lng} => {max_lng}], \
lat: [{min_lat} => {max_lat}) geometricError: {geom_error}"
));
let content_path = {
let normalized_typename = typename.replace(':', "_");
Expand Down Expand Up @@ -331,13 +340,14 @@
feedback.ensure_not_canceled()?;

let feature = {
let (mut feature, _): (SlicedFeature, _) = bincode::serde::decode_from_slice(&serialized_feat, bincode_config)
.map_err(|err| {
PipelineError::Other(format!(
"Failed to deserialize a sliced feature: {:?}",
err
))
})?;
let (mut feature, _): (SlicedFeature, _) =
bincode::serde::decode_from_slice(&serialized_feat, bincode_config)
.map_err(|err| {
PipelineError::Other(format!(
"Failed to deserialize a sliced feature: {:?}",
err
))

Check warning on line 349 in nusamai/src/sink/cesiumtiles/mod.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/cesiumtiles/mod.rs#L346-L349

Added lines #L346 - L349 were not covered by tests
})?;

feature
.polygons
Expand All @@ -356,20 +366,33 @@
// - subtract the translation
// - flip the texture v-coordinate
let (x, y, z) = geodetic_to_geocentric(&ellipsoid, lng, lat, height);
[x - translation[0], z - translation[1], -y - translation[2], u, 1.0 - v]
[
x - translation[0],
z - translation[1],
-y - translation[2],
u,
1.0 - v,
]
});

feature
};

// Encode properties
if metadata_encoder.add_feature(&typename, &feature.attributes).is_err() {
if metadata_encoder
.add_feature(&typename, &feature.attributes)
.is_err()
{
feedback.warn("Failed to encode feature attributes".to_string());
continue
continue;

Check warning on line 387 in nusamai/src/sink/cesiumtiles/mod.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/cesiumtiles/mod.rs#L387

Added line #L387 was not covered by tests
ciscorn marked this conversation as resolved.
Show resolved Hide resolved
}

// Triangulation, etc.
for (poly, orig_mat_id) in feature.polygons.iter().zip_eq(feature.polygon_material_ids.iter()) {
for (poly, orig_mat_id) in feature
.polygons
.iter()
.zip_eq(feature.polygon_material_ids.iter())
{
let num_outer_points = match poly.hole_indices().first() {
Some(&v) => v as usize,
None => poly.raw_coords().len(),
Expand All @@ -379,15 +402,19 @@
let primitive = primitives.entry(mat).or_default();
primitive.feature_ids.insert(feature_id as u32);

if let Some((nx, ny, nz)) = calculate_normal(
poly.exterior().iter().map(|v| [v[0], v[1], v[2]])
) {
if let Some((nx, ny, nz)) =
calculate_normal(poly.exterior().iter().map(|v| [v[0], v[1], v[2]]))
{
buf3d.clear();
buf3d.extend(poly.raw_coords().iter().map(|c| [c[0], c[1], c[2]]));

if project3d_to_2d(&buf3d, num_outer_points, &mut buf2d) {
if project3d_to_2d(&buf3d, num_outer_points, &mut buf2d) {
// earcut
earcutter.earcut(buf2d.iter().cloned(), poly.hole_indices(), &mut index_buf);
earcutter.earcut(
buf2d.iter().cloned(),
poly.hole_indices(),
&mut index_buf,
);

// collect triangles
primitive.indices.extend(index_buf.iter().map(|&idx| {
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/cesiumtiles/slice.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Polygon slicing algorithm based on [geojson-vt](https://github.com/mapbox/geojson-vt).

use flatgeom::{MultiPolygon, Polygon, Polygon2, Polygon3};
use hashbrown::HashMap;
use indexmap::IndexSet;
use itertools::Itertools;
use nusamai_citygml::{
geometry::GeometryType,
object::{ObjectStereotype, Value},
};
use flatgeom::{MultiPolygon, Polygon, Polygon2, Polygon3};
use nusamai_mvt::TileZXY;
use nusamai_plateau::{appearance, Entity};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/czml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ pub fn entity_to_packets(entity: Entity, single_part: bool) -> Vec<Packet> {
mod tests {
use std::sync::RwLock;

use flatgeom::MultiPolygon;
use nusamai_citygml::{object::Object, GeometryRef};
use nusamai_czml::{PositionListProperties, PositionListType};
use flatgeom::MultiPolygon;
use nusamai_projection::crs::EPSG_JGD2011_GEOGRAPHIC_3D;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/geojson/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ pub fn entity_to_geojson_features(entity: &Entity) -> Vec<geojson::Feature> {
mod tests {
use std::sync::RwLock;

use nusamai_citygml::{object::Object, GeometryRef};
use flatgeom::MultiPolygon;
use nusamai_citygml::{object::Object, GeometryRef};
use nusamai_projection::crs::EPSG_JGD2011_GEOGRAPHIC_3D;

use super::*;
Expand Down
3 changes: 2 additions & 1 deletion nusamai/src/sink/minecraft/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
pub fn new(x: u8, y: u8, z: u8) -> Self {
if x > 15 || y > 15 || z > 15 {
panic!(
"Invalid BlockPosition values: x={x}, y={y}, z={z}. The position values must be within the range of 0 to 15."
"Invalid BlockPosition values: x={x}, y={y}, z={z}. The position values must be \
within the range of 0 to 15."

Check warning on line 47 in nusamai/src/sink/minecraft/region.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/minecraft/region.rs#L46-L47

Added lines #L46 - L47 were not covered by tests
);
}
BlockPosition([x, y, z])
Expand Down
7 changes: 5 additions & 2 deletions nusamai/src/sink/mvt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
};

use flate2::{write::ZlibEncoder, Compression};
use flatgeom::{MultiPolygon, MultiPolygon2};
use hashbrown::HashMap;
use itertools::Itertools;
use nusamai_citygml::{object, schema::Schema};
use flatgeom::{MultiPolygon, MultiPolygon2};
use nusamai_mvt::{geometry::GeometryEncoder, tag::TagsEncoder, tileid::TileIdMethod, vector_tile};
use prost::Message;
use rayon::prelude::*;
Expand Down Expand Up @@ -318,7 +318,10 @@
if detail != min_detail && compressed_size > 500_000 {
// If the tile is too large, try a lower detail level
let extent = 1 << detail;
feedback.info(format!("Tile size is too large: {zoom}/{x}/{y} (extent: {extent}), trying a lower detail level."));
feedback.info(format!(
"Tile size is too large: {zoom}/{x}/{y} (extent: {extent}), trying a \
lower detail level."
));

Check warning on line 324 in nusamai/src/sink/mvt/mod.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/mvt/mod.rs#L321-L324

Added lines #L321 - L324 were not covered by tests
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/mvt/slice.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Polygon slicing algorithm based on [geojson-vt](https://github.com/mapbox/geojson-vt).

use flatgeom::{LineString2, MultiPolygon2, Polygon2};
use hashbrown::HashMap;
use nusamai_citygml::{
geometry::GeometryType,
object::{ObjectStereotype, Value},
};
use flatgeom::{LineString2, MultiPolygon2, Polygon2};
use nusamai_mvt::{webmercator::lnglat_to_web_mercator, TileZXY};
use nusamai_plateau::Entity;

Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/transformer/transform/appearance.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Apply appearance to geometries

use feedback::Feedback;
use nusamai_citygml::schema::Schema;
use flatgeom::MultiPolygon;
use nusamai_citygml::schema::Schema;
use nusamai_plateau::Entity;

use crate::{pipeline::feedback, transformer::Transform};
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ use_field_init_shorthand = true
# unstable_features = true
# group_imports = "StdExternalCrate"
# imports_granularity = "Crate"
# format_strings = true
Loading