ci: compile the manual
[nit.git] / lib / gamnit / depth / model_dimensions.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # Dimensions related services for `Model` and `Mesh`
16 module model_dimensions
17
18 import depth_core
19
20 redef class Model
21
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
24
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
27
28 # Minimum coordinates of all vertices on each axes
29 #
30 # This is a corner of the bounding box.
31 var min: Point3d[Float] is lazy do
32 var mx = inf
33 var my = inf
34 var mz = inf
35 for leaf in leaves do
36 var lm = leaf.mesh.min
37 mx = mx.min(lm.x)
38 my = my.min(lm.y)
39 mz = mz.min(lm.z)
40 end
41 return new Point3d[Float](mx, my, mz)
42 end
43
44 # Maximum coordinates of all vertices on each axes
45 #
46 # This is a corner of the bounding box.
47 var max: Point3d[Float] is lazy do
48 var mx = -inf
49 var my = -inf
50 var mz = -inf
51 for leaf in leaves do
52 var lm = leaf.mesh.max
53 mx = mx.max(lm.x)
54 my = my.max(lm.y)
55 mz = mz.max(lm.z)
56 end
57 return new Point3d[Float](mx, my, mz)
58 end
59 end
60
61 redef class LeafModel
62
63 redef fun dimensions do return mesh.dimensions
64
65 redef fun center do return mesh.center
66 end
67
68 redef class Mesh
69
70 # Dimensions of the bounding box containing all vertices
71 var dimensions = new Point3d[Float](max.x-min.x, max.y-min.y, max.z-min.z) is lazy, writable
72
73 # Center coordinates of all the vertices
74 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
75
76 # Minimum coordinates of all vertices on each axes
77 #
78 # This is a corner of the bounding box.
79 var min: Point3d[Float] is lazy do
80 var mx = inf
81 var my = inf
82 var mz = inf
83 var i = 0
84 while i < vertices.length do
85 mx = mx.min(vertices[i])
86 my = my.min(vertices[i+1])
87 mz = mz.min(vertices[i+2])
88 i += 3
89 end
90 return new Point3d[Float](mx, my, mz)
91 end
92
93 # Maximum coordinates of all vertices on each axes
94 #
95 # This is a corner of the bounding box.
96 var max: Point3d[Float] is lazy do
97 var mx = -inf
98 var my = -inf
99 var mz = -inf
100 var i = 0
101 while i < vertices.length do
102 mx = mx.max(vertices[i])
103 my = my.max(vertices[i+1])
104 mz = mz.max(vertices[i+2])
105 i += 3
106 end
107 return new Point3d[Float](mx, my, mz)
108 end
109 end