GeoRectBounds(矩形範囲)
GeoRectBounds は、南西と北東の角の点で定義される矩形の地理的エリアを表します。地図領域の定義、グラウンドイメージの境界、ビューポート計算に使用されます。
コンストラクタ
Section titled “コンストラクタ”class GeoRectBounds( southWest: GeoPoint? = null, northEast: GeoPoint? = null)southWest: GeoPoint?: 矩形の南西角(左下)northEast: GeoPoint?: 矩形の北東角(右上)isEmpty: Boolean: 境界が定義されていない場合はtrueを返します
計算されるプロパティ
Section titled “計算されるプロパティ”center: GeoPoint?: 境界の中心点toSpan(): GeoPoint?: GeoPointInterface として範囲(幅/高さ)を返します
基本的な使用方法
Section titled “基本的な使用方法”// 矩形エリアを定義val bounds = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7649, -122.4294), northeast = GeoPoint.fromLatLong(37.7849, -122.4094))
// 空の境界(後で拡張)val bounds = GeoRectBounds()動的な境界の構築
Section titled “動的な境界の構築”境界は新しい点を含むように動的に拡張できます:
fun extend(point: GeoPointInterface)
// 使用例val bounds = GeoRectBounds() // 空からスタート
val points = listOf( GeoPoint.fromLatLong(37.7749, -122.4194), GeoPoint.fromLatLong(37.7849, -122.4094), GeoPoint.fromLatLong(37.7649, -122.4294))
points.forEach { point -> bounds.extend(point) // 各点を含むように境界が拡大}
println("最終境界: $bounds")val bounds1 = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7649, -122.4294), northEast = GeoPoint.fromLatLong(37.7749, -122.4194))
val bounds2 = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7749, -122.4194), northEast = GeoPoint.fromLatLong(37.7849, -122.4094))
val combinedBounds = bounds1.union(bounds2) // 両方のエリアを含む点と境界のテスト
Section titled “点と境界のテスト”点を含むかどうか
Section titled “点を含むかどうか”fun contains(point: GeoPointInterface): Boolean
// Usageval bounds = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7649, -122.4294), northEast = GeoPoint.fromLatLong(37.7849, -122.4094))
val testPoint = GeoPoint.fromLatLong(37.7749, -122.4194)val isInside = bounds.contains(testPoint)
println("Point is inside bounds: $isInside")fun intersects(other: GeoRectBounds): Boolean
// Usageval bounds1 = GeoRectBounds(/* ... */)val bounds2 = GeoRectBounds(/* ... */)
val doIntersect = bounds1.intersects(bounds2)println("Bounds intersect: $doIntersect")国際日付変更線
Section titled “国際日付変更線”GeoRectBounds は国際日付変更線(経度 ±180°)をまたぐ矩形を処理します:
// Bounds crossing the date lineval pacificBounds = GeoRectBounds( southWest = GeoPoint.fromLatLong(20, 170), // West of date line northEast = GeoPoint.fromLatLong(40, -170) // East of date line)
val pointInPacific = GeoPoint.fromLatLong(30, 175)val containsPoint = pacificBounds.contains(pointInPacific) // true空の境界の処理
Section titled “空の境界の処理”val emptyBounds = GeoRectBounds()
println(emptyBounds.isEmpty) // trueprintln(emptyBounds.center) // nullprintln(emptyBounds.toSpan()) // null
// Extending empty boundsemptyBounds.extend(GeoPoint.fromLatLong(37.7749, -122.4194))println(emptyBounds.isEmpty) // falseユーティリティメソッド
Section titled “ユーティリティメソッド”// For debuggingval bounds = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7649, -122.4294), northEast = GeoPoint.fromLatLong(37.7849, -122.4094))
println(bounds.toString())// Output: ((37.7649, -122.4294), (37.7849, -122.4094))fun toUrlValue(precision: Int = 6): String
// Usage for API callsval urlString = bounds.toUrlValue() // "37.764900,-122.429400,37.784900,-122.409400"val preciseString = bounds.toUrlValue(precision = 8)等価性の比較
Section titled “等価性の比較”fun equalsTo(other: GeoRectBounds): Boolean
// 使用例val bounds1 = GeoRectBounds(/* ... */)val bounds2 = GeoRectBounds(/* ... */)
val areEqual = bounds1.equalsTo(bounds2)