1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

Core: Use Math namespace for constants

This commit is contained in:
Thaddeus Crews
2025-04-10 11:21:05 -05:00
parent 06c71fbf40
commit 94282d88f9
181 changed files with 812 additions and 818 deletions

View File

@@ -2864,14 +2864,14 @@ Control::CursorShape CanvasItemEditor::get_cursor_shape(const Point2 &p_pos) con
List<CanvasItem *> selection = _get_edited_canvas_items();
if (selection.size() == 1) {
const double angle = Math::fposmod((double)selection.front()->get()->get_global_transform_with_canvas().get_rotation(), Math_PI);
if (angle > Math_PI * 7.0 / 8.0) {
const double angle = Math::fposmod((double)selection.front()->get()->get_global_transform_with_canvas().get_rotation(), Math::PI);
if (angle > Math::PI * 7.0 / 8.0) {
rotation_array_index = 0;
} else if (angle > Math_PI * 5.0 / 8.0) {
} else if (angle > Math::PI * 5.0 / 8.0) {
rotation_array_index = 1;
} else if (angle > Math_PI * 3.0 / 8.0) {
} else if (angle > Math::PI * 3.0 / 8.0) {
rotation_array_index = 2;
} else if (angle > Math_PI * 1.0 / 8.0) {
} else if (angle > Math::PI * 1.0 / 8.0) {
rotation_array_index = 3;
} else {
rotation_array_index = 0;
@@ -3103,7 +3103,7 @@ void CanvasItemEditor::_draw_rulers() {
viewport->draw_line(Point2(0, position.y), Point2(RULER_WIDTH, position.y), graduation_color, Math::round(EDSCALE));
real_t val = (ruler_transform * major_subdivide * minor_subdivide).xform(Point2(0, i)).y;
Transform2D text_xform = Transform2D(-Math_PI / 2.0, Point2(font->get_ascent(font_size) + Math::round(EDSCALE), position.y - 2));
Transform2D text_xform = Transform2D(-Math::PI / 2.0, Point2(font->get_ascent(font_size) + Math::round(EDSCALE), position.y - 2));
viewport->draw_set_transform_matrix(viewport->get_transform() * text_xform);
viewport->draw_string(font, Point2(), TS->format_number(vformat(((int)val == val) ? "%d" : "%.1f", val)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color);
viewport->draw_set_transform_matrix(viewport->get_transform());
@@ -3210,7 +3210,7 @@ void CanvasItemEditor::_draw_ruler_tool() {
Vector2 length_vector = (begin - end).abs() / zoom;
const real_t horizontal_angle_rad = length_vector.angle();
const real_t vertical_angle_rad = Math_PI / 2.0 - horizontal_angle_rad;
const real_t vertical_angle_rad = Math::PI / 2.0 - horizontal_angle_rad;
Ref<Font> font = get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));
int font_size = 1.3 * get_theme_font_size(SNAME("bold_size"), EditorStringName(EditorFonts));
@@ -3246,15 +3246,15 @@ void CanvasItemEditor::_draw_ruler_tool() {
const Vector2 end_to_begin = (end - begin);
real_t arc_1_start_angle = end_to_begin.x < 0
? (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 - vertical_angle_rad : Math_PI / 2.0)
: (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 : Math_PI / 2.0 - vertical_angle_rad);
? (end_to_begin.y < 0 ? 3.0 * Math::PI / 2.0 - vertical_angle_rad : Math::PI / 2.0)
: (end_to_begin.y < 0 ? 3.0 * Math::PI / 2.0 : Math::PI / 2.0 - vertical_angle_rad);
real_t arc_1_end_angle = arc_1_start_angle + vertical_angle_rad;
// Constrain arc to triangle height & max size.
real_t arc_1_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, Math::abs(end_to_begin.y)), arc_max_radius);
real_t arc_2_start_angle = end_to_begin.x < 0
? (end_to_begin.y < 0 ? 0.0 : -horizontal_angle_rad)
: (end_to_begin.y < 0 ? Math_PI - horizontal_angle_rad : Math_PI);
: (end_to_begin.y < 0 ? Math::PI - horizontal_angle_rad : Math::PI);
real_t arc_2_end_angle = arc_2_start_angle + horizontal_angle_rad;
// Constrain arc to triangle width & max size.
real_t arc_2_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, Math::abs(end_to_begin.x)), arc_max_radius);
@@ -3275,8 +3275,8 @@ void CanvasItemEditor::_draw_ruler_tool() {
viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color);
if (draw_secondary_lines) {
const int horizontal_angle = round(180 * horizontal_angle_rad / Math_PI);
const int vertical_angle = round(180 * vertical_angle_rad / Math_PI);
const int horizontal_angle = round(180 * horizontal_angle_rad / Math::PI);
const int vertical_angle = round(180 * vertical_angle_rad / Math::PI);
Point2 text_pos2 = text_pos;
text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2);
@@ -3655,7 +3655,7 @@ void CanvasItemEditor::_draw_selection() {
int next = (i + 1) % 4;
Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
ofs *= Math_SQRT2 * (select_handle->get_size().width / 2);
ofs *= Math::SQRT2 * (select_handle->get_size().width / 2);
select_handle->draw(vp_ci, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor());
@@ -4257,8 +4257,8 @@ void CanvasItemEditor::_selection_changed() {
}
selected_from_canvas = false;
if (temp_pivot != Vector2(INFINITY, INFINITY)) {
temp_pivot = Vector2(INFINITY, INFINITY);
if (temp_pivot != Vector2(Math::INF, Math::INF)) {
temp_pivot = Vector2(Math::INF, Math::INF);
viewport->queue_redraw();
}
}
@@ -6175,7 +6175,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
}
bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return false;
}
Dictionary d = p_data;
@@ -6309,7 +6309,7 @@ bool CanvasItemEditorViewport::_is_any_texture_selected() const {
}
void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) {
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return;
}
bool is_shift = Input::get_singleton()->is_key_pressed(Key::SHIFT);