1+ /*
2+ * Copyright 2023 Google Inc.
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+ }
0 commit comments