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

整数値パラメータの追加、MVT で min_z, max_z オプションを使えるようにする #347

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

ciscorn
Copy link
Member

@ciscorn ciscorn commented Feb 27, 2024

  • パラメータ機構の値の種類として Integer 型を追加します
  • 実装サンプル的な意味もふくめて、MVT Sink が max_z, min_z (ズームレベルの上限、下限)を受けとれるようにします
  • MVTSinkMvtSink にリネーム

オプション値の指定方法 (CLI):

cargo run -- ~/Desktop/PLATEAU/13100_tokyo23-ku_2022_citygml_1_2_op/udx/bldg/53392547_bldg_6697_2_op.gml --sink mvt -o min_z=7 -o max_z=12 --output mvt

Summary by CodeRabbit

  • 新機能
    • IntegerParameter型を導入し、バリデーションと値の更新メソッドを追加しました。
    • ズームレベルのパラメータとMvtOptions構造体を追加しました。

@ciscorn ciscorn self-assigned this Feb 27, 2024
Copy link

coderabbitai bot commented Feb 27, 2024

Walkthrough

これらの変更は、特定のファイルではなく、全体の変更の要約を提供しています。命名規則に従い、MVTSinkProviderMvtSinkProviderに変更し、IntegerParameter型を導入してパラメータの種類を拡張し、さらに機能を改善しました。

Changes

ファイル 変更概要
app/src-tauri/src/main.rs, nusamai/src/lib.rs
nusamai/src/sink/mvt/mod.rs
MVTSinkProviderMvtSinkProviderに名称変更
nusamai/src/main.rs Args構造体内でsourceoptsinkoptの宣言順序を入れ替え、コメントを更新
nusamai/src/parameters/mod.rs IntegerParameter型を導入し、ParameterType列挙型を更新、既存のパラメータタイプのエラーメッセージを洗練
nusamai/src/sink/cesiumtiles/gltf.rs, nusamai/src/sink/cesiumtiles/mod.rs GLTF関連の変更を導入し、新しいデータ構造と処理を追加
nusamai/tests/sink.rs Sinkプロバイダのインスタンス化を更新

🐰

