Blender V5.3
transform_mode_rotate_quadrants.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#include <optional>
13
14#include "BLI_math_base.hh"
16
17#include "ED_numinput.hh"
18
19#include "transform.hh"
20#include "transform_snap.hh"
21
23
24namespace blender::ed::transform {
25
26/* -------------------------------------------------------------------- */
29
34static std::optional<int> angle_to_quadrant_or_null_from_degrees(const double degrees)
35{
37 return std::nullopt;
38 }
39 const int64_t deg = int64_t(degrees);
40 if ((deg % 90) != 0) {
41 return std::nullopt;
42 }
43 return int(math::mod_periodic(deg / 90, int64_t(4)));
44}
45
52static std::optional<int> angle_to_quadrant_or_null_from_numinput(const NumInput *n)
53{
54 if (!(n->val_flag[0] & NUM_INT_INPUT_VALUE)) {
55 return std::nullopt;
56 }
58}
59
67static std::optional<int> angle_to_quadrant_or_null_from_radians(const float angle,
68 const float snap_increment)
69{
70 if (angle == 0.0f) {
72 }
73 /* Snap increment is zero when snapping is not active, avoid division by zero below. */
74 if (snap_increment == 0.0f) {
75 return std::nullopt;
76 }
77 /* Recover the integer step count and degree increment. */
78 const double increment_deg = round(RAD2DEG(double(snap_increment)));
79 if (!ED_numinput_double_is_int(increment_deg) || increment_deg == 0.0) {
80 return std::nullopt;
81 }
82 const int64_t steps = int64_t(roundf(angle / snap_increment));
83 return angle_to_quadrant_or_null_from_degrees(double(steps * int64_t(increment_deg)));
84}
85
87
88/* -------------------------------------------------------------------- */
91
93 const bool is_large_rotation_limited)
94{
95 /* `large_rotation_limit` uses float `fmodf` which loses precision for very large angles,
96 * the resulting radian value no longer corresponds to the original degree input. */
97 if (is_large_rotation_limited) {
98 return std::nullopt;
99 }
100 if (hasNumInput(&t->num)) {
102 }
103 /* Only use snap quadrant when increment snap was used (not geometry snap). */
104 if (transform_snap_is_active(t) && !validSnap(t)) {
107 }
108 return std::nullopt;
109}
110
112 const float axis[3],
113 const float angle,
114 const std::optional<int> quadrant)
115{
116 if (quadrant.has_value()) {
117 BLI_assert(*quadrant >= 0 && *quadrant < 4);
118 const float sin_lut[4] = {0.0f, 1.0f, 0.0f, -1.0f};
119 const float cos_lut[4] = {1.0f, 0.0f, -1.0f, 0.0f};
120 axis_angle_normalized_to_mat3_ex(mat, axis, sin_lut[*quadrant], cos_lut[*quadrant]);
121 }
122 else {
124 }
125}
126
128
129} // namespace blender::ed::transform
#define RAD2DEG(_rad)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
#define roundf(x)
#define round
constexpr T degrees(T) RET
bool validSnap(const TransInfo *t)
static std::optional< int > angle_to_quadrant_or_null_from_degrees(const double degrees)
std::optional< int > transform_angle_to_quadrant_or_null(const TransInfo *t, const bool is_large_rotation_limited)
void axis_angle_normalized_to_mat3_with_quadrant(float mat[3][3], const float axis[3], const float angle, const std::optional< int > quadrant)
bool transform_snap_is_active(const TransInfo *t)
static std::optional< int > angle_to_quadrant_or_null_from_numinput(const NumInput *n)
static std::optional< int > angle_to_quadrant_or_null_from_radians(const float angle, const float snap_increment)
float transform_snap_increment_get(const TransInfo *t)
T mod_periodic(const T &a, const T &b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
bool ED_numinput_double_is_int(double value)
Definition numinput.cc:73
bool hasNumInput(const NumInput *n)
Definition numinput.cc:188
void axis_angle_normalized_to_mat3_ex(float mat[3][3], const float axis[3], float angle_sin, float angle_cos)
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], float angle)
@ NUM_INT_INPUT_VALUE
double val_no_units[NUM_MAX_ELEMENTS]
short val_flag[NUM_MAX_ELEMENTS]