1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 //    names, trademarks, service marks, or product names of the Licensor
11 //    and its affiliates, except as required to comply with Section 4(c) of
12 //    the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 // This file is generated by a script.  Do not edit directly.  Edit the
26 // range.template.cpp file to make changes.
27 
28 #include "pxr/base/gf/range3f.h"
29 #include "pxr/base/gf/range3d.h"
30 
31 #include "pxr/base/gf/math.h"
32 #include "pxr/base/gf/ostreamHelpers.h"
33 #include "pxr/base/tf/type.h"
34 
35 #include <cfloat>
36 #include <ostream>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
TF_REGISTRY_FUNCTION(TfType)40 TF_REGISTRY_FUNCTION(TfType) {
41     TfType::Define<GfRange3f>();
42 }
43 
44 std::ostream&
operator <<(std::ostream & out,GfRange3f const & r)45 operator<<(std::ostream &out, GfRange3f const &r)
46 {
47     return out << '['
48                << Gf_OstreamHelperP(r.GetMin()) << "..."
49                << Gf_OstreamHelperP(r.GetMax())
50                << ']';
51 }
52 
53 double
GetDistanceSquared(const GfVec3f & p) const54 GfRange3f::GetDistanceSquared(const GfVec3f &p) const
55 {
56     double dist = 0.0;
57 
58     if (p[0] < _min[0]) {
59 	// p is left of box
60 	dist += GfSqr(_min[0] - p[0]);
61     }
62     else if (p[0] > _max[0]) {
63 	// p is right of box
64 	dist += GfSqr(p[0] - _max[0]);
65     }
66     if (p[1] < _min[1]) {
67 	// p is front of box
68 	dist += GfSqr(_min[1] - p[1]);
69     }
70     else if (p[1] > _max[1]) {
71 	// p is back of box
72 	dist += GfSqr(p[1] - _max[1]);
73     }
74     if (p[2] < _min[2]) {
75 	// p is below of box
76 	dist += GfSqr(_min[2] - p[2]);
77     }
78     else if (p[2] > _max[2]) {
79 	// p is above of box
80 	dist += GfSqr(p[2] - _max[2]);
81     }
82 
83     return dist;
84 }
85 
86 GfVec3f
GetCorner(size_t i) const87 GfRange3f::GetCorner(size_t i) const
88 {
89     if (i > 7) {
90         TF_CODING_ERROR("Invalid corner %zu > 7.", i);
91         return _min;
92     }
93     return GfVec3f(
94         (i & 1 ? _max : _min)[0],
95         (i & 2 ? _max : _min)[1],
96         (i & 4 ? _max : _min)[2]);
97 }
98 
99 GfRange3f
GetOctant(size_t i) const100 GfRange3f::GetOctant(size_t i) const
101 {
102     if (i > 7) {
103         TF_CODING_ERROR("Invalid octant %zu > 7.", i);
104         return GfRange3f();
105     }
106 
107     GfVec3f a = GetCorner(i);
108     GfVec3f b = .5 * (_min + _max);
109 
110     return GfRange3f(
111         GfVec3f(GfMin(a[0], b[0]), GfMin(a[1], b[1]), GfMin(a[2], b[2])),
112         GfVec3f(GfMax(a[0], b[0]), GfMax(a[1], b[1]), GfMax(a[2], b[2])));
113 }
114 
115 const GfRange3f GfRange3f::UnitCube(GfVec3f(0,0,0), GfVec3f(1,1,1));
116 
117 PXR_NAMESPACE_CLOSE_SCOPE
118