変更の風が吹く、コードの海を渡って
名前は新しく、機能はさらに鮮やかに
パラメータ舞い踊る、地図を紡ぐ旅路
ズームの深みに、解の花が咲く
🌟🌍🌟
さあ、冒険の時間だ、友よ!


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@ciscorn ciscorn added Controller Controller CLI Command Line Interface MVT Mapbox Vector Tiles (MVT) labels Feb 27, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dc69114 and 43f90f7.
Files selected for processing (5)
  • app/src-tauri/src/main.rs (2 hunks)
  • nusamai/src/lib.rs (1 hunks)
  • nusamai/src/parameters/mod.rs (7 hunks)
  • nusamai/src/sink/mvt/mod.rs (6 hunks)
  • nusamai/tests/sink.rs (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • app/src-tauri/src/main.rs
  • nusamai/src/lib.rs
  • nusamai/src/sink/mvt/mod.rs
  • nusamai/tests/sink.rs
Additional comments: 7
nusamai/src/parameters/mod.rs (7)
  • 120-120: ParameterType::Integer(p) => p.validate(self.required),の行について、新しいIntegerParameter型のバリデーションロジックが正しく追加されています。これにより、整数型パラメータのバリデーションが可能になり、システムの柔軟性が向上します。
  • 124-130: ParameterEntryupdate_value_with_strメソッドにおいて、ParameterType::Integer(p) => p.update_value_with_str(s),の行が追加されています。これにより、文字列から整数型パラメータへの値の更新が可能になります。ただし、入力値のバリデーションが重要になりますので、不正な値が渡された場合のエラーハンドリングが適切に行われているか確認する必要があります。
  • 140-140: ParameterEntryupdate_value_with_jsonメソッドにおいて、ParameterType::Integer(p) => p.update_value_with_json(v),の行が追加されています。JSON値から整数型パラメータへの値の更新が可能になり、API経由での設定変更などに対応できるようになります。こちらも、不正な値が渡された場合のエラーハンドリングが適切に行われているか確認する必要があります。
  • 150-150: ParameterType列挙型にInteger(IntegerParameter),が追加されています。これにより、新しい整数型パラメータがシステム全体で利用可能になり、より多様な入力値の検証と処理が可能になります。
  • 216-216: StringParameterupdate_value_with_jsonメソッドにおいて、エラーメッセージが"Value must be a string."に変更されています。この変更により、エラーメッセージがより明確になり、ユーザーが問題を理解しやすくなります。
  • 240-240: BooleanParameterupdate_value_with_strメソッドにおいて、エラーメッセージが"Value must be a boolean."に変更されています。この変更により、エラーメッセージがより明確になり、ユーザーが問題を理解しやすくなります。
  • 251-251: BooleanParameterupdate_value_with_jsonメソッドにおいて、エラーメッセージが"Value must be a boolean."に変更されています。この変更により、エラーメッセージがより明確になり、ユーザーが問題を理解しやすくなります。

Comment on lines +256 to +310
#[derive(Debug, Serialize)]
pub struct IntegerParameter {
pub value: Option<i64>,
pub min: Option<i64>,
pub max: Option<i64>,
}

impl IntegerParameter {
pub fn validate(&self, required: bool) -> Result<(), Error> {
match self.value {
Some(v) => {
if let Some(min) = self.min {
if v < min {
return Err(Error::InvalidValue(format!(
"Value must be greater than or equal to {}.",
min
)));
}
}
if let Some(max) = self.max {
if v > max {
return Err(Error::InvalidValue(format!(
"Value must be less than or equal to {}.",
max
)));
}
}
Ok(())
}
None => {
if required {
return Err(Error::RequiredValueNotProvided);
}
Ok(())
}
}
}

pub fn update_value_with_str(&mut self, s: &str) -> Result<(), Error> {
let Ok(v) = s.parse::<i64>() else {
return Err(Error::InvalidValue("Value must be an integer.".into()));
};
self.value = Some(v);
Ok(())
}

pub fn update_value_with_json(&mut self, v: &serde_json::Value) -> Result<(), Error> {
if let serde_json::Value::Number(n) = v {
let Some(v) = n.as_i64() else {
return Err(Error::InvalidValue("Value must be an integer.".into()));
};
self.value = Some(v);
Ok(())
} else {
Err(Error::InvalidValue("Value must be an integer.".into()))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新しく追加されたIntegerParameter構造体とそのメソッド(validate, update_value_with_str, update_value_with_json)について、整数型パラメータのバリデーション、文字列やJSONからの値の更新が適切に実装されています。特に、最小値と最大値の制約を設けることで、パラメータの範囲を制限し、システムの安全性を高めることができます。ただし、update_value_with_strupdate_value_with_jsonメソッドでのエラーメッセージが同じであるため、ユーザーがエラーの原因を特定しにくい可能性があります。エラーメッセージに入力形式(文字列またはJSON)の情報を追加することを検討してください。

- return Err(Error::InvalidValue("Value must be an integer.".into()));
+ return Err(Error::InvalidValue("Value must be an integer in string format.".into()));
- return Err(Error::InvalidValue("Value must be an integer.".into()));
+ return Err(Error::InvalidValue("Value must be an integer in JSON format.".into()));

@ciscorn ciscorn requested a review from a team February 27, 2024 04:34
Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 91.42857% with 18 lines in your changes are missing coverage. Please review.

Files Patch % Lines
nusamai/src/parameters/mod.rs 87.59% 16 Missing ⚠️
app/src-tauri/src/main.rs 0.00% 1 Missing ⚠️
nusamai/src/main.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
Components Coverage Δ
GUI 0.00% <0.00%> (ø)
Backend 89.43% <91.86%> (+0.32%) ⬆️
Libraries 92.00% <ø> (+0.07%) ⬆️

📢 Thoughts on this report? Let us know!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dc69114 and 365fb20.
Files selected for processing (5)
  • app/src-tauri/src/main.rs (2 hunks)
  • nusamai/src/lib.rs (1 hunks)
  • nusamai/src/parameters/mod.rs (7 hunks)
  • nusamai/src/sink/mvt/mod.rs (6 hunks)
  • nusamai/tests/sink.rs (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • app/src-tauri/src/main.rs
  • nusamai/src/lib.rs
  • nusamai/src/parameters/mod.rs
  • nusamai/src/sink/mvt/mod.rs
  • nusamai/tests/sink.rs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dc69114 and 46405a7.
Files selected for processing (6)
  • app/src-tauri/src/main.rs (2 hunks)
  • nusamai/src/lib.rs (1 hunks)
  • nusamai/src/main.rs (1 hunks)
  • nusamai/src/parameters/mod.rs (7 hunks)
  • nusamai/src/sink/mvt/mod.rs (6 hunks)
  • nusamai/tests/sink.rs (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • app/src-tauri/src/main.rs
  • nusamai/src/lib.rs
  • nusamai/src/parameters/mod.rs
  • nusamai/src/sink/mvt/mod.rs
  • nusamai/tests/sink.rs
Additional comments: 2
nusamai/src/main.rs (2)
  • 42-48: sourceoptsinkopt の宣言順序が入れ替わり、それぞれのコメントが更新されています。この変更は、コードの可読性を向上させ、オプションの目的をより正確に反映しています。この変更により、コマンドラインインターフェースの使用がより直感的になり、ユーザーが入力ソースと出力フォーマットのオプションを理解しやすくなります。
  • 39-51: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-141]

ファイル全体を通して、新しい機能や改善点が適切に統合されているか確認しました。特に、Args 構造体の変更は、ユーザーがコマンドラインから新しいオプションを指定する際の使いやすさを向上させることに貢献しています。また、SinkChoice 構造体やその他の関数に関する変更も、全体のコードの整合性と機能性を保つ上で重要な役割を果たしています。このファイルには、パフォーマンスやセキュリティに関する懸念事項は見受けられませんでした。さらに、エラーハンドリングやログ出力の処理も適切に行われており、ユーザーが問題を診断しやすくなっています。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 46405a7 and 6e19cca.
Files selected for processing (2)
  • nusamai/src/sink/cesiumtiles/gltf.rs (7 hunks)
  • nusamai/src/sink/cesiumtiles/mod.rs (3 hunks)
Additional comments: 12
nusamai/src/sink/cesiumtiles/gltf.rs (8)
  • 9-13: PrimitiveInfo 構造体の追加は、頂点のインデックスと機能IDを管理するための明確な方法を提供します。ただし、feature_idsHashSet として保持することで、挿入順序が保持されない点に注意してください。これが意図した設計であるか確認してください。
  • 21-21: write_gltf_glb 関数の vertices 引数が [u32; 6] の配列を受け取るように変更されました。この変更は、頂点データに feature_id を含めるためのものです。この変更により、関数の柔軟性が向上し、機能IDを含む頂点データの処理が可能になります。
  • 37-37: 頂点データのバイトストライドが 4 * 6 に変更されています。これは、feature_id を含む新しい頂点フォーマットに対応するためです。この変更は適切であり、頂点データの構造を正確に反映しています。
  • 34-45: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [42-54]

頂点データの処理において、feature_id の追加が反映されています。この変更により、GLTF出力における機能IDのサポートが可能になります。ただし、feature_id の使用方法については、ドキュメントやコメントでの補足説明があると理解が深まります。

  • 88-96: feature_id に対するアクセサの追加は、GLTF出力における機能IDのサポートを完全にするものです。この変更により、頂点データに含まれる機能IDを適切に扱うことができます。設計の意図に沿った実装であると考えられます。
  • 127-127: _FEATURE_ID_0 属性の追加により、GLTF出力における機能IDのサポートが強化されています。この属性を使用することで、各頂点に関連付けられた機能IDを効果的に表現できます。この変更は、GLTF出力の柔軟性と表現力を高めるものです。
  • 134-146: ext_mesh_features 拡張の使用により、GLTF出力における機能IDのサポートがさらに強化されています。この拡張を通じて、機能IDに関連する追加情報をGLTF出力に含めることができます。この変更は、GLTFの機能を最大限に活用し、より詳細な情報を提供するためのものです。
  • 208-208: EXT_mesh_features 拡張の使用を宣言しています。この宣言により、GLTFファイルが ext_mesh_features 拡張を使用していることが明示され、互換性のあるパーサーによる適切な処理が保証されます。この変更は、GLTF出力の互換性と拡張性を向上させるものです。
nusamai/src/sink/cesiumtiles/mod.rs (4)
  • 259-259: vertices コレクションが [u32; 6] の配列を格納するように変更されました。この変更は、頂点データに feature_id を含めるためのものです。この変更により、機能IDを含む頂点データの処理が可能になり、出力の詳細度が向上します。
  • 263-263: primitives マップの処理が更新され、各プリミティブに feature_ids セットが含まれるようになりました。この変更により、機能IDに基づいてプリミティブをより効果的に追跡および管理できるようになります。この変更は、出力の精度と管理性を向上させるものです。
  • 295-296: primitives マップにおける feature_ids の追加は、各プリミティブに関連付けられた機能IDを追跡するためのものです。この変更により、GLTF出力における機能IDのサポートが強化され、より詳細な情報を提供できるようになります。この変更は、出力の柔軟性と表現力を高めるものです。
  • 292-306: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [303-312]

頂点データの処理において、feature_id の追加が反映されています。この変更により、GLTF出力における機能IDのサポートが可能になります。ただし、feature_idf32 として扱っている点に注意してください。これは、GLTF仕様におけるデータ型の制約によるものかもしれませんが、意図した設計であるか確認してください。

@nokonoko1203 nokonoko1203 self-requested a review February 27, 2024 09:01
Copy link
Collaborator

@nokonoko1203 nokonoko1203 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optionの設定方法など参考になりました!
LGTM!

@ciscorn ciscorn merged commit 65c6113 into main Feb 28, 2024
8 checks passed
@ciscorn ciscorn deleted the integer-params branch February 28, 2024 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI Command Line Interface Controller Controller MVT Mapbox Vector Tiles (MVT)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants