regionunion.go (1950B)
1 // Copyright 2020 Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package s2 16 17 // A RegionUnion represents a union of possibly overlapping regions. 18 // It is convenient for computing a covering of a set of regions. 19 type RegionUnion []Region 20 21 // CapBound returns a bounding cap for this RegionUnion. 22 func (ru RegionUnion) CapBound() Cap { return ru.RectBound().CapBound() } 23 24 // RectBound returns a bounding latitude-longitude rectangle for this RegionUnion. 25 func (ru RegionUnion) RectBound() Rect { 26 ret := EmptyRect() 27 for _, reg := range ru { 28 ret = ret.Union(reg.RectBound()) 29 } 30 return ret 31 } 32 33 // ContainsCell reports whether the given Cell is contained by this RegionUnion. 34 func (ru RegionUnion) ContainsCell(c Cell) bool { 35 for _, reg := range ru { 36 if reg.ContainsCell(c) { 37 return true 38 } 39 } 40 return false 41 } 42 43 // IntersectsCell reports whether this RegionUnion intersects the given cell. 44 func (ru RegionUnion) IntersectsCell(c Cell) bool { 45 for _, reg := range ru { 46 if reg.IntersectsCell(c) { 47 return true 48 } 49 } 50 return false 51 } 52 53 // ContainsPoint reports whether this RegionUnion contains the Point. 54 func (ru RegionUnion) ContainsPoint(p Point) bool { 55 for _, reg := range ru { 56 if reg.ContainsPoint(p) { 57 return true 58 } 59 } 60 return false 61 } 62 63 // CellUnionBound computes a covering of the RegionUnion. 64 func (ru RegionUnion) CellUnionBound() []CellID { 65 return ru.CapBound().CellUnionBound() 66 }