doxygen: add newline after \file
[blender.git] / source / blender / blenkernel / intern / subdiv_inline.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2018 by Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup bke
22  */
23
24 #ifndef __SUBDIV_INLINE_H__
25 #define __SUBDIV_INLINE_H__
26
27 #include "BLI_assert.h"
28 #include "BLI_compiler_compat.h"
29
30 #include "BKE_subdiv.h"
31
32 BLI_INLINE void BKE_subdiv_ptex_face_uv_to_grid_uv(
33         const float ptex_u, const float ptex_v,
34         float *r_grid_u, float *r_grid_v)
35 {
36         *r_grid_u = 1.0f - ptex_v;
37         *r_grid_v = 1.0f - ptex_u;
38 }
39
40 BLI_INLINE void BKE_subdiv_grid_uv_to_ptex_face_uv(
41         const float grid_u, const float grid_v,
42         float *r_ptex_u, float *r_ptex_v)
43 {
44         *r_ptex_u = 1.0f - grid_v;
45         *r_ptex_v = 1.0f - grid_u;
46 }
47
48 BLI_INLINE int BKE_subdiv_grid_size_from_level(const int level)
49 {
50         return (1 << (level - 1)) + 1;
51 }
52
53 BLI_INLINE int BKE_subdiv_rotate_quad_to_corner(
54         const float quad_u, const float quad_v,
55         float *r_corner_u, float *r_corner_v)
56 {
57         int corner;
58         if (quad_u <= 0.5f && quad_v <= 0.5f) {
59                 corner = 0;
60                 *r_corner_u = 2.0f * quad_u;
61                 *r_corner_v = 2.0f * quad_v;
62         }
63         else if (quad_u > 0.5f  && quad_v <= 0.5f) {
64                 corner = 1;
65                 *r_corner_u = 2.0f * quad_v;
66                 *r_corner_v = 2.0f * (1.0f - quad_u);
67         }
68         else if (quad_u > 0.5f  && quad_v > 0.5f) {
69                 corner = 2;
70                 *r_corner_u = 2.0f * (1.0f - quad_u);
71                 *r_corner_v = 2.0f * (1.0f - quad_v);
72         }
73         else {
74                 BLI_assert(quad_u <= 0.5f && quad_v >= 0.5f);
75                 corner = 3;
76                 *r_corner_u = 2.0f * (1.0f - quad_v);
77                 *r_corner_v = 2.0f * quad_u;
78         }
79         return corner;
80 }
81
82 BLI_INLINE void BKE_subdiv_rotate_grid_to_quad(
83         const int corner,
84         const float grid_u, const float grid_v,
85         float *r_quad_u, float *r_quad_v)
86 {
87         if (corner == 0) {
88                 *r_quad_u = 0.5f - grid_v * 0.5f;
89                 *r_quad_v = 0.5f - grid_u * 0.5f;
90         }
91         else if (corner == 1) {
92                 *r_quad_u = 0.5f + grid_u * 0.5f;
93                 *r_quad_v = 0.5f - grid_v * 0.5f;
94         }
95         else if (corner == 2) {
96                 *r_quad_u = 0.5f + grid_v * 0.5f;
97                 *r_quad_v = 0.5f + grid_u * 0.5f;
98         }
99         else {
100                 BLI_assert(corner == 3);
101                 *r_quad_u = 0.5f - grid_u * 0.5f;
102                 *r_quad_v = 0.5f + grid_v * 0.5f;
103         }
104 }
105
106 #endif  /* __SUBDIV_INLINE_H__ */