Repository navigation
Conversation
HexCellRegistry marked the K-D tree dirty on every setPoint and removePoint, including updates that left the marker in the same cell and additions to a cell that already existed. The tree holds cells, not markers, so the next spatial query rebuilt it over every cell for nothing. It is now marked dirty only when the set of cells changes, and an existing cell is not replaced, so the cell returned is the one the tree holds. KDTree sorted a copy of the cells at every level. It now selects only the median inside one array (Wirth's quickselect) and recurses on index ranges. Hex cell centres share x per column, so the partition closes in from both ends; a one-sided partition is O(n^2) on equal keys. Same change as MapConductor/js-sdk-core#20. android-sdk-core already had the registry part.
Contributor
Author
|
K-D 木は f6d85c8 で MarkerGridIndex に置き換え済みで、HexCellRegistry/KDTree はマーカー検索で使われていないため、この最適化は不要。K-D 木そのものの削除は別 PR で行う。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MapConductor/js-sdk-core#20 と同じ修正の iOS 版。
js-sdk-core#20 との対応
pointerdownでドラッグ可能なマーカーが無ければ引き当てないDefaultMarkerEventController.handleLongPress)で、タッチのたびに空間インデックスを引かないHexCellRegistry:セルの集合が変わったときだけ作り直しの印を付ける・既にあるセルは置き換えないKDTree:quickselect で構築不具合
HexCellRegistryはsetPoint/removePointのたびに K-D 木の作り直しの印を付けていた。位置の変わらない更新や、既にあるセルへの追加でも同じで、次の空間検索(タイル方式のマーカーのタップ判定など)が全セルの再構築を待つ。MarkerManager.updateEntityは毎回setPointを呼ぶので、アイコンの差し替えなどでも当たる。KDTreeの構築は、階層ごとにセルの配列を並べ替えて複製していた。修正
HexCellRegistry:K-D 木が持つのはセルなので、セルの集合が変わったときだけ作り直しの印を付ける。同じセルのままなら何もしない。既にあるセルは置き換えず、返すのもそのセル(木が持っているセルと揃える)。removePointも、セルに他のマーカーが残っていれば印を付けないKDTree:1 本の配列の中で中央値だけを選んで(Wirth の quickselect)、添字の範囲で再帰する。六角セルの中心は列ごとに同じ x を持ち、等しい値が大量に並ぶので、左右から寄せる分割にした公開 API の変更は無い(
api/MapConductorCore.api.swiftは変わらない)。確認
xcodebuild build-for-testing -destination 'generic/platform=iOS':通るgeocell/のソースをそのまま macOS 向けの SwiftPM パッケージに入れ(MarkerEntity/MarkerStateはidとpositionだけのスタブ)、以下を流したMarkerSpatialIndexTests(8 件)と既存のKDTreeRadiusTests:すべて通るnearest/withinRadiusWithDistance/nearestKWithDistanceが総当たりと一致する(同じ座標が並ぶ 40×40 の格子・ばらばらの 3,000 点)