Struct BoundingCube
- Namespace
- CADability
- Assembly
- CADability.dll
Represents a bounding cuboid, that is an extent in 3 dimensions
[JsonVersion(serializeAsStruct = true, version = 1)]
public struct BoundingCube : ISerializable, IJsonSerialize
- Implements
- Inherited Members
Constructors
BoundingCube(GeoPoint, double)
Constructs a equal sided BoundingCube from a center point and a "radius" (half width)
public BoundingCube(GeoPoint center, double halfSize)
Parameters
BoundingCube(params GeoPoint[])
Constructs a BoundingCube, that encloses all given points
public BoundingCube(params GeoPoint[] p)
Parameters
pGeoPoint[]points to enclose
BoundingCube(IEnumerable<IGeoObject>)
Constructs the BoundingCube that encloses the extents (GetExtent(0.0)) of all given objects. For an empty
enumeration the result is the EmptyBoundingCube.
public BoundingCube(IEnumerable<IGeoObject> objects)
Parameters
objectsIEnumerable<IGeoObject>the objects to enclose
BoundingCube(double, double, double, double, double, double)
Constructs a BoundingCube from minimum and maximum values
public BoundingCube(double Xmin, double Xmax, double Ymin, double Ymax, double Zmin, double Zmax)
Parameters
XmindoubleMinimum in x-direction
XmaxdoubleMaximum in x-direction
YmindoubleMinimum in y-direction
YmaxdoubleMaximum in y-direction
ZmindoubleMinimum in z-direction
ZmaxdoubleMaximum in z-direction
BoundingCube(SerializationInfo, StreamingContext)
Constructor required by deserialization
public BoundingCube(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
UnitBoundingCube
BoundingCube defining the interval [0,1] in all directions
public static BoundingCube UnitBoundingCube
Field Value
Xmax
The limits of the cube in the three coordinate directions. For the EmptyBoundingCube the minima are MaxValue and the maxima MinValue, so that MinMax(GeoPoint) can grow it from there. The fields may be set directly; IsEmpty and IsValid check the state.
public double Xmax
Field Value
Xmin
The limits of the cube in the three coordinate directions. For the EmptyBoundingCube the minima are MaxValue and the maxima MinValue, so that MinMax(GeoPoint) can grow it from there. The fields may be set directly; IsEmpty and IsValid check the state.
public double Xmin
Field Value
Ymax
The limits of the cube in the three coordinate directions. For the EmptyBoundingCube the minima are MaxValue and the maxima MinValue, so that MinMax(GeoPoint) can grow it from there. The fields may be set directly; IsEmpty and IsValid check the state.
public double Ymax
Field Value
Ymin
The limits of the cube in the three coordinate directions. For the EmptyBoundingCube the minima are MaxValue and the maxima MinValue, so that MinMax(GeoPoint) can grow it from there. The fields may be set directly; IsEmpty and IsValid check the state.
public double Ymin
Field Value
Zmax
The limits of the cube in the three coordinate directions. For the EmptyBoundingCube the minima are MaxValue and the maxima MinValue, so that MinMax(GeoPoint) can grow it from there. The fields may be set directly; IsEmpty and IsValid check the state.
public double Zmax
Field Value
Zmin
The limits of the cube in the three coordinate directions. For the EmptyBoundingCube the minima are MaxValue and the maxima MinValue, so that MinMax(GeoPoint) can grow it from there. The fields may be set directly; IsEmpty and IsValid check the state.
public double Zmin
Field Value
Properties
DiagonalLength
The length of the space diagonal, i.e. the distance between the vertices (Xmin,Ymin,Zmin) and (Xmax,Ymax,Zmax). Often used as a measure for precision values relative to the size of an object, whereas Size is the sum of the three edge lengths.
public double DiagonalLength { get; }
Property Value
EmptyBoundingCube
Empty BoundingCube. Defined by the special values MinValue and MaxValue. Often used with the MinMax(GeoPoint) or MinMax(BoundingCube) Methods.
public static BoundingCube EmptyBoundingCube { get; }
Property Value
InfiniteBoundingCube
public static BoundingCube InfiniteBoundingCube { get; }
Property Value
IsEmpty
Returns true if this is the special empty cube
public bool IsEmpty { get; }
Property Value
IsValid
True, if all limits are finite numbers (neither NaN nor infinite). The EmptyBoundingCube is valid in this sense; test for it with IsEmpty.
public bool IsValid { get; }
Property Value
LineNumbers
Gets an array[12,2] of pairs of point indices defining the 12 edges of this cube. Indices are to the Points
public int[,] LineNumbers { get; }
Property Value
- int[,]
Lines
Gets the 12 edges of the cube as a GeoPoint[12, 2] array
public GeoPoint[,] Lines { get; }
Property Value
- GeoPoint[,]
MaxSide
Gets the length of the maximum side
public double MaxSide { get; }
Property Value
Points
Gets an array of the 8 vertices of this cube
public GeoPoint[] Points { get; }
Property Value
- GeoPoint[]
Size
Gets the sum of width, height and deepth
public double Size { get; }
Property Value
Volume
Gets the product of width, height and deepth
public double Volume { get; }
Property Value
XDiff
Gets the extension in x direction
public double XDiff { get; }
Property Value
YDiff
Gets the extension in y direction
public double YDiff { get; }
Property Value
ZDiff
Gets the extension in z direction
public double ZDiff { get; }
Property Value
Methods
Clip(ICurve)
Clips the given curve by this cube: the curve is split at its intersections with the six face planes and those pieces whose middle point lies inside the cube are returned as trimmed clones. The curve itself is not changed.
public ICurve[] Clip(ICurve toClip)
Parameters
toClipICurvethe curve to clip
Returns
- ICurve[]
the parts of the curve inside the cube, an empty array when the curve lies completely outside
ClipAxis(Axis, out GeoPoint, out GeoPoint)
Clips the infinite line given by axis by this cube (see ClipLine(ref GeoPoint, ref GeoPoint)).
public bool ClipAxis(Axis axis, out GeoPoint startPoint, out GeoPoint endPoint)
Parameters
axisAxisthe line to clip
startPointGeoPointstart of the part of the line inside the cube, in the direction of the axis
endPointGeoPointend of the part of the line inside the cube
Returns
- bool
true, if the line passes through the cube; false if it misses the cube, the two points are then meaningless
ClipLine(ref GeoPoint, ref GeoPoint)
Clips the provided line (defined by start and end) by this cube.
Returns true if the line interferes with this boundingcube, modifies the start and endpoint in the parameters if clipping occures
public bool ClipLine(ref GeoPoint start, ref GeoPoint end)
Parameters
startGeoPointStartpoint of the line, may be changed upon return
endGeoPointEndpoint of the line, may be changed upon return
Returns
- bool
true if the line and this cube interfere
Contains(BoundingCube)
Returns true if this cube contains the provided cube. (<= will be checked)
public bool Contains(BoundingCube extn)
Parameters
extnBoundingCubeCube to be checked
Returns
- bool
trueif there is containment
Contains(GeoPoint)
Returns true if this cube contains the provided point. (<= will be checked)
public bool Contains(GeoPoint p)
Parameters
pGeoPointThe Point
Returns
- bool
trueif there is containment
Contains(GeoPoint, double)
Returns true if this cube contains the provided point.
Points within the cube extended by precision
will also be accepted.
public bool Contains(GeoPoint p, double prec)
Parameters
Returns
- bool
trueif there is containment
Disjoint(BoundingCube, BoundingCube)
Returns true if the two cubes are disjoint (do not overlap and do not touch)
public static bool Disjoint(BoundingCube b1, BoundingCube b2)
Parameters
b1BoundingCubeFirst cube
b2BoundingCubeSecond cube
Returns
- bool
true if disjoint
Equals(object)
Determines whether the specified object is equal to this instance.
public override bool Equals(object obj)
Parameters
Returns
Expand(double)
Expands the bounding cube by the given value in all directions.
public void Expand(double w)
Parameters
wdoubleoffset to expand with
GetCenter()
Returns the center of this BoundingCube
public GeoPoint GetCenter()
Returns
GetExtent(Projection)
Returns the extent of the projected BoundingCube
public BoundingRect GetExtent(Projection pr)
Parameters
prProjectionthe projection
Returns
- BoundingRect
the resulting 2-dimensional extent
GetHashCode()
public override int GetHashCode()
Returns
GetObjectData(IJsonWriteData)
Implements GetObjectData(IJsonWriteData): writes the six limits as a list of values.
public void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDatathe JSON writer
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
GetPlanes()
Returns the 6 planes of the faces of this cube as PlaneSurfaces, in the order x=Xmin, y=Ymin, z=Zmin, z=Zmax, y=Ymax, x=Xmax (the same order as the faces of GetSides()). For a degenerated cube, where a face collapses to a line or a point, an empty array is returned.
public PlaneSurface[] GetPlanes()
Returns
- PlaneSurface[]
the planes of the faces
GetSides()
Returns 6 planar faces, the faces of this cube
public Face[] GetSides()
Returns
- Face[]
the faces
GetSolid()
Returns a solid cube as a Solid.
public Solid GetSolid()
Returns
- Solid
the solid
Interferes(BoundingCube)
Checks the interference of this cube with the other provided cube
public bool Interferes(BoundingCube bc)
Parameters
bcBoundingCubethe other cube to test with
Returns
- bool
true if the two cubes interfere (overlap)
Interferes(GeoPoint, GeoPoint, GeoPoint, GeoPoint)
Returns true if the provided tetrahedron (given by the four points tetra1..tetra4) and this BoundingCube interfere
public bool Interferes(GeoPoint tetra1, GeoPoint tetra2, GeoPoint tetra3, GeoPoint tetra4)
Parameters
tetra1GeoPoint1st tetrahedron vertex
tetra2GeoPoint2nd tetrahedron vertex
tetra3GeoPoint3rd tetrahedron vertex
tetra4GeoPoint4th tetrahedron vertex
Returns
- bool
True if objects interfere
Interferes(GeoPoint, GeoVector, GeoVector, GeoVector)
Checks the interference of this cube with the provided parallelepiped (the affine projection of a cube)
public bool Interferes(GeoPoint loc, GeoVector dirx, GeoVector diry, GeoVector dirz)
Parameters
Returns
Interferes(GeoPoint, GeoVector, double, bool)
Returns true if the given line intersects the this bounding cube. Returns false otherwise.
public bool Interferes(GeoPoint start, GeoVector dir, double maxdist, bool onlyForward)
Parameters
startGeoPointStartpoint of the line
dirGeoVectorDirection of the line
maxdistdoubleMaximum allowable distance from the line
onlyForwardboolSet to true, if only the positive ray should be cinsidered
Returns
Interferes(ref GeoPoint, ref GeoPoint)
Returns true if the given line segment intersects the this bounding cube. Returns false otherwise.
public bool Interferes(ref GeoPoint start, ref GeoPoint end)
Parameters
Returns
- bool
True if intersection
Interferes(ref GeoPoint, ref GeoPoint, ref GeoPoint)
Returns true when the triangle defined by tri1, tri2 and tri3
(including the inside of the triangle) and this BoundingCube interfere.
public bool Interferes(ref GeoPoint tri1, ref GeoPoint tri2, ref GeoPoint tri3)
Parameters
tri1GeoPointFirst point of triangle
tri2GeoPointSecond point of triangle
tri3GeoPointThird point of triangle
Returns
- bool
true if interference, false otherwise
Interferes(GeoPoint[])
Checks the interference of this cube with the provided polyline. The array of points
defines a polyline connecting consecutive points.
public bool Interferes(GeoPoint[] points)
Parameters
pointsGeoPoint[]The polyline
Returns
- bool
truewhen some part of the polyline interferes with this cube
Interferes(GeoPoint[], int[])
Checks the interference of this cube with the provided triangles. The triangles are defined
by three points each. Each triple of indices in triangleIndex defines one
triangle. Not only the edges of the triangle are checked but also the inner surface.
public bool Interferes(GeoPoint[] trianglePoint, int[] triangleIndex)
Parameters
trianglePointGeoPoint[]Array of vertives of the triangles
triangleIndexint[]Indices to
trianglePoint, each triple defines one triangle
Returns
- bool
trueif any of the provides triangles interferes with this cube
Interferes(Plane)
Returns true if the given plane intersects the this bounding cube. Returns false otherwise.
public bool Interferes(Plane plane)
Parameters
planePlaneThe plane to test with
Returns
- bool
true if intersection
Interferes(Projection, BoundingRect)
Returns true, if the provided rectangle rect and this BoundingCube interfere with the provided projection.
public bool Interferes(Projection projection, BoundingRect rect)
Parameters
projectionProjectionThe projection
rectBoundingRectThe rectangle
Returns
- bool
ture if interference, false otherwise
Interferes(PickArea)
Checks the interference of this cube with the provided area. The pickarea
is either a rectangular prism of infinite length or a frustum.
public bool Interferes(Projection.PickArea area)
Parameters
areaProjection.PickArea
Returns
IsOnBounds(GeoPoint, double)
Tests whether the provided point toTest falls on the bounds of this
cube with respect to precision.
public bool IsOnBounds(GeoPoint toTest, double precision)
Parameters
Returns
- bool
True if on bounds, false otherwise
MinMax(BoundingCube)
Makes this BoundingCube include the provided BoundingCube. You can start with an EmptyBoundingCube
public void MinMax(BoundingCube b)
Parameters
bBoundingCubeCube to be included
MinMax(GeoPoint)
Makes this BoundingCube include the provided point. You can start with an EmptyBoundingCube
public void MinMax(GeoPoint p)
Parameters
pGeoPointPoint to be included
MinMax(IEnumerable<IGeoObject>)
Makes this BoundingCube include all the specified objects
public void MinMax(IEnumerable<IGeoObject> objects)
Parameters
objectsIEnumerable<IGeoObject>
Modify(ModOp)
Modifies this cube according to the provided modification. If this modification contains a rotation the resulting cube will contain the rotated original cube. BoundingCubes are always axis aligned.
public void Modify(ModOp m)
Parameters
mModOpModification
OnSameSide(params GeoPoint[])
Checks whether all given points lie outside of this cube beyond the same face, i.e. one of the six face planes separates all the points from the cube. If so, nothing spanned by these points (a line segment, a triangle, a tetrahedron) can interfere with the cube. The converse does not hold: false does not mean that there is an interference.
public bool OnSameSide(params GeoPoint[] pnts)
Parameters
pntsGeoPoint[]the points to test
Returns
- bool
true, if all points are beyond the same face of the cube
Set(double, double, double, double, double, double)
Sets all six limits of this cube at once.
public void Set(double Xmin, double Xmax, double Ymin, double Ymax, double Zmin, double Zmax)
Parameters
XmindoubleMinimum in x-direction
XmaxdoubleMaximum in x-direction
YmindoubleMinimum in y-direction
YmaxdoubleMaximum in y-direction
ZmindoubleMinimum in z-direction
ZmaxdoubleMaximum in z-direction
SetObjectData(IJsonReadData)
Implements SetObjectData(IJsonReadData). Does nothing, because a BoundingCube is serialized as a struct and read back by a constructor taking the stored values.
public void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDatanot used
ToString()
Returns a string that represents this instance.
public override string ToString()
Returns
Operators
operator +(BoundingCube, BoundingCube)
Returns the smallest cube that contains both cubes (the union of their extents), like MinMax(BoundingCube) but without changing the operands.
public static BoundingCube operator +(BoundingCube b1, BoundingCube b2)
Parameters
b1BoundingCubefirst cube
b2BoundingCubesecond cube
Returns
- BoundingCube
the enclosing cube