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

【wip】ポリゴンの頂点をタイル境界にスナップする #678

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

yud0uhu
Copy link

@yud0uhu yud0uhu commented Nov 7, 2024

Close #627

What I did(変更内容)

  • ...

Notes(連絡事項)

None / なし

Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

このプルリクエストでは、demo/cesium/3dtiles.htmlファイルの3Dタイルセットの読み込みURLを変更し、fromUrlメソッドにオプションオブジェクトを追加しています。具体的には、タイルセットの読み込み元が"/examples/3dtiles/tileset.json"から"./examples/3dtiles_textured/tileset.json"に変更され、デバッグ用の新しいパラメータ{ enableDebugWireframe: true }が追加されました。また、nusamai/src/sink/cesiumtiles/slice.rsファイルでは、タイルの境界を定義する新しい構造体TileBoundsが追加され、頂点をタイル境界にスナップする関数snap_to_tile_boundaryが実装されています。

Changes

ファイルパス 変更内容
demo/cesium/3dtiles.html 3Dタイルセットの読み込みURLを変更し、fromUrlメソッドにオプションオブジェクトを追加。
nusamai/src/sink/cesiumtiles/slice.rs TileBounds構造体を追加し、頂点をタイル境界にスナップするsnap_to_tile_boundary関数を追加。slice_polygon関数を修正。

Assessment against linked issues

