File size: 9,683 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# SPDX-License-Identifier: LGPL-2.1-or-later

from __future__ import annotations

from Metadata import export, constmethod
from PyObjectBase import PyObjectBase
from Vector import Vector
from Matrix import Matrix
from typing import overload, Any, Final, Tuple, Union

@export(
    TwinPointer="BoundBox3d",
    Constructor=True,
    Delete=True,
)
class BoundBox(PyObjectBase):
    """
    Base.BoundBox class.

    This class represents a bounding box.
    A bounding box is a rectangular cuboid which is a way to describe outer
    boundaries and is obtained from a lot of 3D types.
    It is often used to check if a 3D entity lies in the range of another object.
    Checking for bounding interference first can save a lot of computing time!
    An invalid BoundBox is represented by inconsistent values at each direction:
    The maximum float value of the system at the minimum coordinates, and the
    opposite value at the maximum coordinates.

    The following constructors are supported:

    BoundBox()
    Empty constructor. Returns an invalid BoundBox.

    BoundBox(boundBox)
    Copy constructor.
    boundBox : Base.BoundBox

    BoundBox(xMin, yMin=0, zMin=0, xMax=0, yMax=0, zMax=0)
    Define from the minimum and maximum values at each direction.
    xMin : float
        Minimum value at x-coordinate.
    yMin : float
        Minimum value at y-coordinate.
    zMin : float
        Minimum value at z-coordinate.
    xMax : float
        Maximum value at x-coordinate.
    yMax : float
        Maximum value at y-coordinate.
    zMax : float
        Maximum value at z-coordinate.

    App.BoundBox(min, max)
    Define from two containers representing the minimum and maximum values of the
    coordinates in each direction.
    min : Base.Vector, tuple
        Minimum values of the coordinates.
    max : Base.Vector, tuple
        Maximum values of the coordinates.

    Author: Juergen Riegel (FreeCAD@juergen-riegel.net)
    Licence: LGPL
    """

    Center: Final[Any] = None
    """Center point of the bounding box."""

    XMax: float = 0.0
    """The maximum x boundary position."""

    YMax: float = 0.0
    """The maximum y boundary position."""

    ZMax: float = 0.0
    """The maximum z boundary position."""

    XMin: float = 0.0
    """The minimum x boundary position."""

    YMin: float = 0.0
    """The minimum y boundary position."""

    ZMin: float = 0.0
    """The minimum z boundary position."""

    XLength: Final[float] = 0.0
    """Length of the bounding box in x direction."""

    YLength: Final[float] = 0.0
    """Length of the bounding box in y direction."""

    ZLength: Final[float] = 0.0
    """Length of the bounding box in z direction."""

    DiagonalLength: Final[float] = 0.0
    """Diagonal length of the bounding box."""

    # fmt: off
    @overload
    def __init__(self) -> None: ...
    @overload
    def __init__(self, boundBox: "BoundBox") -> None: ...
    @overload
    def __init__(
        self,
        xMin: float,
        yMin: float = 0,
        zMin: float = 0,
        xMax: float = 0,
        yMax: float = 0,
        zMax: float = 0,
    ) -> None:        ...
    @overload
    def __init__(
        self,
        min: Union[Vector, Tuple[float, float, float]],
        max: Union[Vector, Tuple[float, float, float]],
    ) -> None:        ...
    # fmt: on

    def setVoid(self) -> None:
        """
        Invalidate the bounding box.
        """
        ...

    @constmethod
    def isValid(self) -> bool:
        """
        Checks if the bounding box is valid.
        """
        ...

    @overload
    def add(self, minMax: Vector, /) -> None: ...
    @overload
    def add(self, minMax: Tuple[float, float, float], /) -> None: ...
    @overload
    def add(self, x: float, y: float, z: float, /) -> None: ...
    def add(self, *args: Any, **kwargs: Any) -> None:
        """
        Increase the maximum values or decrease the minimum values of this BoundBox by
        replacing the current values with the given values, so the bounding box can grow
        but not shrink.

        minMax : Base.Vector, tuple
            Values to enlarge at each direction.
        x : float
            Value to enlarge at x-direction.
        y : float
            Value to enlarge at y-direction.
        z : float
            Value to enlarge at z-direction.
        """
        ...

    @constmethod
    def getPoint(self, index: int, /) -> Vector:
        """
        Get the point of the given index.
        The index must be in the range of [0, 7].

        index : int
        """
        ...

    @constmethod
    def getEdge(self, index: int, /) -> Tuple[Vector, ...]:
        """
        Get the edge points of the given index.
        The index must be in the range of [0, 11].

        index : int
        """
        ...

    @overload
    def closestPoint(self, point: Vector, /) -> Vector: ...
    @overload
    def closestPoint(self, x: float, y: float, z: float, /) -> Vector: ...
    @constmethod
    def closestPoint(self, *args: Any, **kwargs: Any) -> Vector:
        """
        Get the closest point of the bounding box to the given point.

        point : Base.Vector, tuple
            Coordinates of the given point.
        x : float
            X-coordinate of the given point.
        y : float
            Y-coordinate of the given point.
        z : float
            Z-coordinate of the given point.
        """
        ...

    @overload
    def intersect(self, boundBox2: "BoundBox", /) -> bool: ...
    @overload
    def intersect(
        self,
        base: Union[Vector, Tuple[float, float, float]],
        dir: Union[Vector, Tuple[float, float, float]],
        /,
    ) -> bool: ...
    def intersect(self, *args: Any) -> bool:
        """
        Checks if the given object intersects with this bounding box. That can be
        another bounding box or a line specified by base and direction.

        boundBox2 : Base.BoundBox
        base : Base.Vector, tuple
        dir : Base.Vector, tuple
        """
        ...

    def intersected(self, boundBox2: "BoundBox", /) -> "BoundBox":
        """
        Returns the intersection of this and the given bounding box.

        boundBox2 : Base.BoundBox
        """
        ...

    def united(self, boundBox2: "BoundBox", /) -> "BoundBox":
        """
        Returns the union of this and the given bounding box.

        boundBox2 : Base.BoundBox
        """
        ...

    def enlarge(self, variation: float, /) -> None:
        """
        Decrease the minimum values and increase the maximum values by the given value.
        A negative value shrinks the bounding box.

        variation : float
        """
        ...

    def getIntersectionPoint(self, base: Vector, dir: Vector, epsilon: float = 0.0001, /) -> Vector:
        """
        Calculate the intersection point of a line with the bounding box.
        The base point must lie inside the bounding box, if not an exception is thrown.

        base : Base.Vector
            Base point of the line.
        dir : Base.Vector
            Direction of the line.
        epsilon : float
            Bounding box size tolerance.
        """
        ...

    @overload
    def move(self, displacement: Vector, /) -> None: ...
    @overload
    def move(self, displacement: Tuple[float, float, float], /) -> None: ...
    @overload
    def move(self, x: float, y: float, z: float, /) -> None: ...
    def move(self, *args: Any, **kwargs: Any) -> None:
        """
        Move the bounding box by the given values.

        displacement : Base.Vector, tuple
            Displacement at each direction.
        x : float
            Displacement at x-direction.
        y : float
            Displacement at y-direction.
        z : float
            Displacement at z-direction.
        """
        ...

    @overload
    def scale(self, factor: Vector, /) -> None: ...
    @overload
    def scale(self, factor: Tuple[float, float, float], /) -> None: ...
    @overload
    def scale(self, x: float, y: float, z: float, /) -> None: ...
    def scale(self, *args: Any, **kwargs: Any) -> None:
        """
        Scale the bounding box by the given values.

        factor : Base.Vector, tuple
            Factor scale at each direction.
        x : float
            Scale at x-direction.
        y : float
            Scale at y-direction.
        z : float
            Scale at z-direction.
        """
        ...

    def transformed(self, matrix: Matrix, /) -> "BoundBox":
        """
        Returns a new BoundBox containing the transformed rectangular cuboid
        represented by this BoundBox.

        matrix : Base.Matrix
            Transformation matrix.
        """
        ...

    def isCutPlane(self, base: Vector, normal: Vector, /) -> bool:
        """
        Check if the plane specified by base and normal intersects (cuts) this bounding
        box.

        base : Base.Vector
        normal : Base.Vector
        """
        ...

    @overload
    def isInside(self, object: Vector, /) -> bool: ...
    @overload
    def isInside(self, object: "BoundBox", /) -> bool: ...
    @overload
    def isInside(self, x: float, y: float, z: float, /) -> bool: ...
    def isInside(self, *args: Any) -> bool:
        """
        Check if a point or a bounding box is inside this bounding box.

        object : Base.Vector, Base.BoundBox
            Object to check if it is inside this bounding box.
        x : float
            X-coordinate of the point to check.
        y : float
            Y-coordinate of the point to check.
        z : float
            Z-coordinate of the point to check.
        """
        ...