ClangFormat: apply to source, most of intern
[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(const float ptex_u,
33                                                    const float ptex_v,
34                                                    float *r_grid_u,
35                                                    float *r_grid_v)
36 {
37   *r_grid_u = 1.0f - ptex_v;
38   *r_grid_v = 1.0f - ptex_u;
39 }
40
41 BLI_INLINE void BKE_subdiv_grid_uv_to_ptex_face_uv(const float grid_u,
42                                                    const float grid_v,
43                                                    float *r_ptex_u,
44                                                    float *r_ptex_v)
45 {
46   *r_ptex_u = 1.0f - grid_v;
47   *r_ptex_v = 1.0f - grid_u;
48 }
49
50 BLI_INLINE int BKE_subdiv_grid_size_from_level(const int level)
51 {
52   return (1 << (level - 1)) + 1;
53 }
54
55 BLI_INLINE int BKE_subdiv_rotate_quad_to_corner(const float quad_u,
56                                                 const float quad_v,
57                                                 float *r_corner_u,
58                                                 float *r_corner_v)
59 {
60   int corner;
61   if (quad_u <= 0.5f && quad_v <= 0.5f) {
62     corner = 0;
63     *r_corner_u = 2.0f * quad_u;
64     *r_corner_v = 2.0f * quad_v;
65   }
66   else if (quad_u > 0.5f && quad_v <= 0.5f) {
67     corner = 1;
68     *r_corner_u = 2.0f * quad_v;
69     *r_corner_v = 2.0f * (1.0f - quad_u);
70   }
71   else if (quad_u > 0.5f && quad_v > 0.5f) {
72     corner = 2;
73     *r_corner_u = 2.0f * (1.0f - quad_u);
74     *r_corner_v = 2.0f * (1.0f - quad_v);
75   }
76   else {
77     BLI_assert(quad_u <= 0.5f && quad_v >= 0.5f);
78     corner = 3;
79     *r_corner_u = 2.0f * (1.0f - quad_v);
80     *r_corner_v = 2.0f * quad_u;
81   }
82   return corner;
83 }
84
85 BLI_INLINE void BKE_subdiv_rotate_grid_to_quad(
86     const int corner, const float grid_u, const float grid_v, float *r_quad_u, float *r_quad_v)
87 {
88   if (corner == 0) {
89     *r_quad_u = 0.5f - grid_v * 0.5f;
90     *r_quad_v = 0.5f - grid_u * 0.5f;
91   }
92   else if (corner == 1) {
93     *r_quad_u = 0.5f + grid_u * 0.5f;
94     *r_quad_v = 0.5f - grid_v * 0.5f;
95   }
96   else if (corner == 2) {
97     *r_quad_u = 0.5f + grid_v * 0.5f;
98     *r_quad_v = 0.5f + grid_u * 0.5f;
99   }
100   else {
101     BLI_assert(corner == 3);
102     *r_quad_u = 0.5f - grid_u * 0.5f;
103     *r_quad_v = 0.5f + grid_v * 0.5f;
104   }
105 }
106
107 #endif /* __SUBDIV_INLINE_H__ */