Objective Addressed Explanation
3Dタイル境界に関連する不具合の調査 (#627)

Possibly related PRs

Suggested reviewers

  • ciscorn
  • TadaTeruki

うさぎの詩
3Dタイルが新しく、
URLも変わり、
デバッグも楽しく、
タイル境界も整え、
みんなで遊ぼう、
うさぎの世界で! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2560841 and 656b736.

📒 Files selected for processing (1)
  • nusamai/src/sink/cesiumtiles/slice.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • nusamai/src/sink/cesiumtiles/slice.rs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
demo/cesium/3dtiles.html (1)

75-75: デバッグ設定の環境分けを推奨します

enableDebugWireframe オプションがハードコードされていますが、開発環境とプロダクション環境で設定を分けることを推奨します。

以下のような環境変数による制御を検討してください:

-          { enableDebugWireframe: true }
+          { enableDebugWireframe: process.env.NODE_ENV === 'development' }
nusamai/src/sink/cesiumtiles/slice.rs (2)

18-23: 構造体のドキュメントとデライブマクロの追加を推奨

タイル境界を表す構造体として適切ですが、以下の改善を推奨します:

  • ドキュメントコメントの追加
  • DebugCloneデライブマクロの追加
+/// タイルの境界を表す構造体
+/// 
+/// # フィールド
+/// * `min_x` - X座標の最小値
+/// * `max_x` - X座標の最大値
+/// * `min_y` - Y座標の最小値
+/// * `max_y` - Y座標の最大値
+#[derive(Debug, Clone)]
 struct TileBounds {
     min_x: f64,
     max_x: f64,
     min_y: f64,
     max_y: f64,
 }

406-411: 境界値の定数化とドキュメント化を推奨

ハードコードされた境界値(0.0から1.0)は正規化されたタイル座標を表していると思われますが、これを明確にするために以下の改善を推奨します:

+/// 正規化されたタイル座標の境界値
+const NORMALIZED_TILE_MIN: f64 = 0.0;
+const NORMALIZED_TILE_MAX: f64 = 1.0;
+
 let tile_bounds = TileBounds {
-    min_x: 0.0,
-    max_x: 1.0,
-    min_y: 0.0,
-    max_y: 1.0,
+    min_x: NORMALIZED_TILE_MIN,
+    max_x: NORMALIZED_TILE_MAX,
+    min_y: NORMALIZED_TILE_MIN,
+    max_y: NORMALIZED_TILE_MAX,
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 92333bd and c57ba4d.

📒 Files selected for processing (2)
  • demo/cesium/3dtiles.html (1 hunks)
  • nusamai/src/sink/cesiumtiles/slice.rs (3 hunks)

Comment on lines 74 to 75
"/examples/3dtiles_textured",
{ enableDebugWireframe: true }
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

タイルセットのパスが無効です - 修正が必要

検証の結果、以下の問題が確認されました:

  • /examples/3dtiles_textured ディレクトリが存在しません
  • 現在利用可能な3DTilesのサンプルは以下のみです:
    • /examples/ext_mesh_features
    • /examples/ext_structural_metadata

タイルセットのパスを既存のディレクトリのいずれかに変更するか、新しいタイルセットを適切に配置する必要があります。

🔗 Analysis chain

3Dタイルセットの読み込み設定の変更について確認が必要です

タイルセットのURLが変更され、デバッグオプションが追加されました。以下の点について確認をお願いします:

  1. 新しいパス /examples/3dtiles_textured が正しく設定されているか
  2. テクスチャ付きタイルセットへの移行による影響
  3. デバッグワイヤーフレーム表示がタイル境界へのスナップ機能の開発に有用か
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 新しいタイルセットのパスが存在するか確認
fd -t d "3dtiles_textured$" examples/

# タイルセット関連の設定ファイルを検索
fd -e json "tileset.json$" examples/3dtiles_textured

Length of output: 304


Script:

#!/bin/bash
# リポジトリ内の全ての3DTilesに関連するディレクトリを検索
fd -t d "3dtiles"

# リポジトリ内のtileset.jsonファイルを検索
fd -e json "tileset.json$"

# HTMLファイル内のタイルセットパスの参照を検索
rg -g "*.html" "3dtiles_textured"

# デモディレクトリの構造を確認
ls -la demo/cesium/

Length of output: 788

nusamai/src/sink/cesiumtiles/slice.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Additional details and impacted files
Components Coverage Δ
GUI ∅ <ø> (∅)
Backend 74.61% <ø> (+0.39%) ⬆️
Libraries 90.33% <ø> (+0.82%) ⬆️

📢 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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
nusamai/src/sink/cesiumtiles/slice.rs (2)

18-23: 構造体のドキュメントとデバッグサポートの追加を推奨

構造体の目的と各フィールドの説明を追加することで、コードの理解性が向上します。また、デバッグ時の利便性のために、一般的な派生トレイトを追加することを推奨します。

+/// タイルの境界を表す構造体
+/// 
+/// # フィールド
+/// * `min_x` - X座標の最小値
+/// * `max_x` - X座標の最大値
+/// * `min_y` - Y座標の最小値
+/// * `max_y` - Y座標の最大値
+#[derive(Debug, Clone, PartialEq)]
 struct TileBounds {
     min_x: f64,
     max_x: f64,
     min_y: f64,
     max_y: f64,
 }

406-427: タイル境界の固定値の意図を明確にすることを推奨

タイル境界に0.0から1.0の固定値を使用している理由をコメントで説明することで、将来のメンテナンス性が向上します。また、これらの値を定数として定義することも検討してください。

+            // タイル空間は0.0から1.0の正規化された座標系を使用
+            const TILE_MIN: f64 = 0.0;
+            const TILE_MAX: f64 = 1.0;
+
             let tile_bounds = TileBounds {
-                min_x: 0.0,
-                max_x: 1.0,
-                min_y: 0.0,
-                max_y: 1.0,
+                min_x: TILE_MIN,
+                max_x: TILE_MAX,
+                min_y: TILE_MIN,
+                max_y: TILE_MAX,
             };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8b4acae and 8d79093.

📒 Files selected for processing (1)
  • nusamai/src/sink/cesiumtiles/slice.rs (3 hunks)

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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
nusamai/src/sink/cesiumtiles/slice.rs (2)

18-23: 構造体のドキュメントと派生トレイトを追加することを推奨

タイル境界を表す構造体の理解を深めるため、以下の改善を提案します:

+/// タイルの境界を表す構造体
+/// 
+/// # フィールド
+/// * `min_x` - X座標の最小値
+/// * `max_x` - X座標の最大値
+/// * `min_y` - Y座標の最小値
+/// * `max_y` - Y座標の最大値
+#[derive(Debug, Clone, Copy)]
 struct TileBounds {
     min_x: f64,
     max_x: f64,
     min_y: f64,
     max_y: f64,
 }

406-411: マジックナンバーの説明が必要

タイル境界の初期化に使用されている0.0から1.0の値は正規化されたタイル座標を表していますが、これが明確ではありません。以下のような改善を提案します:

+            // タイル座標を0.0から1.0の範囲に正規化
             let tile_bounds = TileBounds {
                 min_x: 0.0,
                 max_x: 1.0,
                 min_y: 0.0,
                 max_y: 1.0,
             };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8d79093 and ad4563b.

📒 Files selected for processing (1)
  • nusamai/src/sink/cesiumtiles/slice.rs (3 hunks)
🔇 Additional comments (2)
nusamai/src/sink/cesiumtiles/slice.rs (2)

413-427: 頂点のスナップ処理が正しく実装されています

以前の問題点が解決され、以下の点が改善されています:

  1. リングのコピーを作成して反復処理
  2. スナップされた頂点を正しくpoly_bufに反映
  3. 空のリングに対する適切なハンドリング

464-481: 🛠️ Refactor suggestion

浮動小数点の比較精度とテストの追加が必要

前回のレビューで指摘された改善点がまだ実装されていません。以下の修正を推奨します:

+/// 頂点をタイル境界にスナップする
+/// 
+/// # 引数
+/// * `vertex` - スナップ対象の頂点 [x, y, z, u, v]
+/// * `tile_bounds` - タイル境界
+/// 
+/// # 戻り値
+/// スナップされた頂点
 fn snap_to_tile_boundary(vertex: [f64; 5], tile_bounds: &TileBounds) -> [f64; 5] {
+    const EPSILON: f64 = 1e-10;
     let mut snapped_vertex = vertex;
 
-    if vertex[0] < tile_bounds.min_x {
+    if vertex[0] < tile_bounds.min_x + EPSILON {
         snapped_vertex[0] = tile_bounds.min_x;
-    } else if vertex[0] > tile_bounds.max_x {
+    } else if vertex[0] > tile_bounds.max_x - EPSILON {
         snapped_vertex[0] = tile_bounds.max_x;
     }
 
     // Snap y coordinate
-    if vertex[1] < tile_bounds.min_y {
+    if vertex[1] < tile_bounds.min_y + EPSILON {
         snapped_vertex[1] = tile_bounds.min_y;
-    } else if vertex[1] > tile_bounds.max_y {
+    } else if vertex[1] > tile_bounds.max_y - EPSILON {
         snapped_vertex[1] = tile_bounds.max_y;
     }
 
     snapped_vertex
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn test_snap_to_tile_boundary() {
+        let bounds = TileBounds {
+            min_x: 0.0,
+            max_x: 1.0,
+            min_y: 0.0,
+            max_y: 1.0,
+        };
+
+        // 境界内の頂点はそのまま
+        let vertex = [0.5, 0.5, 1.0, 0.0, 0.0];
+        assert_eq!(snap_to_tile_boundary(vertex, &bounds), vertex);
+
+        // 境界外の頂点はスナップされる
+        let vertex = [-0.1, 1.1, 1.0, 0.0, 0.0];
+        assert_eq!(
+            snap_to_tile_boundary(vertex, &bounds),
+            [0.0, 1.0, 1.0, 0.0, 0.0]
+        );
+
+        // イプシロン付近の頂点のテスト
+        let vertex = [0.0 + 1e-11, 1.0 - 1e-11, 1.0, 0.0, 0.0];
+        assert_eq!(
+            snap_to_tile_boundary(vertex, &bounds),
+            [0.0, 1.0, 1.0, 0.0, 0.0]
+        );
+    }
+}

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.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
nusamai/src/sink/cesiumtiles/slice.rs (1)

18-23: 構造体のドキュメントと検証機能の追加を推奨

以下の改善を提案します:

  1. 構造体の目的と各フィールドの説明を追加
  2. 境界値の検証メソッドの実装(min <= max)
+/// タイルの境界を表す構造体
+/// 
+/// # フィールド
+/// * `min_x` - X座標の最小値
+/// * `max_x` - X座標の最大値
+/// * `min_y` - Y座標の最小値
+/// * `max_y` - Y座標の最大値
 struct TileBounds {
     min_x: f64,
     max_x: f64,
     min_y: f64,
     max_y: f64,
 }
+
+impl TileBounds {
+    /// 境界値が有効か検証する
+    fn is_valid(&self) -> bool {
+        self.min_x <= self.max_x && self.min_y <= self.max_y
+    }
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ad4563b and 78f90be.

📒 Files selected for processing (1)
  • nusamai/src/sink/cesiumtiles/slice.rs (5 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
nusamai/src/sink/cesiumtiles/slice.rs

[warning] 417-417: nusamai/src/sink/cesiumtiles/slice.rs#L417
Added line #L417 was not covered by tests


[warning] 469-469: nusamai/src/sink/cesiumtiles/slice.rs#L469
Added line #L469 was not covered by tests


[warning] 476-476: nusamai/src/sink/cesiumtiles/slice.rs#L476
Added line #L476 was not covered by tests

Comment on lines 406 to 428
let tile_bounds = TileBounds {
min_x: 0.0,
max_x: 1.0,
min_y: 0.0,
max_y: 1.0,
};

let rings: Vec<_> = poly_buf.rings().map(|r| r.raw_coords().to_vec()).collect();

for ring in rings.iter() {
if ring.is_empty() {
continue;
}

ring_buffer.clear();

for vertex in ring {
let snapped_vertex = snap_to_tile_boundary(*vertex, &tile_bounds);
ring_buffer.push(snapped_vertex);
}
let drained_ring: Vec<_> = ring_buffer.drain(..).collect();
poly_buf.add_ring(drained_ring);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

スナッピング処理の最適化を推奨

現在の実装では、以下の点で非効率的です:

  1. 不必要なベクターのコピー(to_vec()
  2. 二重のメモリ確保(ring_bufferdrained_ring

以下の最適化を提案します:

-            let rings: Vec<_> = poly_buf.rings().map(|r| r.raw_coords().to_vec()).collect();
-
-            for ring in rings.iter() {
+            let rings: Vec<_> = poly_buf.rings().collect();
+            poly_buf.clear();
+
+            for ring in rings {
                 if ring.is_empty() {
                     continue;
                 }
 
                 ring_buffer.clear();
 
-                for vertex in ring {
-                    let snapped_vertex = snap_to_tile_boundary(*vertex, &tile_bounds);
+                for vertex in ring.raw_coords() {
+                    let snapped_vertex = snap_to_tile_boundary(vertex, &tile_bounds);
                     ring_buffer.push(snapped_vertex);
                 }
-                let drained_ring: Vec<_> = ring_buffer.drain(..).collect();
-                poly_buf.add_ring(drained_ring);
+                poly_buf.add_ring(ring_buffer.drain(..));
             }

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 417-417: nusamai/src/sink/cesiumtiles/slice.rs#L417
Added line #L417 was not covered by tests

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.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
nusamai/src/sink/cesiumtiles/slice.rs (1)

18-23: 構造体のドキュメントを追加することを推奨

タイル境界を表現する重要な構造体なので、以下のようなドキュメントの追加を推奨します:

+/// タイルの境界を表現する構造体
+///
+/// # フィールド
+/// * `min_x` - X座標の最小値
+/// * `max_x` - X座標の最大値
+/// * `min_y` - Y座標の最小値
+/// * `max_y` - Y座標の最大値
 struct TileBounds {
     min_x: f64,
     max_x: f64,
     min_y: f64,
     max_y: f64,
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 78f90be and 2560841.

📒 Files selected for processing (1)
  • nusamai/src/sink/cesiumtiles/slice.rs (5 hunks)

Comment on lines 413 to 428
let rings: Vec<_> = poly_buf.rings().map(|r| r.raw_coords().to_vec()).collect();

for ring in rings.iter() {
if ring.is_empty() {
continue;
}

ring_buffer.clear();

for vertex in ring {
let snapped_vertex = snap_to_tile_boundary(*vertex, &tile_bounds);
ring_buffer.push(snapped_vertex);
}
let drained_ring: Vec<_> = std::mem::take(&mut ring_buffer).drain(..).collect();
poly_buf.add_ring(drained_ring);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

スナッピング処理の最適化が必要

現在の実装には以下の非効率な点があります:

  1. 不必要なベクターのコピー(to_vec()
  2. 二重のメモリ確保(ring_bufferdrained_ring

以下の最適化を提案します:

-            let rings: Vec<_> = poly_buf.rings().map(|r| r.raw_coords().to_vec()).collect();
-
-            for ring in rings.iter() {
+            let rings: Vec<_> = poly_buf.rings().collect();
+            poly_buf.clear();
+
+            for ring in rings {
                 if ring.is_empty() {
                     continue;
                 }

                 ring_buffer.clear();

-                for vertex in ring {
-                    let snapped_vertex = snap_to_tile_boundary(*vertex, &tile_bounds);
+                for vertex in ring.raw_coords() {
+                    let snapped_vertex = snap_to_tile_boundary(vertex, &tile_bounds);
                     ring_buffer.push(snapped_vertex);
                 }
-                let drained_ring: Vec<_> = ring_buffer.drain(..).collect();
-                poly_buf.add_ring(drained_ring);
+                poly_buf.add_ring(ring_buffer.drain(..));
             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let rings: Vec<_> = poly_buf.rings().map(|r| r.raw_coords().to_vec()).collect();
for ring in rings.iter() {
if ring.is_empty() {
continue;
}
ring_buffer.clear();
for vertex in ring {
let snapped_vertex = snap_to_tile_boundary(*vertex, &tile_bounds);
ring_buffer.push(snapped_vertex);
}
let drained_ring: Vec<_> = std::mem::take(&mut ring_buffer).drain(..).collect();
poly_buf.add_ring(drained_ring);
}
let rings: Vec<_> = poly_buf.rings().collect();
poly_buf.clear();
for ring in rings {
if ring.is_empty() {
continue;
}
ring_buffer.clear();
for vertex in ring.raw_coords() {
let snapped_vertex = snap_to_tile_boundary(vertex, &tile_bounds);
ring_buffer.push(snapped_vertex);
}
poly_buf.add_ring(ring_buffer.drain(..));
}

Comment on lines 465 to 482
fn snap_to_tile_boundary(vertex: [f64; 5], tile_bounds: &TileBounds) -> [f64; 5] {
let mut snapped_vertex = vertex;

if vertex[0] < tile_bounds.min_x {
snapped_vertex[0] = tile_bounds.min_x;
} else if vertex[0] > tile_bounds.max_x {
snapped_vertex[0] = tile_bounds.max_x;
}

// Snap y coordinate
if vertex[1] < tile_bounds.min_y {
snapped_vertex[1] = tile_bounds.min_y;
} else if vertex[1] > tile_bounds.max_y {
snapped_vertex[1] = tile_bounds.max_y;
}

snapped_vertex
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

スナッピング関数の改善が必要

以下の改善を推奨します:

  1. 浮動小数点の精度問題に対処するためのイプシロン値の追加
  2. 関数のドキュメント追加
  3. テストケースの追加
+/// 頂点をタイル境界にスナップする
+///
+/// # 引数
+/// * `vertex` - スナップ対象の頂点 [x, y, z, u, v]
+/// * `tile_bounds` - タイル境界
+///
+/// # 戻り値
+/// スナップされた頂点
 fn snap_to_tile_boundary(vertex: [f64; 5], tile_bounds: &TileBounds) -> [f64; 5] {
+    const EPSILON: f64 = 1e-10;
     let mut snapped_vertex = vertex;

-    if vertex[0] < tile_bounds.min_x {
+    if vertex[0] < tile_bounds.min_x + EPSILON {
         snapped_vertex[0] = tile_bounds.min_x;
-    } else if vertex[0] > tile_bounds.max_x {
+    } else if vertex[0] > tile_bounds.max_x - EPSILON {
         snapped_vertex[0] = tile_bounds.max_x;
     }

     // Snap y coordinate
-    if vertex[1] < tile_bounds.min_y {
+    if vertex[1] < tile_bounds.min_y + EPSILON {
         snapped_vertex[1] = tile_bounds.min_y;
-    } else if vertex[1] > tile_bounds.max_y {
+    } else if vertex[1] > tile_bounds.max_y - EPSILON {
         snapped_vertex[1] = tile_bounds.max_y;
     }

     snapped_vertex
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn snap_to_tile_boundary(vertex: [f64; 5], tile_bounds: &TileBounds) -> [f64; 5] {
let mut snapped_vertex = vertex;
if vertex[0] < tile_bounds.min_x {
snapped_vertex[0] = tile_bounds.min_x;
} else if vertex[0] > tile_bounds.max_x {
snapped_vertex[0] = tile_bounds.max_x;
}
// Snap y coordinate
if vertex[1] < tile_bounds.min_y {
snapped_vertex[1] = tile_bounds.min_y;
} else if vertex[1] > tile_bounds.max_y {
snapped_vertex[1] = tile_bounds.max_y;
}
snapped_vertex
}
/// 頂点をタイル境界にスナップする
///
/// # 引数
/// * `vertex` - スナップ対象の頂点 [x, y, z, u, v]
/// * `tile_bounds` - タイル境界
///
/// # 戻り値
/// スナップされた頂点
fn snap_to_tile_boundary(vertex: [f64; 5], tile_bounds: &TileBounds) -> [f64; 5] {
const EPSILON: f64 = 1e-10;
let mut snapped_vertex = vertex;
if vertex[0] < tile_bounds.min_x + EPSILON {
snapped_vertex[0] = tile_bounds.min_x;
} else if vertex[0] > tile_bounds.max_x - EPSILON {
snapped_vertex[0] = tile_bounds.max_x;
}
// Snap y coordinate
if vertex[1] < tile_bounds.min_y + EPSILON {
snapped_vertex[1] = tile_bounds.min_y;
} else if vertex[1] > tile_bounds.max_y - EPSILON {
snapped_vertex[1] = tile_bounds.max_y;
}
snapped_vertex
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3dtiles: ワイヤーフレーム表示時の不具合を調査
1 participant