Skip to content

Commit 95dc2f6

Browse files
committed
Migrate geometry objects to Kotlin
1 parent 3471b4d commit 95dc2f6

File tree

3 files changed

+53
-83
lines changed

3 files changed

+53
-83
lines changed

library/src/main/java/com/google/maps/android/geometry/Bounds.java

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2023 Google LLC.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.maps.android.geometry
18+
19+
/**
20+
* Represents an area in the cartesian plane.
21+
*/
22+
data class Bounds(
23+
@JvmField val minX: Double,
24+
@JvmField val maxX: Double,
25+
@JvmField val minY: Double,
26+
@JvmField val maxY: Double
27+
) {
28+
@JvmField val midX: Double = (minX + maxX) / 2
29+
@JvmField val midY: Double = (minY + maxY) / 2
30+
31+
fun contains(x: Double, y: Double): Boolean {
32+
return minX <= x && x <= maxX && minY <= y && y <= maxY
33+
}
34+
35+
fun contains(point: Point): Boolean {
36+
return contains(point.x, point.y)
37+
}
38+
39+
fun intersects(minX: Double, maxX: Double, minY: Double, maxY: Double): Boolean {
40+
return minX < this.maxX && this.minX < maxX && minY < this.maxY && this.minY < maxY
41+
}
42+
43+
fun intersects(bounds: Bounds): Boolean {
44+
return intersects(bounds.minX, bounds.maxX, bounds.minY, bounds.maxY)
45+
}
46+
47+
fun contains(bounds: Bounds): Boolean {
48+
return bounds.minX >= minX && bounds.maxX <= maxX && bounds.minY >= minY && bounds.maxY <= maxY
49+
}
50+
}

library/src/main/java/com/google/maps/android/geometry/Point.java renamed to library/src/main/java/com/google/maps/android/geometry/Point.kt

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Google Inc.
2+
* Copyright 2023 Google LLC.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,25 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.maps.android.geometry;
17+
package com.google.maps.android.geometry
1818

19-
import androidx.annotation.NonNull;
20-
21-
public class Point {
22-
public final double x;
23-
public final double y;
24-
25-
public Point(double x, double y) {
26-
this.x = x;
27-
this.y = y;
28-
}
29-
30-
@NonNull
31-
@Override
32-
public String toString() {
33-
return "Point{" +
34-
"x=" + x +
35-
", y=" + y +
36-
'}';
37-
}
38-
}
19+
open class Point(@JvmField val x: Double, @JvmField val y: Double)

0 commit comments

Comments
 (0)