Commit | Line | Data |
---|---|---|
973c2be1 | 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 2 | // |
973c2be1 | 3 | // This file is part of Open CASCADE Technology software library. |
b311480e | 4 | // |
d5f74e42 | 5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
9 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 10 | // |
973c2be1 | 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. | |
b311480e | 13 | |
92d1589b A |
14 | #include <Bnd_Sphere.hxx> |
15 | ||
16 | Bnd_Sphere::Bnd_Sphere() | |
17 | : myCenter (0., 0., 0.), | |
18 | myRadius (0.), | |
19 | myIsValid (Standard_False), | |
20 | myU (0), | |
21 | myV (0) | |
22 | {} | |
23 | ||
24 | Bnd_Sphere::Bnd_Sphere( const gp_XYZ& theCenter, const Standard_Real theRadius, | |
25 | const Standard_Integer theU, const Standard_Integer theV ) | |
26 | : myCenter (theCenter), | |
27 | myRadius (theRadius), | |
28 | myIsValid (Standard_False), | |
29 | myU (theU), | |
30 | myV (theV) | |
31 | {} | |
32 | ||
33 | void Bnd_Sphere::SquareDistances( const gp_XYZ& theXYZ, | |
34 | Standard_Real& theMin, Standard_Real& theMax ) const | |
35 | { | |
36 | theMax = ( theXYZ - myCenter ).SquareModulus(); | |
37 | theMin = ( theMax - myRadius <0 ? 0.0 : theMax - myRadius * myRadius ); | |
38 | theMax += myRadius * myRadius; | |
39 | } | |
40 | ||
41 | void Bnd_Sphere::Distances( const gp_XYZ& theXYZ, | |
42 | Standard_Real& theMin, Standard_Real& theMax ) const | |
43 | { | |
44 | theMax = ( theXYZ - myCenter ).Modulus(); | |
45 | theMin = ( theMax - myRadius <0 ? 0.0 : theMax - myRadius ); | |
46 | theMax += myRadius; | |
47 | } | |
48 | ||
49 | Standard_Boolean Bnd_Sphere::Project(const gp_XYZ& theNode, gp_XYZ& theProjNode, Standard_Real& theDist, Standard_Boolean& theInside) const | |
50 | { | |
51 | theProjNode = myCenter; | |
52 | theDist = ( theNode - theProjNode ).Modulus(); | |
53 | theInside = Standard_True; | |
54 | return Standard_True; | |
55 | } | |
56 | ||
57 | Standard_Real Bnd_Sphere::Distance(const gp_XYZ& theNode) const | |
58 | { | |
59 | return ( theNode - myCenter ).Modulus(); | |
60 | } | |
61 | ||
62 | Standard_Real Bnd_Sphere::SquareDistance(const gp_XYZ& theNode) const | |
63 | { | |
64 | return ( theNode - myCenter ).SquareModulus(); | |
65 | } | |
66 | ||
67 | void Bnd_Sphere::Add( const Bnd_Sphere& theOther) | |
68 | { | |
69 | if ( myRadius < 0.0 ) | |
70 | { | |
71 | // not initialised yet | |
72 | *this = theOther; | |
73 | return; | |
74 | } | |
75 | ||
76 | const Standard_Real aDist = (myCenter - theOther.myCenter).Modulus(); | |
77 | if ( myRadius + aDist <= theOther.myRadius ) | |
78 | { | |
79 | // the other sphere is larger and encloses this | |
80 | *this = theOther; | |
81 | return; | |
82 | } | |
83 | ||
84 | if ( theOther.myRadius + aDist <= myRadius ) | |
85 | return; // this sphere encloses other | |
86 | ||
87 | // expansion | |
88 | const Standard_Real dfR = ( aDist + myRadius + theOther.myRadius ) * 0.5; | |
89 | const Standard_Real aParamOnDiam = ( dfR - myRadius ) / aDist; | |
90 | myCenter = myCenter * ( 1.0 - aParamOnDiam ) + theOther.myCenter * aParamOnDiam; | |
91 | myRadius = dfR; | |
92 | myIsValid = Standard_False; | |
93 | } | |
94 | ||
95 | Standard_Boolean Bnd_Sphere::IsOut( const Bnd_Sphere& theOther ) const | |
96 | { | |
97 | return (myCenter - theOther.myCenter).SquareModulus() > (myRadius + theOther.myRadius) * (myRadius + theOther.myRadius); | |
98 | } | |
99 | ||
100 | Standard_Boolean Bnd_Sphere::IsOut( const gp_XYZ& theXYZ, | |
101 | Standard_Real& theMaxDist) const | |
102 | { | |
103 | Standard_Real aCurMinDist, aCurMaxDist; | |
104 | Distances( theXYZ, aCurMinDist, aCurMaxDist ); | |
105 | if ( aCurMinDist > theMaxDist ) | |
106 | return Standard_True; | |
107 | if( myIsValid && aCurMaxDist < theMaxDist ) | |
108 | theMaxDist = aCurMaxDist; | |
109 | return Standard_False; | |
110 | } | |
111 | ||
112 | Standard_Real Bnd_Sphere::SquareExtent() const | |
113 | { | |
114 | return 4 * myRadius * myRadius; | |
115 | } |