|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | + |
| 19 | +class Box3D: |
| 20 | + """Planar 3D bounding box. Always a valid finite bbox; absence of a bbox |
| 21 | + is represented by ``None`` (SQL NULL) at the column level rather than by an |
| 22 | + in-band sentinel. Matches PostGIS ``box3d`` semantics. Geometries without a |
| 23 | + Z dimension contribute ``z = 0``; inverted bounds (``xmin > xmax`` etc.) |
| 24 | + are rejected by the Box3D predicates since Z has no wraparound |
| 25 | + convention.""" |
| 26 | + |
| 27 | + __slots__ = ("xmin", "ymin", "zmin", "xmax", "ymax", "zmax") |
| 28 | + |
| 29 | + def __init__( |
| 30 | + self, |
| 31 | + xmin: float, |
| 32 | + ymin: float, |
| 33 | + zmin: float, |
| 34 | + xmax: float, |
| 35 | + ymax: float, |
| 36 | + zmax: float, |
| 37 | + ): |
| 38 | + self.xmin = float(xmin) |
| 39 | + self.ymin = float(ymin) |
| 40 | + self.zmin = float(zmin) |
| 41 | + self.xmax = float(xmax) |
| 42 | + self.ymax = float(ymax) |
| 43 | + self.zmax = float(zmax) |
| 44 | + |
| 45 | + def __eq__(self, other: object) -> bool: |
| 46 | + if not isinstance(other, Box3D): |
| 47 | + return NotImplemented |
| 48 | + return ( |
| 49 | + self.xmin == other.xmin |
| 50 | + and self.ymin == other.ymin |
| 51 | + and self.zmin == other.zmin |
| 52 | + and self.xmax == other.xmax |
| 53 | + and self.ymax == other.ymax |
| 54 | + and self.zmax == other.zmax |
| 55 | + ) |
| 56 | + |
| 57 | + def __hash__(self) -> int: |
| 58 | + return hash((self.xmin, self.ymin, self.zmin, self.xmax, self.ymax, self.zmax)) |
| 59 | + |
| 60 | + def __repr__(self) -> str: |
| 61 | + return ( |
| 62 | + f"Box3D({self.xmin}, {self.ymin}, {self.zmin}, " |
| 63 | + f"{self.xmax}, {self.ymax}, {self.zmax})" |
| 64 | + ) |
0 commit comments