1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Dimensions related services for `Model` and `Mesh`
16 module model_dimensions
22 # Dimensions of the bounding box containing all vertices
23 var dimensions
= new Point3d[Float](max
.x-min
.x
, max
.y-min
.y
, max
.z-min
.z
) is lazy
, writable
25 # Center coordinates of all the vertices
26 var center
= new Point3d[Float]((min
.x
+max
.x
)/2.0, (min
.y
+max
.y
)/2.0, (min
.z
+max
.z
)/2.0) is lazy
, writable
28 # Minimum coordinates of all vertices on each axes
30 # This is a corner of the bounding box.
31 var min
: Point3d[Float] is lazy
do
36 while i
< vertices
.length
do
37 mx
= mx
.min
(vertices
[i
])
38 my
= my
.min
(vertices
[i
+1])
39 mz
= mz
.min
(vertices
[i
+2])
42 return new Point3d[Float](mx
, my
, mz
)
45 # Maximum coordinates of all vertices on each axes
47 # This is a corner of the bounding box.
48 var max
: Point3d[Float] is lazy
do
53 while i
< vertices
.length
do
54 mx
= mx
.max
(vertices
[i
])
55 my
= my
.max
(vertices
[i
+1])
56 mz
= mz
.max
(vertices
[i
+2])
59 return new Point3d[Float](mx
, my
, mz
)