From 41ce7807a65a0b44adea3732143b691b2b001b90 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 11 Jan 2022 18:38:05 +0100 Subject: Fix T94299: Object asset set as visible but doesn't show Differential Revision: https://developer.blender.org/D13738 Reviewed by: Bastien Montagne, Sergey Sharybin --- source/blender/editors/object/object_add.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index b9943d13b19..06e21f91d04 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -3527,6 +3527,8 @@ static int object_add_named_exec(bContext *C, wmOperator *op) } basen->object->visibility_flag &= ~OB_HIDE_VIEWPORT; + /* Do immediately, as #copy_object_set_idnew() below operates on visible objects. */ + BKE_base_eval_flags(basen); /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or * BKE_view_layer_base_deselect_all(). */ -- cgit v1.2.3 From 631067e5597dec9cb5641b69a410d03746b7fa05 Mon Sep 17 00:00:00 2001 From: Henrik Dick Date: Tue, 11 Jan 2022 18:49:08 +0100 Subject: Add support for a longest diagonal quad triangulation mode The new triangulation mode for quads is the opposite of the current default shortest diagonal mode. It is optimal for cloth simulations using quad meshes. Differential Revision: http://developer.blender.org/D13777 --- source/blender/bmesh/intern/bmesh_opdefines.c | 1 + source/blender/bmesh/intern/bmesh_polygon.c | 7 +++++++ source/blender/makesdna/DNA_modifier_types.h | 1 + source/blender/makesdna/DNA_node_types.h | 1 + source/blender/makesrna/intern/rna_modifier.c | 7 ++++++- source/blender/makesrna/intern/rna_nodetree.c | 7 ++++++- 6 files changed, 22 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 7865c79323d..85ea27b0f4e 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -1186,6 +1186,7 @@ static BMO_FlagSet bmo_enum_triangulate_quad_method[] = { {MOD_TRIANGULATE_QUAD_FIXED, "FIXED"}, {MOD_TRIANGULATE_QUAD_ALTERNATE, "ALTERNATE"}, {MOD_TRIANGULATE_QUAD_SHORTEDGE, "SHORT_EDGE"}, + {MOD_TRIANGULATE_QUAD_LONGEDGE, "LONG_EDGE"}, {0, NULL}, }; diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index e9eaf865e3c..e7280303c26 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -1007,6 +1007,7 @@ void BM_face_triangulate(BMesh *bm, break; } case MOD_TRIANGULATE_QUAD_SHORTEDGE: + case MOD_TRIANGULATE_QUAD_LONGEDGE: case MOD_TRIANGULATE_QUAD_BEAUTY: default: { BMLoop *l_v3, *l_v4; @@ -1023,6 +1024,12 @@ void BM_face_triangulate(BMesh *bm, d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); split_24 = ((d2 - d1) > 0.0f); } + else if (quad_method == MOD_TRIANGULATE_QUAD_LONGEDGE) { + float d1, d2; + d1 = len_squared_v3v3(l_v4->v->co, l_v2->v->co); + d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); + split_24 = ((d2 - d1) < 0.0f); + } else { /* first check if the quad is concave on either diagonal */ const int flip_flag = is_quad_flip_v3( diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index fc041e257b0..1d0796bda8b 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1852,6 +1852,7 @@ enum { MOD_TRIANGULATE_QUAD_FIXED = 1, MOD_TRIANGULATE_QUAD_ALTERNATE = 2, MOD_TRIANGULATE_QUAD_SHORTEDGE = 3, + MOD_TRIANGULATE_QUAD_LONGEDGE = 4, }; typedef struct LaplacianSmoothModifierData { diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 29d61bcf2ff..114e350b582 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -2118,6 +2118,7 @@ typedef enum GeometryNodeTriangulateQuads { GEO_NODE_TRIANGULATE_QUAD_FIXED = 1, GEO_NODE_TRIANGULATE_QUAD_ALTERNATE = 2, GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE = 3, + GEO_NODE_TRIANGULATE_QUAD_LONGEDGE = 4, } GeometryNodeTriangulateQuads; typedef enum GeometryNodePointInstanceType { diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index d46ae13b482..0f0734c8448 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -331,7 +331,12 @@ const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[] = { "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads based on the distance between the vertices"}, + "Split the quads along their shortest diagonal"}, + {MOD_TRIANGULATE_QUAD_LONGEDGE, + "LONGEST_DIAGONAL", + 0, + "Longest Diagonal", + "Split the quads along their longest diagonal"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index e7307e6e058..ecbeadf1fa4 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -9488,7 +9488,12 @@ static void def_geo_triangulate(StructRNA *srna) "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads based on the distance between the vertices"}, + "Split the quads along their shortest diagonal"}, + {GEO_NODE_TRIANGULATE_QUAD_LONGEDGE, + "LONGEST_DIAGONAL", + 0, + "Longest Diagonal", + "Split the quads along their longest diagonal"}, {0, NULL, 0, NULL, NULL}, }; -- cgit v1.2.3 From 8cff1ecf9fd5aad79c695de0532cc399b66874a6 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Tue, 11 Jan 2022 19:20:23 +0100 Subject: Fix T94804: GPencil Simplify when strokes are Automerged in Draw Mode The problem was the points were selected in edit mode and then sampled. Now, in draw mode, the points are always unselected to avoid this effect in the auto merge process. --- source/blender/editors/gpencil/gpencil_paint.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 73a94f066e3..ffe050bf01c 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -54,6 +54,7 @@ #include "BKE_deform.h" #include "BKE_global.h" #include "BKE_gpencil.h" +#include "BKE_gpencil_curve.h" #include "BKE_gpencil_geom.h" #include "BKE_layer.h" #include "BKE_main.h" @@ -918,6 +919,19 @@ static short gpencil_stroke_addpoint(tGPsdata *p, return GP_STROKEADD_INVALID; } +static void gpencil_stroke_unselect(bGPdata *gpd, bGPDstroke *gps) +{ + gps->flag &= ~GP_STROKE_SELECT; + BKE_gpencil_stroke_select_index_reset(gps); + for (int i = 0; i < gps->totpoints; i++) { + gps->points[i].flag &= ~GP_SPOINT_SELECT; + } + /* Update the selection from the stroke to the curve. */ + if (gps->editcurve) { + BKE_gpencil_editcurve_stroke_sync_selection(gpd, gps, gps->editcurve); + } +} + /* make a new stroke from the buffer data */ static void gpencil_stroke_newfrombuffer(tGPsdata *p) { @@ -1300,7 +1314,12 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) ctrl2, GPENCIL_MINIMUM_JOIN_DIST, &pt_index); + if (gps_target != NULL) { + /* Unselect all points of source and destination strokes. This is required to avoid + * a change in the resolution of the original strokes during the join. */ + gpencil_stroke_unselect(gpd, gps); + gpencil_stroke_unselect(gpd, gps_target); gps = ED_gpencil_stroke_join_and_trim(p->gpd, p->gpf, gps, gps_target, pt_index); } else { -- cgit v1.2.3 From 259a71cd3c06a258d5795e1a1529db4f687dcd93 Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Tue, 11 Jan 2022 14:18:34 -0500 Subject: Build: use precompiled headers on all platforms Since CMake 3.16, CMake has native precompiled header (PCH) support. This change swaps Blender's own PCH implementation with the native implementation. Previously, PCH was only enabled on Windows however, this new implementation works on all platforms. For more information see https://cmake.org/cmake/help/latest/command/target_precompile_headers.html On my system, Linux with ninja running on an i5 8250U I saw a 60% reduction in compile times for `bf_freestyle` + linking time. Reviewed By: LazyDodo, brecht Differential Revision: https://developer.blender.org/D13797 --- source/blender/freestyle/CMakeLists.txt | 5 ++++- source/blender/freestyle/FRS_precomp.cpp | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 source/blender/freestyle/FRS_precomp.cpp (limited to 'source/blender') diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt index b7eaf018dba..47da6bc55f6 100644 --- a/source/blender/freestyle/CMakeLists.txt +++ b/source/blender/freestyle/CMakeLists.txt @@ -594,4 +594,7 @@ if(WIN32) endif() blender_add_lib(bf_freestyle "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") -blender_precompile_headers(bf_freestyle FRS_precomp.cpp FRS_precomp.h) + +if(COMMAND target_precompile_headers) + target_precompile_headers(bf_freestyle PRIVATE FRS_precomp.h) +endif() diff --git a/source/blender/freestyle/FRS_precomp.cpp b/source/blender/freestyle/FRS_precomp.cpp deleted file mode 100644 index 7e50a47f45b..00000000000 --- a/source/blender/freestyle/FRS_precomp.cpp +++ /dev/null @@ -1,2 +0,0 @@ -/* Pre-compiled headers, see: D2606. */ -#include "FRS_precomp.h" -- cgit v1.2.3 From e95b4dc2ddedac3a6edc5d75e4cdac4059305f04 Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Tue, 11 Jan 2022 12:54:18 -0700 Subject: Cleanup: Fix build warnings with MSVC our UNUSED macro is essentially a no-op for MSVC, which lead to the situation where this well meant macro was emitting the following warning: C4189: 'UNUSED_i': local variable is initialized but not referenced However since we have been on c++17 for a while now the UNUSED macro can be replaced with the standard [[maybe_unused]] attribute in cpp files. This changes cleans up the use of the UNUSED macro in the bf_nodes_geometry project. Differential Revision: https://developer.blender.org/D12915 Reviewed by: JacquesLucke, Severin, Sergey, HooglyBoogly --- .../nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc | 4 ++-- source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc | 6 +++--- .../nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc | 2 +- source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc index c712e82ca18..29eff373d15 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc @@ -321,7 +321,7 @@ BLI_NOINLINE static void interpolate_existing_attributes( continue; } - for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { + for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { const int offset = instance_start_offsets[i_instance]; Span bary_coords = bary_coords_array[i_instance]; Span looptri_indices = looptri_indices_array[i_instance]; @@ -516,7 +516,7 @@ static void distribute_points_poisson_disk(Span set_group const VArray density_factors = component.attribute_get_for_read( density_attribute_name, ATTR_DOMAIN_CORNER, use_one_default ? 1.0f : 0.0f); - for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { + for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { Vector &positions = positions_all[i_instance]; Vector &bary_coords = bary_coords_all[i_instance]; Vector &looptri_indices = looptri_indices_all[i_instance]; diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc index e90a9eb393b..5b67258a947 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc @@ -155,7 +155,7 @@ static void calculate_polys(const CuboidConfig &config, /* Calculate polys for Bottom faces. */ int vert_1_start = 0; - for (const int UNUSED(y) : IndexRange(config.edges_y)) { + for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { const int vert_1 = vert_1_start + x; const int vert_2 = vert_1_start + config.verts_x + x; @@ -173,7 +173,7 @@ static void calculate_polys(const CuboidConfig &config, vert_1_start = 0; int vert_2_start = config.verts_x * config.verts_y; - for (const int UNUSED(z) : IndexRange(config.edges_z)) { + for ([[maybe_unused]] const int z : IndexRange(config.edges_z)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, @@ -196,7 +196,7 @@ static void calculate_polys(const CuboidConfig &config, (config.verts_x - 2) * (config.verts_y - 2)); vert_2_start = vert_1_start + config.verts_x; - for (const int UNUSED(y) : IndexRange(config.edges_y)) { + for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc index 373e6bfdd18..41178d5c4e6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc @@ -178,7 +178,7 @@ static void calculate_sphere_faces(MutableSpan loops, int ring_vert_index_start = 1; int ring_edge_index_start = segments; - for (const int UNUSED(ring) : IndexRange(1, rings - 2)) { + for ([[maybe_unused]] const int ring : IndexRange(1, rings - 2)) { const int next_ring_vert_index_start = ring_vert_index_start + segments; const int next_ring_edge_index_start = ring_edge_index_start + segments * 2; const int ring_vertical_edge_index_start = ring_edge_index_start + segments; diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc index feab0a6743f..82d09bbc208 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc @@ -106,7 +106,7 @@ static void set_position_in_component(const GeometryNodeCurveHandleMode mode, } } else { - for (int UNUSED(i) : spline->positions().index_range()) { + for ([[maybe_unused]] int i : spline->positions().index_range()) { if (current_mask < selection.size() && selection[current_mask] == current_point) { current_mask++; } -- cgit v1.2.3 From 376e425c02ae3ead9137f1a7d019fe3b2f43343e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 11 Jan 2022 21:29:02 +0100 Subject: Fix T93588: some videos loaded flipped over Y axis on macOS Arm Was not actually flipping in the need_aligned_ffmpeg_buffer case. --- source/blender/imbuf/intern/anim_movie.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 1d81653c7cd..6a05b681c88 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -879,7 +879,7 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); # else - /* Scale with swscale then flip image over Y axis. */ + /* Scale with swscale. */ int *dstStride = anim->pFrameRGB->linesize; uint8_t **dst = anim->pFrameRGB->data; const int dstStride2[4] = {dstStride[0], 0, 0, 0}; @@ -896,11 +896,12 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); - bottom = (unsigned char *)ibuf->rect; - top = bottom + ibuf->x * (ibuf->y - 1) * 4; + /* Flip destination image buffer over Y axis. */ + bottom = (unsigned char *)dst[0]; + top = bottom + anim->x * (anim->y - 1) * 4; - h = (ibuf->y + 1) / 2; - w = ibuf->x; + h = (anim->y + 1) / 2; + w = anim->x; for (y = 0; y < h; y++) { unsigned char tmp[4]; -- cgit v1.2.3 From ac3d07ad178d1bcea1b96e22003444e31f66e5da Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Tue, 11 Jan 2022 22:45:21 +0100 Subject: Fix T94799: GPencil Strokes drawn at 0.0 Strength still visible There was a clamp with a value greater than 0. --- source/blender/editors/gpencil/gpencil_paint.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index ffe050bf01c..79dda480a0a 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -835,7 +835,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p, /* color strength */ if (brush_settings->flag & GP_BRUSH_USE_STRENGTH_PRESSURE) { pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); } /* Set vertex colors for buffer. */ @@ -942,6 +942,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) tGPspoint *ptc; MDeformVert *dvert = NULL; Brush *brush = p->brush; + BrushGpencilSettings *brush_settings = brush->gpencil_settings; ToolSettings *ts = p->scene->toolsettings; Depsgraph *depsgraph = p->depsgraph; Object *obact = (Object *)p->ownerPtr.data; @@ -1030,7 +1031,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; /* Apply the vertex color to point. */ @@ -1064,7 +1065,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); pt->time = ptc->time; /* Apply the vertex color to point. */ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); @@ -1189,7 +1190,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; pt->uv_fac = ptc->uv_fac; -- cgit v1.2.3 From e339946515b00bc230bad2ec52a729dd914a8af3 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Tue, 11 Jan 2022 22:48:26 +0100 Subject: Cleanup previous commit Don't need check minimum constant value, brush value is enough. --- source/blender/editors/gpencil/gpencil_paint.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 79dda480a0a..0b713af54ae 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -835,7 +835,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p, /* color strength */ if (brush_settings->flag & GP_BRUSH_USE_STRENGTH_PRESSURE) { pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, brush_settings->draw_strength, 1.0f); } /* Set vertex colors for buffer. */ @@ -1031,7 +1031,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, brush_settings->draw_strength, 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; /* Apply the vertex color to point. */ @@ -1065,7 +1065,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, brush_settings->draw_strength, 1.0f); pt->time = ptc->time; /* Apply the vertex color to point. */ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); @@ -1190,7 +1190,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, brush_settings->draw_strength, 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; pt->uv_fac = ptc->uv_fac; -- cgit v1.2.3 From 48ff9b57f8a53828b30ddbed94df89564b012b44 Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Tue, 11 Jan 2022 16:48:56 -0500 Subject: Build: Add precompiled headers for `bf_compositor` With this change, compilation saw a 2.4x improvement. This can be combined with unity build to give an overall 4x improvement Depends on D13797 Reviewed By: LazyDodo Differential Revision: https://developer.blender.org/D13798 --- source/blender/compositor/CMakeLists.txt | 4 ++++ source/blender/compositor/COM_precomp.h | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 source/blender/compositor/COM_precomp.h (limited to 'source/blender') diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index f59fd885871..af8ba0a24a5 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -645,6 +645,10 @@ endif() blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +if(COMMAND target_precompile_headers) + target_precompile_headers(bf_compositor PRIVATE COM_precomp.h) +endif() + if(CXX_WARN_NO_SUGGEST_OVERRIDE) target_compile_options(bf_compositor PRIVATE "-Wsuggest-override") endif() diff --git a/source/blender/compositor/COM_precomp.h b/source/blender/compositor/COM_precomp.h new file mode 100644 index 00000000000..4d2681ea0cd --- /dev/null +++ b/source/blender/compositor/COM_precomp.h @@ -0,0 +1,33 @@ +/* Pre-compiled headers, see: D13797. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "COM_ConstantOperation.h" +#include "COM_ConvertOperation.h" +#include "COM_Debug.h" +#include "COM_Enums.h" +#include "COM_ExecutionGroup.h" +#include "COM_ExecutionSystem.h" +#include "COM_MultiThreadedOperation.h" +#include "COM_Node.h" +#include "COM_NodeOperation.h" +#include "COM_OpenCLDevice.h" +#include "COM_SetAlphaMultiplyOperation.h" +#include "COM_SetColorOperation.h" +#include "COM_SetSamplerOperation.h" +#include "COM_SetValueOperation.h" +#include "COM_SetVectorOperation.h" +#include "COM_defines.h" -- cgit v1.2.3 From 5a6ec0f0035b6bb8a75b18826f4d0f687ec5ec21 Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Tue, 11 Jan 2022 16:55:18 -0500 Subject: Build: Enable unity build for `bf_compositor` Blender's compositor code already makes extensive use of namespace which makes it very simple to enable unity build. There was one duplicated function that has since to be moved to a common header. I saw roughly a 3x speedup of bf_compositor using ninja on linux using i5 8250u (1:34 down to 0:34). Reviewed By: LazyDodo Differential Revision: https://developer.blender.org/D13792 --- source/blender/compositor/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/blender') diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index af8ba0a24a5..88ce9b88097 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -645,6 +645,11 @@ endif() blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +if(WITH_UNITY_BUILD) + set_target_properties(bf_compositor PROPERTIES UNITY_BUILD ON) + set_target_properties(bf_compositor PROPERTIES UNITY_BUILD_BATCH_SIZE 10) +endif() + if(COMMAND target_precompile_headers) target_precompile_headers(bf_compositor PRIVATE COM_precomp.h) endif() -- cgit v1.2.3 From 947dc219795b0d0c8f172f49c803272ed079384a Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Tue, 11 Jan 2022 14:57:54 -0700 Subject: Cleanup: Fix build warning with MSVC comparing a bool > 0 make MSVC emit warning C4804: '>': unsafe use of type 'bool' in operation. int does the job nicely. --- source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index 0feca806f35..f9151bb97f8 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -236,7 +236,7 @@ TEST(obj_exporter_writer, mtllib) static bool strings_equal_after_first_lines(const std::string &a, const std::string &b) { /* If `dbg_level > 0` then a failing test will print context around the first mismatch. */ - const bool dbg_level = 0; + const int dbg_level = 0; const size_t a_len = a.size(); const size_t b_len = b.size(); const size_t a_next = a.find_first_of('\n'); -- cgit v1.2.3 From bbe59c6014535b125e39f7466ee0930a07116571 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 11 Jan 2022 14:07:40 -0800 Subject: BLF: Reduction of use of BLF_DRAW_STR_DUMMY_MAX Reduction of the number of uses of the define BLF_DRAW_STR_DUMMY_MAX by using actual sizes of static character arrays. See D13793 for more details. Differential Revision: https://developer.blender.org/D13793 Reviewed by Campbell Barton --- source/blender/blenkernel/intern/image.c | 26 ++++++++--------- .../blender/editors/interface/interface_widgets.c | 2 +- source/blender/editors/space_node/node_draw.cc | 2 +- source/blender/editors/util/ed_draw.c | 34 +++++++++++----------- source/blender/sequencer/intern/effects.c | 4 +-- 5 files changed, 34 insertions(+), 34 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 4899c3671aa..23b1054f814 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -2446,7 +2446,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and draw the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.file, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.file, sizeof(stamp_data.file)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2469,7 +2469,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.date, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.date, sizeof(stamp_data.date)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2492,7 +2492,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.rendertime, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.rendertime, sizeof(stamp_data.rendertime)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2515,7 +2515,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.memory, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.memory, sizeof(stamp_data.memory)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2538,7 +2538,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.hostname, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.hostname, sizeof(stamp_data.hostname)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2562,7 +2562,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs + (h - h_fixed), 0.0); - BLF_draw_buffer(mono, stamp_data.note, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.note, sizeof(stamp_data.note)); } BLF_disable(mono, BLF_WORD_WRAP); @@ -2586,7 +2586,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.marker, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.marker, sizeof(stamp_data.marker)); /* space width. */ x += w + pad; @@ -2609,7 +2609,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.time, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.time, sizeof(stamp_data.time)); /* space width. */ x += w + pad; @@ -2631,7 +2631,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.frame, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.frame, sizeof(stamp_data.frame)); /* space width. */ x += w + pad; @@ -2651,7 +2651,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.camera, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.camera, sizeof(stamp_data.camera)); /* space width. */ x += w + pad; @@ -2671,7 +2671,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.cameralens, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.cameralens, sizeof(stamp_data.cameralens)); } if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) { @@ -2693,7 +2693,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.scene, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.scene, sizeof(stamp_data.scene)); } if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) { @@ -2715,7 +2715,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.strip, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.strip, sizeof(stamp_data.strip)); } /* cleanup the buffer. */ diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ad8c0842657..06de4f09d06 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -5421,7 +5421,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, }, - BLF_DRAW_STR_DUMMY_MAX, + sizeof(drawstr), &xofs, &yofs, &info); diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 2d3c42b16d1..e9a385c525b 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2452,7 +2452,7 @@ static void frame_node_draw_label(const bNodeTree &ntree, const bool has_label = node.label[0] != '\0'; if (has_label) { BLF_position(fontid, x, y, 0); - BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, label, sizeof(label)); } /* draw text body */ diff --git a/source/blender/editors/util/ed_draw.c b/source/blender/editors/util/ed_draw.c index ccbde07f5b1..3e85862a847 100644 --- a/source/blender/editors/util/ed_draw.c +++ b/source/blender/editors/util/ed_draw.c @@ -599,9 +599,9 @@ static void metadata_custom_draw_fields(const char *field, const char *value, vo } MetadataCustomDrawContext *ctx = (MetadataCustomDrawContext *)ctx_v; char temp_str[MAX_METADATA_STR]; - BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: %s", field, value); + SNPRINTF(temp_str, "%s: %s", field, value); BLF_position(ctx->fontid, ctx->xmin, ctx->ymin + ctx->current_y, 0.0f); - BLF_draw(ctx->fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(ctx->fontid, temp_str, sizeof(temp_str)); ctx->current_y += ctx->vertical_offset; } @@ -625,18 +625,18 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const /* first line */ if (i == 0) { bool do_newline = false; - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[0]); if (metadata_is_valid(ibuf, temp_str, 0, len)) { BLF_position(fontid, xmin, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); do_newline = true; } - len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]); + len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[1]); if (metadata_is_valid(ibuf, temp_str, 1, len)) { - int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); BLF_position(fontid, xmax - line_width, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); do_newline = true; } @@ -645,32 +645,32 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const } } /* Strip */ else if (ELEM(i, 1, 2)) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); ofs_y += vertical_offset; } } /* Note (wrapped) */ else if (i == 3) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { struct ResultBLF info; BLF_enable(fontid, BLF_WORD_WRAP); BLF_wordwrap(fontid, ibuf->x - (margin * 2)); BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw_ex(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX, &info); + BLF_draw_ex(fontid, temp_str, sizeof(temp_str), &info); BLF_wordwrap(fontid, 0); BLF_disable(fontid, BLF_WORD_WRAP); ofs_y += vertical_offset * info.lines; } } else { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { - int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); BLF_position(fontid, xmax - line_width, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); ofs_y += vertical_offset; } } @@ -687,12 +687,12 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const int ofs_x = 0; ofs_y = ctx.current_y; for (int i = 5; i < 10; i++) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i]); if (metadata_is_valid(ibuf, temp_str, i, len)) { BLF_position(fontid, xmin + ofs_x, ymin + ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); - ofs_x += BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX) + UI_UNIT_X; + ofs_x += BLF_width(fontid, temp_str, sizeof(temp_str)) + UI_UNIT_X; } } } diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index 8776bc63cf0..a35e83a8632 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -3344,12 +3344,12 @@ static ImBuf *do_text_effect(const SeqRenderData *context, fonty = line_height; BLF_position(font, x + max_ii(fontx / 55, 1), y - max_ii(fonty / 30, 1), 0.0f); BLF_buffer_col(font, data->shadow_color); - BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(font, data->text, sizeof(data->text)); } BLF_position(font, x, y, 0.0f); BLF_buffer_col(font, data->color); - BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(font, data->text, sizeof(data->text)); BLF_buffer(font, NULL, NULL, 0, 0, 0, NULL); -- cgit v1.2.3 From 89145341e5ddcefbe71c664db8a853abe3b93344 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 11 Jan 2022 14:52:39 -0800 Subject: BLF: UI_fontstyle_draw Usage Add maximum string length argument to UI_fontstyle_draw to reduce usage of BLF_DRAW_STR_DUMMY_MAX. Reorders arguments to UI_fontstyle_draw_ex See D13794 for more details. Differential Revision: https://developer.blender.org/D13794 Reviewed by Campbell Barton --- source/blender/editors/include/UI_interface.h | 4 +++- source/blender/editors/interface/interface_panel.c | 1 + .../blender/editors/interface/interface_region_tooltip.c | 15 +++++++++------ source/blender/editors/interface/interface_style.c | 13 ++++++------- source/blender/editors/interface/interface_widgets.c | 7 +++++-- source/blender/editors/space_file/file_draw.c | 3 ++- 6 files changed, 26 insertions(+), 17 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index f01b8318e98..5ecc43a9fc9 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -2957,15 +2957,17 @@ void UI_fontstyle_set(const struct uiFontStyle *fs); void UI_fontstyle_draw_ex(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, + size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, - size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info); + void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, + size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params); /** diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index bc1d3387ad7..135cef5fe53 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1146,6 +1146,7 @@ static void panel_draw_aligned_widgets(const uiStyle *style, UI_fontstyle_draw(fontstyle, &title_rect, panel->drawname, + sizeof(panel->drawname), title_color, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index e146443faaa..fe58a6a05ae 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -74,6 +74,8 @@ #define UI_TIP_PADDING (int)(UI_TIP_PAD_FAC * UI_UNIT_Y) #define UI_TIP_MAXWIDTH 600 +#define UI_TIP_STR_MAX 1024 + typedef struct uiTooltipFormat { enum { UI_TIP_STYLE_NORMAL = 0, @@ -214,7 +216,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw header and active data (is done here to be able to change color) */ rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_MAIN]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); /* offset to the end of the last line */ if (field->text_suffix) { @@ -224,7 +226,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.ymax -= yofs; rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_ACTIVE]); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text_suffix, drawcol, &fs_params); + UI_fontstyle_draw( + &data->fstyle, &bbox, field->text_suffix, UI_TIP_STR_MAX, drawcol, &fs_params); /* undo offset */ bbox.xmin -= xofs; @@ -243,7 +246,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* XXX, needed because we don't have mono in 'U.uifonts' */ BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); - UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); } else { BLI_assert(field->format.style == UI_TIP_STYLE_NORMAL); @@ -255,7 +258,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw remaining data */ rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); } bbox.ymax -= data->lineh * field->geom.lines; @@ -1215,12 +1218,12 @@ static ARegion *ui_tooltip_create_with_data(bContext *C, BLI_assert(ELEM(field->format.style, UI_TIP_STYLE_NORMAL, UI_TIP_STYLE_HEADER)); font_id = data->fstyle.uifont_id; } - w = BLF_width_ex(font_id, field->text, BLF_DRAW_STR_DUMMY_MAX, &info); + w = BLF_width_ex(font_id, field->text, UI_TIP_STR_MAX, &info); /* check for suffix (enum label) */ if (field->text_suffix && field->text_suffix[0]) { x_pos = info.width; - w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, BLF_DRAW_STR_DUMMY_MAX)); + w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, UI_TIP_STR_MAX)); } fontw = max_ii(fontw, w); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index c28769a4951..44942d508ca 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -140,9 +140,9 @@ static uiFont *uifont_to_blfont(int id) void UI_fontstyle_draw_ex(const uiFontStyle *fs, const rcti *rect, const char *str, + const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, - size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info) @@ -183,10 +183,10 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, } if (fs_params->align == UI_STYLE_TEXT_CENTER) { - xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); + xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len))); } else if (fs_params->align == UI_STYLE_TEXT_RIGHT) { - xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len); + xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len); } yofs = MAX2(0, yofs); @@ -196,7 +196,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_color4ubv(fs->uifont_id, col); - BLF_draw_ex(fs->uifont_id, str, len, r_info); + BLF_draw_ex(fs->uifont_id, str, str_len, r_info); BLF_disable(fs->uifont_id, font_flag); @@ -211,12 +211,11 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, + const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params) { - int xofs, yofs; - - UI_fontstyle_draw_ex(fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, NULL); + UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, NULL, NULL, NULL); } void UI_fontstyle_draw_rotated(const uiFontStyle *fs, diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 06de4f09d06..b44496731f7 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2130,11 +2130,11 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, + drawlen, wcol->text, &(struct uiFontStyleDraw_Params){ .align = align, }, - drawlen, &font_xofs, &font_yofs, NULL); @@ -2194,6 +2194,7 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, drawstr_right, + UI_MAX_DRAW_STR, col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5417,11 +5418,11 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr, + sizeof(drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, }, - sizeof(drawstr), &xofs, &yofs, &info); @@ -5468,6 +5469,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, hint_drawstr, + sizeof(hint_drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5523,6 +5525,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, &trect, drawstr, + sizeof(drawstr), text_col, &(struct uiFontStyleDraw_Params){ .align = text_align, diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 44e9735866d..dd1b4e10e60 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -240,6 +240,7 @@ static void file_draw_string(int sx, UI_fontstyle_draw(&fs, &rect, fname, + sizeof(fname), col, &(struct uiFontStyleDraw_Params){ .align = align, @@ -289,12 +290,12 @@ static void file_draw_string_multiline(int sx, UI_fontstyle_draw_ex(&style->widget, &rect, string, + len, text_col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, .word_wrap = true, }, - len, NULL, NULL, &result); -- cgit v1.2.3 From f4492629ea0e5018412d5634c7be898a09af8bf0 Mon Sep 17 00:00:00 2001 From: Richard Antalik Date: Wed, 12 Jan 2022 01:36:35 +0100 Subject: Cleanup: VSE channel drawing Remove code that very slightly darkened line on bottom of timeline, when backdrop is enabled. Purpose of the code wasn't dodumented, and 2.79 doesn't seem to produce this darkened line. Rename drawing functions to appropriate names. --- .../editors/space_sequencer/sequencer_draw.c | 37 ++++++++-------------- 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index e814530d1e2..6dffc0bc2a4 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -2262,28 +2262,15 @@ void sequencer_draw_preview(const bContext *C, seq_prefetch_wm_notify(C, scene); } -/* Draw backdrop in sequencer timeline. */ -static void draw_seq_backdrop(View2D *v2d) +static void draw_seq_timeline_channels(View2D *v2d) { - int i; - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - /* View backdrop. */ - immUniformThemeColor(TH_BACK); - immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax); - - /* Darker overlay over the view backdrop. */ - immUniformThemeColorShade(TH_BACK, -10); - immRectf(pos, v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0); - - /* Alternating horizontal stripes. */ - i = max_ii(1, ((int)v2d->cur.ymin) - 1); - GPU_blend(GPU_BLEND_ALPHA); immUniformThemeColor(TH_ROW_ALTERNATE); + /* Alternating horizontal stripes. */ + int i = max_ii(1, ((int)v2d->cur.ymin) - 1); while (i < v2d->cur.ymax) { if (i & 1) { immRectf(pos, v2d->cur.xmin, i, v2d->cur.xmax, i + 1); @@ -2295,6 +2282,14 @@ static void draw_seq_backdrop(View2D *v2d) immUnbindProgram(); } +static void draw_seq_timeline_channel_numbers(ARegion *region) +{ + View2D *v2d = ®ion->v2d; + rcti rect; + BLI_rcti_init(&rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); + UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); +} + static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *region) { Scene *scene = CTX_data_scene(C); @@ -2718,7 +2713,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region) } UI_view2d_view_ortho(v2d); - draw_seq_backdrop(v2d); + draw_seq_timeline_channels(v2d); if ((sseq->flag & SEQ_SHOW_OVERLAY) && (sseq->timeline_overlay.flag & SEQ_TIMELINE_SHOW_GRID)) { U.v2d_min_gridsize *= 3; UI_view2d_draw_lines_x__discrete_frames_or_seconds( @@ -2776,13 +2771,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region) UI_view2d_view_restore(C); ED_time_scrub_draw(region, scene, !(sseq->flag & SEQ_DRAWFRAMES), true); - /* Draw channel numbers. */ - { - rcti rect; - BLI_rcti_init( - &rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); - UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); - } + draw_seq_timeline_channel_numbers(region); } void draw_timeline_seq_display(const bContext *C, ARegion *region) -- cgit v1.2.3 From 0dc309bef636e4da8ee3dad97eb8b27562138701 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 12 Jan 2022 11:42:54 +1100 Subject: Cleanup: remove redundant const qualifiers for POD types --- source/blender/blenfont/BLF_api.h | 2 +- source/blender/blenfont/intern/blf_internal.h | 4 +-- source/blender/blenkernel/BKE_appdir.h | 2 +- source/blender/blenkernel/BKE_attribute.h | 2 +- source/blender/blenkernel/BKE_bvhutils.h | 18 ++++++------- source/blender/blenkernel/BKE_customdata.h | 4 +-- source/blender/blenkernel/BKE_image.h | 2 +- source/blender/blenkernel/BKE_scene.h | 7 ++--- source/blender/blenkernel/BKE_vfont.h | 2 +- .../blenkernel/intern/data_transfer_intern.h | 6 ++--- source/blender/blenlib/BLI_array_store.h | 2 +- source/blender/blenlib/BLI_array_utils.h | 4 +-- source/blender/blenlib/BLI_buffer.h | 4 +-- source/blender/blenlib/BLI_fileops.h | 3 +-- source/blender/blenlib/BLI_gsqueue.h | 2 +- source/blender/blenlib/BLI_listbase.h | 6 ++--- source/blender/blenlib/BLI_memarena.h | 4 +-- source/blender/blenlib/BLI_memory_utils.h | 2 +- source/blender/blenlib/BLI_path_util.h | 19 +++++++------- source/blender/blenlib/BLI_stack.h | 6 ++--- source/blender/blenlib/BLI_string.h | 26 +++++++++---------- source/blender/blenlib/BLI_string_utf8.h | 19 ++++++-------- source/blender/blenlib/BLI_string_utils.h | 6 ++--- source/blender/blenlib/BLI_timecode.h | 6 ++--- source/blender/blenlib/BLI_utildefines.h | 2 +- .../blender/blenlib/intern/BLI_mempool_private.h | 5 ++-- .../operations/COM_OutputFileOperation.h | 2 +- .../depsgraph/intern/node/deg_node_factory.h | 2 +- source/blender/editors/include/ED_util.h | 2 +- source/blender/editors/include/UI_interface.h | 2 +- .../blender/editors/interface/interface_intern.h | 4 +-- source/blender/imbuf/IMB_imbuf.h | 30 ++++++++-------------- source/blender/imbuf/IMB_metadata.h | 5 +--- source/blender/imbuf/intern/IMB_filetype.h | 22 ++++++++-------- source/blender/imbuf/intern/dds/dds_api.h | 2 +- source/blender/imbuf/intern/oiio/openimageio_api.h | 2 +- source/blender/imbuf/intern/openexr/openexr_api.h | 2 +- source/blender/makesrna/RNA_access.h | 2 +- source/blender/makesrna/intern/rna_internal.h | 2 +- .../blender/makesrna/intern/rna_internal_types.h | 2 +- .../blender/nodes/geometry/node_geometry_util.hh | 2 +- source/blender/python/generic/py_capi_utils.h | 12 ++++----- source/blender/render/RE_bake.h | 12 ++++----- source/blender/windowmanager/WM_api.h | 2 +- 44 files changed, 127 insertions(+), 147 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 76a6135baaf..169107b19cb 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -122,7 +122,7 @@ void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth) ATTR_NONNULL(2); typedef bool (*BLF_GlyphBoundsFn)(const char *str, - const size_t str_step_ofs, + size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 23e42ec777f..4e36f522981 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -121,7 +121,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, const char *str, size_t str_len, bool (*user_fn)(const char *str, - const size_t str_step_ofs, + size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, @@ -132,7 +132,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, int blf_font_count_missing_chars(struct FontBLF *font, const char *str, - const size_t str_len, + size_t str_len, int *r_tot_chars); void blf_font_free(struct FontBLF *font); diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index e92909fb3ca..a7baaed141f 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -140,7 +140,7 @@ bool BKE_appdir_font_folder_default(char *dir); * Find Python executable. */ bool BKE_appdir_program_python_search(char *fullpath, - const size_t fullpath_len, + size_t fullpath_len, int version_major, int version_minor); diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index db8f3759bf8..6020da08f51 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -73,7 +73,7 @@ bool BKE_id_attribute_rename(struct ID *id, const char *new_name, struct ReportList *reports); -int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask); +int BKE_id_attributes_length(struct ID *id, CustomDataMask mask); struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id); void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer); diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 42c8a5dae5d..146e6394fd6 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -128,7 +128,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -148,7 +148,7 @@ BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -165,7 +165,7 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -188,7 +188,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -212,7 +212,7 @@ BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -229,7 +229,7 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -251,7 +251,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -263,7 +263,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, */ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, const struct Mesh *mesh, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, int tree_type); /** @@ -272,7 +272,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, BVHTree *BKE_bvhtree_from_editmesh_get(BVHTreeFromEditMesh *data, struct BMEditMesh *em, int tree_type, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index b5b6296a0fa..17a44274712 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -323,7 +323,7 @@ void CustomData_bmesh_copy_data_exclude_by_type(const struct CustomData *source, struct CustomData *dest, void *src_block, void **dest_block, - const CustomDataMask mask_exclude); + CustomDataMask mask_exclude); /** * Copies data of a single layer of a given type. @@ -496,7 +496,7 @@ void CustomData_bmesh_free_block_data(struct CustomData *data, void *block); */ void CustomData_bmesh_free_block_data_exclude_by_type(struct CustomData *data, void *block, - const CustomDataMask mask_exclude); + CustomDataMask mask_exclude); /** * Copy custom data to/from layers as in mesh/derived-mesh, to edit-mesh diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 7b87189a13f..80c6b155be0 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -367,7 +367,7 @@ void BKE_image_packfiles(struct ReportList *reports, struct Image *ima, const ch void BKE_image_packfiles_from_mem(struct ReportList *reports, struct Image *ima, char *data, - const size_t data_len); + size_t data_len); /** * Prints memory statistics for images. diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 8610bc09a92..a40359e8650 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -317,11 +317,8 @@ void BKE_scene_multiview_view_prefix_get(struct Scene *scene, const char *name, char *r_prefix, const char **r_ext); -void BKE_scene_multiview_videos_dimensions_get(const struct RenderData *rd, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); +void BKE_scene_multiview_videos_dimensions_get( + const struct RenderData *rd, size_t width, size_t height, size_t *r_width, size_t *r_height); int BKE_scene_multiview_num_videos_get(const struct RenderData *rd); /* depsgraph */ diff --git a/source/blender/blenkernel/BKE_vfont.h b/source/blender/blenkernel/BKE_vfont.h index d0a44ce4e47..3397f2ef82a 100644 --- a/source/blender/blenkernel/BKE_vfont.h +++ b/source/blender/blenkernel/BKE_vfont.h @@ -104,7 +104,7 @@ void BKE_vfont_select_clamp(struct Object *ob); void BKE_vfont_clipboard_free(void); void BKE_vfont_clipboard_set(const char32_t *text_buf, const struct CharInfo *info_buf, - const size_t len); + size_t len); void BKE_vfont_clipboard_get(char32_t **r_text_buf, struct CharInfo **r_info_buf, size_t *r_len_utf8, diff --git a/source/blender/blenkernel/intern/data_transfer_intern.h b/source/blender/blenkernel/intern/data_transfer_intern.h index e5218415df9..b5b3db31fbf 100644 --- a/source/blender/blenkernel/intern/data_transfer_intern.h +++ b/source/blender/blenkernel/intern/data_transfer_intern.h @@ -44,9 +44,9 @@ void data_transfer_layersmapping_add_item(struct ListBase *r_map, void *data_dst, int data_src_n, int data_dst_n, - const size_t elem_size, - const size_t data_size, - const size_t data_offset, + size_t elem_size, + size_t data_size, + size_t data_offset, uint64_t data_flag, cd_datatransfer_interp interp, void *interp_data); diff --git a/source/blender/blenlib/BLI_array_store.h b/source/blender/blenlib/BLI_array_store.h index 0be361d4ab9..68928f53e55 100644 --- a/source/blender/blenlib/BLI_array_store.h +++ b/source/blender/blenlib/BLI_array_store.h @@ -84,7 +84,7 @@ size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs); */ BArrayState *BLI_array_store_state_add(BArrayStore *bs, const void *data, - const size_t data_len, + size_t data_len, const BArrayState *state_reference); /** * Remove a state and free any unused #BChunk data. diff --git a/source/blender/blenlib/BLI_array_utils.h b/source/blender/blenlib/BLI_array_utils.h index 50fc2ce909b..202ae9a9786 100644 --- a/source/blender/blenlib/BLI_array_utils.h +++ b/source/blender/blenlib/BLI_array_utils.h @@ -52,7 +52,7 @@ void _bli_array_wrap(void *arr, uint arr_len, size_t arr_stride, int dir); * Access via #BLI_array_wrap */ void _bli_array_permute( - void *arr, uint arr_len, const size_t arr_stride, const uint *order, void *arr_temp); + void *arr, uint arr_len, size_t arr_stride, const uint *order, void *arr_temp); #define BLI_array_permute(arr, arr_len, order) \ _bli_array_permute(arr, arr_len, sizeof(*(arr)), order, NULL) #define BLI_array_permute_ex(arr, arr_len, order, arr_temp) \ @@ -152,7 +152,7 @@ bool _bli_array_is_zeroed(const void *arr, uint arr_len, size_t arr_stride); */ bool _bli_array_iter_spiral_square(const void *arr_v, const int arr_shape[2], - const size_t elem_size, + size_t elem_size, const int center[2], bool (*test_fn)(const void *arr_item, void *user_data), void *user_data); diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h index 7f577443cf7..e79d44fd934 100644 --- a/source/blender/blenlib/BLI_buffer.h +++ b/source/blender/blenlib/BLI_buffer.h @@ -74,7 +74,7 @@ enum { /** * \note Never decreases the amount of memory allocated. */ -void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); +void BLI_buffer_resize(BLI_Buffer *buffer, size_t new_count); /** * Ensure size, throwing away old data, respecting #BLI_BUFFER_USE_CALLOC. @@ -83,7 +83,7 @@ void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); * - Ignored (malloc'd). * - Cleared (when #BLI_BUFFER_USE_CALLOC is set). */ -void BLI_buffer_reinit(BLI_Buffer *buffer, const size_t new_count); +void BLI_buffer_reinit(BLI_Buffer *buffer, size_t new_count); /** * Append an array of elements. diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index 0022823b3de..28cb5f6d84b 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -155,8 +155,7 @@ double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL( * * \note can return NULL when the size is not big enough */ -char *BLI_current_working_dir(char *dir, const size_t maxncpy) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); +char *BLI_current_working_dir(char *dir, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); eFileAttributes BLI_file_attributes(const char *path); /** \} */ diff --git a/source/blender/blenlib/BLI_gsqueue.h b/source/blender/blenlib/BLI_gsqueue.h index 8b32c09b56b..a35c743c80b 100644 --- a/source/blender/blenlib/BLI_gsqueue.h +++ b/source/blender/blenlib/BLI_gsqueue.h @@ -31,7 +31,7 @@ extern "C" { typedef struct _GSQueue GSQueue; -GSQueue *BLI_gsqueue_new(const size_t elem_size); +GSQueue *BLI_gsqueue_new(size_t elem_size); /** * Returns true if the queue is empty, false otherwise. */ diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 64852b95ae4..f73d1f22502 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -85,7 +85,7 @@ void *BLI_findptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, - const size_t bytes_size, + size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** * Find the first item in the list that matches the given string, or the given index as fallback. @@ -96,7 +96,7 @@ void *BLI_listbase_bytes_find(const ListBase *listbase, */ void *BLI_listbase_string_or_index_find(const struct ListBase *listbase, const char *string, - const size_t string_offset, + size_t string_offset, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /* Find backwards. */ @@ -133,7 +133,7 @@ void *BLI_rfindptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_rfind(const ListBase *listbase, const void *bytes, - const size_t bytes_size, + size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h index 4ac4712bc8c..bcfe2efc5e5 100644 --- a/source/blender/blenlib/BLI_memarena.h +++ b/source/blender/blenlib/BLI_memarena.h @@ -38,13 +38,13 @@ extern "C" { struct MemArena; typedef struct MemArena MemArena; -struct MemArena *BLI_memarena_new(const size_t bufsize, +struct MemArena *BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC; void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_malloc(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_calloc(struct MemArena *ma) ATTR_NONNULL(1); -void BLI_memarena_use_align(struct MemArena *ma, const size_t align) ATTR_NONNULL(1); +void BLI_memarena_use_align(struct MemArena *ma, size_t align) ATTR_NONNULL(1); void *BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2); void *BLI_memarena_calloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT diff --git a/source/blender/blenlib/BLI_memory_utils.h b/source/blender/blenlib/BLI_memory_utils.h index 79e25e26040..09d8f646905 100644 --- a/source/blender/blenlib/BLI_memory_utils.h +++ b/source/blender/blenlib/BLI_memory_utils.h @@ -29,7 +29,7 @@ extern "C" { /* it may be defined already */ #ifndef __BLI_UTILDEFINES_H__ -bool BLI_memory_is_zero(const void *arr, const size_t size); +bool BLI_memory_is_zero(const void *arr, size_t size); #endif #ifdef __cplusplus diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 16f479cb3b8..658cc0c3825 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -75,16 +75,15 @@ bool BLI_make_existing_file(const char *name); * - Doesn't use CWD, or deal with relative paths. * - Only fill's in \a dir and \a file when they are non NULL. */ -void BLI_split_dirfile( - const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen); +void BLI_split_dirfile(const char *string, char *dir, char *file, size_t dirlen, size_t filelen); /** * Copies the parent directory part of string into `dir`, max length `dirlen`. */ -void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen); +void BLI_split_dir_part(const char *string, char *dir, size_t dirlen); /** * Copies the leaf filename part of string into `file`, max length `filelen`. */ -void BLI_split_file_part(const char *string, char *file, const size_t filelen); +void BLI_split_file_part(const char *string, char *file, size_t filelen); /** * Returns a pointer to the last extension (e.g. the position of the last period). * Returns NULL if there is no extension. @@ -94,7 +93,7 @@ const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(); /** * Append a filename to a dir, ensuring slash separates. */ -void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__restrict file) +void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict file) ATTR_NONNULL(); /** * Simple appending of filename to dir, does not check for valid path! @@ -104,7 +103,7 @@ void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__re * that de-duplicates separators and can handle an arbitrary number of paths. */ void BLI_join_dirfile(char *__restrict dst, - const size_t maxlen, + size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL(); /** @@ -114,7 +113,7 @@ void BLI_join_dirfile(char *__restrict dst, * \note If you want a trailing slash, add `SEP_STR` as the last path argument, * duplicate slashes will be cleaned up. */ -size_t BLI_path_join(char *__restrict dst, const size_t dst_len, const char *path_first, ...) +size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first, ...) ATTR_NONNULL(1, 3) ATTR_SENTINEL(0); /** * Like Python's `os.path.basename()` @@ -164,12 +163,12 @@ void BLI_path_slash_rstrip(char *string) ATTR_NONNULL(); void BLI_path_slash_native(char *path) ATTR_NONNULL(); #ifdef _WIN32 -bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen); +bool BLI_path_program_extensions_add_win32(char *name, size_t maxlen); #endif /** * Search for a binary (executable) */ -bool BLI_path_program_search(char *fullname, const size_t maxlen, const char *name); +bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name); /** * \return true when `str` end with `ext` (case insensitive). @@ -353,7 +352,7 @@ bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(); * This is _not_ something Blender's internal paths support, instead they use the "//" prefix. * In most cases #BLI_path_abs should be used instead. */ -bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) ATTR_NONNULL(); +bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL(); /** * Replaces `file` with a relative version (prefixed by "//") such that #BLI_path_abs, given * the same `relfile`, will convert it back to its original value. diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h index 653f5f61c9e..eb4e69a42d4 100644 --- a/source/blender/blenlib/BLI_stack.h +++ b/source/blender/blenlib/BLI_stack.h @@ -28,13 +28,13 @@ extern "C" { typedef struct BLI_Stack BLI_Stack; -BLI_Stack *BLI_stack_new_ex(const size_t elem_size, +BLI_Stack *BLI_stack_new_ex(size_t elem_size, const char *description, - const size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** * Create a new homogeneous stack with elements of 'elem_size' bytes. */ -BLI_Stack *BLI_stack_new(const size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT +BLI_Stack *BLI_stack_new(size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index a82e97914db..8177545911c 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -42,8 +42,7 @@ extern "C" { * \param len: The number of bytes to duplicate * \retval Returns the duplicated string */ -char *BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); +char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** * Duplicates the cstring \a str into a newly mallocN'd @@ -74,8 +73,7 @@ char *BLI_strdupcat(const char *__restrict str1, * the size of dst) * \retval Returns dst */ -char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) - ATTR_NONNULL(); +char *BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(); /** * Like BLI_strncpy but ensures dst is always padded by given char, @@ -107,7 +105,7 @@ char *BLI_strncpy_ensure_pad(char *__restrict dst, */ size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, - const size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); @@ -186,7 +184,7 @@ void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL(); * \note Larger tables should use a hash table. */ bool BLI_str_replace_table_exact(char *string, - const size_t string_len, + size_t string_len, const char *replace_table[][2], int replace_table_len); @@ -235,7 +233,7 @@ char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT * * \note This is used for creating animation paths in blend files. */ -size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) +size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(); /** * This roughly matches C and Python's string escaping with double quotes - `"`. @@ -251,9 +249,9 @@ size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const si */ size_t BLI_str_unescape_ex(char *__restrict dst, const char *__restrict src, - const size_t src_maxncpy, + size_t src_maxncpy, /* Additional arguments. */ - const size_t dst_maxncpy, + size_t dst_maxncpy, bool *r_is_complete) ATTR_NONNULL(); /** * See #BLI_str_unescape_ex doc-string. @@ -265,7 +263,7 @@ size_t BLI_str_unescape_ex(char *__restrict dst, * * \note This is used for parsing animation paths in blend files (runs often). */ -size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy) +size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_maxncpy) ATTR_NONNULL(); /** @@ -359,10 +357,10 @@ int BLI_strcmp_ignore_pad(const char *str1, const char *str2, char pad) ATTR_WAR /** * Determine the length of a fixed-size string. */ -size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL(); -void BLI_str_toupper_ascii(char *str, const size_t len) ATTR_NONNULL(); +void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(); +void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(); /** * Strip white-space from end of the string. */ @@ -479,7 +477,7 @@ bool BLI_string_all_words_matched(const char *name, * \return The number of words found in \a str */ int BLI_string_find_split_words(const char *str, - const size_t len, + size_t len, char delim, int r_words[][2], int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 82622d442fb..108a2f5fc7d 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -110,14 +110,12 @@ size_t BLI_str_utf8_from_unicode_len(unsigned int c) ATTR_WARN_UNUSED_RESULT; * * \return number of bytes written. */ -size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, const size_t outbuf_len) - ATTR_NONNULL(2); +size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, size_t outbuf_len) ATTR_NONNULL(2); size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, - const size_t maxncpy) ATTR_NONNULL(1, 2); -size_t BLI_str_utf32_as_utf8(char *__restrict dst, - const char32_t *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); +size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, size_t maxncpy) + ATTR_NONNULL(1, 2); /** * \return The UTF-32 len in UTF-8. */ @@ -162,21 +160,20 @@ size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RES size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; -size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes) +size_t BLI_strnlen_utf8_ex(const char *strc, size_t maxlen, size_t *r_len_bytes) ATTR_NONNULL(1, 3); /** * \param strc: the string to measure the length. * \param maxlen: the string length (in bytes) * \return the unicode length (not in bytes!) */ -size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) - ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +size_t BLI_strnlen_utf8(const char *strc, size_t maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); /** * Count columns that character/string occupies (based on `wcwidth.co`). diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index fd3918ff217..818bfe8182b 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -57,11 +57,11 @@ bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(); * Based on `BLI_split_dirfile()` / `os.path.splitext()`, * `"a.b.c"` -> (`"a.b"`, `".c"`). */ -void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len); +void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, size_t str_len); /** * `"a.b.c"` -> (`"a."`, `"b.c"`). */ -void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len); +void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size_t str_len); /** * Join strings, return newly allocated string. @@ -127,7 +127,7 @@ char *BLI_string_join_array_by_sep_char_with_tableN(char sep, size_t BLI_string_flip_side_name(char *r_name, const char *from_name, bool strip_number, - const size_t name_len); + size_t name_len); /** * Ensures name is unique (according to criteria specified by caller in unique_check callback), diff --git a/source/blender/blenlib/BLI_timecode.h b/source/blender/blenlib/BLI_timecode.h index f0349e289ac..1cd18dc86ab 100644 --- a/source/blender/blenlib/BLI_timecode.h +++ b/source/blender/blenlib/BLI_timecode.h @@ -42,7 +42,7 @@ extern "C" { * \return length of \a str */ size_t BLI_timecode_string_from_time(char *str, - const size_t maxncpy, + size_t maxncpy, int brevity_level, float time_seconds, double fps, @@ -56,7 +56,7 @@ size_t BLI_timecode_string_from_time(char *str, * \param time_seconds: time total time in seconds * \return length of \a str */ -size_t BLI_timecode_string_from_time_simple(char *str, const size_t maxncpy, double time_seconds) +size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double time_seconds) ATTR_NONNULL(); /** @@ -72,7 +72,7 @@ size_t BLI_timecode_string_from_time_simple(char *str, const size_t maxncpy, dou * \note in some cases this is used to print non-seconds values. */ size_t BLI_timecode_string_from_time_seconds(char *str, - const size_t maxncpy, + size_t maxncpy, int brevity_level, float time_seconds) ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index b902458bd0b..35d4158de59 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -638,7 +638,7 @@ extern "C" { /** * Check if memory is zeroed, as with `memset(arr, 0, arr_size)`. */ -extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); +extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); #endif #define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member) \ diff --git a/source/blender/blenlib/intern/BLI_mempool_private.h b/source/blender/blenlib/intern/BLI_mempool_private.h index 90569d87c41..03b0b11297b 100644 --- a/source/blender/blenlib/intern/BLI_mempool_private.h +++ b/source/blender/blenlib/intern/BLI_mempool_private.h @@ -54,8 +54,9 @@ typedef struct ParallelMempoolTaskData { * * See #BLI_task_parallel_mempool implementation for detailed usage example. */ -ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter) - ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, + size_t num_iter) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(); void mempool_iter_threadsafe_destroy(ParallelMempoolTaskData *iter_arr) ATTR_NONNULL(); /** diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 0e871f47b87..e601ebac4e1 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -136,7 +136,7 @@ void add_exr_channels(void *exrhandle, const char *layer_name, const DataType datatype, const char *view_name, - const size_t width, + size_t width, bool use_half_float, float *buf); void free_exr_channels(void *exrhandle, diff --git a/source/blender/depsgraph/intern/node/deg_node_factory.h b/source/blender/depsgraph/intern/node/deg_node_factory.h index 125f340a0fa..b3153a7ddfb 100644 --- a/source/blender/depsgraph/intern/node/deg_node_factory.h +++ b/source/blender/depsgraph/intern/node/deg_node_factory.h @@ -55,7 +55,7 @@ template struct DepsNodeFactoryImpl : public DepsNodeFacto void register_node_typeinfo(DepsNodeFactory *factory); /* Get typeinfo for specified type */ -DepsNodeFactory *type_get_factory(const NodeType type); +DepsNodeFactory *type_get_factory(NodeType type); } // namespace deg } // namespace blender diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h index 8a669a2afc2..6bcddfa631a 100644 --- a/source/blender/editors/include/ED_util.h +++ b/source/blender/editors/include/ED_util.h @@ -102,7 +102,7 @@ void ED_slider_destroy(struct bContext *C, struct tSlider *slider); */ void ED_slider_status_string_get(const struct tSlider *slider, char *status_string, - const size_t size_of_status_string); + size_t size_of_status_string); float ED_slider_factor_get(struct tSlider *slider); void ED_slider_factor_set(struct tSlider *slider, float factor); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 5ecc43a9fc9..9ce07cd2e07 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -495,7 +495,7 @@ float UI_text_clip_middle_ex(const struct uiFontStyle *fstyle, char *str, float okwidth, float minwidth, - const size_t max_len, + size_t max_len, char rpart_sep); /** diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 027f03d05c7..923f741e3ae 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -688,11 +688,11 @@ extern void ui_hsvcube_pos_from_vals( */ extern void ui_but_string_get_ex(uiBut *but, char *str, - const size_t maxlen, + size_t maxlen, int float_precision, bool use_exp_float, bool *r_use_exp_float) ATTR_NONNULL(1, 2); -extern void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) ATTR_NONNULL(); +extern void ui_but_string_get(uiBut *but, char *str, size_t maxlen) ATTR_NONNULL(); /** * A version of #ui_but_string_get_ex for dynamic buffer sizes * (where #ui_but_string_get_max_length returns 0). diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index c7481c6ea67..65d7631445d 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -544,7 +544,7 @@ bool IMB_prepare_write_ImBuf(bool isfloat, struct ImBuf *ibuf); */ bool IMB_ispic(const char *filepath); bool IMB_ispic_type_matches(const char *filepath, int filetype); -int IMB_ispic_type_from_memory(const unsigned char *buf, const size_t buf_size); +int IMB_ispic_type_from_memory(const unsigned char *buf, size_t buf_size); int IMB_ispic_type(const char *filepath); /** @@ -972,28 +972,20 @@ void IMB_update_gpu_texture_sub(struct GPUTexture *tex, /** * \attention defined in stereoimbuf.c */ -void IMB_stereo3d_write_dimensions(char mode, - bool is_squeezed, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); -void IMB_stereo3d_read_dimensions(char mode, - bool is_squeezed, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); +void IMB_stereo3d_write_dimensions( + char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); +void IMB_stereo3d_read_dimensions( + char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); int *IMB_stereo3d_from_rect(struct ImageFormatData *im_format, - const size_t x, - const size_t y, - const size_t channels, + size_t x, + size_t y, + size_t channels, int *rect_left, int *rect_right); float *IMB_stereo3d_from_rectf(struct ImageFormatData *im_format, - const size_t x, - const size_t y, - const size_t channels, + size_t x, + size_t y, + size_t channels, float *rectf_left, float *rectf_right); /** diff --git a/source/blender/imbuf/IMB_metadata.h b/source/blender/imbuf/IMB_metadata.h index 652ce913ee5..50982d08c3e 100644 --- a/source/blender/imbuf/IMB_metadata.h +++ b/source/blender/imbuf/IMB_metadata.h @@ -58,10 +58,7 @@ void IMB_metadata_free(struct IDProperty *metadata); * \param len: length of value buffer allocated by user. * \return 1 (true) if metadata is present and value for the key found, 0 (false) otherwise. */ -bool IMB_metadata_get_field(struct IDProperty *metadata, - const char *key, - char *value, - const size_t len); +bool IMB_metadata_get_field(struct IDProperty *metadata, const char *key, char *value, size_t len); /** * Set user data in the metadata. diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h index 104458ffa7a..bf6aef3ecd3 100644 --- a/source/blender/imbuf/intern/IMB_filetype.h +++ b/source/blender/imbuf/intern/IMB_filetype.h @@ -41,7 +41,7 @@ typedef struct ImFileType { * \note that this may only read in a small part of the files header, * see: #IMB_ispic_type for details. */ - bool (*is_a)(const unsigned char *buf, const size_t size); + bool (*is_a)(const unsigned char *buf, size_t size); /** Load an image from memory. */ struct ImBuf *(*load)(const unsigned char *mem, @@ -93,7 +93,7 @@ void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty); /** \name Format: PNG (#IMB_FTYPE_PNG) * \{ */ -bool imb_is_a_png(const unsigned char *mem, const size_t size); +bool imb_is_a_png(const unsigned char *mem, size_t size); struct ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, @@ -106,7 +106,7 @@ bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: TARGA (#IMB_FTYPE_TGA) * \{ */ -bool imb_is_a_targa(const unsigned char *buf, const size_t size); +bool imb_is_a_targa(const unsigned char *buf, size_t size); struct ImBuf *imb_loadtarga(const unsigned char *mem, size_t size, int flags, @@ -119,7 +119,7 @@ bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: IRIS (#IMB_FTYPE_IMAGIC) * \{ */ -bool imb_is_a_iris(const unsigned char *mem, const size_t size); +bool imb_is_a_iris(const unsigned char *mem, size_t size); /** * Read in a B/W RGB or RGBA iris image file and return an image buffer. */ @@ -135,7 +135,7 @@ bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JP2 (#IMB_FTYPE_JP2) * \{ */ -bool imb_is_a_jp2(const unsigned char *buf, const size_t size); +bool imb_is_a_jp2(const unsigned char *buf, size_t size); struct ImBuf *imb_load_jp2(const unsigned char *mem, size_t size, int flags, @@ -151,7 +151,7 @@ bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JPEG (#IMB_FTYPE_JPG) * \{ */ -bool imb_is_a_jpeg(const unsigned char *mem, const size_t size); +bool imb_is_a_jpeg(const unsigned char *mem, size_t size); bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags); struct ImBuf *imb_load_jpeg(const unsigned char *buffer, size_t size, @@ -164,7 +164,7 @@ struct ImBuf *imb_load_jpeg(const unsigned char *buffer, /** \name Format: BMP (#IMB_FTYPE_BMP) * \{ */ -bool imb_is_a_bmp(const unsigned char *buf, const size_t size); +bool imb_is_a_bmp(const unsigned char *buf, size_t size); struct ImBuf *imb_bmp_decode(const unsigned char *mem, size_t size, int flags, @@ -178,7 +178,7 @@ bool imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: CINEON (#IMB_FTYPE_CINEON) * \{ */ -bool imb_is_a_cineon(const unsigned char *buf, const size_t size); +bool imb_is_a_cineon(const unsigned char *buf, size_t size); bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_cineon(const unsigned char *mem, size_t size, @@ -191,7 +191,7 @@ struct ImBuf *imb_load_cineon(const unsigned char *mem, /** \name Format: DPX (#IMB_FTYPE_DPX) * \{ */ -bool imb_is_a_dpx(const unsigned char *buf, const size_t size); +bool imb_is_a_dpx(const unsigned char *buf, size_t size); bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_dpx(const unsigned char *mem, size_t size, @@ -204,7 +204,7 @@ struct ImBuf *imb_load_dpx(const unsigned char *mem, /** \name Format: HDR (#IMB_FTYPE_RADHDR) * \{ */ -bool imb_is_a_hdr(const unsigned char *buf, const size_t size); +bool imb_is_a_hdr(const unsigned char *buf, size_t size); struct ImBuf *imb_loadhdr(const unsigned char *mem, size_t size, int flags, @@ -218,7 +218,7 @@ bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags); * \{ */ void imb_inittiff(void); -bool imb_is_a_tiff(const unsigned char *buf, const size_t size); +bool imb_is_a_tiff(const unsigned char *buf, size_t size); /** * Loads a TIFF file. * \param mem: Memory containing the TIFF file. diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index 931c4f267f9..2d540f13a52 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -26,7 +26,7 @@ extern "C" { #endif -bool imb_is_a_dds(const unsigned char *mem, const size_t size); +bool imb_is_a_dds(const unsigned char *mem, size_t size); bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_dds(const unsigned char *mem, size_t size, diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index 659050cdb00..1201bd1b5e0 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -31,7 +31,7 @@ extern "C" { struct ImBuf; -bool imb_is_a_photoshop(const unsigned char *mem, const size_t size); +bool imb_is_a_photoshop(const unsigned char *mem, size_t size); int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h index 14336620926..4321c95db30 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.h +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -36,7 +36,7 @@ void imb_exitopenexr(void); * Test presence of OpenEXR file. * \param mem: pointer to loaded OpenEXR bit-stream. */ -bool imb_is_a_openexr(const unsigned char *mem, const size_t size); +bool imb_is_a_openexr(const unsigned char *mem, size_t size); bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 20f77626e49..07897231566 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -1742,7 +1742,7 @@ bool RNA_struct_override_matches(struct Main *bmain, struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, const char *root_path, - const size_t root_path_len, + size_t root_path_len, struct IDOverrideLibrary *override, eRNAOverrideMatch flags, eRNAOverrideMatchResult *r_report_flags); diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 20e6e931b4b..95ad184c6b9 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -544,7 +544,7 @@ int rna_property_override_diff_default(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - const size_t rna_path_len, + size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index f0e32a19d04..723ae384fdf 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -214,7 +214,7 @@ typedef int (*RNAPropOverrideDiff)(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - const size_t rna_path_len, + size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh index f0f2b64ec4e..1c2a8f521c0 100644 --- a/source/blender/nodes/geometry/node_geometry_util.hh +++ b/source/blender/nodes/geometry/node_geometry_util.hh @@ -83,7 +83,7 @@ Mesh *create_cylinder_or_cone_mesh(float radius_top, int circle_segments, int side_segments, int fill_segments, - const GeometryNodeMeshCircleFillType fill_type, + GeometryNodeMeshCircleFillType fill_type, ConeAttributeOutputs &attribute_outputs); Mesh *create_cuboid_mesh(float3 size, int verts_x, int verts_y, int verts_z); diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 604792389fa..f08665d75e7 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -57,20 +57,20 @@ void PyC_Err_PrintWithFunc(PyObject *py_func); void PyC_FileAndNum(const char **r_filename, int *r_lineno); void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno); /* checks python is running */ int PyC_AsArray_FAST(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value_fast, - const Py_ssize_t length, + Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value, - const Py_ssize_t length, + Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray_Multi_FAST(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value_fast, const int *dims, int dims_len, @@ -78,7 +78,7 @@ int PyC_AsArray_Multi_FAST(void *array, const char *error_prefix); int PyC_AsArray_Multi(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value, const int *dims, int dims_len, diff --git a/source/blender/render/RE_bake.h b/source/blender/render/RE_bake.h index 43d3b5b323c..b7ce3da71ff 100644 --- a/source/blender/render/RE_bake.h +++ b/source/blender/render/RE_bake.h @@ -96,7 +96,7 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, BakePixel pixel_array_to[], BakeHighPolyData highpoly[], int tot_highpoly, - const size_t num_pixels, + size_t num_pixels, bool is_custom_cage, float cage_extrusion, float max_ray_distance, @@ -106,16 +106,16 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, void RE_bake_pixels_populate(struct Mesh *me, struct BakePixel *pixel_array, - const size_t num_pixels, + size_t num_pixels, const struct BakeTargets *targets, const char *uv_layer); -void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask); +void RE_bake_mask_fill(const BakePixel pixel_array[], size_t num_pixels, char *mask); void RE_bake_margin(struct ImBuf *ibuf, char *mask, int margin); void RE_bake_normal_world_to_object(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], struct Object *ob, @@ -125,14 +125,14 @@ void RE_bake_normal_world_to_object(const BakePixel pixel_array[], * to a tangent space normal map for a given low poly mesh. */ void RE_bake_normal_world_to_tangent(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], struct Mesh *me, const eBakeNormalSwizzle normal_swizzle[3], float mat[4][4]); void RE_bake_normal_world_to_world(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], const eBakeNormalSwizzle normal_swizzle[3]); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 9a8a6a3a3ac..2e305c0bf3c 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -607,7 +607,7 @@ int WM_operator_confirm_message_ex(struct bContext *C, const char *title, int icon, const char *message, - const wmOperatorCallContext opcontext); + wmOperatorCallContext opcontext); int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message); /* Operator API. */ -- cgit v1.2.3 From 77616082f44da5258faf9ec0d53618c721b88c62 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Tue, 11 Jan 2022 20:48:32 -0800 Subject: Fix T89542: Crash when loading certain .hdr files The direct cause of the bug in question was passing in the raw memory buffer to sscanf. It should be called with a null-terminated buffer; which isn't guaranteed when blindly trusting the file data. When attempting to fuzz this code path, a variety of other crashes were discovered and fixed. Differential Revision: https://developer.blender.org/D11952 --- source/blender/imbuf/intern/radiance_hdr.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 7f4e4dd31df..0bca68b93bc 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -77,7 +77,7 @@ static const unsigned char *oldreadcolrs(RGBE *scan, scan[0][BLU] = *mem++; scan[0][EXP] = *mem++; if (scan[0][RED] == 1 && scan[0][GRN] == 1 && scan[0][BLU] == 1) { - for (i = scan[0][EXP] << rshift; i > 0; i--) { + for (i = scan[0][EXP] << rshift; i > 0 && len > 0; i--) { COPY_RGBE(scan[-1], scan[0]); scan++; len--; @@ -227,7 +227,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, int found = 0; int width = 0, height = 0; const unsigned char *ptr, *mem_eof = mem + size; - char oriY[80], oriX[80]; + char oriY[3], oriX[3]; if (!imb_is_a_hdr(mem, size)) { return NULL; @@ -244,13 +244,19 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, } } - if ((found && (x < (size + 2))) == 0) { + if ((found && (x < (size - 1))) == 0) { /* Data not found! */ return NULL; } - if (sscanf((const char *)&mem[x + 1], - "%79s %d %79s %d", + x++; + + /* sscanf requires a null-terminated buffer argument */ + char buf[32] = {0}; + memcpy(buf, &mem[x], MIN2(sizeof(buf) - 1, size - x)); + + if (sscanf(buf, + "%2s %d %2s %d", (char *)&oriY, &height, (char *)&oriX, @@ -258,8 +264,18 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, return NULL; } + if (width < 1 || height < 1) { + return NULL; + } + + /* Checking that width x height does not extend past mem_eof is not easily possible + * since the format uses RLE compression. Can cause excessive memory allocation to occur. */ + /* find end of this line, data right behind it */ - ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n'); + ptr = (const unsigned char *)strchr((const char *)&mem[x], '\n'); + if (ptr == NULL || ptr >= mem_eof) { + return NULL; + } ptr++; if (flags & IB_test) { -- cgit v1.2.3 From 7f28084e2a94da3ea8952b8e355fe672be3f53d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Wed, 12 Jan 2022 06:46:12 +0100 Subject: Cleanup: use utility functions --- .../blender/io/alembic/intern/abc_reader_object.cc | 25 +++------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'source/blender') diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc index 4a359c49d26..86fa580bf1f 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.cc +++ b/source/blender/io/alembic/intern/abc_reader_object.cc @@ -120,29 +120,10 @@ static Imath::M44d blend_matrices(const Imath::M44d &m0, const Imath::M44d &m1, * the matrices manually. */ - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - mat0[i][j] = static_cast(m0[i][j]); - } - } - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - mat1[i][j] = static_cast(m1[i][j]); - } - } - + convert_matrix_datatype(m0, mat0); + convert_matrix_datatype(m1, mat1); interp_m4_m4m4(ret, mat0, mat1, weight); - - Imath::M44d m; - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - m[i][j] = ret[i][j]; - } - } - - return m; + return convert_matrix_datatype(ret); } Imath::M44d get_matrix(const IXformSchema &schema, const float time) -- cgit v1.2.3 From 795cea2cce3bcfaa7489034a90722ee57cb8e358 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Tue, 11 Jan 2022 22:48:26 +0100 Subject: Revert "Cleanup GPencil strength previous commit" This reverts commit e339946515b00bc230bad2ec52a729dd914a8af3. This broken the tablet pressure and it was impossible to set a proper strength. --- source/blender/editors/gpencil/gpencil_paint.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 0b713af54ae..79dda480a0a 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -835,7 +835,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p, /* color strength */ if (brush_settings->flag & GP_BRUSH_USE_STRENGTH_PRESSURE) { pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); - CLAMP(pt->strength, brush_settings->draw_strength, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); } /* Set vertex colors for buffer. */ @@ -1031,7 +1031,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, brush_settings->draw_strength, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; /* Apply the vertex color to point. */ @@ -1065,7 +1065,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, brush_settings->draw_strength, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); pt->time = ptc->time; /* Apply the vertex color to point. */ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); @@ -1190,7 +1190,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, brush_settings->draw_strength, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; pt->uv_fac = ptc->uv_fac; -- cgit v1.2.3 From 7a2b18159170b91694fd7c64825a699314fae3ca Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 11 Jan 2022 11:27:35 +0100 Subject: Fix T94041: Loading a new file gives crash while rendering in viewport The issue was caused by Cycles display driver not being able to restore window's OpenGL context after disposing Cycles-side OpenGL context. This is due to the window OpenGL re-activation needing to access window manager which gets cleared out form global main during file reading. Defer clearing window manager from the global main to until after all screens are "exited". This allows Cycles to properly stop rendering, dispose its OpenGL context, and restore window's drawable context. It is unclear why it was required to clear window manager list early on. Guess is that it comes from an original code in a1c8543f2ac where there was an early return which then got replaced with an actual logic without changing the order of de-initialization and window manager list clear. Differential Revision: https://developer.blender.org/D13799 --- source/blender/windowmanager/intern/wm_files.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 99bab3ae23d..344f4959a93 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -193,7 +193,6 @@ bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWind static void wm_window_match_init(bContext *C, ListBase *wmlist) { *wmlist = G_MAIN->wm; - BLI_listbase_clear(&G_MAIN->wm); wmWindow *active_win = CTX_wm_window(C); @@ -220,6 +219,8 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist) } } + BLI_listbase_clear(&G_MAIN->wm); + /* reset active window */ CTX_wm_window_set(C, active_win); -- cgit v1.2.3 From 145f1d1e0a59c1de311a0511e05541563296d879 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 12 Jan 2022 11:07:31 +0100 Subject: Fix T94812: render layer sockets are missing after file load The main issue was the use of `G_MAIN` during file load. This patch refactors the code so that iterating over `G_MAIN` is not necessary anymore. See D13800 for more details. Differential Revision: https://developer.blender.org/D13800 --- source/blender/blenkernel/BKE_node.h | 8 +------ .../blender/nodes/composite/node_composite_tree.cc | 17 ------------- .../nodes/composite/nodes/node_composite_image.cc | 28 ++++++++++------------ 3 files changed, 14 insertions(+), 39 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 71d1728a870..ef86804cc3b 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1373,18 +1373,12 @@ void ntreeCompositTagRender(struct Scene *scene); * - Each render layer node calls the update function of the * render engine that's used for its scene. * - The render engine calls RE_engine_register_pass for each pass. - * - #RE_engine_register_pass calls #ntreeCompositRegisterPass, - * which calls #node_cmp_rlayers_register_pass for every render layer node. + * - #RE_engine_register_pass calls #node_cmp_rlayers_register_pass. * * TODO: This is *not* part of `blenkernel`, it's defined under "source/blender/nodes/". * This declaration should be moved out of BKE. */ void ntreeCompositUpdateRLayers(struct bNodeTree *ntree); -void ntreeCompositRegisterPass(struct bNodeTree *ntree, - struct Scene *scene, - struct ViewLayer *view_layer, - const char *name, - eNodeSocketDatatype type); void ntreeCompositClearTags(struct bNodeTree *ntree); struct bNodeSocket *ntreeCompositOutputFileAddSocket(struct bNodeTree *ntree, diff --git a/source/blender/nodes/composite/node_composite_tree.cc b/source/blender/nodes/composite/node_composite_tree.cc index 08dbd4ad6f0..c54382cc1ad 100644 --- a/source/blender/nodes/composite/node_composite_tree.cc +++ b/source/blender/nodes/composite/node_composite_tree.cc @@ -249,23 +249,6 @@ void ntreeCompositUpdateRLayers(bNodeTree *ntree) } } -void ntreeCompositRegisterPass(bNodeTree *ntree, - Scene *scene, - ViewLayer *view_layer, - const char *name, - eNodeSocketDatatype type) -{ - if (ntree == nullptr) { - return; - } - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node->type == CMP_NODE_R_LAYERS) { - node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type); - } - } -} - void ntreeCompositTagRender(Scene *scene) { /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes, diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index 6f4f9d7e597..f2b9fbc2215 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -269,7 +269,12 @@ void node_cmp_rlayers_register_pass(bNodeTree *ntree, } } -static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), +struct CreateOutputUserData { + bNodeTree &ntree; + bNode &node; +}; + +static void cmp_node_rlayer_create_outputs_cb(void *userdata, Scene *scene, ViewLayer *view_layer, const char *name, @@ -277,18 +282,8 @@ static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), const char *UNUSED(chanid), eNodeSocketDatatype type) { - /* Register the pass in all scenes that have a render layer node for this layer. - * Since multiple scenes can be used in the compositor, the code must loop over all scenes - * and check whether their nodetree has a node that needs to be updated. */ - /* NOTE: using G_MAIN seems valid here, - * unless we want to register that for every other temp Main we could generate??? */ - ntreeCompositRegisterPass(scene->nodetree, scene, view_layer, name, type); - - for (Scene *sce = (Scene *)G_MAIN->scenes.first; sce; sce = (Scene *)sce->id.next) { - if (sce->nodetree && sce != scene) { - ntreeCompositRegisterPass(sce->nodetree, scene, view_layer, name, type); - } - } + CreateOutputUserData &data = *(CreateOutputUserData *)userdata; + node_cmp_rlayers_register_pass(&data.ntree, &data.node, scene, view_layer, name, type); } static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, @@ -308,14 +303,17 @@ static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, data->prev_index = -1; node->storage = data; + CreateOutputUserData userdata = {*ntree, *node}; + RenderEngine *engine = RE_engine_create(engine_type); RE_engine_update_render_passes( - engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, nullptr); + engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, &userdata); RE_engine_free(engine); if ((scene->r.mode & R_EDGE_FRS) && (view_layer->freestyle_config.flags & FREESTYLE_AS_RENDER_PASS)) { - ntreeCompositRegisterPass(ntree, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); + node_cmp_rlayers_register_pass( + ntree, node, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); } MEM_freeN(data); -- cgit v1.2.3 From 1e61b759c7adc10be2df7edab35c507e804a7fed Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 12 Jan 2022 11:15:22 +0100 Subject: Fix T94797: crash when playing animation in eevee rendered view The issue was caused by rBd09b1d2759861aa012ab2e7e4ce2ffa2. Since this commit, the image users in gpu materials were updated during depsgraph evaluation as well. However, there was a race condition when one thread is deleting gpu materials in `BKE_material_eval` while another thread is updating the image users at the same time. The solution is to make sure that deleting gpu materials is done before iterating over all gpu materials, by adding a new depsgraph relation. --- .../blender/depsgraph/intern/builder/deg_builder_relations.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/blender') diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 1c09417e9ab..fcdc3fe58e8 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1475,6 +1475,17 @@ void DepsgraphRelationBuilder::build_animation_images(ID *id) id, NodeType::IMAGE_ANIMATION, OperationCode::IMAGE_ANIMATION); TimeSourceKey time_src_key; add_relation(time_src_key, image_animation_key, "TimeSrc -> Image Animation"); + + /* The image users of these ids may change during evaluation. Make sure that the image + * animation update happens after evaluation. */ + if (GS(id->name) == ID_MA) { + OperationKey material_update_key(id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE); + add_relation(material_update_key, image_animation_key, "Material Update -> Image Animation"); + } + else if (GS(id->name) == ID_WO) { + OperationKey world_update_key(id, NodeType::SHADING, OperationCode::WORLD_UPDATE); + add_relation(world_update_key, image_animation_key, "World Update -> Image Animation"); + } } } -- cgit v1.2.3 From d320f3677e2a98b12d386a3e6f3da2d7b7018463 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Wed, 12 Jan 2022 11:29:18 +0100 Subject: Cleanup: make format --- source/blender/imbuf/intern/radiance_hdr.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 0bca68b93bc..925ef0a8502 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -255,12 +255,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, char buf[32] = {0}; memcpy(buf, &mem[x], MIN2(sizeof(buf) - 1, size - x)); - if (sscanf(buf, - "%2s %d %2s %d", - (char *)&oriY, - &height, - (char *)&oriX, - &width) != 4) { + if (sscanf(buf, "%2s %d %2s %d", (char *)&oriY, &height, (char *)&oriX, &width) != 4) { return NULL; } -- cgit v1.2.3 From a2c1c368af48644fa8995ecbe7138cc0d7900c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 12 Jan 2022 12:19:00 +0100 Subject: BLI: Refactor vector types & functions to use templates This patch implements the vector types (i.e:float2) by making heavy usage of templating. All vector functions are now outside of the vector classes (inside the blender::math namespace) and are not vector size dependent for the most part. In the ongoing effort to make shaders less GL centric, we are aiming to share more code between GLSL and C++ to avoid code duplication. Motivations: - We are aiming to share UBO and SSBO structures between GLSL and C++. This means we will use many of the existing vector types and others we currently don't have (uintX, intX). All these variations were asking for many more code duplication. - Deduplicate existing code which is duplicated for each vector size. - We also want to share small functions. Which means that vector functions should be static and not in the class namespace. - Reduce friction to use these types in new projects due to their incompleteness. - The current state of the BLI_(float|double|mpq)(2|3|4).hh is a bit of a let down. Most clases are incomplete, out of sync with each others with different codestyles, and some functions that should be static are not (i.e: float3::reflect()). Upsides: - Still support .x, .y, .z, .w for readability. - Compact, readable and easilly extendable. - All of the vector functions are available for all the vectors types and can be restricted to certain types. Also template specialization let us define exception for special class (like mpq). - With optimization ON, the compiler unroll the loops and performance is the same. Downsides: - Might impact debugability. Though I would arge that the bugs are rarelly caused by the vector class itself (since the operations are quite trivial) but by the type conversions. - Might impact compile time. I did not saw a significant impact since the usage is not really widespread. - Functions needs to be rewritten to support arbitrary vector length. For instance, one can't call len_squared_v3v3 in math::length_squared() and call it a day. - Type cast does not work with the template version of the math:: vector functions. Meaning you need to manually cast float * and (float *)[3] to float3 for the function calls. i.e: math::distance_squared(float3(nearest.co), positions[i]); - Some parts might loose in readability: float3::dot(v1.normalized(), v2.normalized()) becoming math::dot(math::normalize(v1), math::normalize(v2)) But I propose, when appropriate, to use using namespace blender::math; on function local or file scope to increase readability. dot(normalize(v1), normalize(v2)) Consideration: - Include back .length() method. It is quite handy and is more C++ oriented. - I considered the GLM library as a candidate for replacement. It felt like too much for what we need and would be difficult to extend / modify to our needs. - I used Macros to reduce code in operators declaration and potential copy paste bugs. This could reduce debugability and could be reverted. - This touches delaunay_2d.cc and the intersection code. I would like to know @Howard Trickey (howardt) opinion on the matter. - The noexcept on the copy constructor of mpq(2|3) is being removed. But according to @Jacques Lucke (JacquesLucke) it is not a real problem for now. I would like to give a huge thanks to @Jacques Lucke (JacquesLucke) who helped during this and pushed me to reduce the duplication further. Reviewed By: brecht, sergey, JacquesLucke Differential Revision: http://developer.blender.org/D13791 --- source/blender/blenfont/BLF_api.h | 2 +- source/blender/blenfont/intern/blf_internal.h | 4 +- source/blender/blenkernel/BKE_appdir.h | 2 +- source/blender/blenkernel/BKE_attribute.h | 2 +- source/blender/blenkernel/BKE_attribute_access.hh | 3 +- source/blender/blenkernel/BKE_attribute_math.hh | 7 +- source/blender/blenkernel/BKE_bvhutils.h | 18 +- source/blender/blenkernel/BKE_customdata.h | 4 +- source/blender/blenkernel/BKE_geometry_set.hh | 2 +- source/blender/blenkernel/BKE_image.h | 2 +- source/blender/blenkernel/BKE_mesh_sample.hh | 2 +- source/blender/blenkernel/BKE_node.h | 8 +- source/blender/blenkernel/BKE_scene.h | 7 +- source/blender/blenkernel/BKE_spline.hh | 2 +- source/blender/blenkernel/BKE_vfont.h | 2 +- source/blender/blenkernel/BKE_volume.h | 2 +- source/blender/blenkernel/intern/DerivedMesh.cc | 2 +- .../blender/blenkernel/intern/attribute_access.cc | 2 +- .../blenkernel/intern/data_transfer_intern.h | 6 +- .../blenkernel/intern/geometry_component_mesh.cc | 5 +- source/blender/blenkernel/intern/gpencil_geom.cc | 2 +- source/blender/blenkernel/intern/hair.cc | 2 +- source/blender/blenkernel/intern/image.c | 26 +- source/blender/blenkernel/intern/mesh.cc | 10 +- .../blenkernel/intern/mesh_boolean_convert.cc | 2 +- .../blender/blenkernel/intern/mesh_remesh_voxel.cc | 2 +- source/blender/blenkernel/intern/object_dupli.cc | 8 +- source/blender/blenkernel/intern/pointcloud.cc | 24 +- source/blender/blenkernel/intern/simulation.cc | 2 +- source/blender/blenkernel/intern/spline_base.cc | 41 +- source/blender/blenkernel/intern/spline_bezier.cc | 37 +- source/blender/blenkernel/intern/tracking_test.cc | 2 +- .../blender/blenkernel/intern/type_conversions.cc | 3 +- source/blender/blenkernel/intern/volume.cc | 2 +- source/blender/blenkernel/intern/volume_render.cc | 2 +- source/blender/blenkernel/intern/volume_to_mesh.cc | 2 +- source/blender/blenlib/BLI_array_store.h | 2 +- source/blender/blenlib/BLI_array_utils.h | 4 +- source/blender/blenlib/BLI_buffer.h | 4 +- source/blender/blenlib/BLI_delaunay_2d.h | 4 +- source/blender/blenlib/BLI_double2.hh | 143 ------ source/blender/blenlib/BLI_double3.hh | 246 --------- source/blender/blenlib/BLI_fileops.h | 3 +- source/blender/blenlib/BLI_float2.hh | 218 -------- source/blender/blenlib/BLI_float3.hh | 320 ------------ source/blender/blenlib/BLI_float4.hh | 138 ----- source/blender/blenlib/BLI_float4x4.hh | 5 +- source/blender/blenlib/BLI_gsqueue.h | 2 +- source/blender/blenlib/BLI_listbase.h | 6 +- source/blender/blenlib/BLI_math_boolean.hh | 6 +- source/blender/blenlib/BLI_math_vec_mpq_types.hh | 91 ++++ source/blender/blenlib/BLI_math_vec_types.hh | 566 +++++++++++++++++++++ source/blender/blenlib/BLI_math_vector.hh | 399 +++++++++++++++ source/blender/blenlib/BLI_memarena.h | 4 +- source/blender/blenlib/BLI_memory_utils.h | 2 +- source/blender/blenlib/BLI_memory_utils.hh | 9 - source/blender/blenlib/BLI_mesh_intersect.hh | 5 +- source/blender/blenlib/BLI_mpq2.hh | 184 ------- source/blender/blenlib/BLI_mpq3.hh | 297 ----------- source/blender/blenlib/BLI_noise.hh | 4 +- source/blender/blenlib/BLI_path_util.h | 19 +- source/blender/blenlib/BLI_rand.hh | 3 +- source/blender/blenlib/BLI_stack.h | 6 +- source/blender/blenlib/BLI_string.h | 26 +- source/blender/blenlib/BLI_string_utf8.h | 19 +- source/blender/blenlib/BLI_string_utils.h | 6 +- source/blender/blenlib/BLI_timecode.h | 6 +- source/blender/blenlib/BLI_utildefines.h | 11 +- source/blender/blenlib/CMakeLists.txt | 10 +- .../blender/blenlib/intern/BLI_mempool_private.h | 5 +- source/blender/blenlib/intern/delaunay_2d.cc | 45 +- source/blender/blenlib/intern/math_boolean.cc | 7 +- source/blender/blenlib/intern/math_vec.cc | 133 ++--- source/blender/blenlib/intern/mesh_boolean.cc | 51 +- source/blender/blenlib/intern/mesh_intersect.cc | 88 ++-- source/blender/blenlib/intern/noise.cc | 79 ++- .../blender/blenlib/tests/BLI_delaunay_2d_test.cc | 3 +- .../blenlib/tests/BLI_math_vec_types_test.cc | 149 ++++++ .../blender/blenlib/tests/BLI_memory_utils_test.cc | 2 +- .../blender/blenlib/tests/BLI_mesh_boolean_test.cc | 2 +- .../blenlib/tests/BLI_mesh_intersect_test.cc | 2 +- source/blender/bmesh/intern/bmesh_opdefines.c | 1 - source/blender/bmesh/intern/bmesh_polygon.c | 7 - source/blender/compositor/CMakeLists.txt | 9 - source/blender/compositor/COM_defines.h | 2 +- source/blender/compositor/COM_precomp.h | 33 -- .../operations/COM_OutputFileOperation.h | 2 +- .../intern/builder/deg_builder_relations.cc | 11 - .../depsgraph/intern/node/deg_node_factory.h | 2 +- .../blender/draw/intern/draw_cache_impl_curve.cc | 2 +- .../mesh_extractors/extract_mesh_vbo_attributes.cc | 4 +- source/blender/editors/gpencil/gpencil_paint.c | 28 +- source/blender/editors/include/ED_util.h | 2 +- source/blender/editors/include/UI_interface.h | 6 +- .../blender/editors/interface/interface_intern.h | 4 +- source/blender/editors/interface/interface_panel.c | 1 - .../editors/interface/interface_region_tooltip.c | 15 +- source/blender/editors/interface/interface_style.c | 13 +- .../blender/editors/interface/interface_widgets.c | 7 +- source/blender/editors/object/object_add.c | 2 - source/blender/editors/render/render_preview.cc | 2 +- source/blender/editors/space_file/file_draw.c | 3 +- source/blender/editors/space_node/node_draw.cc | 2 +- source/blender/editors/space_node/node_group.cc | 2 +- source/blender/editors/space_node/node_intern.hh | 5 +- source/blender/editors/space_node/node_select.cc | 4 +- .../editors/space_sequencer/sequencer_draw.c | 37 +- .../space_spreadsheet/spreadsheet_column.cc | 3 +- .../space_spreadsheet/spreadsheet_layout.cc | 3 +- .../space_spreadsheet/spreadsheet_row_filter.cc | 8 +- source/blender/editors/util/ed_draw.c | 34 +- source/blender/freestyle/CMakeLists.txt | 5 +- source/blender/freestyle/FRS_precomp.cpp | 2 + source/blender/functions/intern/cpp_types.cc | 3 +- source/blender/imbuf/IMB_imbuf.h | 30 +- source/blender/imbuf/IMB_metadata.h | 5 +- source/blender/imbuf/intern/IMB_filetype.h | 22 +- source/blender/imbuf/intern/anim_movie.c | 11 +- source/blender/imbuf/intern/dds/dds_api.h | 2 +- source/blender/imbuf/intern/oiio/openimageio_api.h | 2 +- source/blender/imbuf/intern/openexr/openexr_api.h | 2 +- source/blender/imbuf/intern/radiance_hdr.c | 31 +- .../blender/io/alembic/intern/abc_reader_object.cc | 25 +- .../blender/io/gpencil/intern/gpencil_io_base.cc | 5 +- .../blender/io/gpencil/intern/gpencil_io_base.hh | 3 +- .../io/gpencil/intern/gpencil_io_import_svg.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mesh.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_nurbs.cc | 2 +- .../io/wavefront_obj/tests/obj_exporter_tests.cc | 2 +- source/blender/makesdna/DNA_modifier_types.h | 1 - source/blender/makesdna/DNA_node_types.h | 1 - source/blender/makesrna/RNA_access.h | 2 +- source/blender/makesrna/intern/rna_internal.h | 2 +- .../blender/makesrna/intern/rna_internal_types.h | 2 +- source/blender/makesrna/intern/rna_modifier.c | 7 +- source/blender/makesrna/intern/rna_nodetree.c | 7 +- .../blender/modifiers/intern/MOD_mesh_to_volume.cc | 4 +- source/blender/modifiers/intern/MOD_nodes.cc | 2 +- source/blender/nodes/NOD_math_functions.hh | 75 ++- source/blender/nodes/NOD_socket_declarations.hh | 2 +- .../blender/nodes/composite/node_composite_tree.cc | 17 + .../nodes/composite/nodes/node_composite_image.cc | 28 +- .../blender/nodes/function/node_function_util.hh | 2 +- .../nodes/node_fn_align_euler_to_vector.cc | 8 +- .../nodes/function/nodes/node_fn_compare.cc | 24 +- .../blender/nodes/geometry/node_geometry_util.hh | 4 +- .../node_geo_legacy_align_rotation_to_vector.cc | 8 +- .../legacy/node_geo_legacy_attribute_proximity.cc | 2 +- .../legacy/node_geo_legacy_attribute_transfer.cc | 2 +- .../legacy/node_geo_legacy_curve_to_points.cc | 4 +- .../legacy/node_geo_legacy_point_distribute.cc | 4 +- .../legacy/node_geo_legacy_points_to_volume.cc | 2 +- .../nodes/legacy/node_geo_legacy_raycast.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fill.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fillet.cc | 21 +- .../nodes/node_geo_curve_primitive_circle.cc | 18 +- .../nodes/node_geo_curve_primitive_line.cc | 2 +- .../node_geo_curve_primitive_quadratic_bezier.cc | 6 +- .../nodes/geometry/nodes/node_geo_curve_sample.cc | 4 +- .../nodes/node_geo_curve_spline_parameter.cc | 2 +- .../geometry/nodes/node_geo_curve_to_points.cc | 4 +- .../nodes/geometry/nodes/node_geo_image_texture.cc | 2 +- .../geometry/nodes/node_geo_mesh_primitive_cube.cc | 6 +- .../geometry/nodes/node_geo_mesh_primitive_line.cc | 6 +- .../nodes/node_geo_mesh_primitive_uv_sphere.cc | 2 +- .../geometry/nodes/node_geo_points_to_volume.cc | 2 +- .../nodes/geometry/nodes/node_geo_proximity.cc | 2 +- .../nodes/geometry/nodes/node_geo_raycast.cc | 2 +- .../geometry/nodes/node_geo_set_curve_handles.cc | 2 +- .../geometry/nodes/node_geo_transfer_attribute.cc | 2 +- .../nodes/geometry/nodes/node_geo_transform.cc | 4 +- source/blender/nodes/intern/node_socket.cc | 2 +- source/blender/nodes/shader/node_shader_util.hh | 2 +- .../nodes/shader/nodes/node_shader_map_range.cc | 10 +- .../nodes/shader/nodes/node_shader_tex_brick.cc | 3 +- .../nodes/shader/nodes/node_shader_tex_gradient.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_noise.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_voronoi.cc | 36 +- source/blender/python/generic/py_capi_utils.h | 12 +- source/blender/render/RE_bake.h | 12 +- source/blender/sequencer/intern/effects.c | 4 +- source/blender/windowmanager/WM_api.h | 2 +- source/blender/windowmanager/intern/wm_files.c | 3 +- 185 files changed, 1961 insertions(+), 2433 deletions(-) delete mode 100644 source/blender/blenlib/BLI_double2.hh delete mode 100644 source/blender/blenlib/BLI_double3.hh delete mode 100644 source/blender/blenlib/BLI_float2.hh delete mode 100644 source/blender/blenlib/BLI_float3.hh delete mode 100644 source/blender/blenlib/BLI_float4.hh create mode 100644 source/blender/blenlib/BLI_math_vec_mpq_types.hh create mode 100644 source/blender/blenlib/BLI_math_vec_types.hh create mode 100644 source/blender/blenlib/BLI_math_vector.hh delete mode 100644 source/blender/blenlib/BLI_mpq2.hh delete mode 100644 source/blender/blenlib/BLI_mpq3.hh create mode 100644 source/blender/blenlib/tests/BLI_math_vec_types_test.cc delete mode 100644 source/blender/compositor/COM_precomp.h create mode 100644 source/blender/freestyle/FRS_precomp.cpp (limited to 'source/blender') diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 169107b19cb..76a6135baaf 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -122,7 +122,7 @@ void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth) ATTR_NONNULL(2); typedef bool (*BLF_GlyphBoundsFn)(const char *str, - size_t str_step_ofs, + const size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 4e36f522981..23e42ec777f 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -121,7 +121,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, const char *str, size_t str_len, bool (*user_fn)(const char *str, - size_t str_step_ofs, + const size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, @@ -132,7 +132,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, int blf_font_count_missing_chars(struct FontBLF *font, const char *str, - size_t str_len, + const size_t str_len, int *r_tot_chars); void blf_font_free(struct FontBLF *font); diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index a7baaed141f..e92909fb3ca 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -140,7 +140,7 @@ bool BKE_appdir_font_folder_default(char *dir); * Find Python executable. */ bool BKE_appdir_program_python_search(char *fullpath, - size_t fullpath_len, + const size_t fullpath_len, int version_major, int version_minor); diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index 6020da08f51..db8f3759bf8 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -73,7 +73,7 @@ bool BKE_id_attribute_rename(struct ID *id, const char *new_name, struct ReportList *reports); -int BKE_id_attributes_length(struct ID *id, CustomDataMask mask); +int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask); struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id); void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer); diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index f69ba79e23f..3ffdcee05eb 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -26,9 +26,8 @@ #include "BKE_attribute.h" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_function_ref.hh" +#include "BLI_math_vec_types.hh" /** * This file defines classes that help to provide access to attribute data on a #GeometryComponent. diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh index 802c744972c..a7bdca06790 100644 --- a/source/blender/blenkernel/BKE_attribute_math.hh +++ b/source/blender/blenkernel/BKE_attribute_math.hh @@ -18,8 +18,7 @@ #include "BLI_array.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "DNA_customdata_types.h" @@ -160,12 +159,12 @@ template<> inline float mix2(const float factor, const float &a, const float &b) template<> inline float2 mix2(const float factor, const float2 &a, const float2 &b) { - return float2::interpolate(a, b, factor); + return math::interpolate(a, b, factor); } template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b) { - return float3::interpolate(a, b, factor); + return math::interpolate(a, b, factor); } template<> diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 146e6394fd6..42c8a5dae5d 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -128,7 +128,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -148,7 +148,7 @@ BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -165,7 +165,7 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -188,7 +188,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -212,7 +212,7 @@ BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -229,7 +229,7 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -251,7 +251,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -263,7 +263,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, */ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, const struct Mesh *mesh, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, int tree_type); /** @@ -272,7 +272,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, BVHTree *BKE_bvhtree_from_editmesh_get(BVHTreeFromEditMesh *data, struct BMEditMesh *em, int tree_type, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 17a44274712..b5b6296a0fa 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -323,7 +323,7 @@ void CustomData_bmesh_copy_data_exclude_by_type(const struct CustomData *source, struct CustomData *dest, void *src_block, void **dest_block, - CustomDataMask mask_exclude); + const CustomDataMask mask_exclude); /** * Copies data of a single layer of a given type. @@ -496,7 +496,7 @@ void CustomData_bmesh_free_block_data(struct CustomData *data, void *block); */ void CustomData_bmesh_free_block_data_exclude_by_type(struct CustomData *data, void *block, - CustomDataMask mask_exclude); + const CustomDataMask mask_exclude); /** * Copy custom data to/from layers as in mesh/derived-mesh, to edit-mesh diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index acb89637f20..f92f33b2776 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -23,11 +23,11 @@ #include #include -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_function_ref.hh" #include "BLI_hash.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_set.hh" #include "BLI_user_counter.hh" #include "BLI_vector_set.hh" diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 80c6b155be0..7b87189a13f 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -367,7 +367,7 @@ void BKE_image_packfiles(struct ReportList *reports, struct Image *ima, const ch void BKE_image_packfiles_from_mem(struct ReportList *reports, struct Image *ima, char *data, - size_t data_len); + const size_t data_len); /** * Prints memory statistics for images. diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh index 238b6f4dcae..738b768d906 100644 --- a/source/blender/blenkernel/BKE_mesh_sample.hh +++ b/source/blender/blenkernel/BKE_mesh_sample.hh @@ -22,7 +22,7 @@ #include "FN_generic_virtual_array.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BKE_attribute.h" diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index ef86804cc3b..71d1728a870 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1373,12 +1373,18 @@ void ntreeCompositTagRender(struct Scene *scene); * - Each render layer node calls the update function of the * render engine that's used for its scene. * - The render engine calls RE_engine_register_pass for each pass. - * - #RE_engine_register_pass calls #node_cmp_rlayers_register_pass. + * - #RE_engine_register_pass calls #ntreeCompositRegisterPass, + * which calls #node_cmp_rlayers_register_pass for every render layer node. * * TODO: This is *not* part of `blenkernel`, it's defined under "source/blender/nodes/". * This declaration should be moved out of BKE. */ void ntreeCompositUpdateRLayers(struct bNodeTree *ntree); +void ntreeCompositRegisterPass(struct bNodeTree *ntree, + struct Scene *scene, + struct ViewLayer *view_layer, + const char *name, + eNodeSocketDatatype type); void ntreeCompositClearTags(struct bNodeTree *ntree); struct bNodeSocket *ntreeCompositOutputFileAddSocket(struct bNodeTree *ntree, diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index a40359e8650..8610bc09a92 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -317,8 +317,11 @@ void BKE_scene_multiview_view_prefix_get(struct Scene *scene, const char *name, char *r_prefix, const char **r_ext); -void BKE_scene_multiview_videos_dimensions_get( - const struct RenderData *rd, size_t width, size_t height, size_t *r_width, size_t *r_height); +void BKE_scene_multiview_videos_dimensions_get(const struct RenderData *rd, + const size_t width, + const size_t height, + size_t *r_width, + size_t *r_height); int BKE_scene_multiview_num_videos_get(const struct RenderData *rd); /* depsgraph */ diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh index 2c14880978f..a87f76da8da 100644 --- a/source/blender/blenkernel/BKE_spline.hh +++ b/source/blender/blenkernel/BKE_spline.hh @@ -24,8 +24,8 @@ #include "FN_generic_virtual_array.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BKE_attribute_access.hh" diff --git a/source/blender/blenkernel/BKE_vfont.h b/source/blender/blenkernel/BKE_vfont.h index 3397f2ef82a..d0a44ce4e47 100644 --- a/source/blender/blenkernel/BKE_vfont.h +++ b/source/blender/blenkernel/BKE_vfont.h @@ -104,7 +104,7 @@ void BKE_vfont_select_clamp(struct Object *ob); void BKE_vfont_clipboard_free(void); void BKE_vfont_clipboard_set(const char32_t *text_buf, const struct CharInfo *info_buf, - size_t len); + const size_t len); void BKE_vfont_clipboard_get(char32_t **r_text_buf, struct CharInfo **r_info_buf, size_t *r_len_utf8, diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h index 2b551a76d73..b40facc3572 100644 --- a/source/blender/blenkernel/BKE_volume.h +++ b/source/blender/blenkernel/BKE_volume.h @@ -163,8 +163,8 @@ bool BKE_volume_save(const struct Volume *volume, * file or copy shared grids to make them writeable. */ #ifdef __cplusplus -# include "BLI_float3.hh" # include "BLI_float4x4.hh" +# include "BLI_math_vec_types.hh" # include "BLI_string_ref.hh" bool BKE_volume_min_max(const Volume *volume, blender::float3 &r_min, blender::float3 &r_max); diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 4bfd71ba932..73785e2ee2b 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -38,9 +38,9 @@ #include "BLI_array.h" #include "BLI_bitmap.h" #include "BLI_blenlib.h" -#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_task.h" #include "BLI_task.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 1a4265d936b..cc43a3e26a8 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -30,7 +30,7 @@ #include "DNA_pointcloud_types.h" #include "BLI_color.hh" -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLT_translation.h" diff --git a/source/blender/blenkernel/intern/data_transfer_intern.h b/source/blender/blenkernel/intern/data_transfer_intern.h index b5b3db31fbf..e5218415df9 100644 --- a/source/blender/blenkernel/intern/data_transfer_intern.h +++ b/source/blender/blenkernel/intern/data_transfer_intern.h @@ -44,9 +44,9 @@ void data_transfer_layersmapping_add_item(struct ListBase *r_map, void *data_dst, int data_src_n, int data_dst_n, - size_t elem_size, - size_t data_size, - size_t data_offset, + const size_t elem_size, + const size_t data_size, + const size_t data_offset, uint64_t data_flag, cd_datatransfer_interp interp, void *interp_data); diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 2b4238d26bb..88a58220b23 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -217,9 +217,8 @@ VArray mesh_normals_varray(const MeshComponent &mesh_component, * calculating unnecessary values and to allow normalizing the result much more simply. */ for (const int i : mask) { const MEdge &edge = edges[i]; - edge_normals[i] = float3::interpolate( - vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f) - .normalized(); + edge_normals[i] = math::normalize( + math::interpolate(vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f)); } return VArray::ForContainer(std::move(edge_normals)); diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc index f8681647a77..116d77f1a2a 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.cc +++ b/source/blender/blenkernel/intern/gpencil_geom.cc @@ -33,10 +33,10 @@ #include "BLI_array_utils.h" #include "BLI_blenlib.h" -#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_heap.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_polyfill_2d.h" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/hair.cc b/source/blender/blenkernel/intern/hair.cc index c5b154c9a4b..b7ba159f631 100644 --- a/source/blender/blenkernel/intern/hair.cc +++ b/source/blender/blenkernel/intern/hair.cc @@ -28,9 +28,9 @@ #include "DNA_material_types.h" #include "DNA_object_types.h" -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math_base.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 23b1054f814..4899c3671aa 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -2446,7 +2446,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and draw the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.file, sizeof(stamp_data.file)); + BLF_draw_buffer(mono, stamp_data.file, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2469,7 +2469,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.date, sizeof(stamp_data.date)); + BLF_draw_buffer(mono, stamp_data.date, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2492,7 +2492,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.rendertime, sizeof(stamp_data.rendertime)); + BLF_draw_buffer(mono, stamp_data.rendertime, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2515,7 +2515,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.memory, sizeof(stamp_data.memory)); + BLF_draw_buffer(mono, stamp_data.memory, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2538,7 +2538,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.hostname, sizeof(stamp_data.hostname)); + BLF_draw_buffer(mono, stamp_data.hostname, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2562,7 +2562,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs + (h - h_fixed), 0.0); - BLF_draw_buffer(mono, stamp_data.note, sizeof(stamp_data.note)); + BLF_draw_buffer(mono, stamp_data.note, BLF_DRAW_STR_DUMMY_MAX); } BLF_disable(mono, BLF_WORD_WRAP); @@ -2586,7 +2586,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.marker, sizeof(stamp_data.marker)); + BLF_draw_buffer(mono, stamp_data.marker, BLF_DRAW_STR_DUMMY_MAX); /* space width. */ x += w + pad; @@ -2609,7 +2609,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.time, sizeof(stamp_data.time)); + BLF_draw_buffer(mono, stamp_data.time, BLF_DRAW_STR_DUMMY_MAX); /* space width. */ x += w + pad; @@ -2631,7 +2631,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.frame, sizeof(stamp_data.frame)); + BLF_draw_buffer(mono, stamp_data.frame, BLF_DRAW_STR_DUMMY_MAX); /* space width. */ x += w + pad; @@ -2651,7 +2651,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.camera, sizeof(stamp_data.camera)); + BLF_draw_buffer(mono, stamp_data.camera, BLF_DRAW_STR_DUMMY_MAX); /* space width. */ x += w + pad; @@ -2671,7 +2671,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.cameralens, sizeof(stamp_data.cameralens)); + BLF_draw_buffer(mono, stamp_data.cameralens, BLF_DRAW_STR_DUMMY_MAX); } if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) { @@ -2693,7 +2693,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.scene, sizeof(stamp_data.scene)); + BLF_draw_buffer(mono, stamp_data.scene, BLF_DRAW_STR_DUMMY_MAX); } if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) { @@ -2715,7 +2715,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.strip, sizeof(stamp_data.strip)); + BLF_draw_buffer(mono, stamp_data.strip, BLF_DRAW_STR_DUMMY_MAX); } /* cleanup the buffer. */ diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 12c63ab0523..8ceaced1972 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -36,13 +36,13 @@ #include "BLI_bitmap.h" #include "BLI_edgehash.h" #include "BLI_endian_switch.h" -#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_index_range.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_memarena.h" #include "BLI_string.h" #include "BLI_task.hh" @@ -1597,16 +1597,16 @@ bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3]) [&](IndexRange range, const Result &init) { Result result = init; for (const int i : range) { - float3::min_max(me->mvert[i].co, result.min, result.max); + math::min_max(float3(me->mvert[i].co), result.min, result.max); } return result; }, [](const Result &a, const Result &b) { - return Result{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return Result{math::min(a.min, b.min), math::max(a.max, b.max)}; }); - copy_v3_v3(r_min, float3::min(minmax.min, r_min)); - copy_v3_v3(r_max, float3::max(minmax.max, r_max)); + copy_v3_v3(r_min, math::min(minmax.min, float3(r_min))); + copy_v3_v3(r_max, math::max(minmax.max, float3(r_max))); return true; } diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc index 771d79a0445..a4a5fe2be2e 100644 --- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc +++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc @@ -32,9 +32,9 @@ #include "BLI_alloca.h" #include "BLI_array.hh" -#include "BLI_float2.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_mesh_boolean.hh" #include "BLI_mesh_intersect.hh" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc index 3447185089d..50464da86e9 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc @@ -31,8 +31,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_index_range.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_mesh_types.h" diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc index e682486390c..20fdda8bdc7 100644 --- a/source/blender/blenkernel/intern/object_dupli.cc +++ b/source/blender/blenkernel/intern/object_dupli.cc @@ -31,9 +31,9 @@ #include "BLI_string_utf8.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_vector.hh" @@ -1026,6 +1026,8 @@ static void get_dupliface_transform_from_coords(Span coords, const float scale_fac, float r_mat[4][4]) { + using namespace blender::math; + /* Location. */ float3 location(0); for (const float3 &coord : coords) { @@ -1036,9 +1038,7 @@ static void get_dupliface_transform_from_coords(Span coords, /* Rotation. */ float quat[4]; - float3 f_no; - cross_poly_v3(f_no, (const float(*)[3])coords.data(), (uint)coords.size()); - f_no.normalize(); + float3 f_no = normalize(cross_poly(coords)); tri_to_quat_ex(quat, coords[0], coords[1], coords[2], f_no); /* Scale. */ diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc index a041e04bf71..b5f016e4d76 100644 --- a/source/blender/blenkernel/intern/pointcloud.cc +++ b/source/blender/blenkernel/intern/pointcloud.cc @@ -25,9 +25,9 @@ #include "DNA_object_types.h" #include "DNA_pointcloud_types.h" -#include "BLI_float3.hh" #include "BLI_index_range.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" @@ -275,6 +275,8 @@ struct MinMaxResult { static MinMaxResult min_max_no_radii(Span positions) { + using namespace blender::math; + return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -282,17 +284,19 @@ static MinMaxResult min_max_no_radii(Span positions) [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - float3::min_max(positions[i], result.min, result.max); + min_max(positions[i], result.min, result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; }); } static MinMaxResult min_max_with_radii(Span positions, Span radii) { + using namespace blender::math; + return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -300,18 +304,20 @@ static MinMaxResult min_max_with_radii(Span positions, Span radii [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - result.min = float3::min(positions[i] - radii[i], result.min); - result.max = float3::max(positions[i] + radii[i], result.max); + result.min = min(positions[i] - radii[i], result.min); + result.max = max(positions[i] + radii[i], result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; }); } bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r_max[3]) { + using namespace blender::math; + if (!pointcloud->totpoint) { return false; } @@ -322,8 +328,8 @@ bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r {pointcloud->radius, pointcloud->totpoint}) : min_max_no_radii(positions); - copy_v3_v3(r_min, float3::min(min_max.min, r_min)); - copy_v3_v3(r_max, float3::max(min_max.max, r_max)); + copy_v3_v3(r_min, min(min_max.min, float3(r_min))); + copy_v3_v3(r_max, max(min_max.max, float3(r_max))); return true; } @@ -340,7 +346,7 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob) ob->runtime.bb = static_cast(MEM_callocN(sizeof(BoundBox), "pointcloud boundbox")); } - blender::float3 min, max; + float3 min, max; INIT_MINMAX(min, max); if (ob->runtime.geometry_set_eval != nullptr) { ob->runtime.geometry_set_eval->compute_boundbox_without_instances(&min, &max); diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index b0f9de5963a..ec4b0e8d51d 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -28,9 +28,9 @@ #include "DNA_simulation_types.h" #include "BLI_compiler_compat.h" -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 857022345f3..3262d768b6c 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -166,13 +166,15 @@ static void accumulate_lengths(Span positions, const bool is_cyclic, MutableSpan lengths) { + using namespace blender::math; + float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { - length += float3::distance(positions[i], positions[i + 1]); + length += distance(positions[i], positions[i + 1]); lengths[i] = length; } if (is_cyclic) { - lengths.last() = length + float3::distance(positions.last(), positions.first()); + lengths.last() = length + distance(positions.last(), positions.first()); } } @@ -200,11 +202,13 @@ Span Spline::evaluated_lengths() const static float3 direction_bisect(const float3 &prev, const float3 &middle, const float3 &next) { - const float3 dir_prev = (middle - prev).normalized(); - const float3 dir_next = (next - middle).normalized(); + using namespace blender::math; + + const float3 dir_prev = normalize(middle - prev); + const float3 dir_next = normalize(next - middle); - const float3 result = (dir_prev + dir_next).normalized(); - if (UNLIKELY(result.is_zero())) { + const float3 result = normalize(dir_prev + dir_next); + if (UNLIKELY(is_zero(result))) { return float3(0.0f, 0.0f, 1.0f); } return result; @@ -214,6 +218,8 @@ static void calculate_tangents(Span positions, const bool is_cyclic, MutableSpan tangents) { + using namespace blender::math; + if (positions.size() == 1) { tangents.first() = float3(0.0f, 0.0f, 1.0f); return; @@ -232,8 +238,8 @@ static void calculate_tangents(Span positions, tangents.last() = direction_bisect(second_to_last, last, first); } else { - tangents.first() = (positions[1] - positions[0]).normalized(); - tangents.last() = (positions.last() - positions[positions.size() - 2]).normalized(); + tangents.first() = normalize(positions[1] - positions[0]); + tangents.last() = normalize(positions.last() - positions[positions.size() - 2]); } } @@ -264,18 +270,22 @@ static float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, const float angle) { + using namespace blender::math; + BLI_ASSERT_UNIT_V3(direction); BLI_ASSERT_UNIT_V3(axis); - const float3 axis_scaled = axis * float3::dot(direction, axis); + const float3 axis_scaled = axis * dot(direction, axis); const float3 diff = direction - axis_scaled; - const float3 cross = float3::cross(axis, diff); + const float3 cross = blender::math::cross(axis, diff); return axis_scaled + diff * std::cos(angle) + cross * std::sin(angle); } static void calculate_normals_z_up(Span tangents, MutableSpan r_normals) { + using namespace blender::math; + BLI_assert(r_normals.size() == tangents.size()); /* Same as in `vec_to_quat`. */ @@ -286,7 +296,7 @@ static void calculate_normals_z_up(Span tangents, MutableSpan r_ r_normals[i] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[i] = float3(tangent.y, -tangent.x, 0.0f).normalized(); + r_normals[i] = normalize(float3(tangent.y, -tangent.x, 0.0f)); } } } @@ -298,12 +308,14 @@ static float3 calculate_next_normal(const float3 &last_normal, const float3 &last_tangent, const float3 ¤t_tangent) { - if (last_tangent.is_zero() || current_tangent.is_zero()) { + using namespace blender::math; + + if (is_zero(last_tangent) || is_zero(current_tangent)) { return last_normal; } const float angle = angle_normalized_v3v3(last_tangent, current_tangent); if (angle != 0.0) { - const float3 axis = float3::cross(last_tangent, current_tangent).normalized(); + const float3 axis = normalize(cross(last_tangent, current_tangent)); return rotate_direction_around_axis(last_normal, axis, angle); } return last_normal; @@ -313,6 +325,7 @@ static void calculate_normals_minimum(Span tangents, const bool cyclic, MutableSpan r_normals) { + using namespace blender::math; BLI_assert(r_normals.size() == tangents.size()); if (r_normals.is_empty()) { @@ -327,7 +340,7 @@ static void calculate_normals_minimum(Span tangents, r_normals[0] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[0] = float3(first_tangent.y, -first_tangent.x, 0.0f).normalized(); + r_normals[0] = normalize(float3(first_tangent.y, -first_tangent.x, 0.0f)); } /* Forward normal with minimum twist along the entire spline. */ diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc index b24c8960857..980437014b1 100644 --- a/source/blender/blenkernel/intern/spline_bezier.cc +++ b/source/blender/blenkernel/intern/spline_bezier.cc @@ -199,11 +199,13 @@ void BezierSpline::ensure_auto_handles() const } for (const int i : IndexRange(this->size())) { + using namespace blender; + if (ELEM(HandleType::Auto, handle_types_left_[i], handle_types_right_[i])) { const float3 prev_diff = positions_[i] - previous_position(positions_, is_cyclic_, i); const float3 next_diff = next_position(positions_, is_cyclic_, i) - positions_[i]; - float prev_len = prev_diff.length(); - float next_len = next_diff.length(); + float prev_len = math::length(prev_diff); + float next_len = math::length(next_diff); if (prev_len == 0.0f) { prev_len = 1.0f; } @@ -213,7 +215,7 @@ void BezierSpline::ensure_auto_handles() const const float3 dir = next_diff / next_len + prev_diff / prev_len; /* This magic number is unfortunate, but comes from elsewhere in Blender. */ - const float len = dir.length() * 2.5614f; + const float len = math::length(dir) * 2.5614f; if (len != 0.0f) { if (handle_types_left_[i] == HandleType::Auto) { const float prev_len_clamped = std::min(prev_len, next_len * 5.0f); @@ -228,12 +230,12 @@ void BezierSpline::ensure_auto_handles() const if (handle_types_left_[i] == HandleType::Vector) { const float3 prev = previous_position(positions_, is_cyclic_, i); - handle_positions_left_[i] = float3::interpolate(positions_[i], prev, 1.0f / 3.0f); + handle_positions_left_[i] = math::interpolate(positions_[i], prev, 1.0f / 3.0f); } if (handle_types_right_[i] == HandleType::Vector) { const float3 next = next_position(positions_, is_cyclic_, i); - handle_positions_right_[i] = float3::interpolate(positions_[i], next, 1.0f / 3.0f); + handle_positions_right_[i] = math::interpolate(positions_[i], next, 1.0f / 3.0f); } } @@ -275,6 +277,8 @@ static void set_handle_position(const float3 &position, float3 &handle, float3 &handle_other) { + using namespace blender::math; + /* Don't bother when the handle positions are calculated automatically anyway. */ if (ELEM(type, BezierSpline::HandleType::Auto, BezierSpline::HandleType::Vector)) { return; @@ -283,9 +287,9 @@ static void set_handle_position(const float3 &position, handle = new_value; if (type_other == BezierSpline::HandleType::Align) { /* Keep track of the old length of the opposite handle. */ - const float length = float3::distance(handle_other, position); + const float length = distance(handle_other, position); /* Set the other handle to directly opposite from the current handle. */ - const float3 dir = (handle - position).normalized(); + const float3 dir = normalize(handle - position); handle_other = position - dir * length; } } @@ -353,6 +357,7 @@ int BezierSpline::evaluated_points_size() const void BezierSpline::correct_end_tangents() const { + using namespace blender::math; if (is_cyclic_) { return; } @@ -360,10 +365,10 @@ void BezierSpline::correct_end_tangents() const MutableSpan tangents(evaluated_tangents_cache_); if (handle_positions_right_.first() != positions_.first()) { - tangents.first() = (handle_positions_right_.first() - positions_.first()).normalized(); + tangents.first() = normalize(handle_positions_right_.first() - positions_.first()); } if (handle_positions_left_.last() != positions_.last()) { - tangents.last() = (positions_.last() - handle_positions_left_.last()).normalized(); + tangents.last() = normalize(positions_.last() - handle_positions_left_.last()); } } @@ -371,20 +376,22 @@ BezierSpline::InsertResult BezierSpline::calculate_segment_insertion(const int i const int next_index, const float parameter) { + using namespace blender::math; + BLI_assert(parameter <= 1.0f && parameter >= 0.0f); BLI_assert(next_index == 0 || next_index == index + 1); const float3 &point_prev = positions_[index]; const float3 &handle_prev = handle_positions_right_[index]; const float3 &handle_next = handle_positions_left_[next_index]; const float3 &point_next = positions_[next_index]; - const float3 center_point = float3::interpolate(handle_prev, handle_next, parameter); + const float3 center_point = interpolate(handle_prev, handle_next, parameter); BezierSpline::InsertResult result; - result.handle_prev = float3::interpolate(point_prev, handle_prev, parameter); - result.handle_next = float3::interpolate(handle_next, point_next, parameter); - result.left_handle = float3::interpolate(result.handle_prev, center_point, parameter); - result.right_handle = float3::interpolate(center_point, result.handle_next, parameter); - result.position = float3::interpolate(result.left_handle, result.right_handle, parameter); + result.handle_prev = interpolate(point_prev, handle_prev, parameter); + result.handle_next = interpolate(handle_next, point_next, parameter); + result.left_handle = interpolate(result.handle_prev, center_point, parameter); + result.right_handle = interpolate(center_point, result.handle_next, parameter); + result.position = interpolate(result.left_handle, result.right_handle, parameter); return result; } diff --git a/source/blender/blenkernel/intern/tracking_test.cc b/source/blender/blenkernel/intern/tracking_test.cc index a3845dcad8f..d85d71b7c86 100644 --- a/source/blender/blenkernel/intern/tracking_test.cc +++ b/source/blender/blenkernel/intern/tracking_test.cc @@ -5,7 +5,7 @@ #include "DNA_tracking_types.h" #include "BKE_tracking.h" -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" namespace blender { diff --git a/source/blender/blenkernel/intern/type_conversions.cc b/source/blender/blenkernel/intern/type_conversions.cc index b23220286e6..cb05337ef2a 100644 --- a/source/blender/blenkernel/intern/type_conversions.cc +++ b/source/blender/blenkernel/intern/type_conversions.cc @@ -19,8 +19,7 @@ #include "FN_multi_function_builder.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" namespace blender::bke { diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index 4b71c98339b..c17706dc216 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -28,12 +28,12 @@ #include "BLI_compiler_compat.h" #include "BLI_fileops.h" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_ghash.h" #include "BLI_index_range.hh" #include "BLI_map.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc index 6dc497bb616..c0a205b5673 100644 --- a/source/blender/blenkernel/intern/volume_render.cc +++ b/source/blender/blenkernel/intern/volume_render.cc @@ -21,8 +21,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_math_matrix.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_vector.hh" diff --git a/source/blender/blenkernel/intern/volume_to_mesh.cc b/source/blender/blenkernel/intern/volume_to_mesh.cc index 6e465b2fdf0..733549c0022 100644 --- a/source/blender/blenkernel/intern/volume_to_mesh.cc +++ b/source/blender/blenkernel/intern/volume_to_mesh.cc @@ -16,7 +16,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_array_store.h b/source/blender/blenlib/BLI_array_store.h index 68928f53e55..0be361d4ab9 100644 --- a/source/blender/blenlib/BLI_array_store.h +++ b/source/blender/blenlib/BLI_array_store.h @@ -84,7 +84,7 @@ size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs); */ BArrayState *BLI_array_store_state_add(BArrayStore *bs, const void *data, - size_t data_len, + const size_t data_len, const BArrayState *state_reference); /** * Remove a state and free any unused #BChunk data. diff --git a/source/blender/blenlib/BLI_array_utils.h b/source/blender/blenlib/BLI_array_utils.h index 202ae9a9786..50fc2ce909b 100644 --- a/source/blender/blenlib/BLI_array_utils.h +++ b/source/blender/blenlib/BLI_array_utils.h @@ -52,7 +52,7 @@ void _bli_array_wrap(void *arr, uint arr_len, size_t arr_stride, int dir); * Access via #BLI_array_wrap */ void _bli_array_permute( - void *arr, uint arr_len, size_t arr_stride, const uint *order, void *arr_temp); + void *arr, uint arr_len, const size_t arr_stride, const uint *order, void *arr_temp); #define BLI_array_permute(arr, arr_len, order) \ _bli_array_permute(arr, arr_len, sizeof(*(arr)), order, NULL) #define BLI_array_permute_ex(arr, arr_len, order, arr_temp) \ @@ -152,7 +152,7 @@ bool _bli_array_is_zeroed(const void *arr, uint arr_len, size_t arr_stride); */ bool _bli_array_iter_spiral_square(const void *arr_v, const int arr_shape[2], - size_t elem_size, + const size_t elem_size, const int center[2], bool (*test_fn)(const void *arr_item, void *user_data), void *user_data); diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h index e79d44fd934..7f577443cf7 100644 --- a/source/blender/blenlib/BLI_buffer.h +++ b/source/blender/blenlib/BLI_buffer.h @@ -74,7 +74,7 @@ enum { /** * \note Never decreases the amount of memory allocated. */ -void BLI_buffer_resize(BLI_Buffer *buffer, size_t new_count); +void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); /** * Ensure size, throwing away old data, respecting #BLI_BUFFER_USE_CALLOC. @@ -83,7 +83,7 @@ void BLI_buffer_resize(BLI_Buffer *buffer, size_t new_count); * - Ignored (malloc'd). * - Cleared (when #BLI_BUFFER_USE_CALLOC is set). */ -void BLI_buffer_reinit(BLI_Buffer *buffer, size_t new_count); +void BLI_buffer_reinit(BLI_Buffer *buffer, const size_t new_count); /** * Append an array of elements. diff --git a/source/blender/blenlib/BLI_delaunay_2d.h b/source/blender/blenlib/BLI_delaunay_2d.h index db0df95499f..1ee0be64cee 100644 --- a/source/blender/blenlib/BLI_delaunay_2d.h +++ b/source/blender/blenlib/BLI_delaunay_2d.h @@ -215,9 +215,9 @@ void BLI_delaunay_2d_cdt_free(CDT_result *result); /* C++ Interface. */ # include "BLI_array.hh" -# include "BLI_double2.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_vector.hh" namespace blender::meshintersect { diff --git a/source/blender/blenlib/BLI_double2.hh b/source/blender/blenlib/BLI_double2.hh deleted file mode 100644 index 0abff01ab2f..00000000000 --- a/source/blender/blenlib/BLI_double2.hh +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include "BLI_double3.hh" - -namespace blender { - -struct double2 { - double x, y; - - double2() = default; - - double2(const double *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - double2(double x, double y) : x(x), y(y) - { - } - - double2(const double3 &other) : x(other.x), y(other.y) - { - } - - operator double *() - { - return &x; - } - - operator const double *() const - { - return &x; - } - - double length() const - { - return len_v2_db(*this); - } - - friend double2 operator+(const double2 &a, const double2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend double2 operator-(const double2 &a, const double2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend double2 operator*(const double2 &a, double b) - { - return {a.x * b, a.y * b}; - } - - friend double2 operator/(const double2 &a, double b) - { - BLI_assert(b != 0.0); - return {a.x / b, a.y / b}; - } - - friend double2 operator*(double a, const double2 &b) - { - return b * a; - } - - friend bool operator==(const double2 &a, const double2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const double2 &a, const double2 &b) - { - return a.x != b.x || a.y != b.y; - } - - friend std::ostream &operator<<(std::ostream &stream, const double2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static double dot(const double2 &a, const double2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static double2 interpolate(const double2 &a, const double2 &b, double t) - { - return a * (1 - t) + b * t; - } - - static double2 abs(const double2 &a) - { - return double2(fabs(a.x), fabs(a.y)); - } - - static double distance(const double2 &a, const double2 &b) - { - return (a - b).length(); - } - - static double distance_squared(const double2 &a, const double2 &b) - { - double2 diff = a - b; - return double2::dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - double lambda; - }; - - static isect_result isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4); -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_double3.hh b/source/blender/blenlib/BLI_double3.hh deleted file mode 100644 index ab258c9121b..00000000000 --- a/source/blender/blenlib/BLI_double3.hh +++ /dev/null @@ -1,246 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include - -#include "BLI_math_vector.h" -#include "BLI_span.hh" - -namespace blender { - -struct double3 { - double x, y, z; - - double3() = default; - - double3(const double *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - double3(const double (*ptr)[3]) : double3((const double *)ptr) - { - } - - explicit double3(double value) : x(value), y(value), z(value) - { - } - - explicit double3(int value) : x(value), y(value), z(value) - { - } - - double3(double x, double y, double z) : x{x}, y{y}, z{z} - { - } - - operator const double *() const - { - return &x; - } - - operator double *() - { - return &x; - } - - double normalize_and_get_length() - { - return normalize_v3_db(*this); - } - - double3 normalized() const - { - double3 result; - normalize_v3_v3_db(result, *this); - return result; - } - - double length() const - { - return len_v3_db(*this); - } - - double length_squared() const - { - return len_squared_v3_db(*this); - } - - void reflect(const double3 &normal) - { - *this = this->reflected(normal); - } - - double3 reflected(const double3 &normal) const - { - double3 result; - reflect_v3_v3v3_db(result, *this, normal); - return result; - } - - static double3 safe_divide(const double3 &a, const double3 &b) - { - double3 result; - result.x = (b.x == 0.0) ? 0.0 : a.x / b.x; - result.y = (b.y == 0.0) ? 0.0 : a.y / b.y; - result.z = (b.z == 0.0) ? 0.0 : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - friend double3 operator+(const double3 &a, const double3 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z}; - } - - void operator+=(const double3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - } - - friend double3 operator-(const double3 &a, const double3 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z}; - } - - friend double3 operator-(const double3 &a) - { - return {-a.x, -a.y, -a.z}; - } - - void operator-=(const double3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - } - - void operator*=(const double &scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - } - - void operator*=(const double3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - } - - friend double3 operator*(const double3 &a, const double3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend double3 operator*(const double3 &a, const double &b) - { - return {a.x * b, a.y * b, a.z * b}; - } - - friend double3 operator*(const double &a, const double3 &b) - { - return b * a; - } - - friend double3 operator/(const double3 &a, const double &b) - { - BLI_assert(b != 0.0); - return {a.x / b, a.y / b, a.z / b}; - } - - friend bool operator==(const double3 &a, const double3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const double3 &a, const double3 &b) - { - return a.x != b.x || a.y != b.y || a.z != b.z; - } - - friend std::ostream &operator<<(std::ostream &stream, const double3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - static double dot(const double3 &a, const double3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static double3 cross_high_precision(const double3 &a, const double3 &b) - { - double3 result; - cross_v3_v3v3_db(result, a, b); - return result; - } - - static double3 project(const double3 &a, const double3 &b) - { - double3 result; - project_v3_v3v3_db(result, a, b); - return result; - } - - static double distance(const double3 &a, const double3 &b) - { - return (a - b).length(); - } - - static double distance_squared(const double3 &a, const double3 &b) - { - double3 diff = a - b; - return double3::dot(diff, diff); - } - - static double3 interpolate(const double3 &a, const double3 &b, double t) - { - return a * (1 - t) + b * t; - } - - static double3 abs(const double3 &a) - { - return double3(fabs(a.x), fabs(a.y), fabs(a.z)); - } - - static int dominant_axis(const double3 &a) - { - double x = (a.x >= 0) ? a.x : -a.x; - double y = (a.y >= 0) ? a.y : -a.y; - double z = (a.z >= 0) ? a.z : -a.z; - return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); - } - - static double3 cross_poly(Span poly); -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index 28cb5f6d84b..0022823b3de 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -155,7 +155,8 @@ double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL( * * \note can return NULL when the size is not big enough */ -char *BLI_current_working_dir(char *dir, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +char *BLI_current_working_dir(char *dir, const size_t maxncpy) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(); eFileAttributes BLI_file_attributes(const char *path); /** \} */ diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh deleted file mode 100644 index bb4229db86e..00000000000 --- a/source/blender/blenlib/BLI_float2.hh +++ /dev/null @@ -1,218 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include "BLI_float3.hh" - -namespace blender { - -struct float2 { - float x, y; - - float2() = default; - - float2(const float *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - explicit float2(float value) : x(value), y(value) - { - } - - explicit float2(int value) : x(value), y(value) - { - } - - float2(float x, float y) : x(x), y(y) - { - } - - float2(const float3 &other) : x(other.x), y(other.y) - { - } - - operator float *() - { - return &x; - } - - operator const float *() const - { - return &x; - } - - float length() const - { - return len_v2(*this); - } - - float length_squared() const - { - return len_squared_v2(*this); - } - - bool is_zero() const - { - return this->x == 0.0f && this->y == 0.0f; - } - - float2 &operator+=(const float2 &other) - { - x += other.x; - y += other.y; - return *this; - } - - float2 &operator-=(const float2 &other) - { - x -= other.x; - y -= other.y; - return *this; - } - - float2 &operator*=(float factor) - { - x *= factor; - y *= factor; - return *this; - } - - float2 &operator/=(float divisor) - { - x /= divisor; - y /= divisor; - return *this; - } - - uint64_t hash() const - { - uint64_t x1 = *reinterpret_cast(&x); - uint64_t x2 = *reinterpret_cast(&y); - return (x1 * 812519) ^ (x2 * 707951); - } - - friend float2 operator+(const float2 &a, const float2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend float2 operator-(const float2 &a, const float2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend float2 operator-(const float2 &a, const float &b) - { - return {a.x - b, a.y - b}; - } - - friend float2 operator*(const float2 &a, float b) - { - return {a.x * b, a.y * b}; - } - - friend float2 operator/(const float2 &a, float b) - { - BLI_assert(b != 0.0f); - return {a.x / b, a.y / b}; - } - - friend float2 operator*(float a, const float2 &b) - { - return b * a; - } - - friend std::ostream &operator<<(std::ostream &stream, const float2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static float2 safe_divide(const float2 &a, const float b) - { - return (b != 0.0f) ? a / b : float2(0.0f); - } - - static float2 floor(const float2 &a) - { - return float2(floorf(a.x), floorf(a.y)); - } - - /** - * Returns a normalized vector. The original vector is not changed. - */ - float2 normalized() const - { - float2 result; - normalize_v2_v2(result, *this); - return result; - } - - static float dot(const float2 &a, const float2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static float2 interpolate(const float2 &a, const float2 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float2 abs(const float2 &a) - { - return float2(fabsf(a.x), fabsf(a.y)); - } - - static float distance(const float2 &a, const float2 &b) - { - return (a - b).length(); - } - - static float distance_squared(const float2 &a, const float2 &b) - { - float2 diff = a - b; - return float2::dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - float lambda; - float mu; - }; - - static isect_result isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4); - - friend bool operator==(const float2 &a, const float2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const float2 &a, const float2 &b) - { - return !(a == b); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh deleted file mode 100644 index 765f524fb31..00000000000 --- a/source/blender/blenlib/BLI_float3.hh +++ /dev/null @@ -1,320 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include - -#include "BLI_math_vector.h" - -namespace blender { - -struct float3 { - float x, y, z; - - float3() = default; - - float3(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - float3(const float (*ptr)[3]) : float3(static_cast(ptr[0])) - { - } - - explicit float3(float value) : x(value), y(value), z(value) - { - } - - explicit float3(int value) : x(value), y(value), z(value) - { - } - - float3(float x, float y, float z) : x{x}, y{y}, z{z} - { - } - - operator const float *() const - { - return &x; - } - - operator float *() - { - return &x; - } - - friend float3 operator+(const float3 &a, const float3 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z}; - } - - friend float3 operator+(const float3 &a, const float &b) - { - return {a.x + b, a.y + b, a.z + b}; - } - - float3 &operator+=(const float3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - return *this; - } - - friend float3 operator-(const float3 &a, const float3 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z}; - } - - friend float3 operator-(const float3 &a) - { - return {-a.x, -a.y, -a.z}; - } - - friend float3 operator-(const float3 &a, const float &b) - { - return {a.x - b, a.y - b, a.z - b}; - } - - float3 &operator-=(const float3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - return *this; - } - - float3 &operator*=(float scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - return *this; - } - - float3 &operator*=(const float3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - return *this; - } - - friend float3 operator*(const float3 &a, const float3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend float3 operator*(const float3 &a, float b) - { - return {a.x * b, a.y * b, a.z * b}; - } - - friend float3 operator*(float a, const float3 &b) - { - return b * a; - } - - friend float3 operator/(const float3 &a, float b) - { - BLI_assert(b != 0.0f); - return {a.x / b, a.y / b, a.z / b}; - } - - friend std::ostream &operator<<(std::ostream &stream, const float3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - friend bool operator==(const float3 &a, const float3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const float3 &a, const float3 &b) - { - return !(a == b); - } - - float normalize_and_get_length() - { - return normalize_v3(*this); - } - - /** - * Normalizes the vector in place. - */ - void normalize() - { - normalize_v3(*this); - } - - /** - * Returns a normalized vector. The original vector is not changed. - */ - float3 normalized() const - { - float3 result; - normalize_v3_v3(result, *this); - return result; - } - - float length() const - { - return len_v3(*this); - } - - float length_squared() const - { - return len_squared_v3(*this); - } - - bool is_zero() const - { - return this->x == 0.0f && this->y == 0.0f && this->z == 0.0f; - } - - void reflect(const float3 &normal) - { - *this = this->reflected(normal); - } - - float3 reflected(const float3 &normal) const - { - float3 result; - reflect_v3_v3v3(result, *this, normal); - return result; - } - - static float3 refract(const float3 &incident, const float3 &normal, const float eta) - { - float3 result; - float k = 1.0f - eta * eta * (1.0f - dot(normal, incident) * dot(normal, incident)); - if (k < 0.0f) { - result = float3(0.0f); - } - else { - result = eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal; - } - return result; - } - - static float3 faceforward(const float3 &vector, const float3 &incident, const float3 &reference) - { - return dot(reference, incident) < 0.0f ? vector : -vector; - } - - static float3 safe_divide(const float3 &a, const float3 &b) - { - float3 result; - result.x = (b.x == 0.0f) ? 0.0f : a.x / b.x; - result.y = (b.y == 0.0f) ? 0.0f : a.y / b.y; - result.z = (b.z == 0.0f) ? 0.0f : a.z / b.z; - return result; - } - - static float3 min(const float3 &a, const float3 &b) - { - return {a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z}; - } - - static float3 max(const float3 &a, const float3 &b) - { - return {a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z}; - } - - static void min_max(const float3 &vector, float3 &min, float3 &max) - { - min = float3::min(vector, min); - max = float3::max(vector, max); - } - - static float3 safe_divide(const float3 &a, const float b) - { - return (b != 0.0f) ? a / b : float3(0.0f); - } - - static float3 floor(const float3 &a) - { - return float3(floorf(a.x), floorf(a.y), floorf(a.z)); - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - uint64_t hash() const - { - uint64_t x1 = *reinterpret_cast(&x); - uint64_t x2 = *reinterpret_cast(&y); - uint64_t x3 = *reinterpret_cast(&z); - return (x1 * 435109) ^ (x2 * 380867) ^ (x3 * 1059217); - } - - static float dot(const float3 &a, const float3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static float3 cross_high_precision(const float3 &a, const float3 &b) - { - float3 result; - cross_v3_v3v3_hi_prec(result, a, b); - return result; - } - - static float3 cross(const float3 &a, const float3 &b) - { - float3 result; - cross_v3_v3v3(result, a, b); - return result; - } - - static float3 project(const float3 &a, const float3 &b) - { - float3 result; - project_v3_v3v3(result, a, b); - return result; - } - - static float distance(const float3 &a, const float3 &b) - { - return (a - b).length(); - } - - static float distance_squared(const float3 &a, const float3 &b) - { - float3 diff = a - b; - return float3::dot(diff, diff); - } - - static float3 interpolate(const float3 &a, const float3 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float3 abs(const float3 &a) - { - return float3(fabsf(a.x), fabsf(a.y), fabsf(a.z)); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float4.hh b/source/blender/blenlib/BLI_float4.hh deleted file mode 100644 index 5b487f6d029..00000000000 --- a/source/blender/blenlib/BLI_float4.hh +++ /dev/null @@ -1,138 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -namespace blender { - -struct float4 { - float x, y, z, w; - - float4() = default; - - float4(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]}, w{ptr[3]} - { - } - - explicit float4(float value) : x(value), y(value), z(value), w(value) - { - } - - explicit float4(int value) : x(value), y(value), z(value), w(value) - { - } - - float4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) - { - } - - operator float *() - { - return &x; - } - - friend float4 operator+(const float4 &a, const float &b) - { - return {a.x + b, a.y + b, a.z + b, a.w + b}; - } - - operator const float *() const - { - return &x; - } - - float4 &operator+=(const float4 &other) - { - x += other.x; - y += other.y; - z += other.z; - w += other.w; - return *this; - } - - friend float4 operator-(const float4 &a, const float4 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; - } - - friend float4 operator-(const float4 &a, const float &b) - { - return {a.x - b, a.y - b, a.z - b, a.w - b}; - } - - friend float4 operator+(const float4 &a, const float4 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; - } - - friend float4 operator/(const float4 &a, float f) - { - BLI_assert(f != 0.0f); - return a * (1.0f / f); - } - - float4 &operator*=(float factor) - { - x *= factor; - y *= factor; - z *= factor; - w *= factor; - return *this; - } - - friend float4 operator*(const float4 &a, float b) - { - return {a.x * b, a.y * b, a.z * b, a.w * b}; - } - - friend float4 operator*(float a, const float4 &b) - { - return b * a; - } - - float length() const - { - return len_v4(*this); - } - - static float distance(const float4 &a, const float4 &b) - { - return (a - b).length(); - } - - static float4 safe_divide(const float4 &a, const float b) - { - return (b != 0.0f) ? a / b : float4(0.0f); - } - - static float4 interpolate(const float4 &a, const float4 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float4 floor(const float4 &a) - { - return float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w)); - } - - static float4 normalize(const float4 &a) - { - const float t = len_v4(a); - return (t != 0.0f) ? a / t : float4(0.0f); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float4x4.hh b/source/blender/blenlib/BLI_float4x4.hh index b7f839f4ddf..81c969d02d0 100644 --- a/source/blender/blenlib/BLI_float4x4.hh +++ b/source/blender/blenlib/BLI_float4x4.hh @@ -16,8 +16,9 @@ #pragma once -#include "BLI_float3.hh" #include "BLI_math_matrix.h" +#include "BLI_math_vec_types.hh" +#include "BLI_math_vector.h" namespace blender { @@ -63,7 +64,7 @@ struct float4x4 { * Without the negation, the result would be a so called improper rotation. That means it * contains a reflection. Such an improper rotation matrix could not be converted to another * representation of a rotation such as euler angles. */ - const float3 cross = -float3::cross(forward, up); + const float3 cross = -math::cross(forward, up); float4x4 matrix; matrix.values[0][0] = forward.x; diff --git a/source/blender/blenlib/BLI_gsqueue.h b/source/blender/blenlib/BLI_gsqueue.h index a35c743c80b..8b32c09b56b 100644 --- a/source/blender/blenlib/BLI_gsqueue.h +++ b/source/blender/blenlib/BLI_gsqueue.h @@ -31,7 +31,7 @@ extern "C" { typedef struct _GSQueue GSQueue; -GSQueue *BLI_gsqueue_new(size_t elem_size); +GSQueue *BLI_gsqueue_new(const size_t elem_size); /** * Returns true if the queue is empty, false otherwise. */ diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index f73d1f22502..64852b95ae4 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -85,7 +85,7 @@ void *BLI_findptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, - size_t bytes_size, + const size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** * Find the first item in the list that matches the given string, or the given index as fallback. @@ -96,7 +96,7 @@ void *BLI_listbase_bytes_find(const ListBase *listbase, */ void *BLI_listbase_string_or_index_find(const struct ListBase *listbase, const char *string, - size_t string_offset, + const size_t string_offset, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /* Find backwards. */ @@ -133,7 +133,7 @@ void *BLI_rfindptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_rfind(const ListBase *listbase, const void *bytes, - size_t bytes_size, + const size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** diff --git a/source/blender/blenlib/BLI_math_boolean.hh b/source/blender/blenlib/BLI_math_boolean.hh index 20fd00b2aa4..8cf93c82dec 100644 --- a/source/blender/blenlib/BLI_math_boolean.hh +++ b/source/blender/blenlib/BLI_math_boolean.hh @@ -21,13 +21,11 @@ * \brief Math vector functions needed specifically for mesh intersect and boolean. */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" +#include "BLI_math_vec_types.hh" #ifdef WITH_GMP # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" #endif namespace blender { diff --git a/source/blender/blenlib/BLI_math_vec_mpq_types.hh b/source/blender/blenlib/BLI_math_vec_mpq_types.hh new file mode 100644 index 00000000000..36eb0cac83c --- /dev/null +++ b/source/blender/blenlib/BLI_math_vec_mpq_types.hh @@ -0,0 +1,91 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#ifdef WITH_GMP + +# include "BLI_math_mpq.hh" +# include "BLI_math_vec_types.hh" + +namespace blender { + +using mpq2 = vec_base; +using mpq3 = vec_base; + +namespace math { + +uint64_t hash_mpq_class(const mpq_class &value); + +template<> inline uint64_t vector_hash(const mpq2 &vec) +{ + return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33); +} + +template<> inline uint64_t vector_hash(const mpq3 &vec) +{ + return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33) ^ (hash_mpq_class(vec.z) * 33 * 37); +} + +/** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ +template<> inline mpq_class length(const mpq2 &a) +{ + return mpq_class(sqrt(length_squared(a).get_d())); +} + +/** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ +template<> inline mpq_class length(const mpq3 &a) +{ + return mpq_class(sqrt(length_squared(a).get_d())); +} + +/** + * The buffer avoids allocating a temporary variable. + */ +inline mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) +{ + buffer = a; + buffer -= b; + return dot(buffer, buffer); +} + +/** + * The buffer avoids allocating a temporary variable. + */ +inline mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) +{ + buffer = a; + buffer *= b; + buffer.x += buffer.y; + buffer.x += buffer.z; + return buffer.x; +} + +} // namespace math + +} // namespace blender + +#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh new file mode 100644 index 00000000000..52aacd294e4 --- /dev/null +++ b/source/blender/blenlib/BLI_math_vec_types.hh @@ -0,0 +1,566 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include +#include +#include +#include + +#include "BLI_math_vector.hh" +#include "BLI_utildefines.h" + +namespace blender { + +/* clang-format off */ +template +using as_uint_type = std::conditional_t>>>; +/* clang-format on */ + +template struct vec_struct_base { + std::array values; +}; + +template struct vec_struct_base { + T x, y; +}; + +template struct vec_struct_base { + T x, y, z; +}; + +template struct vec_struct_base { + T x, y, z, w; +}; + +template struct vec_base : public vec_struct_base { + + static constexpr int type_length = Size; + + using base_type = T; + using uint_type = vec_base, Size>; + + vec_base() = default; + + explicit vec_base(uint value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(int value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(float value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(double value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + +/* Workaround issue with template BLI_ENABLE_IF((Size == 2)) not working. */ +#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test)) + + template vec_base(T _x, T _y) + { + (*this)[0] = _x; + (*this)[1] = _y; + } + + template vec_base(T _x, T _y, T _z) + { + (*this)[0] = _x; + (*this)[1] = _y; + (*this)[2] = _z; + } + + template vec_base(T _x, T _y, T _z, T _w) + { + (*this)[0] = _x; + (*this)[1] = _y; + (*this)[2] = _z; + (*this)[3] = _w; + } + + /** Mixed scalar-vector constructors. */ + + template + constexpr vec_base(const vec_base &xy, T z) + : vec_base(static_cast(xy.x), static_cast(xy.y), z) + { + } + + template + constexpr vec_base(T x, const vec_base &yz) + : vec_base(x, static_cast(yz.x), static_cast(yz.y)) + { + } + + template + vec_base(vec_base xyz, T w) + : vec_base( + static_cast(xyz.x), static_cast(xyz.y), static_cast(xyz.z), static_cast(w)) + { + } + + template + vec_base(T x, vec_base yzw) + : vec_base( + static_cast(x), static_cast(yzw.x), static_cast(yzw.y), static_cast(yzw.z)) + { + } + + template + vec_base(vec_base xy, vec_base zw) + : vec_base( + static_cast(xy.x), static_cast(xy.y), static_cast(zw.x), static_cast(zw.y)) + { + } + + template + vec_base(vec_base xy, T z, T w) + : vec_base(static_cast(xy.x), static_cast(xy.y), static_cast(z), static_cast(w)) + { + } + + template + vec_base(T x, vec_base yz, T w) + : vec_base(static_cast(x), static_cast(yz.x), static_cast(yz.y), static_cast(w)) + { + } + + template + vec_base(T x, T y, vec_base zw) + : vec_base(static_cast(x), static_cast(y), static_cast(zw.x), static_cast(zw.y)) + { + } + + /** Masking. */ + + template Size)> + explicit vec_base(const vec_base &other) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(other[i]); + } + } + +#undef BLI_ENABLE_IF_VEC + + /** Conversion from pointers (from C-style vectors). */ + + vec_base(const T *ptr) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = ptr[i]; + } + } + + vec_base(const T (*ptr)[Size]) : vec_base(static_cast(ptr[0])) + { + } + + /** Conversion from other vector types. */ + + template explicit vec_base(const vec_base &vec) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(vec[i]); + } + } + + /** C-style pointer dereference. */ + + operator const T *() const + { + return reinterpret_cast(this); + } + + operator T *() + { + return reinterpret_cast(this); + } + + /** Array access. */ + + const T &operator[](int index) const + { + BLI_assert(index >= 0); + BLI_assert(index < Size); + return reinterpret_cast(this)[index]; + } + + T &operator[](int index) + { + BLI_assert(index >= 0); + BLI_assert(index < Size); + return reinterpret_cast(this)[index]; + } + + /** Internal Operators Macro. */ + +#define BLI_INT_OP(_T) template))> + +#define BLI_VEC_OP_IMPL(_result, _i, _op) \ + vec_base _result; \ + for (int _i = 0; _i < Size; _i++) { \ + _op; \ + } \ + return _result; + +#define BLI_VEC_OP_IMPL_SELF(_i, _op) \ + for (int _i = 0; _i < Size; _i++) { \ + _op; \ + } \ + return *this; + + /** Arithmetic operators. */ + + friend vec_base operator+(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b[i]); + } + + friend vec_base operator+(const vec_base &a, const T &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b); + } + + friend vec_base operator+(const T &a, const vec_base &b) + { + return b + a; + } + + vec_base &operator+=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b[i]); + } + + vec_base &operator+=(const T &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b); + } + + friend vec_base operator-(const vec_base &a) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = -a[i]); + } + + friend vec_base operator-(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b[i]); + } + + friend vec_base operator-(const vec_base &a, const T &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b); + } + + friend vec_base operator-(const T &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a - b[i]); + } + + vec_base &operator-=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b[i]); + } + + vec_base &operator-=(const T &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b); + } + + friend vec_base operator*(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b[i]); + } + + friend vec_base operator*(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b); + } + + friend vec_base operator*(T a, const vec_base &b) + { + return b * a; + } + + vec_base &operator*=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b); + } + + vec_base &operator*=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b[i]); + } + + friend vec_base operator/(const vec_base &a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b[i]); + } + + friend vec_base operator/(const vec_base &a, T b) + { + BLI_assert(b != T(0)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b); + } + + friend vec_base operator/(T a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a / b[i]); + } + + vec_base &operator/=(T b) + { + BLI_assert(b != T(0)); + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b); + } + + vec_base &operator/=(const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b[i]); + } + + /** Binary operators. */ + + BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b[i]); + } + + BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b); + } + + BLI_INT_OP(T) friend vec_base operator&(T a, const vec_base &b) + { + return b & a; + } + + BLI_INT_OP(T) vec_base &operator&=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b); + } + + BLI_INT_OP(T) vec_base &operator&=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b[i]); + } + + BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b); + } + + BLI_INT_OP(T) friend vec_base operator|(T a, const vec_base &b) + { + return b | a; + } + + BLI_INT_OP(T) vec_base &operator|=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b); + } + + BLI_INT_OP(T) vec_base &operator|=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b[i]); + } + + BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b); + } + + BLI_INT_OP(T) friend vec_base operator^(T a, const vec_base &b) + { + return b ^ a; + } + + BLI_INT_OP(T) vec_base &operator^=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b); + } + + BLI_INT_OP(T) vec_base &operator^=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator~(const vec_base &a) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = ~a[i]); + } + + /** Bit-shift operators. */ + + BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b[i]); + } + + BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b); + } + + BLI_INT_OP(T) vec_base &operator<<=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b); + } + + BLI_INT_OP(T) vec_base &operator<<=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b[i]); + } + + BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b); + } + + BLI_INT_OP(T) vec_base &operator>>=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b); + } + + BLI_INT_OP(T) vec_base &operator>>=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b[i]); + } + + /** Modulo operators. */ + + BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b[i]); + } + + BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, T b) + { + BLI_assert(b != 0); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b); + } + + BLI_INT_OP(T) friend vec_base operator%(T a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a % b[i]); + } + +#undef BLI_INT_OP +#undef BLI_VEC_OP_IMPL +#undef BLI_VEC_OP_IMPL_SELF + + /** Compare. */ + + friend bool operator==(const vec_base &a, const vec_base &b) + { + for (int i = 0; i < Size; i++) { + if (a[i] != b[i]) { + return false; + } + } + return true; + } + + friend bool operator!=(const vec_base &a, const vec_base &b) + { + return !(a == b); + } + + /** Misc. */ + + uint64_t hash() const + { + return math::vector_hash(*this); + } + + friend std::ostream &operator<<(std::ostream &stream, const vec_base &v) + { + stream << "("; + for (int i = 0; i < Size; i++) { + stream << v[i]; + if (i != Size - 1) { + stream << ", "; + } + } + stream << ")"; + return stream; + } +}; + +using int2 = vec_base; +using int3 = vec_base; +using int4 = vec_base; + +using uint2 = vec_base; +using uint3 = vec_base; +using uint4 = vec_base; + +using float2 = vec_base; +using float3 = vec_base; +using float4 = vec_base; + +using double2 = vec_base; +using double3 = vec_base; +using double4 = vec_base; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_math_vector.hh b/source/blender/blenlib/BLI_math_vector.hh new file mode 100644 index 00000000000..e7d765df842 --- /dev/null +++ b/source/blender/blenlib/BLI_math_vector.hh @@ -0,0 +1,399 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include +#include + +#include "BLI_math_base_safe.h" +#include "BLI_math_vector.h" +#include "BLI_span.hh" +#include "BLI_utildefines.h" + +#ifdef WITH_GMP +# include "BLI_math_mpq.hh" +#endif + +namespace blender::math { + +#ifndef NDEBUG +# define BLI_ASSERT_UNIT(v) \ + { \ + const float _test_unit = length_squared(v); \ + BLI_assert(!(std::abs(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \ + !(std::abs(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \ + } \ + (void)0 +#else +# define BLI_ASSERT_UNIT(v) (void)(v) +#endif + +#define bT typename T::base_type + +#ifdef WITH_GMP +# define BLI_ENABLE_IF_FLT_VEC(T) \ + BLI_ENABLE_IF((std::is_floating_point_v || \ + std::is_same_v)) +#else +# define BLI_ENABLE_IF_FLT_VEC(T) BLI_ENABLE_IF((std::is_floating_point_v)) +#endif + +#define BLI_ENABLE_IF_INT_VEC(T) BLI_ENABLE_IF((std::is_integral_v)) + +template inline bool is_zero(const T &a) +{ + for (int i = 0; i < T::type_length; i++) { + if (a[i] != bT(0)) { + return false; + } + } + return true; +} + +template inline bool is_any_zero(const T &a) +{ + for (int i = 0; i < T::type_length; i++) { + if (a[i] == bT(0)) { + return true; + } + } + return false; +} + +template inline T abs(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] >= 0 ? a[i] : -a[i]; + } + return result; +} + +template inline T min(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] < b[i] ? a[i] : b[i]; + } + return result; +} + +template inline T max(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] > b[i] ? a[i] : b[i]; + } + return result; +} + +template inline T clamp(const T &a, const T &min_v, const T &max_v) +{ + T result = a; + for (int i = 0; i < T::type_length; i++) { + CLAMP(result[i], min_v[i], max_v[i]); + } + return result; +} + +template inline T clamp(const T &a, const bT &min_v, const bT &max_v) +{ + T result = a; + for (int i = 0; i < T::type_length; i++) { + CLAMP(result[i], min_v, max_v); + } + return result; +} + +template inline T mod(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + BLI_assert(b[i] != 0); + result[i] = std::fmod(a[i], b[i]); + } + return result; +} + +template inline T mod(const T &a, bT b) +{ + BLI_assert(b != 0); + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::fmod(a[i], b); + } + return result; +} + +template inline T safe_mod(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = (b[i] != 0) ? std::fmod(a[i], b[i]) : 0; + } + return result; +} + +template inline T safe_mod(const T &a, bT b) +{ + if (b == 0) { + return T(0.0f); + } + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::fmod(a[i], b); + } + return result; +} + +template inline void min_max(const T &vector, T &min_vec, T &max_vec) +{ + min_vec = min(vector, min_vec); + max_vec = max(vector, max_vec); +} + +template inline T safe_divide(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = (b[i] == 0) ? 0 : a[i] / b[i]; + } + return result; +} + +template inline T safe_divide(const T &a, const bT b) +{ + return (b != 0) ? a / b : T(0.0f); +} + +template inline T floor(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::floor(a[i]); + } + return result; +} + +template inline T ceil(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::ceil(a[i]); + } + return result; +} + +template inline T fract(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] - std::floor(a[i]); + } + return result; +} + +template inline bT dot(const T &a, const T &b) +{ + bT result = a[0] * b[0]; + for (int i = 1; i < T::type_length; i++) { + result += a[i] * b[i]; + } + return result; +} + +template inline bT length_manhattan(const T &a) +{ + bT result = std::abs(a[0]); + for (int i = 1; i < T::type_length; i++) { + result += std::abs(a[i]); + } + return result; +} + +template inline bT length_squared(const T &a) +{ + return dot(a, a); +} + +template inline bT length(const T &a) +{ + return std::sqrt(length_squared(a)); +} + +template inline bT distance_manhattan(const T &a, const T &b) +{ + return length_manhattan(a - b); +} + +template inline bT distance_squared(const T &a, const T &b) +{ + return length_squared(a - b); +} + +template inline bT distance(const T &a, const T &b) +{ + return length(a - b); +} + +template uint64_t vector_hash(const T &vec) +{ + BLI_STATIC_ASSERT(T::type_length <= 4, "Longer types need to implement vector_hash themself."); + const typename T::uint_type &uvec = *reinterpret_cast(&vec); + uint64_t result; + result = uvec[0] * uint64_t(435109); + if constexpr (T::type_length > 1) { + result ^= uvec[1] * uint64_t(380867); + } + if constexpr (T::type_length > 2) { + result ^= uvec[2] * uint64_t(1059217); + } + if constexpr (T::type_length > 3) { + result ^= uvec[3] * uint64_t(2002613); + } + return result; +} + +template inline T reflect(const T &incident, const T &normal) +{ + BLI_ASSERT_UNIT(normal); + return incident - 2.0 * dot(normal, incident) * normal; +} + +template +inline T refract(const T &incident, const T &normal, const bT eta) +{ + float dot_ni = dot(normal, incident); + float k = 1.0f - eta * eta * (1.0f - dot_ni * dot_ni); + if (k < 0.0f) { + return T(0.0f); + } + return eta * incident - (eta * dot_ni + sqrt(k)) * normal; +} + +template inline T project(const T &p, const T &v_proj) +{ + if (UNLIKELY(is_zero(v_proj))) { + return T(0.0f); + } + return v_proj * (dot(p, v_proj) / dot(v_proj, v_proj)); +} + +template +inline T normalize_and_get_length(const T &v, bT &out_length) +{ + out_length = length_squared(v); + /* A larger value causes normalize errors in a scaled down models with camera extreme close. */ + constexpr bT threshold = std::is_same_v ? 1.0e-70 : 1.0e-35f; + if (out_length > threshold) { + out_length = sqrt(out_length); + return v / out_length; + } + /* Either the vector is small or one of it's values contained `nan`. */ + out_length = 0.0; + return T(0.0); +} + +template inline T normalize(const T &v) +{ + bT len; + return normalize_and_get_length(v, len); +} + +template +inline T cross(const T &a, const T &b) +{ + return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; +} + +template)), + BLI_ENABLE_IF((T::type_length == 3))> +inline T cross_high_precision(const T &a, const T &b) +{ + return {(float)((double)a.y * b.z - (double)a.z * b.y), + (float)((double)a.z * b.x - (double)a.x * b.z), + (float)((double)a.x * b.y - (double)a.y * b.x)}; +} + +template +inline T cross_poly(Span poly) +{ + /* Newell's Method. */ + int nv = static_cast(poly.size()); + if (nv < 3) { + return T(0, 0, 0); + } + const T *v_prev = &poly[nv - 1]; + const T *v_curr = &poly[0]; + T n(0, 0, 0); + for (int i = 0; i < nv;) { + n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); + n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); + n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); + v_prev = v_curr; + ++i; + if (i < nv) { + v_curr = &poly[i]; + } + } + return n; +} + +template inline T interpolate(const T &a, const T &b, bT t) +{ + return a * (1 - t) + b * t; +} + +template +inline T faceforward(const T &vector, const T &incident, const T &reference) +{ + return (dot(reference, incident) < 0) ? vector : -vector; +} + +template inline int dominant_axis(const T &a) +{ + T b = abs(a); + return ((b.x > b.y) ? ((b.x > b.z) ? 0 : 2) : ((b.y > b.z) ? 1 : 2)); +} + +/** Intersections. */ + +template struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + bT lambda; +}; + +template +isect_result isect_seg_seg(const T &v1, const T &v2, const T &v3, const T &v4); + +#undef BLI_ENABLE_IF_FLT_VEC +#undef BLI_ENABLE_IF_INT_VEC +#undef bT + +} // namespace blender::math diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h index bcfe2efc5e5..4ac4712bc8c 100644 --- a/source/blender/blenlib/BLI_memarena.h +++ b/source/blender/blenlib/BLI_memarena.h @@ -38,13 +38,13 @@ extern "C" { struct MemArena; typedef struct MemArena MemArena; -struct MemArena *BLI_memarena_new(size_t bufsize, +struct MemArena *BLI_memarena_new(const size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC; void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_malloc(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_calloc(struct MemArena *ma) ATTR_NONNULL(1); -void BLI_memarena_use_align(struct MemArena *ma, size_t align) ATTR_NONNULL(1); +void BLI_memarena_use_align(struct MemArena *ma, const size_t align) ATTR_NONNULL(1); void *BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2); void *BLI_memarena_calloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT diff --git a/source/blender/blenlib/BLI_memory_utils.h b/source/blender/blenlib/BLI_memory_utils.h index 09d8f646905..79e25e26040 100644 --- a/source/blender/blenlib/BLI_memory_utils.h +++ b/source/blender/blenlib/BLI_memory_utils.h @@ -29,7 +29,7 @@ extern "C" { /* it may be defined already */ #ifndef __BLI_UTILDEFINES_H__ -bool BLI_memory_is_zero(const void *arr, size_t size); +bool BLI_memory_is_zero(const void *arr, const size_t size); #endif #ifdef __cplusplus diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh index 37691017c12..9a5be79b61e 100644 --- a/source/blender/blenlib/BLI_memory_utils.hh +++ b/source/blender/blenlib/BLI_memory_utils.hh @@ -557,13 +557,4 @@ Container &move_assign_container(Container &dst, Container &&src) noexcept( return dst; } -/** - * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for - * SFINAE in common cases. - * - * \note Often one has to invoke this macro with double parenthesis. That's because the condition - * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. - */ -#define BLI_ENABLE_IF(condition) typename std::enable_if_t * = nullptr - } // namespace blender diff --git a/source/blender/blenlib/BLI_mesh_intersect.hh b/source/blender/blenlib/BLI_mesh_intersect.hh index 71a8abb822f..0ebee6f16a8 100644 --- a/source/blender/blenlib/BLI_mesh_intersect.hh +++ b/source/blender/blenlib/BLI_mesh_intersect.hh @@ -28,12 +28,11 @@ # include # include "BLI_array.hh" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_index_range.hh" # include "BLI_map.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_span.hh" # include "BLI_utility_mixins.hh" # include "BLI_vector.hh" diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh deleted file mode 100644 index 18bc8821d9c..00000000000 --- a/source/blender/blenlib/BLI_mpq2.hh +++ /dev/null @@ -1,184 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#ifdef WITH_GMP - -# include "BLI_math_mpq.hh" -# include "BLI_mpq3.hh" - -namespace blender { - -struct mpq2 { - mpq_class x, y; - - mpq2() = default; - - mpq2(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - mpq2(mpq_class x, mpq_class y) : x(x), y(y) - { - } - - mpq2(const mpq2 &other) : x(other.x), y(other.y) - { - } - - mpq2(mpq2 &&other) noexcept : x(std::move(other.x)), y(std::move(other.y)) - { - } - - ~mpq2() = default; - - mpq2 &operator=(const mpq2 &other) - { - if (this != &other) { - x = other.x; - y = other.y; - } - return *this; - } - - mpq2 &operator=(mpq2 &&other) noexcept - { - x = std::move(other.x); - y = std::move(other.y); - return *this; - } - - mpq2(const mpq3 &other) : x(other.x), y(other.y) - { - } - - operator mpq_class *() - { - return &x; - } - - operator const mpq_class *() const - { - return &x; - } - - /** - * Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ - mpq_class length() const - { - mpq_class lsquared = dot(*this, *this); - return mpq_class(sqrt(lsquared.get_d())); - } - - friend mpq2 operator+(const mpq2 &a, const mpq2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend mpq2 operator-(const mpq2 &a, const mpq2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend mpq2 operator*(const mpq2 &a, mpq_class b) - { - return {a.x * b, a.y * b}; - } - - friend mpq2 operator/(const mpq2 &a, mpq_class b) - { - BLI_assert(b != 0); - return {a.x / b, a.y / b}; - } - - friend mpq2 operator*(mpq_class a, const mpq2 &b) - { - return b * a; - } - - friend bool operator==(const mpq2 &a, const mpq2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const mpq2 &a, const mpq2 &b) - { - return a.x != b.x || a.y != b.y; - } - - friend std::ostream &operator<<(std::ostream &stream, const mpq2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static mpq_class dot(const mpq2 &a, const mpq2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static mpq2 interpolate(const mpq2 &a, const mpq2 &b, mpq_class t) - { - return a * (1 - t) + b * t; - } - - static mpq2 abs(const mpq2 &a) - { - mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; - mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; - return mpq2(abs_x, abs_y); - } - - static mpq_class distance(const mpq2 &a, const mpq2 &b) - { - return (a - b).length(); - } - - static mpq_class distance_squared(const mpq2 &a, const mpq2 &b) - { - mpq2 diff = a - b; - return dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - mpq_class lambda; - }; - - static isect_result isect_seg_seg(const mpq2 &v1, - const mpq2 &v2, - const mpq2 &v3, - const mpq2 &v4); - - /** There is a sensible use for hashing on exact arithmetic types. */ - uint64_t hash() const; -}; - -} // namespace blender - -#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_mpq3.hh b/source/blender/blenlib/BLI_mpq3.hh deleted file mode 100644 index b9eda2ad7e1..00000000000 --- a/source/blender/blenlib/BLI_mpq3.hh +++ /dev/null @@ -1,297 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#ifdef WITH_GMP - -# include - -# include "BLI_math.h" -# include "BLI_math_mpq.hh" -# include "BLI_span.hh" - -namespace blender { - -struct mpq3 { - mpq_class x, y, z; - - mpq3() = default; - - mpq3(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - mpq3(const mpq_class (*ptr)[3]) : mpq3((const mpq_class *)ptr) - { - } - - explicit mpq3(mpq_class value) : x(value), y(value), z(value) - { - } - - explicit mpq3(int value) : x(value), y(value), z(value) - { - } - - mpq3(mpq_class x, mpq_class y, mpq_class z) : x{x}, y{y}, z{z} - { - } - - operator const mpq_class *() const - { - return &x; - } - - operator mpq_class *() - { - return &x; - } - - /* Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ - mpq_class normalize_and_get_length() - { - double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; - double len = normalize_v3_db(dv); - this->x = mpq_class(dv[0]); - this->y = mpq_class(dv[1]); - this->z = mpq_class(dv[2]); - return len; - } - - mpq3 normalized() const - { - double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; - double dr[3]; - normalize_v3_v3_db(dr, dv); - return mpq3(mpq_class(dr[0]), mpq_class(dr[1]), mpq_class(dr[2])); - } - - /* Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of double. - */ - mpq_class length() const - { - mpq_class lsquared = this->length_squared(); - double dsquared = lsquared.get_d(); - double d = sqrt(dsquared); - return mpq_class(d); - } - - mpq_class length_squared() const - { - return x * x + y * y + z * z; - } - - void reflect(const mpq3 &normal) - { - *this = this->reflected(normal); - } - - mpq3 reflected(const mpq3 &normal) const - { - mpq3 result; - const mpq_class dot2 = 2 * dot(*this, normal); - result.x = this->x - (dot2 * normal.x); - result.y = this->y - (dot2 * normal.y); - result.z = this->z - (dot2 * normal.z); - return result; - } - - static mpq3 safe_divide(const mpq3 &a, const mpq3 &b) - { - mpq3 result; - result.x = (b.x == 0) ? mpq_class(0) : a.x / b.x; - result.y = (b.y == 0) ? mpq_class(0) : a.y / b.y; - result.z = (b.z == 0) ? mpq_class(0) : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - friend mpq3 operator+(const mpq3 &a, const mpq3 &b) - { - return mpq3(a.x + b.x, a.y + b.y, a.z + b.z); - } - - void operator+=(const mpq3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - } - - friend mpq3 operator-(const mpq3 &a, const mpq3 &b) - { - return mpq3(a.x - b.x, a.y - b.y, a.z - b.z); - } - - friend mpq3 operator-(const mpq3 &a) - { - return mpq3(-a.x, -a.y, -a.z); - } - - void operator-=(const mpq3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - } - - void operator*=(mpq_class scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - } - - void operator*=(const mpq3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - } - - friend mpq3 operator*(const mpq3 &a, const mpq3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend mpq3 operator*(const mpq3 &a, const mpq_class &b) - { - return mpq3(a.x * b, a.y * b, a.z * b); - } - - friend mpq3 operator*(const mpq_class &a, const mpq3 &b) - { - return mpq3(a * b.x, a * b.y, a * b.z); - } - - friend mpq3 operator/(const mpq3 &a, const mpq_class &b) - { - BLI_assert(b != 0); - return mpq3(a.x / b, a.y / b, a.z / b); - } - - friend bool operator==(const mpq3 &a, const mpq3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const mpq3 &a, const mpq3 &b) - { - return a.x != b.x || a.y != b.y || a.z != b.z; - } - - friend std::ostream &operator<<(std::ostream &stream, const mpq3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - static mpq_class dot(const mpq3 &a, const mpq3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) - { - buffer = a; - buffer *= b; - buffer.x += buffer.y; - buffer.x += buffer.z; - return buffer.x; - } - - static mpq3 cross(const mpq3 &a, const mpq3 &b) - { - return mpq3(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]); - } - - static mpq3 cross_high_precision(const mpq3 &a, const mpq3 &b) - { - return cross(a, b); - } - - static mpq3 project(const mpq3 &a, const mpq3 &b) - { - const mpq_class mul = mpq3::dot(a, b) / mpq3::dot(b, b); - return mpq3(mul * b[0], mul * b[1], mul * b[2]); - } - - static mpq_class distance(const mpq3 &a, const mpq3 &b) - { - mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); - return diff.length(); - } - - static mpq_class distance_squared(const mpq3 &a, const mpq3 &b) - { - mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); - return mpq3::dot(diff, diff); - } - - static mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) - { - buffer = a; - buffer -= b; - return mpq3::dot(buffer, buffer); - } - - static mpq3 interpolate(const mpq3 &a, const mpq3 &b, mpq_class t) - { - mpq_class s = 1 - t; - return mpq3(a.x * s + b.x * t, a.y * s + b.y * t, a.z * s + b.z * t); - } - - static mpq3 abs(const mpq3 &a) - { - mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; - mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; - mpq_class abs_z = (a.z >= 0) ? a.z : -a.z; - return mpq3(abs_x, abs_y, abs_z); - } - - static int dominant_axis(const mpq3 &a) - { - mpq_class x = (a.x >= 0) ? a.x : -a.x; - mpq_class y = (a.y >= 0) ? a.y : -a.y; - mpq_class z = (a.z >= 0) ? a.z : -a.z; - return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); - } - - static mpq3 cross_poly(Span poly); - - /** There is a sensible use for hashing on exact arithmetic types. */ - uint64_t hash() const; -}; - -uint64_t hash_mpq_class(const mpq_class &value); - -} // namespace blender - -#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_noise.hh b/source/blender/blenlib/BLI_noise.hh index 4f68ef17ca2..297c65c250a 100644 --- a/source/blender/blenlib/BLI_noise.hh +++ b/source/blender/blenlib/BLI_noise.hh @@ -16,9 +16,7 @@ #pragma once -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" namespace blender::noise { diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 658cc0c3825..16f479cb3b8 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -75,15 +75,16 @@ bool BLI_make_existing_file(const char *name); * - Doesn't use CWD, or deal with relative paths. * - Only fill's in \a dir and \a file when they are non NULL. */ -void BLI_split_dirfile(const char *string, char *dir, char *file, size_t dirlen, size_t filelen); +void BLI_split_dirfile( + const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen); /** * Copies the parent directory part of string into `dir`, max length `dirlen`. */ -void BLI_split_dir_part(const char *string, char *dir, size_t dirlen); +void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen); /** * Copies the leaf filename part of string into `file`, max length `filelen`. */ -void BLI_split_file_part(const char *string, char *file, size_t filelen); +void BLI_split_file_part(const char *string, char *file, const size_t filelen); /** * Returns a pointer to the last extension (e.g. the position of the last period). * Returns NULL if there is no extension. @@ -93,7 +94,7 @@ const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(); /** * Append a filename to a dir, ensuring slash separates. */ -void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict file) +void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__restrict file) ATTR_NONNULL(); /** * Simple appending of filename to dir, does not check for valid path! @@ -103,7 +104,7 @@ void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict * that de-duplicates separators and can handle an arbitrary number of paths. */ void BLI_join_dirfile(char *__restrict dst, - size_t maxlen, + const size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL(); /** @@ -113,7 +114,7 @@ void BLI_join_dirfile(char *__restrict dst, * \note If you want a trailing slash, add `SEP_STR` as the last path argument, * duplicate slashes will be cleaned up. */ -size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first, ...) +size_t BLI_path_join(char *__restrict dst, const size_t dst_len, const char *path_first, ...) ATTR_NONNULL(1, 3) ATTR_SENTINEL(0); /** * Like Python's `os.path.basename()` @@ -163,12 +164,12 @@ void BLI_path_slash_rstrip(char *string) ATTR_NONNULL(); void BLI_path_slash_native(char *path) ATTR_NONNULL(); #ifdef _WIN32 -bool BLI_path_program_extensions_add_win32(char *name, size_t maxlen); +bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen); #endif /** * Search for a binary (executable) */ -bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name); +bool BLI_path_program_search(char *fullname, const size_t maxlen, const char *name); /** * \return true when `str` end with `ext` (case insensitive). @@ -352,7 +353,7 @@ bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(); * This is _not_ something Blender's internal paths support, instead they use the "//" prefix. * In most cases #BLI_path_abs should be used instead. */ -bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL(); +bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) ATTR_NONNULL(); /** * Replaces `file` with a relative version (prefixed by "//") such that #BLI_path_abs, given * the same `relfile`, will convert it back to its original value. diff --git a/source/blender/blenlib/BLI_rand.hh b/source/blender/blenlib/BLI_rand.hh index cc9e9b374d7..667d6df8996 100644 --- a/source/blender/blenlib/BLI_rand.hh +++ b/source/blender/blenlib/BLI_rand.hh @@ -20,9 +20,8 @@ #pragma once -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h index eb4e69a42d4..653f5f61c9e 100644 --- a/source/blender/blenlib/BLI_stack.h +++ b/source/blender/blenlib/BLI_stack.h @@ -28,13 +28,13 @@ extern "C" { typedef struct BLI_Stack BLI_Stack; -BLI_Stack *BLI_stack_new_ex(size_t elem_size, +BLI_Stack *BLI_stack_new_ex(const size_t elem_size, const char *description, - size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + const size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** * Create a new homogeneous stack with elements of 'elem_size' bytes. */ -BLI_Stack *BLI_stack_new(size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT +BLI_Stack *BLI_stack_new(const size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 8177545911c..a82e97914db 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -42,7 +42,8 @@ extern "C" { * \param len: The number of bytes to duplicate * \retval Returns the duplicated string */ -char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +char *BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(); /** * Duplicates the cstring \a str into a newly mallocN'd @@ -73,7 +74,8 @@ char *BLI_strdupcat(const char *__restrict str1, * the size of dst) * \retval Returns dst */ -char *BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(); +char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) + ATTR_NONNULL(); /** * Like BLI_strncpy but ensures dst is always padded by given char, @@ -105,7 +107,7 @@ char *BLI_strncpy_ensure_pad(char *__restrict dst, */ size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, - size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + const size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); @@ -184,7 +186,7 @@ void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL(); * \note Larger tables should use a hash table. */ bool BLI_str_replace_table_exact(char *string, - size_t string_len, + const size_t string_len, const char *replace_table[][2], int replace_table_len); @@ -233,7 +235,7 @@ char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT * * \note This is used for creating animation paths in blend files. */ -size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) +size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) ATTR_NONNULL(); /** * This roughly matches C and Python's string escaping with double quotes - `"`. @@ -249,9 +251,9 @@ size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t d */ size_t BLI_str_unescape_ex(char *__restrict dst, const char *__restrict src, - size_t src_maxncpy, + const size_t src_maxncpy, /* Additional arguments. */ - size_t dst_maxncpy, + const size_t dst_maxncpy, bool *r_is_complete) ATTR_NONNULL(); /** * See #BLI_str_unescape_ex doc-string. @@ -263,7 +265,7 @@ size_t BLI_str_unescape_ex(char *__restrict dst, * * \note This is used for parsing animation paths in blend files (runs often). */ -size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_maxncpy) +size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy) ATTR_NONNULL(); /** @@ -357,10 +359,10 @@ int BLI_strcmp_ignore_pad(const char *str1, const char *str2, char pad) ATTR_WAR /** * Determine the length of a fixed-size string. */ -size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(); -void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(); +void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL(); +void BLI_str_toupper_ascii(char *str, const size_t len) ATTR_NONNULL(); /** * Strip white-space from end of the string. */ @@ -477,7 +479,7 @@ bool BLI_string_all_words_matched(const char *name, * \return The number of words found in \a str */ int BLI_string_find_split_words(const char *str, - size_t len, + const size_t len, char delim, int r_words[][2], int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 108a2f5fc7d..82622d442fb 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -110,12 +110,14 @@ size_t BLI_str_utf8_from_unicode_len(unsigned int c) ATTR_WARN_UNUSED_RESULT; * * \return number of bytes written. */ -size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, size_t outbuf_len) ATTR_NONNULL(2); +size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, const size_t outbuf_len) + ATTR_NONNULL(2); size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, - size_t maxncpy) ATTR_NONNULL(1, 2); -size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, size_t maxncpy) - ATTR_NONNULL(1, 2); + const size_t maxncpy) ATTR_NONNULL(1, 2); +size_t BLI_str_utf32_as_utf8(char *__restrict dst, + const char32_t *__restrict src, + const size_t maxncpy) ATTR_NONNULL(1, 2); /** * \return The UTF-32 len in UTF-8. */ @@ -160,20 +162,21 @@ size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RES size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; -size_t BLI_strnlen_utf8_ex(const char *strc, size_t maxlen, size_t *r_len_bytes) +size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes) ATTR_NONNULL(1, 3); /** * \param strc: the string to measure the length. * \param maxlen: the string length (in bytes) * \return the unicode length (not in bytes!) */ -size_t BLI_strnlen_utf8(const char *strc, size_t maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) + ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, - size_t maxncpy) ATTR_NONNULL(1, 2); + const size_t maxncpy) ATTR_NONNULL(1, 2); size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, - size_t maxncpy) ATTR_NONNULL(1, 2); + const size_t maxncpy) ATTR_NONNULL(1, 2); /** * Count columns that character/string occupies (based on `wcwidth.co`). diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index 818bfe8182b..fd3918ff217 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -57,11 +57,11 @@ bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(); * Based on `BLI_split_dirfile()` / `os.path.splitext()`, * `"a.b.c"` -> (`"a.b"`, `".c"`). */ -void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, size_t str_len); +void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len); /** * `"a.b.c"` -> (`"a."`, `"b.c"`). */ -void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size_t str_len); +void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len); /** * Join strings, return newly allocated string. @@ -127,7 +127,7 @@ char *BLI_string_join_array_by_sep_char_with_tableN(char sep, size_t BLI_string_flip_side_name(char *r_name, const char *from_name, bool strip_number, - size_t name_len); + const size_t name_len); /** * Ensures name is unique (according to criteria specified by caller in unique_check callback), diff --git a/source/blender/blenlib/BLI_timecode.h b/source/blender/blenlib/BLI_timecode.h index 1cd18dc86ab..f0349e289ac 100644 --- a/source/blender/blenlib/BLI_timecode.h +++ b/source/blender/blenlib/BLI_timecode.h @@ -42,7 +42,7 @@ extern "C" { * \return length of \a str */ size_t BLI_timecode_string_from_time(char *str, - size_t maxncpy, + const size_t maxncpy, int brevity_level, float time_seconds, double fps, @@ -56,7 +56,7 @@ size_t BLI_timecode_string_from_time(char *str, * \param time_seconds: time total time in seconds * \return length of \a str */ -size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double time_seconds) +size_t BLI_timecode_string_from_time_simple(char *str, const size_t maxncpy, double time_seconds) ATTR_NONNULL(); /** @@ -72,7 +72,7 @@ size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double ti * \note in some cases this is used to print non-seconds values. */ size_t BLI_timecode_string_from_time_seconds(char *str, - size_t maxncpy, + const size_t maxncpy, int brevity_level, float time_seconds) ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 35d4158de59..9fe092fe525 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -638,7 +638,7 @@ extern "C" { /** * Check if memory is zeroed, as with `memset(arr, 0, arr_size)`. */ -extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); +extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); #endif #define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member) \ @@ -840,6 +840,15 @@ extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); /** No-op for expressions we don't want to instantiate, but must remain valid. */ #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) +/** + * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for + * SFINAE in common cases. + * + * \note Often one has to invoke this macro with double parenthesis. That's because the condition + * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. + */ +#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr + /** \} */ #ifdef __cplusplus diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 3958fd8e2d2..90c6760019a 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -192,8 +192,6 @@ set(SRC BLI_dlrbTree.h BLI_dot_export.hh BLI_dot_export_attribute_enums.hh - BLI_double2.hh - BLI_double3.hh BLI_dynlib.h BLI_dynstr.h BLI_easing.h @@ -207,9 +205,6 @@ set(SRC BLI_fileops.hh BLI_fileops_types.h BLI_filereader.h - BLI_float2.hh - BLI_float3.hh - BLI_float4.hh BLI_float4x4.hh BLI_fnmatch.h BLI_function_ref.hh @@ -258,6 +253,8 @@ set(SRC BLI_math_statistics.h BLI_math_time.h BLI_math_vector.h + BLI_math_vec_types.hh + BLI_math_vec_mpq_types.hh BLI_memarena.h BLI_memblock.h BLI_memiter.h @@ -267,8 +264,6 @@ set(SRC BLI_mesh_boolean.hh BLI_mesh_intersect.hh BLI_mmap.h - BLI_mpq2.hh - BLI_mpq3.hh BLI_multi_value_map.hh BLI_noise.h BLI_noise.hh @@ -444,6 +439,7 @@ if(WITH_GTESTS) tests/BLI_math_rotation_test.cc tests/BLI_math_solvers_test.cc tests/BLI_math_time_test.cc + tests/BLI_math_vec_types_test.cc tests/BLI_math_vector_test.cc tests/BLI_memiter_test.cc tests/BLI_memory_utils_test.cc diff --git a/source/blender/blenlib/intern/BLI_mempool_private.h b/source/blender/blenlib/intern/BLI_mempool_private.h index 03b0b11297b..90569d87c41 100644 --- a/source/blender/blenlib/intern/BLI_mempool_private.h +++ b/source/blender/blenlib/intern/BLI_mempool_private.h @@ -54,9 +54,8 @@ typedef struct ParallelMempoolTaskData { * * See #BLI_task_parallel_mempool implementation for detailed usage example. */ -ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, - size_t num_iter) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); +ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter) + ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void mempool_iter_threadsafe_destroy(ParallelMempoolTaskData *iter_arr) ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc index 53e881a9fc7..842e6cb6135 100644 --- a/source/blender/blenlib/intern/delaunay_2d.cc +++ b/source/blender/blenlib/intern/delaunay_2d.cc @@ -25,11 +25,10 @@ #include #include "BLI_array.hh" -#include "BLI_double2.hh" #include "BLI_linklist.h" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_set.hh" #include "BLI_task.hh" #include "BLI_vector.hh" @@ -38,6 +37,8 @@ namespace blender::meshintersect { +using namespace blender::math; + /* Throughout this file, template argument T will be an * arithmetic-like type, like float, double, or mpq_class. */ @@ -788,11 +789,11 @@ bool in_line(const FatCo &a, } vec2 exact_ab = b.exact - a.exact; vec2 exact_ac = c.exact - a.exact; - if (vec2::dot(exact_ab, exact_ac) < 0) { + if (dot(exact_ab, exact_ac) < 0) { return false; } vec2 exact_bc = c.exact - b.exact; - return vec2::dot(exact_bc, exact_ac) >= 0; + return dot(exact_bc, exact_ac) >= 0; } #endif @@ -801,11 +802,11 @@ bool in_line(const FatCo &a, const FatCo &b, const FatCo { vec2 ab = b.approx - a.approx; vec2 ac = c.approx - a.approx; - if (vec2::dot(ab, ac) < 0) { + if (dot(ab, ac) < 0) { return false; } vec2 bc = c.approx - b.approx; - return vec2::dot(bc, ac) >= 0; + return dot(bc, ac) >= 0; } template<> CDTVert::CDTVert(const vec2 &pt) @@ -1081,7 +1082,7 @@ template CDTEdge *CDTArrangement::split_edge(SymEdge *se, T SymEdge *sesymprev = prev(sesym); SymEdge *sesymprevsym = sym(sesymprev); SymEdge *senext = se->next; - CDTVert *v = this->add_vert(vec2::interpolate(*a, *b, lambda)); + CDTVert *v = this->add_vert(interpolate(*a, *b, lambda)); CDTEdge *e = this->add_edge(v, se->next->vert, se->face, sesym->face); sesym->vert = v; SymEdge *newse = &e->symedges[0]; @@ -1704,16 +1705,16 @@ void fill_crossdata_for_intersect(const FatCo &curco, BLI_assert(se_vcva->vert == vc && se_vcva->next->vert == va); BLI_assert(se_vcvb->vert == vc && se_vcvb->next->vert == vb); UNUSED_VARS_NDEBUG(vc); - auto isect = vec2::isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); + auto isect = isect_seg_seg>(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); T &lambda = isect.lambda; switch (isect.kind) { - case vec2::isect_result::LINE_LINE_CROSS: { + case isect_result>::LINE_LINE_CROSS: { #ifdef WITH_GMP if (!std::is_same::value) { #else if (true) { #endif - double len_ab = vec2::distance(va->co.approx, vb->co.approx); + double len_ab = distance(va->co.approx, vb->co.approx); if (lambda * len_ab <= epsilon) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1735,7 +1736,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_EXACT: { + case isect_result>::LINE_LINE_EXACT: { if (lambda == 0) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1750,7 +1751,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_NONE: { + case isect_result>::LINE_LINE_NONE: { #ifdef WITH_GMP if (std::is_same::value) { BLI_assert(false); @@ -1766,9 +1767,9 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_COLINEAR: { - if (vec2::distance_squared(va->co.approx, v2->co.approx) <= - vec2::distance_squared(vb->co.approx, v2->co.approx)) { + case isect_result>::LINE_LINE_COLINEAR: { + if (distance_squared(va->co.approx, v2->co.approx) <= + distance_squared(vb->co.approx, v2->co.approx)) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } else { @@ -1845,7 +1846,7 @@ void get_next_crossing_from_edge(CrossData *cd, { CDTVert *va = cd->in->vert; CDTVert *vb = cd->in->next->vert; - vec2 curco = vec2::interpolate(va->co.exact, vb->co.exact, cd->lambda); + vec2 curco = interpolate(va->co.exact, vb->co.exact, cd->lambda); FatCo fat_curco(curco); SymEdge *se_ac = sym(cd->in)->next; CDTVert *vc = se_ac->next->vert; @@ -2386,7 +2387,7 @@ template void remove_non_constraint_edges_leave_valid_bmesh(CDT_stat dissolvable_edges[i].e = e; const vec2 &co1 = e->symedges[0].vert->co.approx; const vec2 &co2 = e->symedges[1].vert->co.approx; - dissolvable_edges[i].len_squared = vec2::distance_squared(co1, co2); + dissolvable_edges[i].len_squared = distance_squared(co1, co2); i++; } } @@ -2569,18 +2570,18 @@ template void detect_holes(CDT_state *cdt_state) if (e->symedges[0].face->visit_index == e->symedges[1].face->visit_index) { continue; /* Don't count hits on edges between faces in same region. */ } - auto isect = vec2::isect_seg_seg(ray_end.exact, + auto isect = isect_seg_seg>(ray_end.exact, mid.exact, e->symedges[0].vert->co.exact, e->symedges[1].vert->co.exact); switch (isect.kind) { - case vec2::isect_result::LINE_LINE_CROSS: { + case isect_result>::LINE_LINE_CROSS: { hits++; break; } - case vec2::isect_result::LINE_LINE_EXACT: - case vec2::isect_result::LINE_LINE_NONE: - case vec2::isect_result::LINE_LINE_COLINEAR: + case isect_result>::LINE_LINE_EXACT: + case isect_result>::LINE_LINE_NONE: + case isect_result>::LINE_LINE_COLINEAR: break; } } diff --git a/source/blender/blenlib/intern/math_boolean.cc b/source/blender/blenlib/intern/math_boolean.cc index c16755868aa..0bae3c23f79 100644 --- a/source/blender/blenlib/intern/math_boolean.cc +++ b/source/blender/blenlib/intern/math_boolean.cc @@ -18,15 +18,10 @@ * \ingroup bli */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" -#include "BLI_mpq3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc index 223c0e273f0..6fab6c9a383 100644 --- a/source/blender/blenlib/intern/math_vec.cc +++ b/source/blender/blenlib/intern/math_vec.cc @@ -18,89 +18,83 @@ * \ingroup bli */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" -#include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" -#include "BLI_mpq3.hh" +#include "BLI_math_vec_mpq_types.hh" +#include "BLI_math_vector.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" -namespace blender { +namespace blender::math { -float2::isect_result float2::isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4) +template<> +isect_result isect_seg_seg(const float2 &v1, + const float2 &v2, + const float2 &v3, + const float2 &v4) { - float2::isect_result ans; + isect_result ans; float div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0f) { ans.lambda = 0.0f; - ans.mu = 0.0f; - ans.kind = float2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; - ans.mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; - if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && ans.mu >= 0.0f && ans.mu <= 1.0f) { - if (ans.lambda == 0.0f || ans.lambda == 1.0f || ans.mu == 0.0f || ans.mu == 1.0f) { - ans.kind = float2::isect_result::LINE_LINE_EXACT; + float mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; + if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) { + if (ans.lambda == 0.0f || ans.lambda == 1.0f || mu == 0.0f || mu == 1.0f) { + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = float2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = float2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } -double2::isect_result double2::isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4) +template<> +isect_result isect_seg_seg(const double2 &v1, + const double2 &v2, + const double2 &v3, + const double2 &v4) { - double2::isect_result ans; + isect_result ans; double div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = double2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; double mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; if (ans.lambda >= 0.0 && ans.lambda <= 1.0 && mu >= 0.0 && mu <= 1.0) { if (ans.lambda == 0.0 || ans.lambda == 1.0 || mu == 0.0 || mu == 1.0) { - ans.kind = double2::isect_result::LINE_LINE_EXACT; + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = double2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = double2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } #ifdef WITH_GMP -mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, - const mpq2 &v2, - const mpq2 &v3, - const mpq2 &v4) +template<> +isect_result isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4) { - mpq2::isect_result ans; + isect_result ans; mpq_class div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = mpq2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; @@ -109,66 +103,21 @@ mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, if (ans.lambda >= 0 && ans.lambda <= 1 && ((div > 0 && mudiv >= 0 && mudiv <= div) || (div < 0 && mudiv <= 0 && mudiv >= div))) { if (ans.lambda == 0 || ans.lambda == 1 || mudiv == 0 || mudiv == div) { - ans.kind = mpq2::isect_result::LINE_LINE_EXACT; + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = mpq2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = mpq2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } #endif -double3 double3::cross_poly(Span poly) -{ - /* Newell's Method. */ - int nv = static_cast(poly.size()); - if (nv < 3) { - return double3(0, 0, 0); - } - const double3 *v_prev = &poly[nv - 1]; - const double3 *v_curr = &poly[0]; - double3 n(0, 0, 0); - for (int i = 0; i < nv;) { - n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); - n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); - n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); - v_prev = v_curr; - ++i; - if (i < nv) { - v_curr = &poly[i]; - } - } - return n; -} - #ifdef WITH_GMP -mpq3 mpq3::cross_poly(Span poly) -{ - /* Newell's Method. */ - int nv = static_cast(poly.size()); - if (nv < 3) { - return mpq3(0); - } - const mpq3 *v_prev = &poly[nv - 1]; - const mpq3 *v_curr = &poly[0]; - mpq3 n(0); - for (int i = 0; i < nv;) { - n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); - n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); - n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); - v_prev = v_curr; - ++i; - if (i < nv) { - v_curr = &poly[i]; - } - } - return n; -} uint64_t hash_mpq_class(const mpq_class &value) { @@ -176,20 +125,6 @@ uint64_t hash_mpq_class(const mpq_class &value) return get_default_hash(static_cast(value.get_d())); } -uint64_t mpq2::hash() const -{ - uint64_t hashx = hash_mpq_class(this->x); - uint64_t hashy = hash_mpq_class(this->y); - return hashx ^ (hashy * 33); -} - -uint64_t mpq3::hash() const -{ - uint64_t hashx = hash_mpq_class(this->x); - uint64_t hashy = hash_mpq_class(this->y); - uint64_t hashz = hash_mpq_class(this->z); - return hashx ^ (hashy * 33) ^ (hashz * 33 * 37); -} #endif -} // namespace blender +} // namespace blender::math diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index ce4db0c6b9d..a3eae1896d3 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -28,8 +28,6 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" @@ -37,8 +35,9 @@ # include "BLI_math_boolean.hh" # include "BLI_math_geom.h" # include "BLI_math_mpq.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_mesh_intersect.hh" -# include "BLI_mpq3.hh" # include "BLI_set.hh" # include "BLI_span.hh" # include "BLI_stack.hh" @@ -1633,13 +1632,13 @@ static Edge find_good_sorting_edge(const Vert *testp, ordinate[axis_next] = -abscissa[axis]; ordinate[axis_next_next] = 0; /* By construction, dot(abscissa, ordinate) == 0, so they are perpendicular. */ - mpq3 normal = mpq3::cross(abscissa, ordinate); + mpq3 normal = math::cross(abscissa, ordinate); if (dbg_level > 0) { std::cout << "abscissa = " << abscissa << "\n"; std::cout << "ordinate = " << ordinate << "\n"; std::cout << "normal = " << normal << "\n"; } - mpq_class nlen2 = normal.length_squared(); + mpq_class nlen2 = math::length_squared(normal); mpq_class max_abs_slope = -1; Edge esort; const Vector &edges = tmtopo.vert_edges(closestp); @@ -1648,12 +1647,12 @@ static Edge find_good_sorting_edge(const Vert *testp, const mpq3 &co_other = v_other->co_exact; mpq3 evec = co_other - co_closest; /* Get projection of evec onto plane of abscissa and ordinate. */ - mpq3 proj_evec = evec - (mpq3::dot(evec, normal) / nlen2) * normal; + mpq3 proj_evec = evec - (math::dot(evec, normal) / nlen2) * normal; /* The projection calculations along the abscissa and ordinate should * be scaled by 1/abscissa and 1/ordinate respectively, * but we can skip: it won't affect which `evec` has the maximum slope. */ - mpq_class evec_a = mpq3::dot(proj_evec, abscissa); - mpq_class evec_o = mpq3::dot(proj_evec, ordinate); + mpq_class evec_a = math::dot(proj_evec, abscissa); + mpq_class evec_o = math::dot(proj_evec, ordinate); if (dbg_level > 0) { std::cout << "e = " << e << "\n"; std::cout << "v_other = " << v_other << "\n"; @@ -1791,8 +1790,8 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, ap = p; ap -= a; - mpq_class d1 = mpq3::dot_with_buffer(ab, ap, m); - mpq_class d2 = mpq3::dot_with_buffer(ac, ap, m); + mpq_class d1 = math::dot_with_buffer(ab, ap, m); + mpq_class d2 = math::dot_with_buffer(ac, ap, m); if (d1 <= 0 && d2 <= 0) { /* Barycentric coordinates (1,0,0). */ *r_edge = -1; @@ -1800,13 +1799,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = a\n"; } - return mpq3::distance_squared_with_buffer(p, a, m); + return math::distance_squared_with_buffer(p, a, m); } /* Check if p in vertex region outside b. */ bp = p; bp -= b; - mpq_class d3 = mpq3::dot_with_buffer(ab, bp, m); - mpq_class d4 = mpq3::dot_with_buffer(ac, bp, m); + mpq_class d3 = math::dot_with_buffer(ab, bp, m); + mpq_class d4 = math::dot_with_buffer(ac, bp, m); if (d3 >= 0 && d4 <= d3) { /* Barycentric coordinates (0,1,0). */ *r_edge = -1; @@ -1814,7 +1813,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = b\n"; } - return mpq3::distance_squared_with_buffer(p, b, m); + return math::distance_squared_with_buffer(p, b, m); } /* Check if p in region of ab. */ mpq_class vc = d1 * d4 - d3 * d2; @@ -1829,13 +1828,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ab at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* Check if p in vertex region outside c. */ cp = p; cp -= c; - mpq_class d5 = mpq3::dot_with_buffer(ab, cp, m); - mpq_class d6 = mpq3::dot_with_buffer(ac, cp, m); + mpq_class d5 = math::dot_with_buffer(ab, cp, m); + mpq_class d6 = math::dot_with_buffer(ac, cp, m); if (d6 >= 0 && d5 <= d6) { /* Barycentric coordinates (0,0,1). */ *r_edge = -1; @@ -1843,7 +1842,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = c\n"; } - return mpq3::distance_squared_with_buffer(p, c, m); + return math::distance_squared_with_buffer(p, c, m); } /* Check if p in edge region of ac. */ mpq_class vb = d5 * d2 - d1 * d6; @@ -1858,7 +1857,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ac at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* Check if p in edge region of bc. */ mpq_class va = d3 * d6 - d5 * d4; @@ -1874,7 +1873,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on bc at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* p inside face region. Compute barycentric coordinates (u,v,w). */ mpq_class denom = 1 / (va + vb + vc); @@ -1890,7 +1889,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = inside at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } static float closest_on_tri_to_point_float_dist_squared(const float3 &p, @@ -2610,7 +2609,7 @@ static void test_tri_inside_shapes(const IMesh &tm, double3 test_point = calc_point_inside_tri_db(tri_test); /* Offset the test point a tiny bit in the tri_test normal direction. */ tri_test.populate_plane(false); - double3 norm = tri_test.plane->norm.normalized(); + double3 norm = math::normalize(tri_test.plane->norm); const double offset_amount = 1e-5; double3 offset_test_point = test_point + offset_amount * norm; if (dbg_level > 0) { @@ -3002,7 +3001,7 @@ static void init_face_merge_state(FaceMergeState *fms, std::cout << "process tri = " << &tri << "\n"; } BLI_assert(tri.plane_populated()); - if (double3::dot(norm, tri.plane->norm) <= 0.0) { + if (math::dot(norm, tri.plane->norm) <= 0.0) { if (dbg_level > 0) { std::cout << "triangle has wrong orientation, skipping\n"; } @@ -3027,7 +3026,7 @@ static void init_face_merge_state(FaceMergeState *fms, } if (me_index == -1) { double3 vec = new_me.v2->co - new_me.v1->co; - new_me.len_squared = vec.length_squared(); + new_me.len_squared = math::length_squared(vec); new_me.orig = tri.edge_orig[i]; new_me.is_intersect = tri.is_intersect[i]; new_me.dissolvable = (new_me.orig == NO_INDEX && !new_me.is_intersect); @@ -3267,7 +3266,7 @@ static Vector merge_tris_for_face(Vector tris, bool done = false; double3 first_tri_normal = tm.face(tris[0])->plane->norm; double3 second_tri_normal = tm.face(tris[1])->plane->norm; - if (tris.size() == 2 && double3::dot(first_tri_normal, second_tri_normal) > 0.0) { + if (tris.size() == 2 && math::dot(first_tri_normal, second_tri_normal) > 0.0) { /* Is this a case where quad with one diagonal remained unchanged? * Worth special handling because this case will be very common. */ Face &tri1 = *tm.face(tris[0]); @@ -3332,7 +3331,7 @@ static bool approx_in_line(const double3 &a, const double3 &b, const double3 &c) { double3 vec1 = b - a; double3 vec2 = c - b; - double cos_ang = double3::dot(vec1.normalized(), vec2.normalized()); + double cos_ang = math::dot(math::normalize(vec1), math::normalize(vec2)); return fabs(cos_ang - 1.0) < 1e-4; } diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc index 1f150137ba3..982759ffcff 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -30,15 +30,13 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" # include "BLI_math_boolean.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_polyfill_2d.h" # include "BLI_set.hh" # include "BLI_span.hh" @@ -198,14 +196,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co_exact; } - normal_exact = mpq3::cross_poly(co); + normal_exact = math::cross_poly(co.as_span()); } else { mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact; mpq3 tr12 = vert[1]->co_exact - vert[2]->co_exact; - normal_exact = mpq3::cross(tr02, tr12); + normal_exact = math::cross(tr02, tr12); } - mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact); + mpq_class d_exact = -math::dot(normal_exact, vert[0]->co_exact); plane = new Plane(normal_exact, d_exact); } else { @@ -215,14 +213,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co; } - normal = double3::cross_poly(co); + normal = math::cross_poly(co.as_span()); } else { double3 tr02 = vert[0]->co - vert[2]->co; double3 tr12 = vert[1]->co - vert[2]->co; - normal = double3::cross_high_precision(tr02, tr12); + normal = math::cross(tr02, tr12); } - double d = -double3::dot(normal, vert[0]->co); + double d = -math::dot(normal, vert[0]->co); plane = new Plane(normal, d); } } @@ -1098,15 +1096,15 @@ static mpq2 project_3d_to_2d(const mpq3 &p3d, int proj_axis) */ static double supremum_dot_cross(const double3 &a, const double3 &b) { - double3 abs_a = double3::abs(a); - double3 abs_b = double3::abs(b); + double3 abs_a = math::abs(a); + double3 abs_b = math::abs(b); double3 c; /* This is dot(cross(a, b), cross(a,b)) but using absolute values for a and b * and always using + when operation is + or -. */ c[0] = abs_a[1] * abs_b[2] + abs_a[2] * abs_b[1]; c[1] = abs_a[2] * abs_b[0] + abs_a[0] * abs_b[2]; c[2] = abs_a[0] * abs_b[1] + abs_a[1] * abs_b[0]; - return double3::dot(c, c); + return math::dot(c, c); } /* The index of dot when inputs are plane_coords with index 1 is much higher. @@ -1143,11 +1141,11 @@ static int filter_plane_side(const double3 &p, const double3 &abs_plane_p, const double3 &abs_plane_no) { - double d = double3::dot(p - plane_p, plane_no); + double d = math::dot(p - plane_p, plane_no); if (d == 0.0) { return 0; } - double supremum = double3::dot(abs_p + abs_plane_p, abs_plane_no); + double supremum = math::dot(abs_p + abs_plane_p, abs_plane_no); double err_bound = supremum * index_plane_side * DBL_EPSILON; if (fabs(d) > err_bound) { return d > 0 ? 1 : -1; @@ -1178,9 +1176,9 @@ static inline mpq3 tti_interp( ab -= b; ac = a; ac -= c; - mpq_class den = mpq3::dot_with_buffer(ab, n, dotbuf); + mpq_class den = math::dot_with_buffer(ab, n, dotbuf); BLI_assert(den != 0); - mpq_class alpha = mpq3::dot_with_buffer(ac, n, dotbuf) / den; + mpq_class alpha = math::dot_with_buffer(ac, n, dotbuf) / den; return a - alpha * ab; } @@ -1209,7 +1207,7 @@ static inline int tti_above(const mpq3 &a, n.y = ba.z * ca.x - ba.x * ca.z; n.z = ba.x * ca.y - ba.y * ca.x; - return sgn(mpq3::dot_with_buffer(ad, n, dotbuf)); + return sgn(math::dot_with_buffer(ad, n, dotbuf)); } /** @@ -1428,11 +1426,11 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) const double3 &d_r2 = vr2->co; const double3 &d_n2 = tri2.plane->norm; - const double3 &abs_d_p1 = double3::abs(d_p1); - const double3 &abs_d_q1 = double3::abs(d_q1); - const double3 &abs_d_r1 = double3::abs(d_r1); - const double3 &abs_d_r2 = double3::abs(d_r2); - const double3 &abs_d_n2 = double3::abs(d_n2); + const double3 &abs_d_p1 = math::abs(d_p1); + const double3 &abs_d_q1 = math::abs(d_q1); + const double3 &abs_d_r1 = math::abs(d_r1); + const double3 &abs_d_r2 = math::abs(d_r2); + const double3 &abs_d_n2 = math::abs(d_n2); int sp1 = filter_plane_side(d_p1, d_r2, d_n2, abs_d_p1, abs_d_r2, abs_d_n2); int sq1 = filter_plane_side(d_q1, d_r2, d_n2, abs_d_q1, abs_d_r2, abs_d_n2); @@ -1448,9 +1446,9 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) } const double3 &d_n1 = tri1.plane->norm; - const double3 &abs_d_p2 = double3::abs(d_p2); - const double3 &abs_d_q2 = double3::abs(d_q2); - const double3 &abs_d_n1 = double3::abs(d_n1); + const double3 &abs_d_p2 = math::abs(d_p2); + const double3 &abs_d_q2 = math::abs(d_q2); + const double3 &abs_d_n1 = math::abs(d_n1); int sp2 = filter_plane_side(d_p2, d_r1, d_n1, abs_d_p2, abs_d_r1, abs_d_n1); int sq2 = filter_plane_side(d_q2, d_r1, d_n1, abs_d_q2, abs_d_r1, abs_d_n1); @@ -1477,17 +1475,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp1 == 0) { buf[0] = p1; buf[0] -= r2; - sp1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sp1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (sq1 == 0) { buf[0] = q1; buf[0] -= r2; - sq1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sq1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (sr1 == 0) { buf[0] = r1; buf[0] -= r2; - sr1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sr1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (dbg_level > 1) { @@ -1509,17 +1507,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp2 == 0) { buf[0] = p2; buf[0] -= r1; - sp2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sp2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (sq2 == 0) { buf[0] = q2; buf[0] -= r1; - sq2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sq2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (sr2 == 0) { buf[0] = r2; buf[0] -= r1; - sr2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sr2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (dbg_level > 1) { @@ -1721,7 +1719,7 @@ static CDT_data prepare_cdt_input(const IMesh &tm, int t, const Vectorplane_populated()); ans.t_plane = tm.face(t)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); prepare_need_tri(ans, tm, t); for (const ITT_value &itt : itts) { switch (itt.kind) { @@ -1757,7 +1755,7 @@ static CDT_data prepare_cdt_input_for_cluster(const IMesh &tm, BLI_assert(tm.face(t0)->plane_populated()); ans.t_plane = tm.face(t0)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); for (const int t : cl) { prepare_need_tri(ans, tm, t); } @@ -2004,9 +2002,9 @@ static bool is_quad_flip_first_third(const double3 &v1, const double3 &normal) { double3 dir_v3v1 = v3 - v1; - double3 tangent = double3::cross_high_precision(dir_v3v1, normal); - double dot = double3::dot(v1, tangent); - return (double3::dot(v4, tangent) >= dot) || (double3::dot(v2, tangent) <= dot); + double3 tangent = math::cross(dir_v3v1, normal); + double dot = math::dot(v1, tangent); + return (math::dot(v4, tangent) >= dot) || (math::dot(v2, tangent) <= dot); } /** @@ -2124,7 +2122,7 @@ static Array exact_triangulate_poly(Face *f, IMeshArena *arena) f->populate_plane(false); } const double3 &poly_normal = f->plane->norm; - int axis = double3::dominant_axis(poly_normal); + int axis = math::dominant_axis(poly_normal); /* If project down y axis as opposed to x or z, the orientation * of the polygon will be reversed. * Yet another reversal happens if the poly normal in the dominant @@ -2203,15 +2201,15 @@ static bool face_is_degenerate(const Face *f) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double3 dab = double3::cross_high_precision(da, db); - double dab_length_squared = dab.length_squared(); + double3 dab = math::cross(da, db); + double dab_length_squared = math::length_squared(dab); double err_bound = supremum_dot_cross(dab, dab) * index_dot_cross * DBL_EPSILON; if (dab_length_squared > err_bound) { return false; } mpq3 a = v2->co_exact - v0->co_exact; mpq3 b = v2->co_exact - v1->co_exact; - mpq3 ab = mpq3::cross(a, b); + mpq3 ab = math::cross(a, b); if (ab.x == 0 && ab.y == 0 && ab.z == 0) { return true; } @@ -2231,8 +2229,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double da_length_squared = da.length_squared(); - double db_length_squared = db.length_squared(); + double da_length_squared = math::length_squared(da); + double db_length_squared = math::length_squared(db); if (da_length_squared == 0.0 || db_length_squared == 0.0) { return true; } @@ -2240,8 +2238,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) * The triangle is almost degenerate if sin t is almost 0. * sin^2 t = |da x db|^2 / (|da|^2 |db|^2) */ - double3 dab = double3::cross_high_precision(da, db); - double dab_length_squared = dab.length_squared(); + double3 dab = math::cross(da, db); + double dab_length_squared = math::length_squared(dab); double sin_squared_t = dab_length_squared / (da_length_squared * db_length_squared); if (sin_squared_t < 1e-8) { return true; diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc index a6ad18801fd..3460c1284fc 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -50,9 +50,7 @@ #include #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_math_base_safe.h" #include "BLI_noise.hh" #include "BLI_utildefines.h" @@ -1469,7 +1467,7 @@ void voronoi_smooth_f1(const float w, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_w != nullptr) { smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor; @@ -1592,7 +1590,7 @@ static float voronoi_distance(const float2 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float2::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1615,7 +1613,7 @@ void voronoi_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1654,7 +1652,7 @@ void voronoi_smooth_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1676,11 +1674,10 @@ void voronoi_smooth_f1(const float2 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float2::interpolate(smoothPosition, pointPosition, h) - - correctionFactor; + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } } @@ -1704,7 +1701,7 @@ void voronoi_f2(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1748,7 +1745,7 @@ void voronoi_f2(const float2 coord, void voronoi_distance_to_edge(const float2 coord, const float randomness, float *r_distance) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float2 vectorToClosest = float2(0.0f, 0.0f); @@ -1777,7 +1774,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float const float2 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v2v2(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v2v2((vectorToClosest + vectorToPoint) / 2.0f, - perpendicularToEdge.normalized()); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -1787,7 +1784,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *r_radius) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float2 closestPoint = float2(0.0f, 0.0f); @@ -1798,7 +1795,7 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j); const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float2::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -1817,14 +1814,14 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j) + closestPointOffset; const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float2::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; } } } - *r_radius = float2::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 3D Voronoi **** */ @@ -1836,7 +1833,7 @@ static float voronoi_distance(const float3 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float3::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1860,7 +1857,7 @@ void voronoi_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1902,7 +1899,7 @@ void voronoi_smooth_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1925,10 +1922,10 @@ void voronoi_smooth_f1(const float3 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float3::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -1954,7 +1951,7 @@ void voronoi_f2(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2000,7 +1997,7 @@ void voronoi_f2(const float3 coord, void voronoi_distance_to_edge(const float3 coord, const float randomness, float *r_distance) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float3 vectorToClosest = float3(0.0f, 0.0f, 0.0f); @@ -2032,7 +2029,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float const float3 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v3v3(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v3v3((vectorToClosest + vectorToPoint) / 2.0f, - perpendicularToEdge.normalized()); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2043,7 +2040,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *r_radius) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float3 closestPoint = float3(0.0f, 0.0f, 0.0f); @@ -2055,7 +2052,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k); const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float3::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2076,7 +2073,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k) + closestPointOffset; const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float3::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2084,7 +2081,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * } } } - *r_radius = float3::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 4D Voronoi **** */ @@ -2096,7 +2093,7 @@ static float voronoi_distance(const float4 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float4::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z) + fabsf(a.w - b.w); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -2121,7 +2118,7 @@ void voronoi_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -2166,7 +2163,7 @@ void voronoi_smooth_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -2191,10 +2188,10 @@ void voronoi_smooth_f1(const float4 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float4::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -2221,7 +2218,7 @@ void voronoi_f2(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2270,7 +2267,7 @@ void voronoi_f2(const float4 coord, void voronoi_distance_to_edge(const float4 coord, const float randomness, float *r_distance) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float4 vectorToClosest = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2307,7 +2304,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float const float4 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v4v4(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v4v4((vectorToClosest + vectorToPoint) / 2.0f, - float4::normalize(perpendicularToEdge)); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2319,7 +2316,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *r_radius) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float4 closestPoint = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2333,7 +2330,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float4::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2357,7 +2354,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float4::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2366,7 +2363,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * } } } - *r_radius = float4::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /** \} */ diff --git a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc index 70e3a99e57a..eac3faa6d15 100644 --- a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc +++ b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc @@ -21,10 +21,9 @@ extern "C" { #define DO_RANDOM_TESTS 0 #include "BLI_array.hh" -#include "BLI_double2.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_vector.hh" #include "BLI_delaunay_2d.h" diff --git a/source/blender/blenlib/tests/BLI_math_vec_types_test.cc b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc new file mode 100644 index 00000000000..8aa1f90fde2 --- /dev/null +++ b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc @@ -0,0 +1,149 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +#include "BLI_math_vec_types.hh" + +namespace blender::tests { + +using namespace blender::math; + +TEST(math_vec_types, ScalarConstructorUnsigned) +{ + float2 u(5u); + EXPECT_EQ(u[0], 5.0f); + EXPECT_EQ(u[1], 5.0f); +} + +TEST(math_vec_types, ScalarConstructorInt) +{ + float2 i(-5); + EXPECT_EQ(i[0], -5.0f); + EXPECT_EQ(i[1], -5.0f); +} + +TEST(math_vec_types, ScalarConstructorFloat) +{ + float2 f(5.2f); + EXPECT_FLOAT_EQ(f[0], 5.2f); + EXPECT_FLOAT_EQ(f[1], 5.2f); +} + +TEST(math_vec_types, ScalarConstructorDouble) +{ + float2 d(5.2); + EXPECT_FLOAT_EQ(d[0], 5.2f); + EXPECT_FLOAT_EQ(d[1], 5.2f); +} + +TEST(math_vec_types, MultiScalarConstructorVec2) +{ + int2 i(5.5f, -1.8); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); +} + +TEST(math_vec_types, MultiScalarConstructorVec3) +{ + int3 i(5.5f, -1.8, 6u); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); + EXPECT_EQ(i[2], 6); +} + +TEST(math_vec_types, MultiScalarConstructorVec4) +{ + int4 i(5.5f, -1.8, 6u, 0.888f); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); + EXPECT_EQ(i[2], 6); + EXPECT_EQ(i[3], 0); +} + +TEST(math_vec_types, MixedScalarVectorConstructorVec3) +{ + float3 fl_v2(float2(5.5f), 1.8f); + EXPECT_FLOAT_EQ(fl_v2[0], 5.5f); + EXPECT_FLOAT_EQ(fl_v2[1], 5.5f); + EXPECT_FLOAT_EQ(fl_v2[2], 1.8f); + + float3 v2_fl(1.8f, float2(5.5f)); + EXPECT_FLOAT_EQ(v2_fl[0], 1.8f); + EXPECT_FLOAT_EQ(v2_fl[1], 5.5f); + EXPECT_FLOAT_EQ(v2_fl[2], 5.5f); +} + +TEST(math_vec_types, MixedScalarVectorConstructorVec4) +{ + int4 v2_fl_fl(float2(1), 2, 3); + EXPECT_EQ(v2_fl_fl[0], 1); + EXPECT_EQ(v2_fl_fl[1], 1); + EXPECT_EQ(v2_fl_fl[2], 2); + EXPECT_EQ(v2_fl_fl[3], 3); + + float4 fl_v2_fl(1, int2(2), 3); + EXPECT_EQ(fl_v2_fl[0], 1); + EXPECT_EQ(fl_v2_fl[1], 2); + EXPECT_EQ(fl_v2_fl[2], 2); + EXPECT_EQ(fl_v2_fl[3], 3); + + double4 fl_fl_v2(1, 2, double2(3)); + EXPECT_EQ(fl_fl_v2[0], 1); + EXPECT_EQ(fl_fl_v2[1], 2); + EXPECT_EQ(fl_fl_v2[2], 3); + EXPECT_EQ(fl_fl_v2[3], 3); + + int4 v2_v2(float2(1), uint2(2)); + EXPECT_EQ(v2_v2[0], 1); + EXPECT_EQ(v2_v2[1], 1); + EXPECT_EQ(v2_v2[2], 2); + EXPECT_EQ(v2_v2[3], 2); + + float4 v3_fl(uint3(1), 2); + EXPECT_EQ(v3_fl[0], 1); + EXPECT_EQ(v3_fl[1], 1); + EXPECT_EQ(v3_fl[2], 1); + EXPECT_EQ(v3_fl[3], 2); + + uint4 fl_v3(1, float3(2)); + EXPECT_EQ(fl_v3[0], 1); + EXPECT_EQ(fl_v3[1], 2); + EXPECT_EQ(fl_v3[2], 2); + EXPECT_EQ(fl_v3[3], 2); +} + +TEST(math_vec_types, ComponentMasking) +{ + int4 i(0, 1, 2, 3); + float2 f2 = float2(i); + EXPECT_EQ(f2[0], 0.0f); + EXPECT_EQ(f2[1], 1.0f); +} + +TEST(math_vec_types, PointerConversion) +{ + float array[3] = {1.0f, 2.0f, 3.0f}; + float3 farray(array); + EXPECT_EQ(farray[0], 1.0f); + EXPECT_EQ(farray[1], 2.0f); + EXPECT_EQ(farray[2], 3.0f); +} + +TEST(math_vec_types, PointerArrayConversion) +{ + float array[1][3] = {{1.0f, 2.0f, 3.0f}}; + float(*ptr)[3] = array; + float3 fptr(ptr); + EXPECT_EQ(fptr[0], 1.0f); + EXPECT_EQ(fptr[1], 2.0f); + EXPECT_EQ(fptr[2], 3.0f); +} + +TEST(math_vec_types, VectorTypeConversion) +{ + double2 d(int2(float2(5.75f, -1.57f))); + EXPECT_EQ(d[0], 5.0); + EXPECT_EQ(d[1], -1.0); +} + +} // namespace blender::tests diff --git a/source/blender/blenlib/tests/BLI_memory_utils_test.cc b/source/blender/blenlib/tests/BLI_memory_utils_test.cc index 207f310d902..74e54151a06 100644 --- a/source/blender/blenlib/tests/BLI_memory_utils_test.cc +++ b/source/blender/blenlib/tests/BLI_memory_utils_test.cc @@ -1,6 +1,6 @@ /* Apache License, Version 2.0 */ -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_memory_utils.hh" #include "BLI_strict_flags.h" #include "testing/testing.h" diff --git a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc index d759f0c3be4..2b8fb3dbea4 100644 --- a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc @@ -11,8 +11,8 @@ #include "BLI_array.hh" #include "BLI_map.hh" #include "BLI_math_mpq.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_boolean.hh" -#include "BLI_mpq3.hh" #include "BLI_vector.hh" #ifdef WITH_GMP diff --git a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc index 68111fb8eb1..d2d76593129 100644 --- a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc @@ -10,8 +10,8 @@ #include "BLI_array.hh" #include "BLI_math_mpq.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_intersect.hh" -#include "BLI_mpq3.hh" #include "BLI_task.h" #include "BLI_vector.hh" diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 85ea27b0f4e..7865c79323d 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -1186,7 +1186,6 @@ static BMO_FlagSet bmo_enum_triangulate_quad_method[] = { {MOD_TRIANGULATE_QUAD_FIXED, "FIXED"}, {MOD_TRIANGULATE_QUAD_ALTERNATE, "ALTERNATE"}, {MOD_TRIANGULATE_QUAD_SHORTEDGE, "SHORT_EDGE"}, - {MOD_TRIANGULATE_QUAD_LONGEDGE, "LONG_EDGE"}, {0, NULL}, }; diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index e7280303c26..e9eaf865e3c 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -1007,7 +1007,6 @@ void BM_face_triangulate(BMesh *bm, break; } case MOD_TRIANGULATE_QUAD_SHORTEDGE: - case MOD_TRIANGULATE_QUAD_LONGEDGE: case MOD_TRIANGULATE_QUAD_BEAUTY: default: { BMLoop *l_v3, *l_v4; @@ -1024,12 +1023,6 @@ void BM_face_triangulate(BMesh *bm, d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); split_24 = ((d2 - d1) > 0.0f); } - else if (quad_method == MOD_TRIANGULATE_QUAD_LONGEDGE) { - float d1, d2; - d1 = len_squared_v3v3(l_v4->v->co, l_v2->v->co); - d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); - split_24 = ((d2 - d1) < 0.0f); - } else { /* first check if the quad is concave on either diagonal */ const int flip_flag = is_quad_flip_v3( diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 88ce9b88097..f59fd885871 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -645,15 +645,6 @@ endif() blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") -if(WITH_UNITY_BUILD) - set_target_properties(bf_compositor PROPERTIES UNITY_BUILD ON) - set_target_properties(bf_compositor PROPERTIES UNITY_BUILD_BATCH_SIZE 10) -endif() - -if(COMMAND target_precompile_headers) - target_precompile_headers(bf_compositor PRIVATE COM_precomp.h) -endif() - if(CXX_WARN_NO_SUGGEST_OVERRIDE) target_compile_options(bf_compositor PRIVATE "-Wsuggest-override") endif() diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index 1c3a28670df..794bf1b23bc 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -18,7 +18,7 @@ #pragma once -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "DNA_vec_types.h" diff --git a/source/blender/compositor/COM_precomp.h b/source/blender/compositor/COM_precomp.h deleted file mode 100644 index 4d2681ea0cd..00000000000 --- a/source/blender/compositor/COM_precomp.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Pre-compiled headers, see: D13797. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "COM_ConstantOperation.h" -#include "COM_ConvertOperation.h" -#include "COM_Debug.h" -#include "COM_Enums.h" -#include "COM_ExecutionGroup.h" -#include "COM_ExecutionSystem.h" -#include "COM_MultiThreadedOperation.h" -#include "COM_Node.h" -#include "COM_NodeOperation.h" -#include "COM_OpenCLDevice.h" -#include "COM_SetAlphaMultiplyOperation.h" -#include "COM_SetColorOperation.h" -#include "COM_SetSamplerOperation.h" -#include "COM_SetValueOperation.h" -#include "COM_SetVectorOperation.h" -#include "COM_defines.h" diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index e601ebac4e1..0e871f47b87 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -136,7 +136,7 @@ void add_exr_channels(void *exrhandle, const char *layer_name, const DataType datatype, const char *view_name, - size_t width, + const size_t width, bool use_half_float, float *buf); void free_exr_channels(void *exrhandle, diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index fcdc3fe58e8..1c09417e9ab 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1475,17 +1475,6 @@ void DepsgraphRelationBuilder::build_animation_images(ID *id) id, NodeType::IMAGE_ANIMATION, OperationCode::IMAGE_ANIMATION); TimeSourceKey time_src_key; add_relation(time_src_key, image_animation_key, "TimeSrc -> Image Animation"); - - /* The image users of these ids may change during evaluation. Make sure that the image - * animation update happens after evaluation. */ - if (GS(id->name) == ID_MA) { - OperationKey material_update_key(id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE); - add_relation(material_update_key, image_animation_key, "Material Update -> Image Animation"); - } - else if (GS(id->name) == ID_WO) { - OperationKey world_update_key(id, NodeType::SHADING, OperationCode::WORLD_UPDATE); - add_relation(world_update_key, image_animation_key, "World Update -> Image Animation"); - } } } diff --git a/source/blender/depsgraph/intern/node/deg_node_factory.h b/source/blender/depsgraph/intern/node/deg_node_factory.h index b3153a7ddfb..125f340a0fa 100644 --- a/source/blender/depsgraph/intern/node/deg_node_factory.h +++ b/source/blender/depsgraph/intern/node/deg_node_factory.h @@ -55,7 +55,7 @@ template struct DepsNodeFactoryImpl : public DepsNodeFacto void register_node_typeinfo(DepsNodeFactory *factory); /* Get typeinfo for specified type */ -DepsNodeFactory *type_get_factory(NodeType type); +DepsNodeFactory *type_get_factory(const NodeType type); } // namespace deg } // namespace blender diff --git a/source/blender/draw/intern/draw_cache_impl_curve.cc b/source/blender/draw/intern/draw_cache_impl_curve.cc index 1108d40125b..33cf0e9a3cd 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.cc +++ b/source/blender/draw/intern/draw_cache_impl_curve.cc @@ -26,8 +26,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc index ea702e5efdd..b846da3f016 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc @@ -25,9 +25,7 @@ #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BKE_attribute.h" diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 79dda480a0a..73a94f066e3 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -54,7 +54,6 @@ #include "BKE_deform.h" #include "BKE_global.h" #include "BKE_gpencil.h" -#include "BKE_gpencil_curve.h" #include "BKE_gpencil_geom.h" #include "BKE_layer.h" #include "BKE_main.h" @@ -835,7 +834,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p, /* color strength */ if (brush_settings->flag & GP_BRUSH_USE_STRENGTH_PRESSURE) { pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); } /* Set vertex colors for buffer. */ @@ -919,19 +918,6 @@ static short gpencil_stroke_addpoint(tGPsdata *p, return GP_STROKEADD_INVALID; } -static void gpencil_stroke_unselect(bGPdata *gpd, bGPDstroke *gps) -{ - gps->flag &= ~GP_STROKE_SELECT; - BKE_gpencil_stroke_select_index_reset(gps); - for (int i = 0; i < gps->totpoints; i++) { - gps->points[i].flag &= ~GP_SPOINT_SELECT; - } - /* Update the selection from the stroke to the curve. */ - if (gps->editcurve) { - BKE_gpencil_editcurve_stroke_sync_selection(gpd, gps, gps->editcurve); - } -} - /* make a new stroke from the buffer data */ static void gpencil_stroke_newfrombuffer(tGPsdata *p) { @@ -942,7 +928,6 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) tGPspoint *ptc; MDeformVert *dvert = NULL; Brush *brush = p->brush; - BrushGpencilSettings *brush_settings = brush->gpencil_settings; ToolSettings *ts = p->scene->toolsettings; Depsgraph *depsgraph = p->depsgraph; Object *obact = (Object *)p->ownerPtr.data; @@ -1031,7 +1016,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; /* Apply the vertex color to point. */ @@ -1065,7 +1050,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); pt->time = ptc->time; /* Apply the vertex color to point. */ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); @@ -1190,7 +1175,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; pt->uv_fac = ptc->uv_fac; @@ -1315,12 +1300,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) ctrl2, GPENCIL_MINIMUM_JOIN_DIST, &pt_index); - if (gps_target != NULL) { - /* Unselect all points of source and destination strokes. This is required to avoid - * a change in the resolution of the original strokes during the join. */ - gpencil_stroke_unselect(gpd, gps); - gpencil_stroke_unselect(gpd, gps_target); gps = ED_gpencil_stroke_join_and_trim(p->gpd, p->gpf, gps, gps_target, pt_index); } else { diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h index 6bcddfa631a..8a669a2afc2 100644 --- a/source/blender/editors/include/ED_util.h +++ b/source/blender/editors/include/ED_util.h @@ -102,7 +102,7 @@ void ED_slider_destroy(struct bContext *C, struct tSlider *slider); */ void ED_slider_status_string_get(const struct tSlider *slider, char *status_string, - size_t size_of_status_string); + const size_t size_of_status_string); float ED_slider_factor_get(struct tSlider *slider); void ED_slider_factor_set(struct tSlider *slider, float factor); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 9ce07cd2e07..f01b8318e98 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -495,7 +495,7 @@ float UI_text_clip_middle_ex(const struct uiFontStyle *fstyle, char *str, float okwidth, float minwidth, - size_t max_len, + const size_t max_len, char rpart_sep); /** @@ -2957,17 +2957,15 @@ void UI_fontstyle_set(const struct uiFontStyle *fs); void UI_fontstyle_draw_ex(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, - size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, + size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info); - void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, - size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params); /** diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 923f741e3ae..027f03d05c7 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -688,11 +688,11 @@ extern void ui_hsvcube_pos_from_vals( */ extern void ui_but_string_get_ex(uiBut *but, char *str, - size_t maxlen, + const size_t maxlen, int float_precision, bool use_exp_float, bool *r_use_exp_float) ATTR_NONNULL(1, 2); -extern void ui_but_string_get(uiBut *but, char *str, size_t maxlen) ATTR_NONNULL(); +extern void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) ATTR_NONNULL(); /** * A version of #ui_but_string_get_ex for dynamic buffer sizes * (where #ui_but_string_get_max_length returns 0). diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 135cef5fe53..bc1d3387ad7 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1146,7 +1146,6 @@ static void panel_draw_aligned_widgets(const uiStyle *style, UI_fontstyle_draw(fontstyle, &title_rect, panel->drawname, - sizeof(panel->drawname), title_color, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index fe58a6a05ae..e146443faaa 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -74,8 +74,6 @@ #define UI_TIP_PADDING (int)(UI_TIP_PAD_FAC * UI_UNIT_Y) #define UI_TIP_MAXWIDTH 600 -#define UI_TIP_STR_MAX 1024 - typedef struct uiTooltipFormat { enum { UI_TIP_STYLE_NORMAL = 0, @@ -216,7 +214,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw header and active data (is done here to be able to change color) */ rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_MAIN]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); /* offset to the end of the last line */ if (field->text_suffix) { @@ -226,8 +224,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.ymax -= yofs; rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_ACTIVE]); - UI_fontstyle_draw( - &data->fstyle, &bbox, field->text_suffix, UI_TIP_STR_MAX, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text_suffix, drawcol, &fs_params); /* undo offset */ bbox.xmin -= xofs; @@ -246,7 +243,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* XXX, needed because we don't have mono in 'U.uifonts' */ BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); - UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); + UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol, &fs_params); } else { BLI_assert(field->format.style == UI_TIP_STYLE_NORMAL); @@ -258,7 +255,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw remaining data */ rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); } bbox.ymax -= data->lineh * field->geom.lines; @@ -1218,12 +1215,12 @@ static ARegion *ui_tooltip_create_with_data(bContext *C, BLI_assert(ELEM(field->format.style, UI_TIP_STYLE_NORMAL, UI_TIP_STYLE_HEADER)); font_id = data->fstyle.uifont_id; } - w = BLF_width_ex(font_id, field->text, UI_TIP_STR_MAX, &info); + w = BLF_width_ex(font_id, field->text, BLF_DRAW_STR_DUMMY_MAX, &info); /* check for suffix (enum label) */ if (field->text_suffix && field->text_suffix[0]) { x_pos = info.width; - w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, UI_TIP_STR_MAX)); + w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, BLF_DRAW_STR_DUMMY_MAX)); } fontw = max_ii(fontw, w); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 44942d508ca..c28769a4951 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -140,9 +140,9 @@ static uiFont *uifont_to_blfont(int id) void UI_fontstyle_draw_ex(const uiFontStyle *fs, const rcti *rect, const char *str, - const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, + size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info) @@ -183,10 +183,10 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, } if (fs_params->align == UI_STYLE_TEXT_CENTER) { - xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len))); + xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); } else if (fs_params->align == UI_STYLE_TEXT_RIGHT) { - xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len); + xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len); } yofs = MAX2(0, yofs); @@ -196,7 +196,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_color4ubv(fs->uifont_id, col); - BLF_draw_ex(fs->uifont_id, str, str_len, r_info); + BLF_draw_ex(fs->uifont_id, str, len, r_info); BLF_disable(fs->uifont_id, font_flag); @@ -211,11 +211,12 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, - const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params) { - UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, NULL, NULL, NULL); + int xofs, yofs; + + UI_fontstyle_draw_ex(fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, NULL); } void UI_fontstyle_draw_rotated(const uiFontStyle *fs, diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index b44496731f7..ad8c0842657 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2130,11 +2130,11 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, - drawlen, wcol->text, &(struct uiFontStyleDraw_Params){ .align = align, }, + drawlen, &font_xofs, &font_yofs, NULL); @@ -2194,7 +2194,6 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, drawstr_right, - UI_MAX_DRAW_STR, col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5418,11 +5417,11 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr, - sizeof(drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, }, + BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, &info); @@ -5469,7 +5468,6 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, hint_drawstr, - sizeof(hint_drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5525,7 +5523,6 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, &trect, drawstr, - sizeof(drawstr), text_col, &(struct uiFontStyleDraw_Params){ .align = text_align, diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 06e21f91d04..b9943d13b19 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -3527,8 +3527,6 @@ static int object_add_named_exec(bContext *C, wmOperator *op) } basen->object->visibility_flag &= ~OB_HIDE_VIEWPORT; - /* Do immediately, as #copy_object_set_idnew() below operates on visible objects. */ - BKE_base_eval_flags(basen); /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or * BKE_view_layer_base_deselect_all(). */ diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 4f94927533b..16e83395401 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -722,7 +722,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r SpaceProperties *sbuts = CTX_wm_space_properties(C); ShaderPreview *sp = static_cast(WM_jobs_customdata(wm, area)); rcti newrect; - bool ok; + int ok; int newx = BLI_rcti_size_x(rect); int newy = BLI_rcti_size_y(rect); diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index dd1b4e10e60..44e9735866d 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -240,7 +240,6 @@ static void file_draw_string(int sx, UI_fontstyle_draw(&fs, &rect, fname, - sizeof(fname), col, &(struct uiFontStyleDraw_Params){ .align = align, @@ -290,12 +289,12 @@ static void file_draw_string_multiline(int sx, UI_fontstyle_draw_ex(&style->widget, &rect, string, - len, text_col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, .word_wrap = true, }, + len, NULL, NULL, &result); diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index e9a385c525b..2d3c42b16d1 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2452,7 +2452,7 @@ static void frame_node_draw_label(const bNodeTree &ntree, const bool has_label = node.label[0] != '\0'; if (has_label) { BLF_position(fontid, x, y, 0); - BLF_draw(fontid, label, sizeof(label)); + BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX); } /* draw text body */ diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 4834ca3174a..02d68189997 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -28,9 +28,9 @@ #include "DNA_anim_types.h" #include "DNA_node_types.h" -#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_vector.hh" diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index 0f542734f66..740d1fbb6f9 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -23,7 +23,7 @@ #pragma once -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BKE_node.h" @@ -43,9 +43,6 @@ struct bNodeLink; struct bNodeSocket; struct wmGizmoGroupType; struct wmKeyConfig; -namespace blender { -struct float2; -} struct wmWindow; /** Temporary data used in node link drag modal operator. */ diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index 334ca1f76ee..803cf38c53a 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -111,11 +111,13 @@ static bNode *node_under_mouse_select(bNodeTree &ntree, int mx, int my) static bNode *node_under_mouse_tweak(bNodeTree &ntree, const float2 &mouse) { + using namespace blender::math; + LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) { if (node->type == NODE_REROUTE) { bNodeSocket *socket = (bNodeSocket *)node->inputs.first; const float2 location{socket->locx, socket->locy}; - if (float2::distance(mouse, location) < 24.0f) { + if (distance(mouse, location) < 24.0f) { return node; } } diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 6dffc0bc2a4..e814530d1e2 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -2262,15 +2262,28 @@ void sequencer_draw_preview(const bContext *C, seq_prefetch_wm_notify(C, scene); } -static void draw_seq_timeline_channels(View2D *v2d) +/* Draw backdrop in sequencer timeline. */ +static void draw_seq_backdrop(View2D *v2d) { + int i; + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + /* View backdrop. */ + immUniformThemeColor(TH_BACK); + immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax); + + /* Darker overlay over the view backdrop. */ + immUniformThemeColorShade(TH_BACK, -10); + immRectf(pos, v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0); + + /* Alternating horizontal stripes. */ + i = max_ii(1, ((int)v2d->cur.ymin) - 1); + GPU_blend(GPU_BLEND_ALPHA); immUniformThemeColor(TH_ROW_ALTERNATE); - /* Alternating horizontal stripes. */ - int i = max_ii(1, ((int)v2d->cur.ymin) - 1); while (i < v2d->cur.ymax) { if (i & 1) { immRectf(pos, v2d->cur.xmin, i, v2d->cur.xmax, i + 1); @@ -2282,14 +2295,6 @@ static void draw_seq_timeline_channels(View2D *v2d) immUnbindProgram(); } -static void draw_seq_timeline_channel_numbers(ARegion *region) -{ - View2D *v2d = ®ion->v2d; - rcti rect; - BLI_rcti_init(&rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); - UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); -} - static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *region) { Scene *scene = CTX_data_scene(C); @@ -2713,7 +2718,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region) } UI_view2d_view_ortho(v2d); - draw_seq_timeline_channels(v2d); + draw_seq_backdrop(v2d); if ((sseq->flag & SEQ_SHOW_OVERLAY) && (sseq->timeline_overlay.flag & SEQ_TIMELINE_SHOW_GRID)) { U.v2d_min_gridsize *= 3; UI_view2d_draw_lines_x__discrete_frames_or_seconds( @@ -2771,7 +2776,13 @@ void draw_timeline_seq(const bContext *C, ARegion *region) UI_view2d_view_restore(C); ED_time_scrub_draw(region, scene, !(sseq->flag & SEQ_DRAWFRAMES), true); - draw_seq_timeline_channel_numbers(region); + /* Draw channel numbers. */ + { + rcti rect; + BLI_rcti_init( + &rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); + UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); + } } void draw_timeline_seq_display(const bContext *C, ARegion *region) diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc index ee623083db7..ede8756a9da 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc @@ -19,9 +19,8 @@ #include "MEM_guardedalloc.h" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index 7cc2d8d0b48..f4b5ff819ed 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -17,8 +17,7 @@ #include #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BKE_geometry_set.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc index 36c7f1057df..556c0b0d5ca 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc @@ -123,9 +123,7 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float2 cell) { - return float2::distance_squared(cell, value) > threshold_sq; - }, + [&](const float2 cell) { return math::distance_squared(cell, value) > threshold_sq; }, prev_mask, new_indices); break; @@ -155,9 +153,7 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float3 cell) { - return float3::distance_squared(cell, value) > threshold_sq; - }, + [&](const float3 cell) { return math::distance_squared(cell, value) > threshold_sq; }, prev_mask, new_indices); break; diff --git a/source/blender/editors/util/ed_draw.c b/source/blender/editors/util/ed_draw.c index 3e85862a847..ccbde07f5b1 100644 --- a/source/blender/editors/util/ed_draw.c +++ b/source/blender/editors/util/ed_draw.c @@ -599,9 +599,9 @@ static void metadata_custom_draw_fields(const char *field, const char *value, vo } MetadataCustomDrawContext *ctx = (MetadataCustomDrawContext *)ctx_v; char temp_str[MAX_METADATA_STR]; - SNPRINTF(temp_str, "%s: %s", field, value); + BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: %s", field, value); BLF_position(ctx->fontid, ctx->xmin, ctx->ymin + ctx->current_y, 0.0f); - BLF_draw(ctx->fontid, temp_str, sizeof(temp_str)); + BLF_draw(ctx->fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); ctx->current_y += ctx->vertical_offset; } @@ -625,18 +625,18 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const /* first line */ if (i == 0) { bool do_newline = false; - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[0]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]); if (metadata_is_valid(ibuf, temp_str, 0, len)) { BLF_position(fontid, xmin, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); do_newline = true; } - len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[1]); + len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]); if (metadata_is_valid(ibuf, temp_str, 1, len)) { - int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); + int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); BLF_position(fontid, xmax - line_width, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); do_newline = true; } @@ -645,32 +645,32 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const } } /* Strip */ else if (ELEM(i, 1, 2)) { - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); ofs_y += vertical_offset; } } /* Note (wrapped) */ else if (i == 3) { - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { struct ResultBLF info; BLF_enable(fontid, BLF_WORD_WRAP); BLF_wordwrap(fontid, ibuf->x - (margin * 2)); BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw_ex(fontid, temp_str, sizeof(temp_str), &info); + BLF_draw_ex(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX, &info); BLF_wordwrap(fontid, 0); BLF_disable(fontid, BLF_WORD_WRAP); ofs_y += vertical_offset * info.lines; } } else { - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { - int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); + int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); BLF_position(fontid, xmax - line_width, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); ofs_y += vertical_offset; } } @@ -687,12 +687,12 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const int ofs_x = 0; ofs_y = ctx.current_y; for (int i = 5; i < 10; i++) { - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); if (metadata_is_valid(ibuf, temp_str, i, len)) { BLF_position(fontid, xmin + ofs_x, ymin + ofs_y, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); - ofs_x += BLF_width(fontid, temp_str, sizeof(temp_str)) + UI_UNIT_X; + ofs_x += BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX) + UI_UNIT_X; } } } diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt index 47da6bc55f6..b7eaf018dba 100644 --- a/source/blender/freestyle/CMakeLists.txt +++ b/source/blender/freestyle/CMakeLists.txt @@ -594,7 +594,4 @@ if(WIN32) endif() blender_add_lib(bf_freestyle "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") - -if(COMMAND target_precompile_headers) - target_precompile_headers(bf_freestyle PRIVATE FRS_precomp.h) -endif() +blender_precompile_headers(bf_freestyle FRS_precomp.cpp FRS_precomp.h) diff --git a/source/blender/freestyle/FRS_precomp.cpp b/source/blender/freestyle/FRS_precomp.cpp new file mode 100644 index 00000000000..7e50a47f45b --- /dev/null +++ b/source/blender/freestyle/FRS_precomp.cpp @@ -0,0 +1,2 @@ +/* Pre-compiled headers, see: D2606. */ +#include "FRS_precomp.h" diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc index 058fb76af2b..0bbfbc8cb10 100644 --- a/source/blender/functions/intern/cpp_types.cc +++ b/source/blender/functions/intern/cpp_types.cc @@ -18,9 +18,8 @@ #include "FN_field_cpp_type.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" namespace blender::fn { diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 65d7631445d..c7481c6ea67 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -544,7 +544,7 @@ bool IMB_prepare_write_ImBuf(bool isfloat, struct ImBuf *ibuf); */ bool IMB_ispic(const char *filepath); bool IMB_ispic_type_matches(const char *filepath, int filetype); -int IMB_ispic_type_from_memory(const unsigned char *buf, size_t buf_size); +int IMB_ispic_type_from_memory(const unsigned char *buf, const size_t buf_size); int IMB_ispic_type(const char *filepath); /** @@ -972,20 +972,28 @@ void IMB_update_gpu_texture_sub(struct GPUTexture *tex, /** * \attention defined in stereoimbuf.c */ -void IMB_stereo3d_write_dimensions( - char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); -void IMB_stereo3d_read_dimensions( - char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); +void IMB_stereo3d_write_dimensions(char mode, + bool is_squeezed, + const size_t width, + const size_t height, + size_t *r_width, + size_t *r_height); +void IMB_stereo3d_read_dimensions(char mode, + bool is_squeezed, + const size_t width, + const size_t height, + size_t *r_width, + size_t *r_height); int *IMB_stereo3d_from_rect(struct ImageFormatData *im_format, - size_t x, - size_t y, - size_t channels, + const size_t x, + const size_t y, + const size_t channels, int *rect_left, int *rect_right); float *IMB_stereo3d_from_rectf(struct ImageFormatData *im_format, - size_t x, - size_t y, - size_t channels, + const size_t x, + const size_t y, + const size_t channels, float *rectf_left, float *rectf_right); /** diff --git a/source/blender/imbuf/IMB_metadata.h b/source/blender/imbuf/IMB_metadata.h index 50982d08c3e..652ce913ee5 100644 --- a/source/blender/imbuf/IMB_metadata.h +++ b/source/blender/imbuf/IMB_metadata.h @@ -58,7 +58,10 @@ void IMB_metadata_free(struct IDProperty *metadata); * \param len: length of value buffer allocated by user. * \return 1 (true) if metadata is present and value for the key found, 0 (false) otherwise. */ -bool IMB_metadata_get_field(struct IDProperty *metadata, const char *key, char *value, size_t len); +bool IMB_metadata_get_field(struct IDProperty *metadata, + const char *key, + char *value, + const size_t len); /** * Set user data in the metadata. diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h index bf6aef3ecd3..104458ffa7a 100644 --- a/source/blender/imbuf/intern/IMB_filetype.h +++ b/source/blender/imbuf/intern/IMB_filetype.h @@ -41,7 +41,7 @@ typedef struct ImFileType { * \note that this may only read in a small part of the files header, * see: #IMB_ispic_type for details. */ - bool (*is_a)(const unsigned char *buf, size_t size); + bool (*is_a)(const unsigned char *buf, const size_t size); /** Load an image from memory. */ struct ImBuf *(*load)(const unsigned char *mem, @@ -93,7 +93,7 @@ void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty); /** \name Format: PNG (#IMB_FTYPE_PNG) * \{ */ -bool imb_is_a_png(const unsigned char *mem, size_t size); +bool imb_is_a_png(const unsigned char *mem, const size_t size); struct ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, @@ -106,7 +106,7 @@ bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: TARGA (#IMB_FTYPE_TGA) * \{ */ -bool imb_is_a_targa(const unsigned char *buf, size_t size); +bool imb_is_a_targa(const unsigned char *buf, const size_t size); struct ImBuf *imb_loadtarga(const unsigned char *mem, size_t size, int flags, @@ -119,7 +119,7 @@ bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: IRIS (#IMB_FTYPE_IMAGIC) * \{ */ -bool imb_is_a_iris(const unsigned char *mem, size_t size); +bool imb_is_a_iris(const unsigned char *mem, const size_t size); /** * Read in a B/W RGB or RGBA iris image file and return an image buffer. */ @@ -135,7 +135,7 @@ bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JP2 (#IMB_FTYPE_JP2) * \{ */ -bool imb_is_a_jp2(const unsigned char *buf, size_t size); +bool imb_is_a_jp2(const unsigned char *buf, const size_t size); struct ImBuf *imb_load_jp2(const unsigned char *mem, size_t size, int flags, @@ -151,7 +151,7 @@ bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JPEG (#IMB_FTYPE_JPG) * \{ */ -bool imb_is_a_jpeg(const unsigned char *mem, size_t size); +bool imb_is_a_jpeg(const unsigned char *mem, const size_t size); bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags); struct ImBuf *imb_load_jpeg(const unsigned char *buffer, size_t size, @@ -164,7 +164,7 @@ struct ImBuf *imb_load_jpeg(const unsigned char *buffer, /** \name Format: BMP (#IMB_FTYPE_BMP) * \{ */ -bool imb_is_a_bmp(const unsigned char *buf, size_t size); +bool imb_is_a_bmp(const unsigned char *buf, const size_t size); struct ImBuf *imb_bmp_decode(const unsigned char *mem, size_t size, int flags, @@ -178,7 +178,7 @@ bool imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: CINEON (#IMB_FTYPE_CINEON) * \{ */ -bool imb_is_a_cineon(const unsigned char *buf, size_t size); +bool imb_is_a_cineon(const unsigned char *buf, const size_t size); bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_cineon(const unsigned char *mem, size_t size, @@ -191,7 +191,7 @@ struct ImBuf *imb_load_cineon(const unsigned char *mem, /** \name Format: DPX (#IMB_FTYPE_DPX) * \{ */ -bool imb_is_a_dpx(const unsigned char *buf, size_t size); +bool imb_is_a_dpx(const unsigned char *buf, const size_t size); bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_dpx(const unsigned char *mem, size_t size, @@ -204,7 +204,7 @@ struct ImBuf *imb_load_dpx(const unsigned char *mem, /** \name Format: HDR (#IMB_FTYPE_RADHDR) * \{ */ -bool imb_is_a_hdr(const unsigned char *buf, size_t size); +bool imb_is_a_hdr(const unsigned char *buf, const size_t size); struct ImBuf *imb_loadhdr(const unsigned char *mem, size_t size, int flags, @@ -218,7 +218,7 @@ bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags); * \{ */ void imb_inittiff(void); -bool imb_is_a_tiff(const unsigned char *buf, size_t size); +bool imb_is_a_tiff(const unsigned char *buf, const size_t size); /** * Loads a TIFF file. * \param mem: Memory containing the TIFF file. diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 6a05b681c88..1d81653c7cd 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -879,7 +879,7 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); # else - /* Scale with swscale. */ + /* Scale with swscale then flip image over Y axis. */ int *dstStride = anim->pFrameRGB->linesize; uint8_t **dst = anim->pFrameRGB->data; const int dstStride2[4] = {dstStride[0], 0, 0, 0}; @@ -896,12 +896,11 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); - /* Flip destination image buffer over Y axis. */ - bottom = (unsigned char *)dst[0]; - top = bottom + anim->x * (anim->y - 1) * 4; + bottom = (unsigned char *)ibuf->rect; + top = bottom + ibuf->x * (ibuf->y - 1) * 4; - h = (anim->y + 1) / 2; - w = anim->x; + h = (ibuf->y + 1) / 2; + w = ibuf->x; for (y = 0; y < h; y++) { unsigned char tmp[4]; diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index 2d540f13a52..931c4f267f9 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -26,7 +26,7 @@ extern "C" { #endif -bool imb_is_a_dds(const unsigned char *mem, size_t size); +bool imb_is_a_dds(const unsigned char *mem, const size_t size); bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_dds(const unsigned char *mem, size_t size, diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index 1201bd1b5e0..659050cdb00 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -31,7 +31,7 @@ extern "C" { struct ImBuf; -bool imb_is_a_photoshop(const unsigned char *mem, size_t size); +bool imb_is_a_photoshop(const unsigned char *mem, const size_t size); int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h index 4321c95db30..14336620926 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.h +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -36,7 +36,7 @@ void imb_exitopenexr(void); * Test presence of OpenEXR file. * \param mem: pointer to loaded OpenEXR bit-stream. */ -bool imb_is_a_openexr(const unsigned char *mem, size_t size); +bool imb_is_a_openexr(const unsigned char *mem, const size_t size); bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 925ef0a8502..7f4e4dd31df 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -77,7 +77,7 @@ static const unsigned char *oldreadcolrs(RGBE *scan, scan[0][BLU] = *mem++; scan[0][EXP] = *mem++; if (scan[0][RED] == 1 && scan[0][GRN] == 1 && scan[0][BLU] == 1) { - for (i = scan[0][EXP] << rshift; i > 0 && len > 0; i--) { + for (i = scan[0][EXP] << rshift; i > 0; i--) { COPY_RGBE(scan[-1], scan[0]); scan++; len--; @@ -227,7 +227,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, int found = 0; int width = 0, height = 0; const unsigned char *ptr, *mem_eof = mem + size; - char oriY[3], oriX[3]; + char oriY[80], oriX[80]; if (!imb_is_a_hdr(mem, size)) { return NULL; @@ -244,33 +244,22 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, } } - if ((found && (x < (size - 1))) == 0) { + if ((found && (x < (size + 2))) == 0) { /* Data not found! */ return NULL; } - x++; - - /* sscanf requires a null-terminated buffer argument */ - char buf[32] = {0}; - memcpy(buf, &mem[x], MIN2(sizeof(buf) - 1, size - x)); - - if (sscanf(buf, "%2s %d %2s %d", (char *)&oriY, &height, (char *)&oriX, &width) != 4) { - return NULL; - } - - if (width < 1 || height < 1) { + if (sscanf((const char *)&mem[x + 1], + "%79s %d %79s %d", + (char *)&oriY, + &height, + (char *)&oriX, + &width) != 4) { return NULL; } - /* Checking that width x height does not extend past mem_eof is not easily possible - * since the format uses RLE compression. Can cause excessive memory allocation to occur. */ - /* find end of this line, data right behind it */ - ptr = (const unsigned char *)strchr((const char *)&mem[x], '\n'); - if (ptr == NULL || ptr >= mem_eof) { - return NULL; - } + ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n'); ptr++; if (flags & IB_test) { diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc index 86fa580bf1f..4a359c49d26 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.cc +++ b/source/blender/io/alembic/intern/abc_reader_object.cc @@ -120,10 +120,29 @@ static Imath::M44d blend_matrices(const Imath::M44d &m0, const Imath::M44d &m1, * the matrices manually. */ - convert_matrix_datatype(m0, mat0); - convert_matrix_datatype(m1, mat1); + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + mat0[i][j] = static_cast(m0[i][j]); + } + } + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + mat1[i][j] = static_cast(m1[i][j]); + } + } + interp_m4_m4m4(ret, mat0, mat1, weight); - return convert_matrix_datatype(ret); + + Imath::M44d m; + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + m[i][j] = ret[i][j]; + } + } + + return m; } Imath::M44d get_matrix(const IXformSchema &schema, const float time) diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc index f031648d2ed..7868bade8c1 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc @@ -23,9 +23,8 @@ * \ingroup bgpencil */ -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_span.hh" @@ -283,7 +282,7 @@ float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, bGPDstroke *gps) const float2 screen_ex = gpencil_3D_point_to_2D(&pt->x); const float2 v1 = screen_co - screen_ex; - float radius = v1.length(); + float radius = math::length(v1); BKE_gpencil_free_stroke(gps_perimeter); return MAX2(radius, 1.0f); diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.hh b/source/blender/io/gpencil/intern/gpencil_io_base.hh index 09557cd7a4d..ae54d5056dc 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.hh +++ b/source/blender/io/gpencil/intern/gpencil_io_base.hh @@ -22,9 +22,8 @@ * \ingroup bgpencil */ -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "DNA_space_types.h" /* for FILE_MAX */ diff --git a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc index 941d1137f4d..455ebb7c3cb 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc @@ -21,8 +21,8 @@ * \ingroup bgpencil */ -#include "BLI_float3.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_gpencil_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh index 9a4dfe3efe3..e6d2853d040 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh @@ -22,7 +22,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utility_mixins.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index b99d41e0c72..5b710939e00 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -21,8 +21,8 @@ #include "BKE_image.h" #include "BKE_node.h" -#include "BLI_float3.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "DNA_material_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh index 2f62d189bd1..a84dcb80a48 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh @@ -20,8 +20,8 @@ #pragma once -#include "BLI_float3.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc index 91aabd8fa76..ec690115115 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc @@ -18,9 +18,9 @@ * \ingroup obj */ -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index f9151bb97f8..0feca806f35 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -236,7 +236,7 @@ TEST(obj_exporter_writer, mtllib) static bool strings_equal_after_first_lines(const std::string &a, const std::string &b) { /* If `dbg_level > 0` then a failing test will print context around the first mismatch. */ - const int dbg_level = 0; + const bool dbg_level = 0; const size_t a_len = a.size(); const size_t b_len = b.size(); const size_t a_next = a.find_first_of('\n'); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 1d0796bda8b..fc041e257b0 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1852,7 +1852,6 @@ enum { MOD_TRIANGULATE_QUAD_FIXED = 1, MOD_TRIANGULATE_QUAD_ALTERNATE = 2, MOD_TRIANGULATE_QUAD_SHORTEDGE = 3, - MOD_TRIANGULATE_QUAD_LONGEDGE = 4, }; typedef struct LaplacianSmoothModifierData { diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 114e350b582..29d61bcf2ff 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -2118,7 +2118,6 @@ typedef enum GeometryNodeTriangulateQuads { GEO_NODE_TRIANGULATE_QUAD_FIXED = 1, GEO_NODE_TRIANGULATE_QUAD_ALTERNATE = 2, GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE = 3, - GEO_NODE_TRIANGULATE_QUAD_LONGEDGE = 4, } GeometryNodeTriangulateQuads; typedef enum GeometryNodePointInstanceType { diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 07897231566..20f77626e49 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -1742,7 +1742,7 @@ bool RNA_struct_override_matches(struct Main *bmain, struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, const char *root_path, - size_t root_path_len, + const size_t root_path_len, struct IDOverrideLibrary *override, eRNAOverrideMatch flags, eRNAOverrideMatchResult *r_report_flags); diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 95ad184c6b9..20e6e931b4b 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -544,7 +544,7 @@ int rna_property_override_diff_default(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - size_t rna_path_len, + const size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 723ae384fdf..f0e32a19d04 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -214,7 +214,7 @@ typedef int (*RNAPropOverrideDiff)(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - size_t rna_path_len, + const size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 0f0734c8448..d46ae13b482 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -331,12 +331,7 @@ const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[] = { "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads along their shortest diagonal"}, - {MOD_TRIANGULATE_QUAD_LONGEDGE, - "LONGEST_DIAGONAL", - 0, - "Longest Diagonal", - "Split the quads along their longest diagonal"}, + "Split the quads based on the distance between the vertices"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index ecbeadf1fa4..e7307e6e058 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -9488,12 +9488,7 @@ static void def_geo_triangulate(StructRNA *srna) "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads along their shortest diagonal"}, - {GEO_NODE_TRIANGULATE_QUAD_LONGEDGE, - "LONGEST_DIAGONAL", - 0, - "Longest Diagonal", - "Split the quads along their longest diagonal"}, + "Split the quads based on the distance between the vertices"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc index 778b5746471..910b52dea67 100644 --- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc +++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc @@ -197,8 +197,8 @@ static float compute_voxel_size(const ModifierEvalContext *ctx, /* Compute the voxel size based on the desired number of voxels and the approximated bounding box * of the volume. */ const BoundBox *bb = BKE_object_boundbox_get(mvmd->object); - const float diagonal = float3::distance(transform * float3(bb->vec[6]), - transform * float3(bb->vec[0])); + const float diagonal = math::distance(transform * float3(bb->vec[6]), + transform * float3(bb->vec[0])); const float approximate_volume_side_length = diagonal + mvmd->exterior_band_width * 2.0f; const float voxel_size = approximate_volume_side_length / mvmd->voxel_amount / volume_simplify; return voxel_size; diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index cee5d0be65d..49528845197 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -28,8 +28,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_multi_value_map.hh" #include "BLI_set.hh" #include "BLI_string.h" diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh index a0a2e6f81f8..6ea89beee2e 100644 --- a/source/blender/nodes/NOD_math_functions.hh +++ b/source/blender/nodes/NOD_math_functions.hh @@ -18,9 +18,9 @@ #include "DNA_node_types.h" -#include "BLI_float3.hh" #include "BLI_math_base_safe.h" #include "BLI_math_rotation.h" +#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" namespace blender::nodes { @@ -240,6 +240,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -259,40 +261,21 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation case NODE_VECTOR_MATH_MULTIPLY: return dispatch([](float3 a, float3 b) { return a * b; }); case NODE_VECTOR_MATH_DIVIDE: - return dispatch([](float3 a, float3 b) { - return float3(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return safe_divide(a, b); }); case NODE_VECTOR_MATH_CROSS_PRODUCT: - return dispatch([](float3 a, float3 b) { return float3::cross_high_precision(a, b); }); + return dispatch([](float3 a, float3 b) { return cross_high_precision(a, b); }); case NODE_VECTOR_MATH_PROJECT: - return dispatch([](float3 a, float3 b) { - float length_squared = b.length_squared(); - return (length_squared != 0.0) ? (float3::dot(a, b) / length_squared) * b : float3(0.0f); - }); + return dispatch([](float3 a, float3 b) { return project(a, b); }); case NODE_VECTOR_MATH_REFLECT: - return dispatch([](float3 a, float3 b) { - b.normalize(); - return a.reflected(b); - }); + return dispatch([](float3 a, float3 b) { return reflect(a, normalize(b)); }); case NODE_VECTOR_MATH_SNAP: - return dispatch([](float3 a, float3 b) { - return float3(floor(safe_divide(a.x, b.x)), - floor(safe_divide(a.y, b.y)), - floor(safe_divide(a.z, b.z))) * - b; - }); + return dispatch([](float3 a, float3 b) { return floor(safe_divide(a, b)) * b; }); case NODE_VECTOR_MATH_MODULO: - return dispatch([](float3 a, float3 b) { - return float3(safe_modf(a.x, b.x), safe_modf(a.y, b.y), safe_modf(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return mod(a, b); }); case NODE_VECTOR_MATH_MINIMUM: - return dispatch([](float3 a, float3 b) { - return float3(min_ff(a.x, b.x), min_ff(a.y, b.y), min_ff(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return min(a, b); }); case NODE_VECTOR_MATH_MAXIMUM: - return dispatch([](float3 a, float3 b) { - return float3(max_ff(a.x, b.x), max_ff(a.y, b.y), max_ff(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return max(a, b); }); default: return false; } @@ -306,6 +289,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -319,9 +304,9 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation switch (operation) { case NODE_VECTOR_MATH_DOT_PRODUCT: - return dispatch([](float3 a, float3 b) { return float3::dot(a, b); }); + return dispatch([](float3 a, float3 b) { return dot(a, b); }); case NODE_VECTOR_MATH_DISTANCE: - return dispatch([](float3 a, float3 b) { return float3::distance(a, b); }); + return dispatch([](float3 a, float3 b) { return distance(a, b); }); default: return false; } @@ -335,6 +320,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -354,7 +341,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOpera return float3(wrapf(a.x, b.x, c.x), wrapf(a.y, b.y, c.y), wrapf(a.z, b.z, c.z)); }); case NODE_VECTOR_MATH_FACEFORWARD: - return dispatch([](float3 a, float3 b, float3 c) { return float3::faceforward(a, b, c); }); + return dispatch([](float3 a, float3 b, float3 c) { return faceforward(a, b, c); }); default: return false; } @@ -368,6 +355,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -381,8 +370,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperat switch (operation) { case NODE_VECTOR_MATH_REFRACT: - return dispatch( - [](float3 a, float3 b, float c) { return float3::refract(a, b.normalized(), c); }); + return dispatch([](float3 a, float3 b, float c) { return refract(a, normalize(b), c); }); default: return false; } @@ -396,6 +384,8 @@ template inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -409,7 +399,7 @@ inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation oper switch (operation) { case NODE_VECTOR_MATH_LENGTH: - return dispatch([](float3 in) { return in.length(); }); + return dispatch([](float3 in) { return length(in); }); default: return false; } @@ -450,6 +440,8 @@ template inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -463,20 +455,15 @@ inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation ope switch (operation) { case NODE_VECTOR_MATH_NORMALIZE: - return dispatch([](float3 in) { - float3 out = in; - out.normalize(); - return out; - }); /* Should be safe. */ + return dispatch([](float3 in) { return normalize(in); }); /* Should be safe. */ case NODE_VECTOR_MATH_FLOOR: - return dispatch([](float3 in) { return float3(floor(in.x), floor(in.y), floor(in.z)); }); + return dispatch([](float3 in) { return floor(in); }); case NODE_VECTOR_MATH_CEIL: - return dispatch([](float3 in) { return float3(ceil(in.x), ceil(in.y), ceil(in.z)); }); + return dispatch([](float3 in) { return ceil(in); }); case NODE_VECTOR_MATH_FRACTION: - return dispatch( - [](float3 in) { return in - float3(floor(in.x), floor(in.y), floor(in.z)); }); + return dispatch([](float3 in) { return fract(in); }); case NODE_VECTOR_MATH_ABSOLUTE: - return dispatch([](float3 in) { return float3::abs(in); }); + return dispatch([](float3 in) { return abs(in); }); case NODE_VECTOR_MATH_SINE: return dispatch([](float3 in) { return float3(sinf(in.x), sinf(in.y), sinf(in.z)); }); case NODE_VECTOR_MATH_COSINE: diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh index c0580a2c919..a1972c66ca2 100644 --- a/source/blender/nodes/NOD_socket_declarations.hh +++ b/source/blender/nodes/NOD_socket_declarations.hh @@ -21,7 +21,7 @@ #include "RNA_types.h" #include "BLI_color.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" namespace blender::nodes::decl { diff --git a/source/blender/nodes/composite/node_composite_tree.cc b/source/blender/nodes/composite/node_composite_tree.cc index c54382cc1ad..08dbd4ad6f0 100644 --- a/source/blender/nodes/composite/node_composite_tree.cc +++ b/source/blender/nodes/composite/node_composite_tree.cc @@ -249,6 +249,23 @@ void ntreeCompositUpdateRLayers(bNodeTree *ntree) } } +void ntreeCompositRegisterPass(bNodeTree *ntree, + Scene *scene, + ViewLayer *view_layer, + const char *name, + eNodeSocketDatatype type) +{ + if (ntree == nullptr) { + return; + } + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type == CMP_NODE_R_LAYERS) { + node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type); + } + } +} + void ntreeCompositTagRender(Scene *scene) { /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes, diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index f2b9fbc2215..6f4f9d7e597 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -269,12 +269,7 @@ void node_cmp_rlayers_register_pass(bNodeTree *ntree, } } -struct CreateOutputUserData { - bNodeTree &ntree; - bNode &node; -}; - -static void cmp_node_rlayer_create_outputs_cb(void *userdata, +static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), Scene *scene, ViewLayer *view_layer, const char *name, @@ -282,8 +277,18 @@ static void cmp_node_rlayer_create_outputs_cb(void *userdata, const char *UNUSED(chanid), eNodeSocketDatatype type) { - CreateOutputUserData &data = *(CreateOutputUserData *)userdata; - node_cmp_rlayers_register_pass(&data.ntree, &data.node, scene, view_layer, name, type); + /* Register the pass in all scenes that have a render layer node for this layer. + * Since multiple scenes can be used in the compositor, the code must loop over all scenes + * and check whether their nodetree has a node that needs to be updated. */ + /* NOTE: using G_MAIN seems valid here, + * unless we want to register that for every other temp Main we could generate??? */ + ntreeCompositRegisterPass(scene->nodetree, scene, view_layer, name, type); + + for (Scene *sce = (Scene *)G_MAIN->scenes.first; sce; sce = (Scene *)sce->id.next) { + if (sce->nodetree && sce != scene) { + ntreeCompositRegisterPass(sce->nodetree, scene, view_layer, name, type); + } + } } static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, @@ -303,17 +308,14 @@ static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, data->prev_index = -1; node->storage = data; - CreateOutputUserData userdata = {*ntree, *node}; - RenderEngine *engine = RE_engine_create(engine_type); RE_engine_update_render_passes( - engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, &userdata); + engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, nullptr); RE_engine_free(engine); if ((scene->r.mode & R_EDGE_FRS) && (view_layer->freestyle_config.flags & FREESTYLE_AS_RENDER_PASS)) { - node_cmp_rlayers_register_pass( - ntree, node, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); + ntreeCompositRegisterPass(ntree, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); } MEM_freeN(data); diff --git a/source/blender/nodes/function/node_function_util.hh b/source/blender/nodes/function/node_function_util.hh index acde9c4b55b..69c617b4f01 100644 --- a/source/blender/nodes/function/node_function_util.hh +++ b/source/blender/nodes/function/node_function_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc index f4ce8d2f35a..bcc035e6ede 100644 --- a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc +++ b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc @@ -69,14 +69,14 @@ static void align_rotations_auto_pivot(IndexMask mask, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = vector.normalized(); - float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); + const float3 new_axis = math::normalize(vector); + float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc index 3bb46511eeb..7c09bace756 100644 --- a/source/blender/nodes/function/nodes/node_fn_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_compare.cc @@ -265,7 +265,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Than - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) < comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) < comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -283,7 +283,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Than - Length", - [](float3 a, float3 b) { return a.length() < b.length(); }}; + [](float3 a, float3 b) { return math::length(a) < math::length(b); }}; return &fn; } } @@ -299,7 +299,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Equal - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) <= comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) <= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -317,7 +317,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Equal - Length", - [](float3 a, float3 b) { return a.length() <= b.length(); }}; + [](float3 a, float3 b) { return math::length(a) <= math::length(b); }}; return &fn; } } @@ -333,7 +333,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Than - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) > comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) > comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -351,7 +351,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Than - Length", - [](float3 a, float3 b) { return a.length() > b.length(); }}; + [](float3 a, float3 b) { return math::length(a) > math::length(b); }}; return &fn; } } @@ -367,7 +367,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Equal - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) >= comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) >= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -385,7 +385,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Equal - Length", - [](float3 a, float3 b) { return a.length() >= b.length(); }}; + [](float3 a, float3 b) { return math::length(a) >= math::length(b); }}; return &fn; } } @@ -402,7 +402,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(float3::dot(a, b) - comp) <= epsilon; + return abs(math::dot(a, b) - comp) <= epsilon; }}; return &fn; } @@ -424,7 +424,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(a.length() - b.length()) <= epsilon; + return abs(math::length(a) - math::length(b)) <= epsilon; }}; return &fn; } @@ -442,7 +442,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Not Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(float3::dot(a, b) - comp) >= epsilon; + return abs(math::dot(a, b) - comp) >= epsilon; }}; return &fn; } @@ -464,7 +464,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Not Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(a.length() - b.length()) > epsilon; + return abs(math::length(a) - math::length(b)) > epsilon; }}; return &fn; } diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh index 1c2a8f521c0..e063be62987 100644 --- a/source/blender/nodes/geometry/node_geometry_util.hh +++ b/source/blender/nodes/geometry/node_geometry_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" @@ -83,7 +83,7 @@ Mesh *create_cylinder_or_cone_mesh(float radius_top, int circle_segments, int side_segments, int fill_segments, - GeometryNodeMeshCircleFillType fill_type, + const GeometryNodeMeshCircleFillType fill_type, ConeAttributeOutputs &attribute_outputs); Mesh *create_cuboid_mesh(float3 size, int verts_x, int verts_y, int verts_z); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc index 36ad4605a4b..1d064586238 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc @@ -90,14 +90,14 @@ static void align_rotations_auto_pivot(const VArray &vectors, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = vector.normalized(); - float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); + const float3 new_axis = math::normalize(vector); + float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc index 74dac73f255..20f500b1bd8 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc @@ -81,7 +81,7 @@ static void calculate_mesh_proximity(const VArray &positions, for (int i : range) { /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = float3::distance_squared(nearest.co, positions[i]); + nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[i]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[i], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc index b0210f2eb94..a85a7c56cb9 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc @@ -229,7 +229,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = float3::distance_squared(position, mvert.co); + const float distance_sq = math::distance_squared(position, float3(mvert.co)); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc index 8555d7cc8a3..1e6b7f92a77 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc @@ -241,13 +241,13 @@ static void copy_uniform_sample_point_attributes(Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent.normalize(); + tangent = math::normalize(tangent); } spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals.normalize(); + normals = math::normalize(normals); } } }); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc index 29eff373d15..c712e82ca18 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc @@ -321,7 +321,7 @@ BLI_NOINLINE static void interpolate_existing_attributes( continue; } - for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { + for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { const int offset = instance_start_offsets[i_instance]; Span bary_coords = bary_coords_array[i_instance]; Span looptri_indices = looptri_indices_array[i_instance]; @@ -516,7 +516,7 @@ static void distribute_points_poisson_disk(Span set_group const VArray density_factors = component.attribute_get_for_read( density_attribute_name, ATTR_DOMAIN_CORNER, use_one_default ? 1.0f : 0.0f); - for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { + for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { Vector &positions = positions_all[i_instance]; Vector &bary_coords = bary_coords_all[i_instance]; Vector &looptri_indices = looptri_indices_all[i_instance]; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc index 7b1bbed8ae4..f54ffc53a6e 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc @@ -161,7 +161,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = float3::distance(min, max); + const float diagonal = math::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc index dd03092a594..cfae88e0625 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc @@ -107,7 +107,7 @@ static void raycast_to_mesh(const Mesh &mesh, for (const int i : ray_origins.index_range()) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = ray_directions[i].normalized(); + const float3 ray_direction = math::normalize(ray_directions[i]); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc index 7e09721273a..929d9046f98 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc @@ -16,7 +16,7 @@ #include "BLI_array.hh" #include "BLI_delaunay_2d.h" -#include "BLI_double2.hh" +#include "BLI_math_vec_types.hh" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc index 1a44fce86a6..68b609f8045 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc @@ -122,9 +122,9 @@ static Array calculate_directions(const Span positions) Array directions(size); for (const int i : IndexRange(size - 1)) { - directions[i] = (positions[i + 1] - positions[i]).normalized(); + directions[i] = math::normalize(positions[i + 1] - positions[i]); } - directions[size - 1] = (positions[0] - positions[size - 1]).normalized(); + directions[size - 1] = math::normalize(positions[0] - positions[size - 1]); return directions; } @@ -135,9 +135,9 @@ static Array calculate_axes(const Span directions) const int size = directions.size(); Array axes(size); - axes[0] = float3::cross(-directions[size - 1], directions[0]).normalized(); + axes[0] = math::normalize(math::cross(-directions[size - 1], directions[0])); for (const int i : IndexRange(1, size - 1)) { - axes[i] = float3::cross(-directions[i - 1], directions[i]).normalized(); + axes[i] = math::normalize(math::cross(-directions[i - 1], directions[i])); } return axes; @@ -248,8 +248,8 @@ static void limit_radii(FilletData &fd, const bool cyclic) if (cyclic) { /* Calculate lengths between adjacent control points. */ - const float len_prev = float3::distance(positions[0], positions[size - 1]); - const float len_next = float3::distance(positions[0], positions[1]); + const float len_prev = math::distance(positions[0], positions[size - 1]); + const float len_next = math::distance(positions[0], positions[1]); /* Calculate tangent lengths of fillets in control points. */ const float tan_len = radii[0] * tan(angles[0] / 2.0f); @@ -271,16 +271,16 @@ static void limit_radii(FilletData &fd, const bool cyclic) } /* Initialize max_radii to largest possible radii. */ - float prev_dist = float3::distance(positions[1], positions[0]); + float prev_dist = math::distance(positions[1], positions[0]); for (const int i : IndexRange(1, size - 2)) { - const float temp_dist = float3::distance(positions[i], positions[i + 1]); + const float temp_dist = math::distance(positions[i], positions[i + 1]); max_radii[i] = std::min(prev_dist, temp_dist) / tan(angles[i] / 2.0f); prev_dist = temp_dist; } /* Max radii calculations for each index. */ for (const int i : IndexRange(start, fillet_count - 1)) { - const float len_next = float3::distance(positions[i], positions[i + 1]); + const float len_next = math::distance(positions[i], positions[i + 1]); const float tan_len = radii[i] * tan(angles[i] / 2.0f); const float tan_len_next = radii[i + 1] * tan(angles[i + 1] / 2.0f); @@ -415,7 +415,8 @@ static void update_bezier_positions(const FilletData &fd, const float3 center = get_center(dst_spline.positions()[i_dst] - positions[i_src], fd, i_src); /* Calculate the vector of the radius formed by the first vertex. */ float3 radius_vec = dst_spline.positions()[i_dst] - center; - const float radius = radius_vec.normalize_and_get_length(); + float radius; + radius_vec = math::normalize_and_get_length(radius_vec, radius); dst_spline.handle_types_right().slice(1, count - 2).fill(BezierSpline::HandleType::Align); dst_spline.handle_types_left().slice(1, count - 2).fill(BezierSpline::HandleType::Align); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc index a7fb493c7d7..7b5d1a1dc80 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc @@ -101,8 +101,8 @@ static void node_update(bNodeTree *ntree, bNode *node) static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3) { - const float3 a = (p2 - p1).normalized(); - const float3 b = (p3 - p1).normalized(); + const float3 a = math::normalize(p2 - p1); + const float3 b = math::normalize(p3 - p1); return (ELEM(a, b, b * -1.0f)); } @@ -122,18 +122,18 @@ static std::unique_ptr create_point_circle_curve( float3 center; /* Midpoints of `P1->P2` and `P2->P3`. */ - const float3 q1 = float3::interpolate(p1, p2, 0.5f); - const float3 q2 = float3::interpolate(p2, p3, 0.5f); + const float3 q1 = math::interpolate(p1, p2, 0.5f); + const float3 q2 = math::interpolate(p2, p3, 0.5f); /* Normal Vectors of `P1->P2` and `P2->P3` */ - const float3 v1 = (p2 - p1).normalized(); - const float3 v2 = (p3 - p2).normalized(); + const float3 v1 = math::normalize(p2 - p1); + const float3 v2 = math::normalize(p3 - p2); /* Normal of plane of main 2 segments P1->P2 and `P2->P3`. */ - const float3 v3 = float3::cross(v1, v2).normalized(); + const float3 v3 = math::normalize(math::cross(v1, v2)); /* Normal of plane of first perpendicular bisector and `P1->P2`. */ - const float3 v4 = float3::cross(v3, v1).normalized(); + const float3 v4 = math::normalize(math::cross(v3, v1)); /* Determine Center-point from the intersection of 3 planes. */ float plane_1[4], plane_2[4], plane_3[4]; @@ -148,7 +148,7 @@ static std::unique_ptr create_point_circle_curve( } /* Get the radius from the center-point to p1. */ - const float r = float3::distance(p1, center); + const float r = math::distance(p1, center); const float theta_step = ((2 * M_PI) / (float)resolution); for (const int i : IndexRange(resolution)) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc index ff9218b1ac2..d35fa0a2fdc 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc @@ -100,7 +100,7 @@ static std::unique_ptr create_direction_line_curve(const float3 start spline->resize(2); MutableSpan positions = spline->positions(); positions[0] = start; - positions[1] = direction.normalized() * length + start; + positions[1] = math::normalize(direction) * length + start; spline->radii().fill(1.0f); spline->tilts().fill(0.0f); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc index 084d27e9d24..885d92a111b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc @@ -58,9 +58,9 @@ static std::unique_ptr create_quadratic_bezier_curve(const float3 p1, const float step = 1.0f / resolution; for (const int i : IndexRange(resolution + 1)) { const float factor = step * i; - const float3 q1 = float3::interpolate(p1, p2, factor); - const float3 q2 = float3::interpolate(p2, p3, factor); - positions[i] = float3::interpolate(q1, q2, factor); + const float3 q1 = math::interpolate(p1, p2, factor); + const float3 q2 = math::interpolate(p2, p3, factor); + positions[i] = math::interpolate(q1, q2, factor); } curve->add_spline(std::move(spline)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc index 038f7625825..56fbc50f033 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc @@ -185,7 +185,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_tangents = splines[spline_indices[i]]->evaluated_tangents(); - sampled_tangents[i] = sample_with_lookup(lookup, evaluated_tangents).normalized(); + sampled_tangents[i] = math::normalize(sample_with_lookup(lookup, evaluated_tangents)); } } @@ -193,7 +193,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_normals = splines[spline_indices[i]]->evaluated_normals(); - sampled_normals[i] = sample_with_lookup(lookup, evaluated_normals).normalized(); + sampled_normals[i] = math::normalize(sample_with_lookup(lookup, evaluated_normals)); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc index 40dde645756..257a5b8df00 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc @@ -96,7 +96,7 @@ static void calculate_nurbs_lengths(const NURBSpline &spline, MutableSpan float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { lengths[i] = length; - length += float3::distance(positions[i], positions[i + 1]); + length += math::distance(positions[i], positions[i + 1]); } lengths.last() = length; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc index a8553b636a4..19efd4b7508 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc @@ -285,7 +285,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent.normalize(); + tangent = math::normalize(tangent); } } @@ -293,7 +293,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals.normalize(); + normals = math::normalize(normals); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc index 28a8fb80294..624a8b6b0f6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc @@ -21,7 +21,7 @@ #include "BKE_image.h" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_threads.h" #include "BLI_timeit.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc index 5b67258a947..e90a9eb393b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc @@ -155,7 +155,7 @@ static void calculate_polys(const CuboidConfig &config, /* Calculate polys for Bottom faces. */ int vert_1_start = 0; - for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { + for (const int UNUSED(y) : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { const int vert_1 = vert_1_start + x; const int vert_2 = vert_1_start + config.verts_x + x; @@ -173,7 +173,7 @@ static void calculate_polys(const CuboidConfig &config, vert_1_start = 0; int vert_2_start = config.verts_x * config.verts_y; - for ([[maybe_unused]] const int z : IndexRange(config.edges_z)) { + for (const int UNUSED(z) : IndexRange(config.edges_z)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, @@ -196,7 +196,7 @@ static void calculate_polys(const CuboidConfig &config, (config.verts_x - 2) * (config.verts_y - 2)); vert_2_start = vert_1_start + config.verts_x; - for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { + for (const int UNUSED(y) : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc index 5116e78fdda..8a2b054ece0 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc @@ -155,8 +155,8 @@ static void node_geo_exec(GeoNodeExecParams params) if (count_mode == GEO_NODE_MESH_LINE_COUNT_RESOLUTION) { /* Don't allow asymptotic count increase for low resolution values. */ const float resolution = std::max(params.extract_input("Resolution"), 0.0001f); - const int count = total_delta.length() / resolution + 1; - const float3 delta = total_delta.normalized() * resolution; + const int count = math::length(total_delta) / resolution + 1; + const float3 delta = math::normalize(total_delta) * resolution; mesh = create_line_mesh(start, delta, count); } else if (count_mode == GEO_NODE_MESH_LINE_COUNT_TOTAL) { @@ -204,7 +204,7 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count) MutableSpan edges{mesh->medge, mesh->totedge}; short normal[3]; - normal_float_to_short_v3(normal, delta.normalized()); + normal_float_to_short_v3(normal, math::normalize(delta)); for (const int i : verts.index_range()) { copy_v3_v3(verts[i].co, start + delta * i); diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc index 41178d5c4e6..373e6bfdd18 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc @@ -178,7 +178,7 @@ static void calculate_sphere_faces(MutableSpan loops, int ring_vert_index_start = 1; int ring_edge_index_start = segments; - for ([[maybe_unused]] const int ring : IndexRange(1, rings - 2)) { + for (const int UNUSED(ring) : IndexRange(1, rings - 2)) { const int next_ring_vert_index_start = ring_vert_index_start + segments; const int next_ring_edge_index_start = ring_edge_index_start + segments * 2; const int ring_vertical_edge_index_start = ring_edge_index_start + segments; diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc index dda4543d5e1..c165bcf8e35 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc @@ -166,7 +166,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = float3::distance(min, max); + const float diagonal = math::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc index e0117c4726d..772638ef240 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc @@ -85,7 +85,7 @@ static bool calculate_mesh_proximity(const VArray &positions, for (int i : range) { const int index = mask[i]; /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = float3::distance_squared(nearest.co, positions[index]); + nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[index]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[index], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc index 2c35ca0afc9..c38503f688c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc @@ -163,7 +163,7 @@ static void raycast_to_mesh(IndexMask mask, for (const int i : mask) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = ray_directions[i].normalized(); + const float3 ray_direction = math::normalize(ray_directions[i]); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc index 82d09bbc208..feab0a6743f 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc @@ -106,7 +106,7 @@ static void set_position_in_component(const GeometryNodeCurveHandleMode mode, } } else { - for ([[maybe_unused]] int i : spline->positions().index_range()) { + for (int UNUSED(i) : spline->positions().index_range()) { if (current_mask < selection.size() && selection[current_mask] == current_point) { current_mask++; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc index 331460296a6..6867051ecfe 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc @@ -296,7 +296,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = float3::distance_squared(position, mvert.co); + const float distance_sq = math::distance_squared(position, float3(mvert.co)); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc index 7f866ea6f4a..6187a2eacf9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc @@ -37,7 +37,7 @@ namespace blender::nodes { static bool use_translate(const float3 rotation, const float3 scale) { - if (compare_ff(rotation.length_squared(), 0.0f, 1e-9f) != 1) { + if (compare_ff(math::length_squared(rotation), 0.0f, 1e-9f) != 1) { return false; } if (compare_ff(scale.x, 1.0f, 1e-9f) != 1 || compare_ff(scale.y, 1.0f, 1e-9f) != 1 || @@ -49,7 +49,7 @@ static bool use_translate(const float3 rotation, const float3 scale) static void translate_mesh(Mesh &mesh, const float3 translation) { - if (!translation.is_zero()) { + if (!math::is_zero(translation)) { BKE_mesh_translate(&mesh, translation, false); } } diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc index 6a6b6e3d3cc..ed72580ccf1 100644 --- a/source/blender/nodes/intern/node_socket.cc +++ b/source/blender/nodes/intern/node_socket.cc @@ -26,8 +26,8 @@ #include "DNA_node_types.h" #include "BLI_color.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/node_shader_util.hh b/source/blender/nodes/shader/node_shader_util.hh index 9d4d57d01dd..5a5b4f613f3 100644 --- a/source/blender/nodes/shader/node_shader_util.hh +++ b/source/blender/nodes/shader/node_shader_util.hh @@ -29,9 +29,9 @@ #include "BLI_blenlib.h" #include "BLI_color.hh" -#include "BLI_float3.hh" #include "BLI_math.h" #include "BLI_math_base_safe.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_threads.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc index 3276a1bfd72..bc7ca661a77 100644 --- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc +++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc @@ -272,7 +272,7 @@ class MapRangeVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -315,8 +315,8 @@ class MapRangeSteppedVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(6, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); - factor = float3::safe_divide(float3::floor(factor * (steps[i] + 1.0f)), steps[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + factor = math::safe_divide(math::floor(factor * (steps[i] + 1.0f)), steps[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -355,7 +355,7 @@ class MapRangeSmoothstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = (float3(3.0f) - 2.0f * factor) * (factor * factor); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; @@ -390,7 +390,7 @@ class MapRangeSmootherstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc index 61b1613c11a..81a69ef18da 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc @@ -19,8 +19,7 @@ #include "node_shader_util.hh" -#include "BLI_float2.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc index 85e0f262ca7..53be5bc09d9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc @@ -130,7 +130,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - const float r = std::max(0.999999f - vector[i].length(), 0.0f); + const float r = std::max(0.999999f - math::length(vector[i]), 0.0f); fac[i] = r * r; } break; @@ -140,7 +140,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - fac[i] = std::max(0.999999f - vector[i].length(), 0.0f); + fac[i] = std::max(0.999999f - math::length(vector[i]), 0.0f); } break; } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc index 0e549859a39..1c703313edf 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc @@ -176,14 +176,14 @@ class NoiseFunction : public fn::MultiFunction { const VArray &vector = params.readonly_single_input(0, "Vector"); if (compute_factor) { for (int64_t i : mask) { - const float2 position = vector[i] * scale[i]; + const float2 position = float2(vector[i] * scale[i]); r_factor[i] = noise::perlin_fractal_distorted( position, detail[i], roughness[i], distortion[i]); } } if (compute_color) { for (int64_t i : mask) { - const float2 position = vector[i] * scale[i]; + const float2 position = float2(vector[i] * scale[i]); const float3 c = noise::perlin_float3_fractal_distorted( position, detail[i], roughness[i], distortion[i]); r_color[i] = ColorGeometry4f(c[0], c[1], c[2], 1.0f); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc index 2b5c1ddfe21..209f96449cd 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc @@ -313,7 +313,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -345,7 +345,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -380,7 +380,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -416,7 +416,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -446,7 +446,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -479,7 +479,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -519,7 +519,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -560,7 +560,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -604,7 +604,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -837,7 +837,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -868,7 +868,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -902,7 +902,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -937,7 +937,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -966,7 +966,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -999,7 +999,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } } @@ -1040,7 +1040,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1080,7 +1080,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1123,7 +1123,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index f08665d75e7..604792389fa 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -57,20 +57,20 @@ void PyC_Err_PrintWithFunc(PyObject *py_func); void PyC_FileAndNum(const char **r_filename, int *r_lineno); void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno); /* checks python is running */ int PyC_AsArray_FAST(void *array, - size_t array_item_size, + const size_t array_item_size, PyObject *value_fast, - Py_ssize_t length, + const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray(void *array, - size_t array_item_size, + const size_t array_item_size, PyObject *value, - Py_ssize_t length, + const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray_Multi_FAST(void *array, - size_t array_item_size, + const size_t array_item_size, PyObject *value_fast, const int *dims, int dims_len, @@ -78,7 +78,7 @@ int PyC_AsArray_Multi_FAST(void *array, const char *error_prefix); int PyC_AsArray_Multi(void *array, - size_t array_item_size, + const size_t array_item_size, PyObject *value, const int *dims, int dims_len, diff --git a/source/blender/render/RE_bake.h b/source/blender/render/RE_bake.h index b7ce3da71ff..43d3b5b323c 100644 --- a/source/blender/render/RE_bake.h +++ b/source/blender/render/RE_bake.h @@ -96,7 +96,7 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, BakePixel pixel_array_to[], BakeHighPolyData highpoly[], int tot_highpoly, - size_t num_pixels, + const size_t num_pixels, bool is_custom_cage, float cage_extrusion, float max_ray_distance, @@ -106,16 +106,16 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, void RE_bake_pixels_populate(struct Mesh *me, struct BakePixel *pixel_array, - size_t num_pixels, + const size_t num_pixels, const struct BakeTargets *targets, const char *uv_layer); -void RE_bake_mask_fill(const BakePixel pixel_array[], size_t num_pixels, char *mask); +void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask); void RE_bake_margin(struct ImBuf *ibuf, char *mask, int margin); void RE_bake_normal_world_to_object(const BakePixel pixel_array[], - size_t num_pixels, + const size_t num_pixels, int depth, float result[], struct Object *ob, @@ -125,14 +125,14 @@ void RE_bake_normal_world_to_object(const BakePixel pixel_array[], * to a tangent space normal map for a given low poly mesh. */ void RE_bake_normal_world_to_tangent(const BakePixel pixel_array[], - size_t num_pixels, + const size_t num_pixels, int depth, float result[], struct Mesh *me, const eBakeNormalSwizzle normal_swizzle[3], float mat[4][4]); void RE_bake_normal_world_to_world(const BakePixel pixel_array[], - size_t num_pixels, + const size_t num_pixels, int depth, float result[], const eBakeNormalSwizzle normal_swizzle[3]); diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index a35e83a8632..8776bc63cf0 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -3344,12 +3344,12 @@ static ImBuf *do_text_effect(const SeqRenderData *context, fonty = line_height; BLF_position(font, x + max_ii(fontx / 55, 1), y - max_ii(fonty / 30, 1), 0.0f); BLF_buffer_col(font, data->shadow_color); - BLF_draw_buffer(font, data->text, sizeof(data->text)); + BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); } BLF_position(font, x, y, 0.0f); BLF_buffer_col(font, data->color); - BLF_draw_buffer(font, data->text, sizeof(data->text)); + BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); BLF_buffer(font, NULL, NULL, 0, 0, 0, NULL); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 2e305c0bf3c..9a8a6a3a3ac 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -607,7 +607,7 @@ int WM_operator_confirm_message_ex(struct bContext *C, const char *title, int icon, const char *message, - wmOperatorCallContext opcontext); + const wmOperatorCallContext opcontext); int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message); /* Operator API. */ diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 344f4959a93..99bab3ae23d 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -193,6 +193,7 @@ bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWind static void wm_window_match_init(bContext *C, ListBase *wmlist) { *wmlist = G_MAIN->wm; + BLI_listbase_clear(&G_MAIN->wm); wmWindow *active_win = CTX_wm_window(C); @@ -219,8 +220,6 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist) } } - BLI_listbase_clear(&G_MAIN->wm); - /* reset active window */ CTX_wm_window_set(C, active_win); -- cgit v1.2.3 From b2ccd8546c7249a5ce279210d45ddbb5e90cd10d Mon Sep 17 00:00:00 2001 From: Nathan Rozendaal Date: Wed, 12 Jan 2022 12:16:41 +0100 Subject: Compositor: Add Scene Time Node, Rename Time node Fixes issue T94603 It adds a new compositor node called Scene Time which is already present as a geo node, having the same basic nodes available in all node trees is a nice thing to have. Renames "Time" node to "Time Curve", this is done to avoid confusion between the Time node and the Scene Time node. Reviewed By: jbakker Maniphest Tasks: T94603 Differential Revision: https://developer.blender.org/D13762 --- source/blender/blenkernel/BKE_node.h | 1 + source/blender/blenkernel/intern/node.cc | 1 + source/blender/compositor/CMakeLists.txt | 2 + source/blender/compositor/intern/COM_Converter.cc | 4 ++ .../blender/compositor/nodes/COM_SceneTimeNode.cc | 50 ++++++++++++++++++++++ .../blender/compositor/nodes/COM_SceneTimeNode.h | 36 ++++++++++++++++ source/blender/makesrna/RNA_access.h | 1 + source/blender/nodes/NOD_composite.h | 1 + source/blender/nodes/NOD_static_types.h | 3 +- source/blender/nodes/composite/CMakeLists.txt | 1 + .../nodes/composite/nodes/node_composite_curves.cc | 2 +- .../composite/nodes/node_composite_scene_time.cc | 39 +++++++++++++++++ 12 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 source/blender/compositor/nodes/COM_SceneTimeNode.cc create mode 100644 source/blender/compositor/nodes/COM_SceneTimeNode.h create mode 100644 source/blender/nodes/composite/nodes/node_composite_scene_time.cc (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 71d1728a870..5f8222e33d4 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1313,6 +1313,7 @@ void ntreeGPUMaterialNodes(struct bNodeTree *localtree, #define CMP_NODE_CRYPTOMATTE 326 #define CMP_NODE_POSTERIZE 327 #define CMP_NODE_CONVERT_COLOR_SPACE 328 +#define CMP_NODE_SCENE_TIME 329 /* channel toggles */ #define CMP_CHAN_RGB 1 diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 1cb3fd6153c..8c6bdb13708 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -4447,6 +4447,7 @@ static void registerCompositNodes() register_node_type_cmp_value(); register_node_type_cmp_rgb(); register_node_type_cmp_curve_time(); + register_node_type_cmp_scene_time(); register_node_type_cmp_movieclip(); register_node_type_cmp_composite(); diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index f59fd885871..96dc17c2d1a 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -147,6 +147,8 @@ set(SRC nodes/COM_TimeNode.h nodes/COM_ValueNode.cc nodes/COM_ValueNode.h + nodes/COM_SceneTimeNode.cc + nodes/COM_SceneTimeNode.h # output nodes nodes/COM_CompositorNode.cc diff --git a/source/blender/compositor/intern/COM_Converter.cc b/source/blender/compositor/intern/COM_Converter.cc index 1b98a04cf96..6cf6c698a2f 100644 --- a/source/blender/compositor/intern/COM_Converter.cc +++ b/source/blender/compositor/intern/COM_Converter.cc @@ -94,6 +94,7 @@ #include "COM_RotateNode.h" #include "COM_ScaleNode.h" #include "COM_ScaleOperation.h" +#include "COM_SceneTimeNode.h" #include "COM_SeparateColorNode.h" #include "COM_SetAlphaNode.h" #include "COM_SetValueOperation.h" @@ -360,6 +361,9 @@ Node *COM_convert_bnode(bNode *b_node) case CMP_NODE_TRANSFORM: node = new TransformNode(b_node); break; + case CMP_NODE_SCENE_TIME: + node = new SceneTimeNode(b_node); + break; case CMP_NODE_STABILIZE2D: node = new Stabilize2dNode(b_node); break; diff --git a/source/blender/compositor/nodes/COM_SceneTimeNode.cc b/source/blender/compositor/nodes/COM_SceneTimeNode.cc new file mode 100644 index 00000000000..f495db5ed4c --- /dev/null +++ b/source/blender/compositor/nodes/COM_SceneTimeNode.cc @@ -0,0 +1,50 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#include "COM_SceneTimeNode.h" + +#include "COM_SetValueOperation.h" + +namespace blender::compositor { + +SceneTimeNode::SceneTimeNode(bNode *editor_node) : Node(editor_node) +{ + /* pass */ +} + +void SceneTimeNode::convert_to_operations(NodeConverter &converter, + const CompositorContext &context) const +{ + SetValueOperation *SecondOperation = new SetValueOperation(); + SetValueOperation *frameOperation = new SetValueOperation(); + + const int frameNumber = context.get_framenumber(); + const Scene* scene = context.get_scene(); + const double frameRate = (((double)scene->r.frs_sec) / (double)scene->r.frs_sec_base); + + SecondOperation->set_value(float(frameNumber / frameRate)); + converter.add_operation(SecondOperation); + + frameOperation->set_value(frameNumber); + converter.add_operation(frameOperation); + + converter.map_output_socket(get_output_socket(0), SecondOperation->get_output_socket()); + converter.map_output_socket(get_output_socket(1), frameOperation->get_output_socket()); +} + +} // namespace blender::compositor diff --git a/source/blender/compositor/nodes/COM_SceneTimeNode.h b/source/blender/compositor/nodes/COM_SceneTimeNode.h new file mode 100644 index 00000000000..62c502d26d2 --- /dev/null +++ b/source/blender/compositor/nodes/COM_SceneTimeNode.h @@ -0,0 +1,36 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#pragma once + +#include "COM_Node.h" + +namespace blender::compositor { + +/** + * \brief SceneTimeNode + * \ingroup Node + */ +class SceneTimeNode : public Node { + public: + SceneTimeNode(bNode *editor_node); + void convert_to_operations(NodeConverter &converter, + const CompositorContext &context) const override; +}; + +} // namespace blender::compositor diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 20f77626e49..77c0db81b37 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -185,6 +185,7 @@ extern StructRNA RNA_CompositorNodeRGBToBW; extern StructRNA RNA_CompositorNodeRLayers; extern StructRNA RNA_CompositorNodeRotate; extern StructRNA RNA_CompositorNodeScale; +extern StructRNA RNA_CompositorNodeSceneTime; extern StructRNA RNA_CompositorNodeSepHSVA; extern StructRNA RNA_CompositorNodeSepRGBA; extern StructRNA RNA_CompositorNodeSepYCCA; diff --git a/source/blender/nodes/NOD_composite.h b/source/blender/nodes/NOD_composite.h index 72539f6081e..c80d0bcdd1e 100644 --- a/source/blender/nodes/NOD_composite.h +++ b/source/blender/nodes/NOD_composite.h @@ -43,6 +43,7 @@ void register_node_type_cmp_texture(void); void register_node_type_cmp_value(void); void register_node_type_cmp_rgb(void); void register_node_type_cmp_curve_time(void); +void register_node_type_cmp_scene_time(void); void register_node_type_cmp_movieclip(void); void register_node_type_cmp_composite(void); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index 07a29677b72..e3566f81e2d 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -148,7 +148,7 @@ DefNode(CompositorNode, CMP_NODE_BLUR, def_cmp_blur, "BLUR", DefNode(CompositorNode, CMP_NODE_FILTER, def_cmp_filter, "FILTER", Filter, "Filter", "" ) DefNode(CompositorNode, CMP_NODE_MAP_VALUE, def_cmp_map_value, "MAP_VALUE", MapValue, "Map Value", "" ) DefNode(CompositorNode, CMP_NODE_MAP_RANGE, def_cmp_map_range, "MAP_RANGE", MapRange, "Map Range", "" ) -DefNode(CompositorNode, CMP_NODE_TIME, def_time, "TIME", Time, "Time", "" ) +DefNode(CompositorNode, CMP_NODE_TIME, def_time, "TIME", Time, "Time Curve", "" ) DefNode(CompositorNode, CMP_NODE_VECBLUR, def_cmp_vector_blur, "VECBLUR", VecBlur, "Vector Blur", "" ) DefNode(CompositorNode, CMP_NODE_SEPRGBA, 0, "SEPRGBA", SepRGBA, "Separate RGBA", "" ) DefNode(CompositorNode, CMP_NODE_SEPHSVA, 0, "SEPHSVA", SepHSVA, "Separate HSVA", "" ) @@ -228,6 +228,7 @@ DefNode(CompositorNode, CMP_NODE_EXPOSURE, 0, "EXPOSU DefNode(CompositorNode, CMP_NODE_ANTIALIASING, def_cmp_antialiasing, "ANTIALIASING", AntiAliasing, "Anti-Aliasing", "" ) DefNode(CompositorNode, CMP_NODE_POSTERIZE, 0, "POSTERIZE", Posterize, "Posterize", "" ) DefNode(CompositorNode, CMP_NODE_CONVERT_COLOR_SPACE,def_cmp_convert_color_space, "CONVERT_COLORSPACE", ConvertColorSpace, "Color Space","" ) +DefNode(CompositorNode, CMP_NODE_SCENE_TIME, 0, "SCENE_TIME", SceneTime, "Scene Time", "" ) DefNode(TextureNode, TEX_NODE_OUTPUT, def_tex_output, "OUTPUT", Output, "Output", "" ) DefNode(TextureNode, TEX_NODE_CHECKER, 0, "CHECKER", Checker, "Checker", "" ) diff --git a/source/blender/nodes/composite/CMakeLists.txt b/source/blender/nodes/composite/CMakeLists.txt index 086c820ce1e..c2d9c8a71bb 100644 --- a/source/blender/nodes/composite/CMakeLists.txt +++ b/source/blender/nodes/composite/CMakeLists.txt @@ -122,6 +122,7 @@ set(SRC nodes/node_composite_vec_blur.cc nodes/node_composite_viewer.cc nodes/node_composite_zcombine.cc + nodes/node_composite_scene_time.cc node_composite_tree.cc node_composite_util.cc diff --git a/source/blender/nodes/composite/nodes/node_composite_curves.cc b/source/blender/nodes/composite/nodes/node_composite_curves.cc index cb96fd0bb60..12390a8549d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_curves.cc +++ b/source/blender/nodes/composite/nodes/node_composite_curves.cc @@ -51,7 +51,7 @@ void register_node_type_cmp_curve_time() static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_TIME, "Time", NODE_CLASS_INPUT); + cmp_node_type_base(&ntype, CMP_NODE_TIME, "Time Curve", NODE_CLASS_INPUT); ntype.declare = file_ns::cmp_node_time_declare; node_type_size(&ntype, 200, 140, 320); node_type_init(&ntype, file_ns::node_composit_init_curves_time); diff --git a/source/blender/nodes/composite/nodes/node_composite_scene_time.cc b/source/blender/nodes/composite/nodes/node_composite_scene_time.cc new file mode 100644 index 00000000000..845390665f2 --- /dev/null +++ b/source/blender/nodes/composite/nodes/node_composite_scene_time.cc @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +/** \file + * \ingroup cmpnodes + */ + +#include "node_composite_util.hh" + +namespace blender::nodes { + +static void cmp_node_scene_time_declare(NodeDeclarationBuilder &b) +{ + b.add_output(N_("Seconds")); + b.add_output(N_("Frame")); +} + +} // namespace blender::nodes + +void register_node_type_cmp_scene_time() +{ + static bNodeType ntype; + + cmp_node_type_base(&ntype, CMP_NODE_SCENE_TIME, "Scene Time", NODE_CLASS_INPUT); + ntype.declare = blender::nodes::cmp_node_scene_time_declare; + nodeRegisterType(&ntype); +} \ No newline at end of file -- cgit v1.2.3 From e5766752d04794c2693dedad75baeb8c7d68f4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 12 Jan 2022 12:43:40 +0100 Subject: Revert "BLI: Refactor vector types & functions to use templates" Reverted because the commit removes a lot of commits. This reverts commit a2c1c368af48644fa8995ecbe7138cc0d7900c30. --- source/blender/blenfont/BLF_api.h | 2 +- source/blender/blenfont/intern/blf_internal.h | 4 +- source/blender/blenkernel/BKE_appdir.h | 2 +- source/blender/blenkernel/BKE_attribute.h | 2 +- source/blender/blenkernel/BKE_attribute_access.hh | 3 +- source/blender/blenkernel/BKE_attribute_math.hh | 7 +- source/blender/blenkernel/BKE_bvhutils.h | 18 +- source/blender/blenkernel/BKE_customdata.h | 4 +- source/blender/blenkernel/BKE_geometry_set.hh | 2 +- source/blender/blenkernel/BKE_image.h | 2 +- source/blender/blenkernel/BKE_mesh_sample.hh | 2 +- source/blender/blenkernel/BKE_node.h | 8 +- source/blender/blenkernel/BKE_scene.h | 7 +- source/blender/blenkernel/BKE_spline.hh | 2 +- source/blender/blenkernel/BKE_vfont.h | 2 +- source/blender/blenkernel/BKE_volume.h | 2 +- source/blender/blenkernel/intern/DerivedMesh.cc | 2 +- .../blender/blenkernel/intern/attribute_access.cc | 2 +- .../blenkernel/intern/data_transfer_intern.h | 6 +- .../blenkernel/intern/geometry_component_mesh.cc | 5 +- source/blender/blenkernel/intern/gpencil_geom.cc | 2 +- source/blender/blenkernel/intern/hair.cc | 2 +- source/blender/blenkernel/intern/image.c | 26 +- source/blender/blenkernel/intern/mesh.cc | 10 +- .../blenkernel/intern/mesh_boolean_convert.cc | 2 +- .../blender/blenkernel/intern/mesh_remesh_voxel.cc | 2 +- source/blender/blenkernel/intern/object_dupli.cc | 8 +- source/blender/blenkernel/intern/pointcloud.cc | 24 +- source/blender/blenkernel/intern/simulation.cc | 2 +- source/blender/blenkernel/intern/spline_base.cc | 41 +- source/blender/blenkernel/intern/spline_bezier.cc | 37 +- source/blender/blenkernel/intern/tracking_test.cc | 2 +- .../blender/blenkernel/intern/type_conversions.cc | 3 +- source/blender/blenkernel/intern/volume.cc | 2 +- source/blender/blenkernel/intern/volume_render.cc | 2 +- source/blender/blenkernel/intern/volume_to_mesh.cc | 2 +- source/blender/blenlib/BLI_array_store.h | 2 +- source/blender/blenlib/BLI_array_utils.h | 4 +- source/blender/blenlib/BLI_buffer.h | 4 +- source/blender/blenlib/BLI_delaunay_2d.h | 4 +- source/blender/blenlib/BLI_double2.hh | 143 ++++++ source/blender/blenlib/BLI_double3.hh | 246 +++++++++ source/blender/blenlib/BLI_fileops.h | 3 +- source/blender/blenlib/BLI_float2.hh | 218 ++++++++ source/blender/blenlib/BLI_float3.hh | 320 ++++++++++++ source/blender/blenlib/BLI_float4.hh | 138 +++++ source/blender/blenlib/BLI_float4x4.hh | 5 +- source/blender/blenlib/BLI_gsqueue.h | 2 +- source/blender/blenlib/BLI_listbase.h | 6 +- source/blender/blenlib/BLI_math_boolean.hh | 6 +- source/blender/blenlib/BLI_math_vec_mpq_types.hh | 91 ---- source/blender/blenlib/BLI_math_vec_types.hh | 566 --------------------- source/blender/blenlib/BLI_math_vector.hh | 399 --------------- source/blender/blenlib/BLI_memarena.h | 4 +- source/blender/blenlib/BLI_memory_utils.h | 2 +- source/blender/blenlib/BLI_memory_utils.hh | 9 + source/blender/blenlib/BLI_mesh_intersect.hh | 5 +- source/blender/blenlib/BLI_mpq2.hh | 184 +++++++ source/blender/blenlib/BLI_mpq3.hh | 297 +++++++++++ source/blender/blenlib/BLI_noise.hh | 4 +- source/blender/blenlib/BLI_path_util.h | 19 +- source/blender/blenlib/BLI_rand.hh | 3 +- source/blender/blenlib/BLI_stack.h | 6 +- source/blender/blenlib/BLI_string.h | 26 +- source/blender/blenlib/BLI_string_utf8.h | 19 +- source/blender/blenlib/BLI_string_utils.h | 6 +- source/blender/blenlib/BLI_timecode.h | 6 +- source/blender/blenlib/BLI_utildefines.h | 11 +- source/blender/blenlib/CMakeLists.txt | 10 +- .../blender/blenlib/intern/BLI_mempool_private.h | 5 +- source/blender/blenlib/intern/delaunay_2d.cc | 45 +- source/blender/blenlib/intern/math_boolean.cc | 7 +- source/blender/blenlib/intern/math_vec.cc | 133 +++-- source/blender/blenlib/intern/mesh_boolean.cc | 51 +- source/blender/blenlib/intern/mesh_intersect.cc | 88 ++-- source/blender/blenlib/intern/noise.cc | 79 +-- .../blender/blenlib/tests/BLI_delaunay_2d_test.cc | 3 +- .../blenlib/tests/BLI_math_vec_types_test.cc | 149 ------ .../blender/blenlib/tests/BLI_memory_utils_test.cc | 2 +- .../blender/blenlib/tests/BLI_mesh_boolean_test.cc | 2 +- .../blenlib/tests/BLI_mesh_intersect_test.cc | 2 +- source/blender/bmesh/intern/bmesh_opdefines.c | 1 + source/blender/bmesh/intern/bmesh_polygon.c | 7 + source/blender/compositor/CMakeLists.txt | 9 + source/blender/compositor/COM_defines.h | 2 +- source/blender/compositor/COM_precomp.h | 33 ++ .../operations/COM_OutputFileOperation.h | 2 +- .../intern/builder/deg_builder_relations.cc | 11 + .../depsgraph/intern/node/deg_node_factory.h | 2 +- .../blender/draw/intern/draw_cache_impl_curve.cc | 2 +- .../mesh_extractors/extract_mesh_vbo_attributes.cc | 4 +- source/blender/editors/gpencil/gpencil_paint.c | 28 +- source/blender/editors/include/ED_util.h | 2 +- source/blender/editors/include/UI_interface.h | 6 +- .../blender/editors/interface/interface_intern.h | 4 +- source/blender/editors/interface/interface_panel.c | 1 + .../editors/interface/interface_region_tooltip.c | 15 +- source/blender/editors/interface/interface_style.c | 13 +- .../blender/editors/interface/interface_widgets.c | 7 +- source/blender/editors/object/object_add.c | 2 + source/blender/editors/render/render_preview.cc | 2 +- source/blender/editors/space_file/file_draw.c | 3 +- source/blender/editors/space_node/node_draw.cc | 2 +- source/blender/editors/space_node/node_group.cc | 2 +- source/blender/editors/space_node/node_intern.hh | 5 +- source/blender/editors/space_node/node_select.cc | 4 +- .../editors/space_sequencer/sequencer_draw.c | 37 +- .../space_spreadsheet/spreadsheet_column.cc | 3 +- .../space_spreadsheet/spreadsheet_layout.cc | 3 +- .../space_spreadsheet/spreadsheet_row_filter.cc | 8 +- source/blender/editors/util/ed_draw.c | 34 +- source/blender/freestyle/CMakeLists.txt | 5 +- source/blender/freestyle/FRS_precomp.cpp | 2 - source/blender/functions/intern/cpp_types.cc | 3 +- source/blender/imbuf/IMB_imbuf.h | 30 +- source/blender/imbuf/IMB_metadata.h | 5 +- source/blender/imbuf/intern/IMB_filetype.h | 22 +- source/blender/imbuf/intern/anim_movie.c | 11 +- source/blender/imbuf/intern/dds/dds_api.h | 2 +- source/blender/imbuf/intern/oiio/openimageio_api.h | 2 +- source/blender/imbuf/intern/openexr/openexr_api.h | 2 +- source/blender/imbuf/intern/radiance_hdr.c | 31 +- .../blender/io/alembic/intern/abc_reader_object.cc | 25 +- .../blender/io/gpencil/intern/gpencil_io_base.cc | 5 +- .../blender/io/gpencil/intern/gpencil_io_base.hh | 3 +- .../io/gpencil/intern/gpencil_io_import_svg.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mesh.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_nurbs.cc | 2 +- .../io/wavefront_obj/tests/obj_exporter_tests.cc | 2 +- source/blender/makesdna/DNA_modifier_types.h | 1 + source/blender/makesdna/DNA_node_types.h | 1 + source/blender/makesrna/RNA_access.h | 2 +- source/blender/makesrna/intern/rna_internal.h | 2 +- .../blender/makesrna/intern/rna_internal_types.h | 2 +- source/blender/makesrna/intern/rna_modifier.c | 7 +- source/blender/makesrna/intern/rna_nodetree.c | 7 +- .../blender/modifiers/intern/MOD_mesh_to_volume.cc | 4 +- source/blender/modifiers/intern/MOD_nodes.cc | 2 +- source/blender/nodes/NOD_math_functions.hh | 75 +-- source/blender/nodes/NOD_socket_declarations.hh | 2 +- .../blender/nodes/composite/node_composite_tree.cc | 17 - .../nodes/composite/nodes/node_composite_image.cc | 28 +- .../blender/nodes/function/node_function_util.hh | 2 +- .../nodes/node_fn_align_euler_to_vector.cc | 8 +- .../nodes/function/nodes/node_fn_compare.cc | 24 +- .../blender/nodes/geometry/node_geometry_util.hh | 4 +- .../node_geo_legacy_align_rotation_to_vector.cc | 8 +- .../legacy/node_geo_legacy_attribute_proximity.cc | 2 +- .../legacy/node_geo_legacy_attribute_transfer.cc | 2 +- .../legacy/node_geo_legacy_curve_to_points.cc | 4 +- .../legacy/node_geo_legacy_point_distribute.cc | 4 +- .../legacy/node_geo_legacy_points_to_volume.cc | 2 +- .../nodes/legacy/node_geo_legacy_raycast.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fill.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fillet.cc | 21 +- .../nodes/node_geo_curve_primitive_circle.cc | 18 +- .../nodes/node_geo_curve_primitive_line.cc | 2 +- .../node_geo_curve_primitive_quadratic_bezier.cc | 6 +- .../nodes/geometry/nodes/node_geo_curve_sample.cc | 4 +- .../nodes/node_geo_curve_spline_parameter.cc | 2 +- .../geometry/nodes/node_geo_curve_to_points.cc | 4 +- .../nodes/geometry/nodes/node_geo_image_texture.cc | 2 +- .../geometry/nodes/node_geo_mesh_primitive_cube.cc | 6 +- .../geometry/nodes/node_geo_mesh_primitive_line.cc | 6 +- .../nodes/node_geo_mesh_primitive_uv_sphere.cc | 2 +- .../geometry/nodes/node_geo_points_to_volume.cc | 2 +- .../nodes/geometry/nodes/node_geo_proximity.cc | 2 +- .../nodes/geometry/nodes/node_geo_raycast.cc | 2 +- .../geometry/nodes/node_geo_set_curve_handles.cc | 2 +- .../geometry/nodes/node_geo_transfer_attribute.cc | 2 +- .../nodes/geometry/nodes/node_geo_transform.cc | 4 +- source/blender/nodes/intern/node_socket.cc | 2 +- source/blender/nodes/shader/node_shader_util.hh | 2 +- .../nodes/shader/nodes/node_shader_map_range.cc | 10 +- .../nodes/shader/nodes/node_shader_tex_brick.cc | 3 +- .../nodes/shader/nodes/node_shader_tex_gradient.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_noise.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_voronoi.cc | 36 +- source/blender/python/generic/py_capi_utils.h | 12 +- source/blender/render/RE_bake.h | 12 +- source/blender/sequencer/intern/effects.c | 4 +- source/blender/windowmanager/WM_api.h | 2 +- source/blender/windowmanager/intern/wm_files.c | 3 +- 185 files changed, 2433 insertions(+), 1961 deletions(-) create mode 100644 source/blender/blenlib/BLI_double2.hh create mode 100644 source/blender/blenlib/BLI_double3.hh create mode 100644 source/blender/blenlib/BLI_float2.hh create mode 100644 source/blender/blenlib/BLI_float3.hh create mode 100644 source/blender/blenlib/BLI_float4.hh delete mode 100644 source/blender/blenlib/BLI_math_vec_mpq_types.hh delete mode 100644 source/blender/blenlib/BLI_math_vec_types.hh delete mode 100644 source/blender/blenlib/BLI_math_vector.hh create mode 100644 source/blender/blenlib/BLI_mpq2.hh create mode 100644 source/blender/blenlib/BLI_mpq3.hh delete mode 100644 source/blender/blenlib/tests/BLI_math_vec_types_test.cc create mode 100644 source/blender/compositor/COM_precomp.h delete mode 100644 source/blender/freestyle/FRS_precomp.cpp (limited to 'source/blender') diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 76a6135baaf..169107b19cb 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -122,7 +122,7 @@ void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth) ATTR_NONNULL(2); typedef bool (*BLF_GlyphBoundsFn)(const char *str, - const size_t str_step_ofs, + size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 23e42ec777f..4e36f522981 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -121,7 +121,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, const char *str, size_t str_len, bool (*user_fn)(const char *str, - const size_t str_step_ofs, + size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, @@ -132,7 +132,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, int blf_font_count_missing_chars(struct FontBLF *font, const char *str, - const size_t str_len, + size_t str_len, int *r_tot_chars); void blf_font_free(struct FontBLF *font); diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index e92909fb3ca..a7baaed141f 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -140,7 +140,7 @@ bool BKE_appdir_font_folder_default(char *dir); * Find Python executable. */ bool BKE_appdir_program_python_search(char *fullpath, - const size_t fullpath_len, + size_t fullpath_len, int version_major, int version_minor); diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index db8f3759bf8..6020da08f51 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -73,7 +73,7 @@ bool BKE_id_attribute_rename(struct ID *id, const char *new_name, struct ReportList *reports); -int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask); +int BKE_id_attributes_length(struct ID *id, CustomDataMask mask); struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id); void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer); diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index 3ffdcee05eb..f69ba79e23f 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -26,8 +26,9 @@ #include "BKE_attribute.h" #include "BLI_color.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_function_ref.hh" -#include "BLI_math_vec_types.hh" /** * This file defines classes that help to provide access to attribute data on a #GeometryComponent. diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh index a7bdca06790..802c744972c 100644 --- a/source/blender/blenkernel/BKE_attribute_math.hh +++ b/source/blender/blenkernel/BKE_attribute_math.hh @@ -18,7 +18,8 @@ #include "BLI_array.hh" #include "BLI_color.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "DNA_customdata_types.h" @@ -159,12 +160,12 @@ template<> inline float mix2(const float factor, const float &a, const float &b) template<> inline float2 mix2(const float factor, const float2 &a, const float2 &b) { - return math::interpolate(a, b, factor); + return float2::interpolate(a, b, factor); } template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b) { - return math::interpolate(a, b, factor); + return float3::interpolate(a, b, factor); } template<> diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 42c8a5dae5d..146e6394fd6 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -128,7 +128,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -148,7 +148,7 @@ BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -165,7 +165,7 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -188,7 +188,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -212,7 +212,7 @@ BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -229,7 +229,7 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -251,7 +251,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -263,7 +263,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, */ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, const struct Mesh *mesh, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, int tree_type); /** @@ -272,7 +272,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, BVHTree *BKE_bvhtree_from_editmesh_get(BVHTreeFromEditMesh *data, struct BMEditMesh *em, int tree_type, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index b5b6296a0fa..17a44274712 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -323,7 +323,7 @@ void CustomData_bmesh_copy_data_exclude_by_type(const struct CustomData *source, struct CustomData *dest, void *src_block, void **dest_block, - const CustomDataMask mask_exclude); + CustomDataMask mask_exclude); /** * Copies data of a single layer of a given type. @@ -496,7 +496,7 @@ void CustomData_bmesh_free_block_data(struct CustomData *data, void *block); */ void CustomData_bmesh_free_block_data_exclude_by_type(struct CustomData *data, void *block, - const CustomDataMask mask_exclude); + CustomDataMask mask_exclude); /** * Copy custom data to/from layers as in mesh/derived-mesh, to edit-mesh diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index f92f33b2776..acb89637f20 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -23,11 +23,11 @@ #include #include +#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_function_ref.hh" #include "BLI_hash.hh" #include "BLI_map.hh" -#include "BLI_math_vec_types.hh" #include "BLI_set.hh" #include "BLI_user_counter.hh" #include "BLI_vector_set.hh" diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 7b87189a13f..80c6b155be0 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -367,7 +367,7 @@ void BKE_image_packfiles(struct ReportList *reports, struct Image *ima, const ch void BKE_image_packfiles_from_mem(struct ReportList *reports, struct Image *ima, char *data, - const size_t data_len); + size_t data_len); /** * Prints memory statistics for images. diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh index 738b768d906..238b6f4dcae 100644 --- a/source/blender/blenkernel/BKE_mesh_sample.hh +++ b/source/blender/blenkernel/BKE_mesh_sample.hh @@ -22,7 +22,7 @@ #include "FN_generic_virtual_array.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BKE_attribute.h" diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 5f8222e33d4..a76fe2f83e0 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1374,18 +1374,12 @@ void ntreeCompositTagRender(struct Scene *scene); * - Each render layer node calls the update function of the * render engine that's used for its scene. * - The render engine calls RE_engine_register_pass for each pass. - * - #RE_engine_register_pass calls #ntreeCompositRegisterPass, - * which calls #node_cmp_rlayers_register_pass for every render layer node. + * - #RE_engine_register_pass calls #node_cmp_rlayers_register_pass. * * TODO: This is *not* part of `blenkernel`, it's defined under "source/blender/nodes/". * This declaration should be moved out of BKE. */ void ntreeCompositUpdateRLayers(struct bNodeTree *ntree); -void ntreeCompositRegisterPass(struct bNodeTree *ntree, - struct Scene *scene, - struct ViewLayer *view_layer, - const char *name, - eNodeSocketDatatype type); void ntreeCompositClearTags(struct bNodeTree *ntree); struct bNodeSocket *ntreeCompositOutputFileAddSocket(struct bNodeTree *ntree, diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 8610bc09a92..a40359e8650 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -317,11 +317,8 @@ void BKE_scene_multiview_view_prefix_get(struct Scene *scene, const char *name, char *r_prefix, const char **r_ext); -void BKE_scene_multiview_videos_dimensions_get(const struct RenderData *rd, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); +void BKE_scene_multiview_videos_dimensions_get( + const struct RenderData *rd, size_t width, size_t height, size_t *r_width, size_t *r_height); int BKE_scene_multiview_num_videos_get(const struct RenderData *rd); /* depsgraph */ diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh index a87f76da8da..2c14880978f 100644 --- a/source/blender/blenkernel/BKE_spline.hh +++ b/source/blender/blenkernel/BKE_spline.hh @@ -24,8 +24,8 @@ #include "FN_generic_virtual_array.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" -#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BKE_attribute_access.hh" diff --git a/source/blender/blenkernel/BKE_vfont.h b/source/blender/blenkernel/BKE_vfont.h index d0a44ce4e47..3397f2ef82a 100644 --- a/source/blender/blenkernel/BKE_vfont.h +++ b/source/blender/blenkernel/BKE_vfont.h @@ -104,7 +104,7 @@ void BKE_vfont_select_clamp(struct Object *ob); void BKE_vfont_clipboard_free(void); void BKE_vfont_clipboard_set(const char32_t *text_buf, const struct CharInfo *info_buf, - const size_t len); + size_t len); void BKE_vfont_clipboard_get(char32_t **r_text_buf, struct CharInfo **r_info_buf, size_t *r_len_utf8, diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h index b40facc3572..2b551a76d73 100644 --- a/source/blender/blenkernel/BKE_volume.h +++ b/source/blender/blenkernel/BKE_volume.h @@ -163,8 +163,8 @@ bool BKE_volume_save(const struct Volume *volume, * file or copy shared grids to make them writeable. */ #ifdef __cplusplus +# include "BLI_float3.hh" # include "BLI_float4x4.hh" -# include "BLI_math_vec_types.hh" # include "BLI_string_ref.hh" bool BKE_volume_min_max(const Volume *volume, blender::float3 &r_min, blender::float3 &r_max); diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 73785e2ee2b..4bfd71ba932 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -38,9 +38,9 @@ #include "BLI_array.h" #include "BLI_bitmap.h" #include "BLI_blenlib.h" +#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_task.h" #include "BLI_task.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index cc43a3e26a8..1a4265d936b 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -30,7 +30,7 @@ #include "DNA_pointcloud_types.h" #include "BLI_color.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" #include "BLI_span.hh" #include "BLT_translation.h" diff --git a/source/blender/blenkernel/intern/data_transfer_intern.h b/source/blender/blenkernel/intern/data_transfer_intern.h index e5218415df9..b5b3db31fbf 100644 --- a/source/blender/blenkernel/intern/data_transfer_intern.h +++ b/source/blender/blenkernel/intern/data_transfer_intern.h @@ -44,9 +44,9 @@ void data_transfer_layersmapping_add_item(struct ListBase *r_map, void *data_dst, int data_src_n, int data_dst_n, - const size_t elem_size, - const size_t data_size, - const size_t data_offset, + size_t elem_size, + size_t data_size, + size_t data_offset, uint64_t data_flag, cd_datatransfer_interp interp, void *interp_data); diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 88a58220b23..2b4238d26bb 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -217,8 +217,9 @@ VArray mesh_normals_varray(const MeshComponent &mesh_component, * calculating unnecessary values and to allow normalizing the result much more simply. */ for (const int i : mask) { const MEdge &edge = edges[i]; - edge_normals[i] = math::normalize( - math::interpolate(vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f)); + edge_normals[i] = float3::interpolate( + vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f) + .normalized(); } return VArray::ForContainer(std::move(edge_normals)); diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc index 116d77f1a2a..f8681647a77 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.cc +++ b/source/blender/blenkernel/intern/gpencil_geom.cc @@ -33,10 +33,10 @@ #include "BLI_array_utils.h" #include "BLI_blenlib.h" +#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_heap.h" -#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_polyfill_2d.h" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/hair.cc b/source/blender/blenkernel/intern/hair.cc index b7ba159f631..c5b154c9a4b 100644 --- a/source/blender/blenkernel/intern/hair.cc +++ b/source/blender/blenkernel/intern/hair.cc @@ -28,9 +28,9 @@ #include "DNA_material_types.h" #include "DNA_object_types.h" +#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math_base.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 4899c3671aa..23b1054f814 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -2446,7 +2446,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and draw the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.file, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.file, sizeof(stamp_data.file)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2469,7 +2469,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.date, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.date, sizeof(stamp_data.date)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2492,7 +2492,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.rendertime, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.rendertime, sizeof(stamp_data.rendertime)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2515,7 +2515,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.memory, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.memory, sizeof(stamp_data.memory)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2538,7 +2538,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.hostname, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.hostname, sizeof(stamp_data.hostname)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2562,7 +2562,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs + (h - h_fixed), 0.0); - BLF_draw_buffer(mono, stamp_data.note, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.note, sizeof(stamp_data.note)); } BLF_disable(mono, BLF_WORD_WRAP); @@ -2586,7 +2586,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.marker, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.marker, sizeof(stamp_data.marker)); /* space width. */ x += w + pad; @@ -2609,7 +2609,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.time, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.time, sizeof(stamp_data.time)); /* space width. */ x += w + pad; @@ -2631,7 +2631,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.frame, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.frame, sizeof(stamp_data.frame)); /* space width. */ x += w + pad; @@ -2651,7 +2651,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.camera, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.camera, sizeof(stamp_data.camera)); /* space width. */ x += w + pad; @@ -2671,7 +2671,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.cameralens, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.cameralens, sizeof(stamp_data.cameralens)); } if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) { @@ -2693,7 +2693,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.scene, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.scene, sizeof(stamp_data.scene)); } if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) { @@ -2715,7 +2715,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.strip, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.strip, sizeof(stamp_data.strip)); } /* cleanup the buffer. */ diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 8ceaced1972..12c63ab0523 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -36,13 +36,13 @@ #include "BLI_bitmap.h" #include "BLI_edgehash.h" #include "BLI_endian_switch.h" +#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_index_range.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_memarena.h" #include "BLI_string.h" #include "BLI_task.hh" @@ -1597,16 +1597,16 @@ bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3]) [&](IndexRange range, const Result &init) { Result result = init; for (const int i : range) { - math::min_max(float3(me->mvert[i].co), result.min, result.max); + float3::min_max(me->mvert[i].co, result.min, result.max); } return result; }, [](const Result &a, const Result &b) { - return Result{math::min(a.min, b.min), math::max(a.max, b.max)}; + return Result{float3::min(a.min, b.min), float3::max(a.max, b.max)}; }); - copy_v3_v3(r_min, math::min(minmax.min, float3(r_min))); - copy_v3_v3(r_max, math::max(minmax.max, float3(r_max))); + copy_v3_v3(r_min, float3::min(minmax.min, r_min)); + copy_v3_v3(r_max, float3::max(minmax.max, r_max)); return true; } diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc index a4a5fe2be2e..771d79a0445 100644 --- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc +++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc @@ -32,9 +32,9 @@ #include "BLI_alloca.h" #include "BLI_array.hh" +#include "BLI_float2.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_mesh_boolean.hh" #include "BLI_mesh_intersect.hh" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc index 50464da86e9..3447185089d 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc @@ -31,8 +31,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_index_range.hh" -#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_mesh_types.h" diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc index 20fdda8bdc7..e682486390c 100644 --- a/source/blender/blenkernel/intern/object_dupli.cc +++ b/source/blender/blenkernel/intern/object_dupli.cc @@ -31,9 +31,9 @@ #include "BLI_string_utf8.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_vector.hh" @@ -1026,8 +1026,6 @@ static void get_dupliface_transform_from_coords(Span coords, const float scale_fac, float r_mat[4][4]) { - using namespace blender::math; - /* Location. */ float3 location(0); for (const float3 &coord : coords) { @@ -1038,7 +1036,9 @@ static void get_dupliface_transform_from_coords(Span coords, /* Rotation. */ float quat[4]; - float3 f_no = normalize(cross_poly(coords)); + float3 f_no; + cross_poly_v3(f_no, (const float(*)[3])coords.data(), (uint)coords.size()); + f_no.normalize(); tri_to_quat_ex(quat, coords[0], coords[1], coords[2], f_no); /* Scale. */ diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc index b5f016e4d76..a041e04bf71 100644 --- a/source/blender/blenkernel/intern/pointcloud.cc +++ b/source/blender/blenkernel/intern/pointcloud.cc @@ -25,9 +25,9 @@ #include "DNA_object_types.h" #include "DNA_pointcloud_types.h" +#include "BLI_float3.hh" #include "BLI_index_range.hh" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" @@ -275,8 +275,6 @@ struct MinMaxResult { static MinMaxResult min_max_no_radii(Span positions) { - using namespace blender::math; - return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -284,19 +282,17 @@ static MinMaxResult min_max_no_radii(Span positions) [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - min_max(positions[i], result.min, result.max); + float3::min_max(positions[i], result.min, result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; + return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; }); } static MinMaxResult min_max_with_radii(Span positions, Span radii) { - using namespace blender::math; - return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -304,20 +300,18 @@ static MinMaxResult min_max_with_radii(Span positions, Span radii [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - result.min = min(positions[i] - radii[i], result.min); - result.max = max(positions[i] + radii[i], result.max); + result.min = float3::min(positions[i] - radii[i], result.min); + result.max = float3::max(positions[i] + radii[i], result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; + return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; }); } bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r_max[3]) { - using namespace blender::math; - if (!pointcloud->totpoint) { return false; } @@ -328,8 +322,8 @@ bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r {pointcloud->radius, pointcloud->totpoint}) : min_max_no_radii(positions); - copy_v3_v3(r_min, min(min_max.min, float3(r_min))); - copy_v3_v3(r_max, max(min_max.max, float3(r_max))); + copy_v3_v3(r_min, float3::min(min_max.min, r_min)); + copy_v3_v3(r_max, float3::max(min_max.max, r_max)); return true; } @@ -346,7 +340,7 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob) ob->runtime.bb = static_cast(MEM_callocN(sizeof(BoundBox), "pointcloud boundbox")); } - float3 min, max; + blender::float3 min, max; INIT_MINMAX(min, max); if (ob->runtime.geometry_set_eval != nullptr) { ob->runtime.geometry_set_eval->compute_boundbox_without_instances(&min, &max); diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index ec4b0e8d51d..b0f9de5963a 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -28,9 +28,9 @@ #include "DNA_simulation_types.h" #include "BLI_compiler_compat.h" +#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 3262d768b6c..857022345f3 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -166,15 +166,13 @@ static void accumulate_lengths(Span positions, const bool is_cyclic, MutableSpan lengths) { - using namespace blender::math; - float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { - length += distance(positions[i], positions[i + 1]); + length += float3::distance(positions[i], positions[i + 1]); lengths[i] = length; } if (is_cyclic) { - lengths.last() = length + distance(positions.last(), positions.first()); + lengths.last() = length + float3::distance(positions.last(), positions.first()); } } @@ -202,13 +200,11 @@ Span Spline::evaluated_lengths() const static float3 direction_bisect(const float3 &prev, const float3 &middle, const float3 &next) { - using namespace blender::math; - - const float3 dir_prev = normalize(middle - prev); - const float3 dir_next = normalize(next - middle); + const float3 dir_prev = (middle - prev).normalized(); + const float3 dir_next = (next - middle).normalized(); - const float3 result = normalize(dir_prev + dir_next); - if (UNLIKELY(is_zero(result))) { + const float3 result = (dir_prev + dir_next).normalized(); + if (UNLIKELY(result.is_zero())) { return float3(0.0f, 0.0f, 1.0f); } return result; @@ -218,8 +214,6 @@ static void calculate_tangents(Span positions, const bool is_cyclic, MutableSpan tangents) { - using namespace blender::math; - if (positions.size() == 1) { tangents.first() = float3(0.0f, 0.0f, 1.0f); return; @@ -238,8 +232,8 @@ static void calculate_tangents(Span positions, tangents.last() = direction_bisect(second_to_last, last, first); } else { - tangents.first() = normalize(positions[1] - positions[0]); - tangents.last() = normalize(positions.last() - positions[positions.size() - 2]); + tangents.first() = (positions[1] - positions[0]).normalized(); + tangents.last() = (positions.last() - positions[positions.size() - 2]).normalized(); } } @@ -270,22 +264,18 @@ static float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, const float angle) { - using namespace blender::math; - BLI_ASSERT_UNIT_V3(direction); BLI_ASSERT_UNIT_V3(axis); - const float3 axis_scaled = axis * dot(direction, axis); + const float3 axis_scaled = axis * float3::dot(direction, axis); const float3 diff = direction - axis_scaled; - const float3 cross = blender::math::cross(axis, diff); + const float3 cross = float3::cross(axis, diff); return axis_scaled + diff * std::cos(angle) + cross * std::sin(angle); } static void calculate_normals_z_up(Span tangents, MutableSpan r_normals) { - using namespace blender::math; - BLI_assert(r_normals.size() == tangents.size()); /* Same as in `vec_to_quat`. */ @@ -296,7 +286,7 @@ static void calculate_normals_z_up(Span tangents, MutableSpan r_ r_normals[i] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[i] = normalize(float3(tangent.y, -tangent.x, 0.0f)); + r_normals[i] = float3(tangent.y, -tangent.x, 0.0f).normalized(); } } } @@ -308,14 +298,12 @@ static float3 calculate_next_normal(const float3 &last_normal, const float3 &last_tangent, const float3 ¤t_tangent) { - using namespace blender::math; - - if (is_zero(last_tangent) || is_zero(current_tangent)) { + if (last_tangent.is_zero() || current_tangent.is_zero()) { return last_normal; } const float angle = angle_normalized_v3v3(last_tangent, current_tangent); if (angle != 0.0) { - const float3 axis = normalize(cross(last_tangent, current_tangent)); + const float3 axis = float3::cross(last_tangent, current_tangent).normalized(); return rotate_direction_around_axis(last_normal, axis, angle); } return last_normal; @@ -325,7 +313,6 @@ static void calculate_normals_minimum(Span tangents, const bool cyclic, MutableSpan r_normals) { - using namespace blender::math; BLI_assert(r_normals.size() == tangents.size()); if (r_normals.is_empty()) { @@ -340,7 +327,7 @@ static void calculate_normals_minimum(Span tangents, r_normals[0] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[0] = normalize(float3(first_tangent.y, -first_tangent.x, 0.0f)); + r_normals[0] = float3(first_tangent.y, -first_tangent.x, 0.0f).normalized(); } /* Forward normal with minimum twist along the entire spline. */ diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc index 980437014b1..b24c8960857 100644 --- a/source/blender/blenkernel/intern/spline_bezier.cc +++ b/source/blender/blenkernel/intern/spline_bezier.cc @@ -199,13 +199,11 @@ void BezierSpline::ensure_auto_handles() const } for (const int i : IndexRange(this->size())) { - using namespace blender; - if (ELEM(HandleType::Auto, handle_types_left_[i], handle_types_right_[i])) { const float3 prev_diff = positions_[i] - previous_position(positions_, is_cyclic_, i); const float3 next_diff = next_position(positions_, is_cyclic_, i) - positions_[i]; - float prev_len = math::length(prev_diff); - float next_len = math::length(next_diff); + float prev_len = prev_diff.length(); + float next_len = next_diff.length(); if (prev_len == 0.0f) { prev_len = 1.0f; } @@ -215,7 +213,7 @@ void BezierSpline::ensure_auto_handles() const const float3 dir = next_diff / next_len + prev_diff / prev_len; /* This magic number is unfortunate, but comes from elsewhere in Blender. */ - const float len = math::length(dir) * 2.5614f; + const float len = dir.length() * 2.5614f; if (len != 0.0f) { if (handle_types_left_[i] == HandleType::Auto) { const float prev_len_clamped = std::min(prev_len, next_len * 5.0f); @@ -230,12 +228,12 @@ void BezierSpline::ensure_auto_handles() const if (handle_types_left_[i] == HandleType::Vector) { const float3 prev = previous_position(positions_, is_cyclic_, i); - handle_positions_left_[i] = math::interpolate(positions_[i], prev, 1.0f / 3.0f); + handle_positions_left_[i] = float3::interpolate(positions_[i], prev, 1.0f / 3.0f); } if (handle_types_right_[i] == HandleType::Vector) { const float3 next = next_position(positions_, is_cyclic_, i); - handle_positions_right_[i] = math::interpolate(positions_[i], next, 1.0f / 3.0f); + handle_positions_right_[i] = float3::interpolate(positions_[i], next, 1.0f / 3.0f); } } @@ -277,8 +275,6 @@ static void set_handle_position(const float3 &position, float3 &handle, float3 &handle_other) { - using namespace blender::math; - /* Don't bother when the handle positions are calculated automatically anyway. */ if (ELEM(type, BezierSpline::HandleType::Auto, BezierSpline::HandleType::Vector)) { return; @@ -287,9 +283,9 @@ static void set_handle_position(const float3 &position, handle = new_value; if (type_other == BezierSpline::HandleType::Align) { /* Keep track of the old length of the opposite handle. */ - const float length = distance(handle_other, position); + const float length = float3::distance(handle_other, position); /* Set the other handle to directly opposite from the current handle. */ - const float3 dir = normalize(handle - position); + const float3 dir = (handle - position).normalized(); handle_other = position - dir * length; } } @@ -357,7 +353,6 @@ int BezierSpline::evaluated_points_size() const void BezierSpline::correct_end_tangents() const { - using namespace blender::math; if (is_cyclic_) { return; } @@ -365,10 +360,10 @@ void BezierSpline::correct_end_tangents() const MutableSpan tangents(evaluated_tangents_cache_); if (handle_positions_right_.first() != positions_.first()) { - tangents.first() = normalize(handle_positions_right_.first() - positions_.first()); + tangents.first() = (handle_positions_right_.first() - positions_.first()).normalized(); } if (handle_positions_left_.last() != positions_.last()) { - tangents.last() = normalize(positions_.last() - handle_positions_left_.last()); + tangents.last() = (positions_.last() - handle_positions_left_.last()).normalized(); } } @@ -376,22 +371,20 @@ BezierSpline::InsertResult BezierSpline::calculate_segment_insertion(const int i const int next_index, const float parameter) { - using namespace blender::math; - BLI_assert(parameter <= 1.0f && parameter >= 0.0f); BLI_assert(next_index == 0 || next_index == index + 1); const float3 &point_prev = positions_[index]; const float3 &handle_prev = handle_positions_right_[index]; const float3 &handle_next = handle_positions_left_[next_index]; const float3 &point_next = positions_[next_index]; - const float3 center_point = interpolate(handle_prev, handle_next, parameter); + const float3 center_point = float3::interpolate(handle_prev, handle_next, parameter); BezierSpline::InsertResult result; - result.handle_prev = interpolate(point_prev, handle_prev, parameter); - result.handle_next = interpolate(handle_next, point_next, parameter); - result.left_handle = interpolate(result.handle_prev, center_point, parameter); - result.right_handle = interpolate(center_point, result.handle_next, parameter); - result.position = interpolate(result.left_handle, result.right_handle, parameter); + result.handle_prev = float3::interpolate(point_prev, handle_prev, parameter); + result.handle_next = float3::interpolate(handle_next, point_next, parameter); + result.left_handle = float3::interpolate(result.handle_prev, center_point, parameter); + result.right_handle = float3::interpolate(center_point, result.handle_next, parameter); + result.position = float3::interpolate(result.left_handle, result.right_handle, parameter); return result; } diff --git a/source/blender/blenkernel/intern/tracking_test.cc b/source/blender/blenkernel/intern/tracking_test.cc index d85d71b7c86..a3845dcad8f 100644 --- a/source/blender/blenkernel/intern/tracking_test.cc +++ b/source/blender/blenkernel/intern/tracking_test.cc @@ -5,7 +5,7 @@ #include "DNA_tracking_types.h" #include "BKE_tracking.h" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" namespace blender { diff --git a/source/blender/blenkernel/intern/type_conversions.cc b/source/blender/blenkernel/intern/type_conversions.cc index cb05337ef2a..b23220286e6 100644 --- a/source/blender/blenkernel/intern/type_conversions.cc +++ b/source/blender/blenkernel/intern/type_conversions.cc @@ -19,7 +19,8 @@ #include "FN_multi_function_builder.hh" #include "BLI_color.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" namespace blender::bke { diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index c17706dc216..4b71c98339b 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -28,12 +28,12 @@ #include "BLI_compiler_compat.h" #include "BLI_fileops.h" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_ghash.h" #include "BLI_index_range.hh" #include "BLI_map.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc index c0a205b5673..6dc497bb616 100644 --- a/source/blender/blenkernel/intern/volume_render.cc +++ b/source/blender/blenkernel/intern/volume_render.cc @@ -21,8 +21,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_math_matrix.h" -#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_vector.hh" diff --git a/source/blender/blenkernel/intern/volume_to_mesh.cc b/source/blender/blenkernel/intern/volume_to_mesh.cc index 733549c0022..6e465b2fdf0 100644 --- a/source/blender/blenkernel/intern/volume_to_mesh.cc +++ b/source/blender/blenkernel/intern/volume_to_mesh.cc @@ -16,7 +16,7 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_array_store.h b/source/blender/blenlib/BLI_array_store.h index 0be361d4ab9..68928f53e55 100644 --- a/source/blender/blenlib/BLI_array_store.h +++ b/source/blender/blenlib/BLI_array_store.h @@ -84,7 +84,7 @@ size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs); */ BArrayState *BLI_array_store_state_add(BArrayStore *bs, const void *data, - const size_t data_len, + size_t data_len, const BArrayState *state_reference); /** * Remove a state and free any unused #BChunk data. diff --git a/source/blender/blenlib/BLI_array_utils.h b/source/blender/blenlib/BLI_array_utils.h index 50fc2ce909b..202ae9a9786 100644 --- a/source/blender/blenlib/BLI_array_utils.h +++ b/source/blender/blenlib/BLI_array_utils.h @@ -52,7 +52,7 @@ void _bli_array_wrap(void *arr, uint arr_len, size_t arr_stride, int dir); * Access via #BLI_array_wrap */ void _bli_array_permute( - void *arr, uint arr_len, const size_t arr_stride, const uint *order, void *arr_temp); + void *arr, uint arr_len, size_t arr_stride, const uint *order, void *arr_temp); #define BLI_array_permute(arr, arr_len, order) \ _bli_array_permute(arr, arr_len, sizeof(*(arr)), order, NULL) #define BLI_array_permute_ex(arr, arr_len, order, arr_temp) \ @@ -152,7 +152,7 @@ bool _bli_array_is_zeroed(const void *arr, uint arr_len, size_t arr_stride); */ bool _bli_array_iter_spiral_square(const void *arr_v, const int arr_shape[2], - const size_t elem_size, + size_t elem_size, const int center[2], bool (*test_fn)(const void *arr_item, void *user_data), void *user_data); diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h index 7f577443cf7..e79d44fd934 100644 --- a/source/blender/blenlib/BLI_buffer.h +++ b/source/blender/blenlib/BLI_buffer.h @@ -74,7 +74,7 @@ enum { /** * \note Never decreases the amount of memory allocated. */ -void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); +void BLI_buffer_resize(BLI_Buffer *buffer, size_t new_count); /** * Ensure size, throwing away old data, respecting #BLI_BUFFER_USE_CALLOC. @@ -83,7 +83,7 @@ void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); * - Ignored (malloc'd). * - Cleared (when #BLI_BUFFER_USE_CALLOC is set). */ -void BLI_buffer_reinit(BLI_Buffer *buffer, const size_t new_count); +void BLI_buffer_reinit(BLI_Buffer *buffer, size_t new_count); /** * Append an array of elements. diff --git a/source/blender/blenlib/BLI_delaunay_2d.h b/source/blender/blenlib/BLI_delaunay_2d.h index 1ee0be64cee..db0df95499f 100644 --- a/source/blender/blenlib/BLI_delaunay_2d.h +++ b/source/blender/blenlib/BLI_delaunay_2d.h @@ -215,9 +215,9 @@ void BLI_delaunay_2d_cdt_free(CDT_result *result); /* C++ Interface. */ # include "BLI_array.hh" +# include "BLI_double2.hh" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" +# include "BLI_mpq2.hh" # include "BLI_vector.hh" namespace blender::meshintersect { diff --git a/source/blender/blenlib/BLI_double2.hh b/source/blender/blenlib/BLI_double2.hh new file mode 100644 index 00000000000..0abff01ab2f --- /dev/null +++ b/source/blender/blenlib/BLI_double2.hh @@ -0,0 +1,143 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include "BLI_double3.hh" + +namespace blender { + +struct double2 { + double x, y; + + double2() = default; + + double2(const double *ptr) : x{ptr[0]}, y{ptr[1]} + { + } + + double2(double x, double y) : x(x), y(y) + { + } + + double2(const double3 &other) : x(other.x), y(other.y) + { + } + + operator double *() + { + return &x; + } + + operator const double *() const + { + return &x; + } + + double length() const + { + return len_v2_db(*this); + } + + friend double2 operator+(const double2 &a, const double2 &b) + { + return {a.x + b.x, a.y + b.y}; + } + + friend double2 operator-(const double2 &a, const double2 &b) + { + return {a.x - b.x, a.y - b.y}; + } + + friend double2 operator*(const double2 &a, double b) + { + return {a.x * b, a.y * b}; + } + + friend double2 operator/(const double2 &a, double b) + { + BLI_assert(b != 0.0); + return {a.x / b, a.y / b}; + } + + friend double2 operator*(double a, const double2 &b) + { + return b * a; + } + + friend bool operator==(const double2 &a, const double2 &b) + { + return a.x == b.x && a.y == b.y; + } + + friend bool operator!=(const double2 &a, const double2 &b) + { + return a.x != b.x || a.y != b.y; + } + + friend std::ostream &operator<<(std::ostream &stream, const double2 &v) + { + stream << "(" << v.x << ", " << v.y << ")"; + return stream; + } + + static double dot(const double2 &a, const double2 &b) + { + return a.x * b.x + a.y * b.y; + } + + static double2 interpolate(const double2 &a, const double2 &b, double t) + { + return a * (1 - t) + b * t; + } + + static double2 abs(const double2 &a) + { + return double2(fabs(a.x), fabs(a.y)); + } + + static double distance(const double2 &a, const double2 &b) + { + return (a - b).length(); + } + + static double distance_squared(const double2 &a, const double2 &b) + { + double2 diff = a - b; + return double2::dot(diff, diff); + } + + struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + double lambda; + }; + + static isect_result isect_seg_seg(const double2 &v1, + const double2 &v2, + const double2 &v3, + const double2 &v4); +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_double3.hh b/source/blender/blenlib/BLI_double3.hh new file mode 100644 index 00000000000..ab258c9121b --- /dev/null +++ b/source/blender/blenlib/BLI_double3.hh @@ -0,0 +1,246 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include + +#include "BLI_math_vector.h" +#include "BLI_span.hh" + +namespace blender { + +struct double3 { + double x, y, z; + + double3() = default; + + double3(const double *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} + { + } + + double3(const double (*ptr)[3]) : double3((const double *)ptr) + { + } + + explicit double3(double value) : x(value), y(value), z(value) + { + } + + explicit double3(int value) : x(value), y(value), z(value) + { + } + + double3(double x, double y, double z) : x{x}, y{y}, z{z} + { + } + + operator const double *() const + { + return &x; + } + + operator double *() + { + return &x; + } + + double normalize_and_get_length() + { + return normalize_v3_db(*this); + } + + double3 normalized() const + { + double3 result; + normalize_v3_v3_db(result, *this); + return result; + } + + double length() const + { + return len_v3_db(*this); + } + + double length_squared() const + { + return len_squared_v3_db(*this); + } + + void reflect(const double3 &normal) + { + *this = this->reflected(normal); + } + + double3 reflected(const double3 &normal) const + { + double3 result; + reflect_v3_v3v3_db(result, *this, normal); + return result; + } + + static double3 safe_divide(const double3 &a, const double3 &b) + { + double3 result; + result.x = (b.x == 0.0) ? 0.0 : a.x / b.x; + result.y = (b.y == 0.0) ? 0.0 : a.y / b.y; + result.z = (b.z == 0.0) ? 0.0 : a.z / b.z; + return result; + } + + void invert() + { + x = -x; + y = -y; + z = -z; + } + + friend double3 operator+(const double3 &a, const double3 &b) + { + return {a.x + b.x, a.y + b.y, a.z + b.z}; + } + + void operator+=(const double3 &b) + { + this->x += b.x; + this->y += b.y; + this->z += b.z; + } + + friend double3 operator-(const double3 &a, const double3 &b) + { + return {a.x - b.x, a.y - b.y, a.z - b.z}; + } + + friend double3 operator-(const double3 &a) + { + return {-a.x, -a.y, -a.z}; + } + + void operator-=(const double3 &b) + { + this->x -= b.x; + this->y -= b.y; + this->z -= b.z; + } + + void operator*=(const double &scalar) + { + this->x *= scalar; + this->y *= scalar; + this->z *= scalar; + } + + void operator*=(const double3 &other) + { + this->x *= other.x; + this->y *= other.y; + this->z *= other.z; + } + + friend double3 operator*(const double3 &a, const double3 &b) + { + return {a.x * b.x, a.y * b.y, a.z * b.z}; + } + + friend double3 operator*(const double3 &a, const double &b) + { + return {a.x * b, a.y * b, a.z * b}; + } + + friend double3 operator*(const double &a, const double3 &b) + { + return b * a; + } + + friend double3 operator/(const double3 &a, const double &b) + { + BLI_assert(b != 0.0); + return {a.x / b, a.y / b, a.z / b}; + } + + friend bool operator==(const double3 &a, const double3 &b) + { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + + friend bool operator!=(const double3 &a, const double3 &b) + { + return a.x != b.x || a.y != b.y || a.z != b.z; + } + + friend std::ostream &operator<<(std::ostream &stream, const double3 &v) + { + stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; + return stream; + } + + static double dot(const double3 &a, const double3 &b) + { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static double3 cross_high_precision(const double3 &a, const double3 &b) + { + double3 result; + cross_v3_v3v3_db(result, a, b); + return result; + } + + static double3 project(const double3 &a, const double3 &b) + { + double3 result; + project_v3_v3v3_db(result, a, b); + return result; + } + + static double distance(const double3 &a, const double3 &b) + { + return (a - b).length(); + } + + static double distance_squared(const double3 &a, const double3 &b) + { + double3 diff = a - b; + return double3::dot(diff, diff); + } + + static double3 interpolate(const double3 &a, const double3 &b, double t) + { + return a * (1 - t) + b * t; + } + + static double3 abs(const double3 &a) + { + return double3(fabs(a.x), fabs(a.y), fabs(a.z)); + } + + static int dominant_axis(const double3 &a) + { + double x = (a.x >= 0) ? a.x : -a.x; + double y = (a.y >= 0) ? a.y : -a.y; + double z = (a.z >= 0) ? a.z : -a.z; + return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); + } + + static double3 cross_poly(Span poly); +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index 0022823b3de..28cb5f6d84b 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -155,8 +155,7 @@ double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL( * * \note can return NULL when the size is not big enough */ -char *BLI_current_working_dir(char *dir, const size_t maxncpy) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); +char *BLI_current_working_dir(char *dir, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); eFileAttributes BLI_file_attributes(const char *path); /** \} */ diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh new file mode 100644 index 00000000000..bb4229db86e --- /dev/null +++ b/source/blender/blenlib/BLI_float2.hh @@ -0,0 +1,218 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +#include "BLI_float3.hh" + +namespace blender { + +struct float2 { + float x, y; + + float2() = default; + + float2(const float *ptr) : x{ptr[0]}, y{ptr[1]} + { + } + + explicit float2(float value) : x(value), y(value) + { + } + + explicit float2(int value) : x(value), y(value) + { + } + + float2(float x, float y) : x(x), y(y) + { + } + + float2(const float3 &other) : x(other.x), y(other.y) + { + } + + operator float *() + { + return &x; + } + + operator const float *() const + { + return &x; + } + + float length() const + { + return len_v2(*this); + } + + float length_squared() const + { + return len_squared_v2(*this); + } + + bool is_zero() const + { + return this->x == 0.0f && this->y == 0.0f; + } + + float2 &operator+=(const float2 &other) + { + x += other.x; + y += other.y; + return *this; + } + + float2 &operator-=(const float2 &other) + { + x -= other.x; + y -= other.y; + return *this; + } + + float2 &operator*=(float factor) + { + x *= factor; + y *= factor; + return *this; + } + + float2 &operator/=(float divisor) + { + x /= divisor; + y /= divisor; + return *this; + } + + uint64_t hash() const + { + uint64_t x1 = *reinterpret_cast(&x); + uint64_t x2 = *reinterpret_cast(&y); + return (x1 * 812519) ^ (x2 * 707951); + } + + friend float2 operator+(const float2 &a, const float2 &b) + { + return {a.x + b.x, a.y + b.y}; + } + + friend float2 operator-(const float2 &a, const float2 &b) + { + return {a.x - b.x, a.y - b.y}; + } + + friend float2 operator-(const float2 &a, const float &b) + { + return {a.x - b, a.y - b}; + } + + friend float2 operator*(const float2 &a, float b) + { + return {a.x * b, a.y * b}; + } + + friend float2 operator/(const float2 &a, float b) + { + BLI_assert(b != 0.0f); + return {a.x / b, a.y / b}; + } + + friend float2 operator*(float a, const float2 &b) + { + return b * a; + } + + friend std::ostream &operator<<(std::ostream &stream, const float2 &v) + { + stream << "(" << v.x << ", " << v.y << ")"; + return stream; + } + + static float2 safe_divide(const float2 &a, const float b) + { + return (b != 0.0f) ? a / b : float2(0.0f); + } + + static float2 floor(const float2 &a) + { + return float2(floorf(a.x), floorf(a.y)); + } + + /** + * Returns a normalized vector. The original vector is not changed. + */ + float2 normalized() const + { + float2 result; + normalize_v2_v2(result, *this); + return result; + } + + static float dot(const float2 &a, const float2 &b) + { + return a.x * b.x + a.y * b.y; + } + + static float2 interpolate(const float2 &a, const float2 &b, float t) + { + return a * (1 - t) + b * t; + } + + static float2 abs(const float2 &a) + { + return float2(fabsf(a.x), fabsf(a.y)); + } + + static float distance(const float2 &a, const float2 &b) + { + return (a - b).length(); + } + + static float distance_squared(const float2 &a, const float2 &b) + { + float2 diff = a - b; + return float2::dot(diff, diff); + } + + struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + float lambda; + float mu; + }; + + static isect_result isect_seg_seg(const float2 &v1, + const float2 &v2, + const float2 &v3, + const float2 &v4); + + friend bool operator==(const float2 &a, const float2 &b) + { + return a.x == b.x && a.y == b.y; + } + + friend bool operator!=(const float2 &a, const float2 &b) + { + return !(a == b); + } +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh new file mode 100644 index 00000000000..765f524fb31 --- /dev/null +++ b/source/blender/blenlib/BLI_float3.hh @@ -0,0 +1,320 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +#include + +#include "BLI_math_vector.h" + +namespace blender { + +struct float3 { + float x, y, z; + + float3() = default; + + float3(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} + { + } + + float3(const float (*ptr)[3]) : float3(static_cast(ptr[0])) + { + } + + explicit float3(float value) : x(value), y(value), z(value) + { + } + + explicit float3(int value) : x(value), y(value), z(value) + { + } + + float3(float x, float y, float z) : x{x}, y{y}, z{z} + { + } + + operator const float *() const + { + return &x; + } + + operator float *() + { + return &x; + } + + friend float3 operator+(const float3 &a, const float3 &b) + { + return {a.x + b.x, a.y + b.y, a.z + b.z}; + } + + friend float3 operator+(const float3 &a, const float &b) + { + return {a.x + b, a.y + b, a.z + b}; + } + + float3 &operator+=(const float3 &b) + { + this->x += b.x; + this->y += b.y; + this->z += b.z; + return *this; + } + + friend float3 operator-(const float3 &a, const float3 &b) + { + return {a.x - b.x, a.y - b.y, a.z - b.z}; + } + + friend float3 operator-(const float3 &a) + { + return {-a.x, -a.y, -a.z}; + } + + friend float3 operator-(const float3 &a, const float &b) + { + return {a.x - b, a.y - b, a.z - b}; + } + + float3 &operator-=(const float3 &b) + { + this->x -= b.x; + this->y -= b.y; + this->z -= b.z; + return *this; + } + + float3 &operator*=(float scalar) + { + this->x *= scalar; + this->y *= scalar; + this->z *= scalar; + return *this; + } + + float3 &operator*=(const float3 &other) + { + this->x *= other.x; + this->y *= other.y; + this->z *= other.z; + return *this; + } + + friend float3 operator*(const float3 &a, const float3 &b) + { + return {a.x * b.x, a.y * b.y, a.z * b.z}; + } + + friend float3 operator*(const float3 &a, float b) + { + return {a.x * b, a.y * b, a.z * b}; + } + + friend float3 operator*(float a, const float3 &b) + { + return b * a; + } + + friend float3 operator/(const float3 &a, float b) + { + BLI_assert(b != 0.0f); + return {a.x / b, a.y / b, a.z / b}; + } + + friend std::ostream &operator<<(std::ostream &stream, const float3 &v) + { + stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; + return stream; + } + + friend bool operator==(const float3 &a, const float3 &b) + { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + + friend bool operator!=(const float3 &a, const float3 &b) + { + return !(a == b); + } + + float normalize_and_get_length() + { + return normalize_v3(*this); + } + + /** + * Normalizes the vector in place. + */ + void normalize() + { + normalize_v3(*this); + } + + /** + * Returns a normalized vector. The original vector is not changed. + */ + float3 normalized() const + { + float3 result; + normalize_v3_v3(result, *this); + return result; + } + + float length() const + { + return len_v3(*this); + } + + float length_squared() const + { + return len_squared_v3(*this); + } + + bool is_zero() const + { + return this->x == 0.0f && this->y == 0.0f && this->z == 0.0f; + } + + void reflect(const float3 &normal) + { + *this = this->reflected(normal); + } + + float3 reflected(const float3 &normal) const + { + float3 result; + reflect_v3_v3v3(result, *this, normal); + return result; + } + + static float3 refract(const float3 &incident, const float3 &normal, const float eta) + { + float3 result; + float k = 1.0f - eta * eta * (1.0f - dot(normal, incident) * dot(normal, incident)); + if (k < 0.0f) { + result = float3(0.0f); + } + else { + result = eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal; + } + return result; + } + + static float3 faceforward(const float3 &vector, const float3 &incident, const float3 &reference) + { + return dot(reference, incident) < 0.0f ? vector : -vector; + } + + static float3 safe_divide(const float3 &a, const float3 &b) + { + float3 result; + result.x = (b.x == 0.0f) ? 0.0f : a.x / b.x; + result.y = (b.y == 0.0f) ? 0.0f : a.y / b.y; + result.z = (b.z == 0.0f) ? 0.0f : a.z / b.z; + return result; + } + + static float3 min(const float3 &a, const float3 &b) + { + return {a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z}; + } + + static float3 max(const float3 &a, const float3 &b) + { + return {a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z}; + } + + static void min_max(const float3 &vector, float3 &min, float3 &max) + { + min = float3::min(vector, min); + max = float3::max(vector, max); + } + + static float3 safe_divide(const float3 &a, const float b) + { + return (b != 0.0f) ? a / b : float3(0.0f); + } + + static float3 floor(const float3 &a) + { + return float3(floorf(a.x), floorf(a.y), floorf(a.z)); + } + + void invert() + { + x = -x; + y = -y; + z = -z; + } + + uint64_t hash() const + { + uint64_t x1 = *reinterpret_cast(&x); + uint64_t x2 = *reinterpret_cast(&y); + uint64_t x3 = *reinterpret_cast(&z); + return (x1 * 435109) ^ (x2 * 380867) ^ (x3 * 1059217); + } + + static float dot(const float3 &a, const float3 &b) + { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static float3 cross_high_precision(const float3 &a, const float3 &b) + { + float3 result; + cross_v3_v3v3_hi_prec(result, a, b); + return result; + } + + static float3 cross(const float3 &a, const float3 &b) + { + float3 result; + cross_v3_v3v3(result, a, b); + return result; + } + + static float3 project(const float3 &a, const float3 &b) + { + float3 result; + project_v3_v3v3(result, a, b); + return result; + } + + static float distance(const float3 &a, const float3 &b) + { + return (a - b).length(); + } + + static float distance_squared(const float3 &a, const float3 &b) + { + float3 diff = a - b; + return float3::dot(diff, diff); + } + + static float3 interpolate(const float3 &a, const float3 &b, float t) + { + return a * (1 - t) + b * t; + } + + static float3 abs(const float3 &a) + { + return float3(fabsf(a.x), fabsf(a.y), fabsf(a.z)); + } +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_float4.hh b/source/blender/blenlib/BLI_float4.hh new file mode 100644 index 00000000000..5b487f6d029 --- /dev/null +++ b/source/blender/blenlib/BLI_float4.hh @@ -0,0 +1,138 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +namespace blender { + +struct float4 { + float x, y, z, w; + + float4() = default; + + float4(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]}, w{ptr[3]} + { + } + + explicit float4(float value) : x(value), y(value), z(value), w(value) + { + } + + explicit float4(int value) : x(value), y(value), z(value), w(value) + { + } + + float4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) + { + } + + operator float *() + { + return &x; + } + + friend float4 operator+(const float4 &a, const float &b) + { + return {a.x + b, a.y + b, a.z + b, a.w + b}; + } + + operator const float *() const + { + return &x; + } + + float4 &operator+=(const float4 &other) + { + x += other.x; + y += other.y; + z += other.z; + w += other.w; + return *this; + } + + friend float4 operator-(const float4 &a, const float4 &b) + { + return {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; + } + + friend float4 operator-(const float4 &a, const float &b) + { + return {a.x - b, a.y - b, a.z - b, a.w - b}; + } + + friend float4 operator+(const float4 &a, const float4 &b) + { + return {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; + } + + friend float4 operator/(const float4 &a, float f) + { + BLI_assert(f != 0.0f); + return a * (1.0f / f); + } + + float4 &operator*=(float factor) + { + x *= factor; + y *= factor; + z *= factor; + w *= factor; + return *this; + } + + friend float4 operator*(const float4 &a, float b) + { + return {a.x * b, a.y * b, a.z * b, a.w * b}; + } + + friend float4 operator*(float a, const float4 &b) + { + return b * a; + } + + float length() const + { + return len_v4(*this); + } + + static float distance(const float4 &a, const float4 &b) + { + return (a - b).length(); + } + + static float4 safe_divide(const float4 &a, const float b) + { + return (b != 0.0f) ? a / b : float4(0.0f); + } + + static float4 interpolate(const float4 &a, const float4 &b, float t) + { + return a * (1 - t) + b * t; + } + + static float4 floor(const float4 &a) + { + return float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w)); + } + + static float4 normalize(const float4 &a) + { + const float t = len_v4(a); + return (t != 0.0f) ? a / t : float4(0.0f); + } +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_float4x4.hh b/source/blender/blenlib/BLI_float4x4.hh index 81c969d02d0..b7f839f4ddf 100644 --- a/source/blender/blenlib/BLI_float4x4.hh +++ b/source/blender/blenlib/BLI_float4x4.hh @@ -16,9 +16,8 @@ #pragma once +#include "BLI_float3.hh" #include "BLI_math_matrix.h" -#include "BLI_math_vec_types.hh" -#include "BLI_math_vector.h" namespace blender { @@ -64,7 +63,7 @@ struct float4x4 { * Without the negation, the result would be a so called improper rotation. That means it * contains a reflection. Such an improper rotation matrix could not be converted to another * representation of a rotation such as euler angles. */ - const float3 cross = -math::cross(forward, up); + const float3 cross = -float3::cross(forward, up); float4x4 matrix; matrix.values[0][0] = forward.x; diff --git a/source/blender/blenlib/BLI_gsqueue.h b/source/blender/blenlib/BLI_gsqueue.h index 8b32c09b56b..a35c743c80b 100644 --- a/source/blender/blenlib/BLI_gsqueue.h +++ b/source/blender/blenlib/BLI_gsqueue.h @@ -31,7 +31,7 @@ extern "C" { typedef struct _GSQueue GSQueue; -GSQueue *BLI_gsqueue_new(const size_t elem_size); +GSQueue *BLI_gsqueue_new(size_t elem_size); /** * Returns true if the queue is empty, false otherwise. */ diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 64852b95ae4..f73d1f22502 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -85,7 +85,7 @@ void *BLI_findptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, - const size_t bytes_size, + size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** * Find the first item in the list that matches the given string, or the given index as fallback. @@ -96,7 +96,7 @@ void *BLI_listbase_bytes_find(const ListBase *listbase, */ void *BLI_listbase_string_or_index_find(const struct ListBase *listbase, const char *string, - const size_t string_offset, + size_t string_offset, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /* Find backwards. */ @@ -133,7 +133,7 @@ void *BLI_rfindptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_rfind(const ListBase *listbase, const void *bytes, - const size_t bytes_size, + size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** diff --git a/source/blender/blenlib/BLI_math_boolean.hh b/source/blender/blenlib/BLI_math_boolean.hh index 8cf93c82dec..20fd00b2aa4 100644 --- a/source/blender/blenlib/BLI_math_boolean.hh +++ b/source/blender/blenlib/BLI_math_boolean.hh @@ -21,11 +21,13 @@ * \brief Math vector functions needed specifically for mesh intersect and boolean. */ -#include "BLI_math_vec_types.hh" +#include "BLI_double2.hh" +#include "BLI_double3.hh" #ifdef WITH_GMP # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" +# include "BLI_mpq2.hh" +# include "BLI_mpq3.hh" #endif namespace blender { diff --git a/source/blender/blenlib/BLI_math_vec_mpq_types.hh b/source/blender/blenlib/BLI_math_vec_mpq_types.hh deleted file mode 100644 index 36eb0cac83c..00000000000 --- a/source/blender/blenlib/BLI_math_vec_mpq_types.hh +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#ifdef WITH_GMP - -# include "BLI_math_mpq.hh" -# include "BLI_math_vec_types.hh" - -namespace blender { - -using mpq2 = vec_base; -using mpq3 = vec_base; - -namespace math { - -uint64_t hash_mpq_class(const mpq_class &value); - -template<> inline uint64_t vector_hash(const mpq2 &vec) -{ - return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33); -} - -template<> inline uint64_t vector_hash(const mpq3 &vec) -{ - return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33) ^ (hash_mpq_class(vec.z) * 33 * 37); -} - -/** - * Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ -template<> inline mpq_class length(const mpq2 &a) -{ - return mpq_class(sqrt(length_squared(a).get_d())); -} - -/** - * Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ -template<> inline mpq_class length(const mpq3 &a) -{ - return mpq_class(sqrt(length_squared(a).get_d())); -} - -/** - * The buffer avoids allocating a temporary variable. - */ -inline mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) -{ - buffer = a; - buffer -= b; - return dot(buffer, buffer); -} - -/** - * The buffer avoids allocating a temporary variable. - */ -inline mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) -{ - buffer = a; - buffer *= b; - buffer.x += buffer.y; - buffer.x += buffer.z; - return buffer.x; -} - -} // namespace math - -} // namespace blender - -#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh deleted file mode 100644 index 52aacd294e4..00000000000 --- a/source/blender/blenlib/BLI_math_vec_types.hh +++ /dev/null @@ -1,566 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright 2022, Blender Foundation. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include -#include -#include -#include - -#include "BLI_math_vector.hh" -#include "BLI_utildefines.h" - -namespace blender { - -/* clang-format off */ -template -using as_uint_type = std::conditional_t>>>; -/* clang-format on */ - -template struct vec_struct_base { - std::array values; -}; - -template struct vec_struct_base { - T x, y; -}; - -template struct vec_struct_base { - T x, y, z; -}; - -template struct vec_struct_base { - T x, y, z, w; -}; - -template struct vec_base : public vec_struct_base { - - static constexpr int type_length = Size; - - using base_type = T; - using uint_type = vec_base, Size>; - - vec_base() = default; - - explicit vec_base(uint value) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(value); - } - } - - explicit vec_base(int value) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(value); - } - } - - explicit vec_base(float value) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(value); - } - } - - explicit vec_base(double value) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(value); - } - } - -/* Workaround issue with template BLI_ENABLE_IF((Size == 2)) not working. */ -#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test)) - - template vec_base(T _x, T _y) - { - (*this)[0] = _x; - (*this)[1] = _y; - } - - template vec_base(T _x, T _y, T _z) - { - (*this)[0] = _x; - (*this)[1] = _y; - (*this)[2] = _z; - } - - template vec_base(T _x, T _y, T _z, T _w) - { - (*this)[0] = _x; - (*this)[1] = _y; - (*this)[2] = _z; - (*this)[3] = _w; - } - - /** Mixed scalar-vector constructors. */ - - template - constexpr vec_base(const vec_base &xy, T z) - : vec_base(static_cast(xy.x), static_cast(xy.y), z) - { - } - - template - constexpr vec_base(T x, const vec_base &yz) - : vec_base(x, static_cast(yz.x), static_cast(yz.y)) - { - } - - template - vec_base(vec_base xyz, T w) - : vec_base( - static_cast(xyz.x), static_cast(xyz.y), static_cast(xyz.z), static_cast(w)) - { - } - - template - vec_base(T x, vec_base yzw) - : vec_base( - static_cast(x), static_cast(yzw.x), static_cast(yzw.y), static_cast(yzw.z)) - { - } - - template - vec_base(vec_base xy, vec_base zw) - : vec_base( - static_cast(xy.x), static_cast(xy.y), static_cast(zw.x), static_cast(zw.y)) - { - } - - template - vec_base(vec_base xy, T z, T w) - : vec_base(static_cast(xy.x), static_cast(xy.y), static_cast(z), static_cast(w)) - { - } - - template - vec_base(T x, vec_base yz, T w) - : vec_base(static_cast(x), static_cast(yz.x), static_cast(yz.y), static_cast(w)) - { - } - - template - vec_base(T x, T y, vec_base zw) - : vec_base(static_cast(x), static_cast(y), static_cast(zw.x), static_cast(zw.y)) - { - } - - /** Masking. */ - - template Size)> - explicit vec_base(const vec_base &other) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(other[i]); - } - } - -#undef BLI_ENABLE_IF_VEC - - /** Conversion from pointers (from C-style vectors). */ - - vec_base(const T *ptr) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = ptr[i]; - } - } - - vec_base(const T (*ptr)[Size]) : vec_base(static_cast(ptr[0])) - { - } - - /** Conversion from other vector types. */ - - template explicit vec_base(const vec_base &vec) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(vec[i]); - } - } - - /** C-style pointer dereference. */ - - operator const T *() const - { - return reinterpret_cast(this); - } - - operator T *() - { - return reinterpret_cast(this); - } - - /** Array access. */ - - const T &operator[](int index) const - { - BLI_assert(index >= 0); - BLI_assert(index < Size); - return reinterpret_cast(this)[index]; - } - - T &operator[](int index) - { - BLI_assert(index >= 0); - BLI_assert(index < Size); - return reinterpret_cast(this)[index]; - } - - /** Internal Operators Macro. */ - -#define BLI_INT_OP(_T) template))> - -#define BLI_VEC_OP_IMPL(_result, _i, _op) \ - vec_base _result; \ - for (int _i = 0; _i < Size; _i++) { \ - _op; \ - } \ - return _result; - -#define BLI_VEC_OP_IMPL_SELF(_i, _op) \ - for (int _i = 0; _i < Size; _i++) { \ - _op; \ - } \ - return *this; - - /** Arithmetic operators. */ - - friend vec_base operator+(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b[i]); - } - - friend vec_base operator+(const vec_base &a, const T &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b); - } - - friend vec_base operator+(const T &a, const vec_base &b) - { - return b + a; - } - - vec_base &operator+=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b[i]); - } - - vec_base &operator+=(const T &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b); - } - - friend vec_base operator-(const vec_base &a) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = -a[i]); - } - - friend vec_base operator-(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b[i]); - } - - friend vec_base operator-(const vec_base &a, const T &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b); - } - - friend vec_base operator-(const T &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a - b[i]); - } - - vec_base &operator-=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b[i]); - } - - vec_base &operator-=(const T &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b); - } - - friend vec_base operator*(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b[i]); - } - - friend vec_base operator*(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b); - } - - friend vec_base operator*(T a, const vec_base &b) - { - return b * a; - } - - vec_base &operator*=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b); - } - - vec_base &operator*=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b[i]); - } - - friend vec_base operator/(const vec_base &a, const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b[i]); - } - - friend vec_base operator/(const vec_base &a, T b) - { - BLI_assert(b != T(0)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b); - } - - friend vec_base operator/(T a, const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a / b[i]); - } - - vec_base &operator/=(T b) - { - BLI_assert(b != T(0)); - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b); - } - - vec_base &operator/=(const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b[i]); - } - - /** Binary operators. */ - - BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b[i]); - } - - BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b); - } - - BLI_INT_OP(T) friend vec_base operator&(T a, const vec_base &b) - { - return b & a; - } - - BLI_INT_OP(T) vec_base &operator&=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b); - } - - BLI_INT_OP(T) vec_base &operator&=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b[i]); - } - - BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b[i]); - } - - BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b); - } - - BLI_INT_OP(T) friend vec_base operator|(T a, const vec_base &b) - { - return b | a; - } - - BLI_INT_OP(T) vec_base &operator|=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b); - } - - BLI_INT_OP(T) vec_base &operator|=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b[i]); - } - - BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b[i]); - } - - BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b); - } - - BLI_INT_OP(T) friend vec_base operator^(T a, const vec_base &b) - { - return b ^ a; - } - - BLI_INT_OP(T) vec_base &operator^=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b); - } - - BLI_INT_OP(T) vec_base &operator^=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b[i]); - } - - BLI_INT_OP(T) friend vec_base operator~(const vec_base &a) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = ~a[i]); - } - - /** Bit-shift operators. */ - - BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b[i]); - } - - BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b); - } - - BLI_INT_OP(T) vec_base &operator<<=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b); - } - - BLI_INT_OP(T) vec_base &operator<<=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b[i]); - } - - BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b[i]); - } - - BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b); - } - - BLI_INT_OP(T) vec_base &operator>>=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b); - } - - BLI_INT_OP(T) vec_base &operator>>=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b[i]); - } - - /** Modulo operators. */ - - BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b[i]); - } - - BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, T b) - { - BLI_assert(b != 0); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b); - } - - BLI_INT_OP(T) friend vec_base operator%(T a, const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a % b[i]); - } - -#undef BLI_INT_OP -#undef BLI_VEC_OP_IMPL -#undef BLI_VEC_OP_IMPL_SELF - - /** Compare. */ - - friend bool operator==(const vec_base &a, const vec_base &b) - { - for (int i = 0; i < Size; i++) { - if (a[i] != b[i]) { - return false; - } - } - return true; - } - - friend bool operator!=(const vec_base &a, const vec_base &b) - { - return !(a == b); - } - - /** Misc. */ - - uint64_t hash() const - { - return math::vector_hash(*this); - } - - friend std::ostream &operator<<(std::ostream &stream, const vec_base &v) - { - stream << "("; - for (int i = 0; i < Size; i++) { - stream << v[i]; - if (i != Size - 1) { - stream << ", "; - } - } - stream << ")"; - return stream; - } -}; - -using int2 = vec_base; -using int3 = vec_base; -using int4 = vec_base; - -using uint2 = vec_base; -using uint3 = vec_base; -using uint4 = vec_base; - -using float2 = vec_base; -using float3 = vec_base; -using float4 = vec_base; - -using double2 = vec_base; -using double3 = vec_base; -using double4 = vec_base; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_math_vector.hh b/source/blender/blenlib/BLI_math_vector.hh deleted file mode 100644 index e7d765df842..00000000000 --- a/source/blender/blenlib/BLI_math_vector.hh +++ /dev/null @@ -1,399 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright 2022, Blender Foundation. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include -#include - -#include "BLI_math_base_safe.h" -#include "BLI_math_vector.h" -#include "BLI_span.hh" -#include "BLI_utildefines.h" - -#ifdef WITH_GMP -# include "BLI_math_mpq.hh" -#endif - -namespace blender::math { - -#ifndef NDEBUG -# define BLI_ASSERT_UNIT(v) \ - { \ - const float _test_unit = length_squared(v); \ - BLI_assert(!(std::abs(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \ - !(std::abs(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \ - } \ - (void)0 -#else -# define BLI_ASSERT_UNIT(v) (void)(v) -#endif - -#define bT typename T::base_type - -#ifdef WITH_GMP -# define BLI_ENABLE_IF_FLT_VEC(T) \ - BLI_ENABLE_IF((std::is_floating_point_v || \ - std::is_same_v)) -#else -# define BLI_ENABLE_IF_FLT_VEC(T) BLI_ENABLE_IF((std::is_floating_point_v)) -#endif - -#define BLI_ENABLE_IF_INT_VEC(T) BLI_ENABLE_IF((std::is_integral_v)) - -template inline bool is_zero(const T &a) -{ - for (int i = 0; i < T::type_length; i++) { - if (a[i] != bT(0)) { - return false; - } - } - return true; -} - -template inline bool is_any_zero(const T &a) -{ - for (int i = 0; i < T::type_length; i++) { - if (a[i] == bT(0)) { - return true; - } - } - return false; -} - -template inline T abs(const T &a) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = a[i] >= 0 ? a[i] : -a[i]; - } - return result; -} - -template inline T min(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = a[i] < b[i] ? a[i] : b[i]; - } - return result; -} - -template inline T max(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = a[i] > b[i] ? a[i] : b[i]; - } - return result; -} - -template inline T clamp(const T &a, const T &min_v, const T &max_v) -{ - T result = a; - for (int i = 0; i < T::type_length; i++) { - CLAMP(result[i], min_v[i], max_v[i]); - } - return result; -} - -template inline T clamp(const T &a, const bT &min_v, const bT &max_v) -{ - T result = a; - for (int i = 0; i < T::type_length; i++) { - CLAMP(result[i], min_v, max_v); - } - return result; -} - -template inline T mod(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - BLI_assert(b[i] != 0); - result[i] = std::fmod(a[i], b[i]); - } - return result; -} - -template inline T mod(const T &a, bT b) -{ - BLI_assert(b != 0); - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = std::fmod(a[i], b); - } - return result; -} - -template inline T safe_mod(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = (b[i] != 0) ? std::fmod(a[i], b[i]) : 0; - } - return result; -} - -template inline T safe_mod(const T &a, bT b) -{ - if (b == 0) { - return T(0.0f); - } - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = std::fmod(a[i], b); - } - return result; -} - -template inline void min_max(const T &vector, T &min_vec, T &max_vec) -{ - min_vec = min(vector, min_vec); - max_vec = max(vector, max_vec); -} - -template inline T safe_divide(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = (b[i] == 0) ? 0 : a[i] / b[i]; - } - return result; -} - -template inline T safe_divide(const T &a, const bT b) -{ - return (b != 0) ? a / b : T(0.0f); -} - -template inline T floor(const T &a) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = std::floor(a[i]); - } - return result; -} - -template inline T ceil(const T &a) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = std::ceil(a[i]); - } - return result; -} - -template inline T fract(const T &a) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = a[i] - std::floor(a[i]); - } - return result; -} - -template inline bT dot(const T &a, const T &b) -{ - bT result = a[0] * b[0]; - for (int i = 1; i < T::type_length; i++) { - result += a[i] * b[i]; - } - return result; -} - -template inline bT length_manhattan(const T &a) -{ - bT result = std::abs(a[0]); - for (int i = 1; i < T::type_length; i++) { - result += std::abs(a[i]); - } - return result; -} - -template inline bT length_squared(const T &a) -{ - return dot(a, a); -} - -template inline bT length(const T &a) -{ - return std::sqrt(length_squared(a)); -} - -template inline bT distance_manhattan(const T &a, const T &b) -{ - return length_manhattan(a - b); -} - -template inline bT distance_squared(const T &a, const T &b) -{ - return length_squared(a - b); -} - -template inline bT distance(const T &a, const T &b) -{ - return length(a - b); -} - -template uint64_t vector_hash(const T &vec) -{ - BLI_STATIC_ASSERT(T::type_length <= 4, "Longer types need to implement vector_hash themself."); - const typename T::uint_type &uvec = *reinterpret_cast(&vec); - uint64_t result; - result = uvec[0] * uint64_t(435109); - if constexpr (T::type_length > 1) { - result ^= uvec[1] * uint64_t(380867); - } - if constexpr (T::type_length > 2) { - result ^= uvec[2] * uint64_t(1059217); - } - if constexpr (T::type_length > 3) { - result ^= uvec[3] * uint64_t(2002613); - } - return result; -} - -template inline T reflect(const T &incident, const T &normal) -{ - BLI_ASSERT_UNIT(normal); - return incident - 2.0 * dot(normal, incident) * normal; -} - -template -inline T refract(const T &incident, const T &normal, const bT eta) -{ - float dot_ni = dot(normal, incident); - float k = 1.0f - eta * eta * (1.0f - dot_ni * dot_ni); - if (k < 0.0f) { - return T(0.0f); - } - return eta * incident - (eta * dot_ni + sqrt(k)) * normal; -} - -template inline T project(const T &p, const T &v_proj) -{ - if (UNLIKELY(is_zero(v_proj))) { - return T(0.0f); - } - return v_proj * (dot(p, v_proj) / dot(v_proj, v_proj)); -} - -template -inline T normalize_and_get_length(const T &v, bT &out_length) -{ - out_length = length_squared(v); - /* A larger value causes normalize errors in a scaled down models with camera extreme close. */ - constexpr bT threshold = std::is_same_v ? 1.0e-70 : 1.0e-35f; - if (out_length > threshold) { - out_length = sqrt(out_length); - return v / out_length; - } - /* Either the vector is small or one of it's values contained `nan`. */ - out_length = 0.0; - return T(0.0); -} - -template inline T normalize(const T &v) -{ - bT len; - return normalize_and_get_length(v, len); -} - -template -inline T cross(const T &a, const T &b) -{ - return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; -} - -template)), - BLI_ENABLE_IF((T::type_length == 3))> -inline T cross_high_precision(const T &a, const T &b) -{ - return {(float)((double)a.y * b.z - (double)a.z * b.y), - (float)((double)a.z * b.x - (double)a.x * b.z), - (float)((double)a.x * b.y - (double)a.y * b.x)}; -} - -template -inline T cross_poly(Span poly) -{ - /* Newell's Method. */ - int nv = static_cast(poly.size()); - if (nv < 3) { - return T(0, 0, 0); - } - const T *v_prev = &poly[nv - 1]; - const T *v_curr = &poly[0]; - T n(0, 0, 0); - for (int i = 0; i < nv;) { - n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); - n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); - n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); - v_prev = v_curr; - ++i; - if (i < nv) { - v_curr = &poly[i]; - } - } - return n; -} - -template inline T interpolate(const T &a, const T &b, bT t) -{ - return a * (1 - t) + b * t; -} - -template -inline T faceforward(const T &vector, const T &incident, const T &reference) -{ - return (dot(reference, incident) < 0) ? vector : -vector; -} - -template inline int dominant_axis(const T &a) -{ - T b = abs(a); - return ((b.x > b.y) ? ((b.x > b.z) ? 0 : 2) : ((b.y > b.z) ? 1 : 2)); -} - -/** Intersections. */ - -template struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - bT lambda; -}; - -template -isect_result isect_seg_seg(const T &v1, const T &v2, const T &v3, const T &v4); - -#undef BLI_ENABLE_IF_FLT_VEC -#undef BLI_ENABLE_IF_INT_VEC -#undef bT - -} // namespace blender::math diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h index 4ac4712bc8c..bcfe2efc5e5 100644 --- a/source/blender/blenlib/BLI_memarena.h +++ b/source/blender/blenlib/BLI_memarena.h @@ -38,13 +38,13 @@ extern "C" { struct MemArena; typedef struct MemArena MemArena; -struct MemArena *BLI_memarena_new(const size_t bufsize, +struct MemArena *BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC; void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_malloc(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_calloc(struct MemArena *ma) ATTR_NONNULL(1); -void BLI_memarena_use_align(struct MemArena *ma, const size_t align) ATTR_NONNULL(1); +void BLI_memarena_use_align(struct MemArena *ma, size_t align) ATTR_NONNULL(1); void *BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2); void *BLI_memarena_calloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT diff --git a/source/blender/blenlib/BLI_memory_utils.h b/source/blender/blenlib/BLI_memory_utils.h index 79e25e26040..09d8f646905 100644 --- a/source/blender/blenlib/BLI_memory_utils.h +++ b/source/blender/blenlib/BLI_memory_utils.h @@ -29,7 +29,7 @@ extern "C" { /* it may be defined already */ #ifndef __BLI_UTILDEFINES_H__ -bool BLI_memory_is_zero(const void *arr, const size_t size); +bool BLI_memory_is_zero(const void *arr, size_t size); #endif #ifdef __cplusplus diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh index 9a5be79b61e..37691017c12 100644 --- a/source/blender/blenlib/BLI_memory_utils.hh +++ b/source/blender/blenlib/BLI_memory_utils.hh @@ -557,4 +557,13 @@ Container &move_assign_container(Container &dst, Container &&src) noexcept( return dst; } +/** + * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for + * SFINAE in common cases. + * + * \note Often one has to invoke this macro with double parenthesis. That's because the condition + * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. + */ +#define BLI_ENABLE_IF(condition) typename std::enable_if_t * = nullptr + } // namespace blender diff --git a/source/blender/blenlib/BLI_mesh_intersect.hh b/source/blender/blenlib/BLI_mesh_intersect.hh index 0ebee6f16a8..71a8abb822f 100644 --- a/source/blender/blenlib/BLI_mesh_intersect.hh +++ b/source/blender/blenlib/BLI_mesh_intersect.hh @@ -28,11 +28,12 @@ # include # include "BLI_array.hh" +# include "BLI_double3.hh" +# include "BLI_float3.hh" # include "BLI_index_range.hh" # include "BLI_map.hh" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" +# include "BLI_mpq3.hh" # include "BLI_span.hh" # include "BLI_utility_mixins.hh" # include "BLI_vector.hh" diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh new file mode 100644 index 00000000000..18bc8821d9c --- /dev/null +++ b/source/blender/blenlib/BLI_mpq2.hh @@ -0,0 +1,184 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#ifdef WITH_GMP + +# include "BLI_math_mpq.hh" +# include "BLI_mpq3.hh" + +namespace blender { + +struct mpq2 { + mpq_class x, y; + + mpq2() = default; + + mpq2(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]} + { + } + + mpq2(mpq_class x, mpq_class y) : x(x), y(y) + { + } + + mpq2(const mpq2 &other) : x(other.x), y(other.y) + { + } + + mpq2(mpq2 &&other) noexcept : x(std::move(other.x)), y(std::move(other.y)) + { + } + + ~mpq2() = default; + + mpq2 &operator=(const mpq2 &other) + { + if (this != &other) { + x = other.x; + y = other.y; + } + return *this; + } + + mpq2 &operator=(mpq2 &&other) noexcept + { + x = std::move(other.x); + y = std::move(other.y); + return *this; + } + + mpq2(const mpq3 &other) : x(other.x), y(other.y) + { + } + + operator mpq_class *() + { + return &x; + } + + operator const mpq_class *() const + { + return &x; + } + + /** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ + mpq_class length() const + { + mpq_class lsquared = dot(*this, *this); + return mpq_class(sqrt(lsquared.get_d())); + } + + friend mpq2 operator+(const mpq2 &a, const mpq2 &b) + { + return {a.x + b.x, a.y + b.y}; + } + + friend mpq2 operator-(const mpq2 &a, const mpq2 &b) + { + return {a.x - b.x, a.y - b.y}; + } + + friend mpq2 operator*(const mpq2 &a, mpq_class b) + { + return {a.x * b, a.y * b}; + } + + friend mpq2 operator/(const mpq2 &a, mpq_class b) + { + BLI_assert(b != 0); + return {a.x / b, a.y / b}; + } + + friend mpq2 operator*(mpq_class a, const mpq2 &b) + { + return b * a; + } + + friend bool operator==(const mpq2 &a, const mpq2 &b) + { + return a.x == b.x && a.y == b.y; + } + + friend bool operator!=(const mpq2 &a, const mpq2 &b) + { + return a.x != b.x || a.y != b.y; + } + + friend std::ostream &operator<<(std::ostream &stream, const mpq2 &v) + { + stream << "(" << v.x << ", " << v.y << ")"; + return stream; + } + + static mpq_class dot(const mpq2 &a, const mpq2 &b) + { + return a.x * b.x + a.y * b.y; + } + + static mpq2 interpolate(const mpq2 &a, const mpq2 &b, mpq_class t) + { + return a * (1 - t) + b * t; + } + + static mpq2 abs(const mpq2 &a) + { + mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; + mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; + return mpq2(abs_x, abs_y); + } + + static mpq_class distance(const mpq2 &a, const mpq2 &b) + { + return (a - b).length(); + } + + static mpq_class distance_squared(const mpq2 &a, const mpq2 &b) + { + mpq2 diff = a - b; + return dot(diff, diff); + } + + struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + mpq_class lambda; + }; + + static isect_result isect_seg_seg(const mpq2 &v1, + const mpq2 &v2, + const mpq2 &v3, + const mpq2 &v4); + + /** There is a sensible use for hashing on exact arithmetic types. */ + uint64_t hash() const; +}; + +} // namespace blender + +#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_mpq3.hh b/source/blender/blenlib/BLI_mpq3.hh new file mode 100644 index 00000000000..b9eda2ad7e1 --- /dev/null +++ b/source/blender/blenlib/BLI_mpq3.hh @@ -0,0 +1,297 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#ifdef WITH_GMP + +# include + +# include "BLI_math.h" +# include "BLI_math_mpq.hh" +# include "BLI_span.hh" + +namespace blender { + +struct mpq3 { + mpq_class x, y, z; + + mpq3() = default; + + mpq3(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} + { + } + + mpq3(const mpq_class (*ptr)[3]) : mpq3((const mpq_class *)ptr) + { + } + + explicit mpq3(mpq_class value) : x(value), y(value), z(value) + { + } + + explicit mpq3(int value) : x(value), y(value), z(value) + { + } + + mpq3(mpq_class x, mpq_class y, mpq_class z) : x{x}, y{y}, z{z} + { + } + + operator const mpq_class *() const + { + return &x; + } + + operator mpq_class *() + { + return &x; + } + + /* Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ + mpq_class normalize_and_get_length() + { + double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; + double len = normalize_v3_db(dv); + this->x = mpq_class(dv[0]); + this->y = mpq_class(dv[1]); + this->z = mpq_class(dv[2]); + return len; + } + + mpq3 normalized() const + { + double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; + double dr[3]; + normalize_v3_v3_db(dr, dv); + return mpq3(mpq_class(dr[0]), mpq_class(dr[1]), mpq_class(dr[2])); + } + + /* Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of double. + */ + mpq_class length() const + { + mpq_class lsquared = this->length_squared(); + double dsquared = lsquared.get_d(); + double d = sqrt(dsquared); + return mpq_class(d); + } + + mpq_class length_squared() const + { + return x * x + y * y + z * z; + } + + void reflect(const mpq3 &normal) + { + *this = this->reflected(normal); + } + + mpq3 reflected(const mpq3 &normal) const + { + mpq3 result; + const mpq_class dot2 = 2 * dot(*this, normal); + result.x = this->x - (dot2 * normal.x); + result.y = this->y - (dot2 * normal.y); + result.z = this->z - (dot2 * normal.z); + return result; + } + + static mpq3 safe_divide(const mpq3 &a, const mpq3 &b) + { + mpq3 result; + result.x = (b.x == 0) ? mpq_class(0) : a.x / b.x; + result.y = (b.y == 0) ? mpq_class(0) : a.y / b.y; + result.z = (b.z == 0) ? mpq_class(0) : a.z / b.z; + return result; + } + + void invert() + { + x = -x; + y = -y; + z = -z; + } + + friend mpq3 operator+(const mpq3 &a, const mpq3 &b) + { + return mpq3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + void operator+=(const mpq3 &b) + { + this->x += b.x; + this->y += b.y; + this->z += b.z; + } + + friend mpq3 operator-(const mpq3 &a, const mpq3 &b) + { + return mpq3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + friend mpq3 operator-(const mpq3 &a) + { + return mpq3(-a.x, -a.y, -a.z); + } + + void operator-=(const mpq3 &b) + { + this->x -= b.x; + this->y -= b.y; + this->z -= b.z; + } + + void operator*=(mpq_class scalar) + { + this->x *= scalar; + this->y *= scalar; + this->z *= scalar; + } + + void operator*=(const mpq3 &other) + { + this->x *= other.x; + this->y *= other.y; + this->z *= other.z; + } + + friend mpq3 operator*(const mpq3 &a, const mpq3 &b) + { + return {a.x * b.x, a.y * b.y, a.z * b.z}; + } + + friend mpq3 operator*(const mpq3 &a, const mpq_class &b) + { + return mpq3(a.x * b, a.y * b, a.z * b); + } + + friend mpq3 operator*(const mpq_class &a, const mpq3 &b) + { + return mpq3(a * b.x, a * b.y, a * b.z); + } + + friend mpq3 operator/(const mpq3 &a, const mpq_class &b) + { + BLI_assert(b != 0); + return mpq3(a.x / b, a.y / b, a.z / b); + } + + friend bool operator==(const mpq3 &a, const mpq3 &b) + { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + + friend bool operator!=(const mpq3 &a, const mpq3 &b) + { + return a.x != b.x || a.y != b.y || a.z != b.z; + } + + friend std::ostream &operator<<(std::ostream &stream, const mpq3 &v) + { + stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; + return stream; + } + + static mpq_class dot(const mpq3 &a, const mpq3 &b) + { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) + { + buffer = a; + buffer *= b; + buffer.x += buffer.y; + buffer.x += buffer.z; + return buffer.x; + } + + static mpq3 cross(const mpq3 &a, const mpq3 &b) + { + return mpq3(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]); + } + + static mpq3 cross_high_precision(const mpq3 &a, const mpq3 &b) + { + return cross(a, b); + } + + static mpq3 project(const mpq3 &a, const mpq3 &b) + { + const mpq_class mul = mpq3::dot(a, b) / mpq3::dot(b, b); + return mpq3(mul * b[0], mul * b[1], mul * b[2]); + } + + static mpq_class distance(const mpq3 &a, const mpq3 &b) + { + mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); + return diff.length(); + } + + static mpq_class distance_squared(const mpq3 &a, const mpq3 &b) + { + mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); + return mpq3::dot(diff, diff); + } + + static mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) + { + buffer = a; + buffer -= b; + return mpq3::dot(buffer, buffer); + } + + static mpq3 interpolate(const mpq3 &a, const mpq3 &b, mpq_class t) + { + mpq_class s = 1 - t; + return mpq3(a.x * s + b.x * t, a.y * s + b.y * t, a.z * s + b.z * t); + } + + static mpq3 abs(const mpq3 &a) + { + mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; + mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; + mpq_class abs_z = (a.z >= 0) ? a.z : -a.z; + return mpq3(abs_x, abs_y, abs_z); + } + + static int dominant_axis(const mpq3 &a) + { + mpq_class x = (a.x >= 0) ? a.x : -a.x; + mpq_class y = (a.y >= 0) ? a.y : -a.y; + mpq_class z = (a.z >= 0) ? a.z : -a.z; + return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); + } + + static mpq3 cross_poly(Span poly); + + /** There is a sensible use for hashing on exact arithmetic types. */ + uint64_t hash() const; +}; + +uint64_t hash_mpq_class(const mpq_class &value); + +} // namespace blender + +#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_noise.hh b/source/blender/blenlib/BLI_noise.hh index 297c65c250a..4f68ef17ca2 100644 --- a/source/blender/blenlib/BLI_noise.hh +++ b/source/blender/blenlib/BLI_noise.hh @@ -16,7 +16,9 @@ #pragma once -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" +#include "BLI_float4.hh" namespace blender::noise { diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 16f479cb3b8..658cc0c3825 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -75,16 +75,15 @@ bool BLI_make_existing_file(const char *name); * - Doesn't use CWD, or deal with relative paths. * - Only fill's in \a dir and \a file when they are non NULL. */ -void BLI_split_dirfile( - const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen); +void BLI_split_dirfile(const char *string, char *dir, char *file, size_t dirlen, size_t filelen); /** * Copies the parent directory part of string into `dir`, max length `dirlen`. */ -void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen); +void BLI_split_dir_part(const char *string, char *dir, size_t dirlen); /** * Copies the leaf filename part of string into `file`, max length `filelen`. */ -void BLI_split_file_part(const char *string, char *file, const size_t filelen); +void BLI_split_file_part(const char *string, char *file, size_t filelen); /** * Returns a pointer to the last extension (e.g. the position of the last period). * Returns NULL if there is no extension. @@ -94,7 +93,7 @@ const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(); /** * Append a filename to a dir, ensuring slash separates. */ -void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__restrict file) +void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict file) ATTR_NONNULL(); /** * Simple appending of filename to dir, does not check for valid path! @@ -104,7 +103,7 @@ void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__re * that de-duplicates separators and can handle an arbitrary number of paths. */ void BLI_join_dirfile(char *__restrict dst, - const size_t maxlen, + size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL(); /** @@ -114,7 +113,7 @@ void BLI_join_dirfile(char *__restrict dst, * \note If you want a trailing slash, add `SEP_STR` as the last path argument, * duplicate slashes will be cleaned up. */ -size_t BLI_path_join(char *__restrict dst, const size_t dst_len, const char *path_first, ...) +size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first, ...) ATTR_NONNULL(1, 3) ATTR_SENTINEL(0); /** * Like Python's `os.path.basename()` @@ -164,12 +163,12 @@ void BLI_path_slash_rstrip(char *string) ATTR_NONNULL(); void BLI_path_slash_native(char *path) ATTR_NONNULL(); #ifdef _WIN32 -bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen); +bool BLI_path_program_extensions_add_win32(char *name, size_t maxlen); #endif /** * Search for a binary (executable) */ -bool BLI_path_program_search(char *fullname, const size_t maxlen, const char *name); +bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name); /** * \return true when `str` end with `ext` (case insensitive). @@ -353,7 +352,7 @@ bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(); * This is _not_ something Blender's internal paths support, instead they use the "//" prefix. * In most cases #BLI_path_abs should be used instead. */ -bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) ATTR_NONNULL(); +bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL(); /** * Replaces `file` with a relative version (prefixed by "//") such that #BLI_path_abs, given * the same `relfile`, will convert it back to its original value. diff --git a/source/blender/blenlib/BLI_rand.hh b/source/blender/blenlib/BLI_rand.hh index 667d6df8996..cc9e9b374d7 100644 --- a/source/blender/blenlib/BLI_rand.hh +++ b/source/blender/blenlib/BLI_rand.hh @@ -20,8 +20,9 @@ #pragma once +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h index 653f5f61c9e..eb4e69a42d4 100644 --- a/source/blender/blenlib/BLI_stack.h +++ b/source/blender/blenlib/BLI_stack.h @@ -28,13 +28,13 @@ extern "C" { typedef struct BLI_Stack BLI_Stack; -BLI_Stack *BLI_stack_new_ex(const size_t elem_size, +BLI_Stack *BLI_stack_new_ex(size_t elem_size, const char *description, - const size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** * Create a new homogeneous stack with elements of 'elem_size' bytes. */ -BLI_Stack *BLI_stack_new(const size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT +BLI_Stack *BLI_stack_new(size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index a82e97914db..8177545911c 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -42,8 +42,7 @@ extern "C" { * \param len: The number of bytes to duplicate * \retval Returns the duplicated string */ -char *BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); +char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** * Duplicates the cstring \a str into a newly mallocN'd @@ -74,8 +73,7 @@ char *BLI_strdupcat(const char *__restrict str1, * the size of dst) * \retval Returns dst */ -char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) - ATTR_NONNULL(); +char *BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(); /** * Like BLI_strncpy but ensures dst is always padded by given char, @@ -107,7 +105,7 @@ char *BLI_strncpy_ensure_pad(char *__restrict dst, */ size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, - const size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); @@ -186,7 +184,7 @@ void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL(); * \note Larger tables should use a hash table. */ bool BLI_str_replace_table_exact(char *string, - const size_t string_len, + size_t string_len, const char *replace_table[][2], int replace_table_len); @@ -235,7 +233,7 @@ char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT * * \note This is used for creating animation paths in blend files. */ -size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) +size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(); /** * This roughly matches C and Python's string escaping with double quotes - `"`. @@ -251,9 +249,9 @@ size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const si */ size_t BLI_str_unescape_ex(char *__restrict dst, const char *__restrict src, - const size_t src_maxncpy, + size_t src_maxncpy, /* Additional arguments. */ - const size_t dst_maxncpy, + size_t dst_maxncpy, bool *r_is_complete) ATTR_NONNULL(); /** * See #BLI_str_unescape_ex doc-string. @@ -265,7 +263,7 @@ size_t BLI_str_unescape_ex(char *__restrict dst, * * \note This is used for parsing animation paths in blend files (runs often). */ -size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy) +size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_maxncpy) ATTR_NONNULL(); /** @@ -359,10 +357,10 @@ int BLI_strcmp_ignore_pad(const char *str1, const char *str2, char pad) ATTR_WAR /** * Determine the length of a fixed-size string. */ -size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL(); -void BLI_str_toupper_ascii(char *str, const size_t len) ATTR_NONNULL(); +void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(); +void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(); /** * Strip white-space from end of the string. */ @@ -479,7 +477,7 @@ bool BLI_string_all_words_matched(const char *name, * \return The number of words found in \a str */ int BLI_string_find_split_words(const char *str, - const size_t len, + size_t len, char delim, int r_words[][2], int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 82622d442fb..108a2f5fc7d 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -110,14 +110,12 @@ size_t BLI_str_utf8_from_unicode_len(unsigned int c) ATTR_WARN_UNUSED_RESULT; * * \return number of bytes written. */ -size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, const size_t outbuf_len) - ATTR_NONNULL(2); +size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, size_t outbuf_len) ATTR_NONNULL(2); size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, - const size_t maxncpy) ATTR_NONNULL(1, 2); -size_t BLI_str_utf32_as_utf8(char *__restrict dst, - const char32_t *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); +size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, size_t maxncpy) + ATTR_NONNULL(1, 2); /** * \return The UTF-32 len in UTF-8. */ @@ -162,21 +160,20 @@ size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RES size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; -size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes) +size_t BLI_strnlen_utf8_ex(const char *strc, size_t maxlen, size_t *r_len_bytes) ATTR_NONNULL(1, 3); /** * \param strc: the string to measure the length. * \param maxlen: the string length (in bytes) * \return the unicode length (not in bytes!) */ -size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) - ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +size_t BLI_strnlen_utf8(const char *strc, size_t maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); /** * Count columns that character/string occupies (based on `wcwidth.co`). diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index fd3918ff217..818bfe8182b 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -57,11 +57,11 @@ bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(); * Based on `BLI_split_dirfile()` / `os.path.splitext()`, * `"a.b.c"` -> (`"a.b"`, `".c"`). */ -void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len); +void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, size_t str_len); /** * `"a.b.c"` -> (`"a."`, `"b.c"`). */ -void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len); +void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size_t str_len); /** * Join strings, return newly allocated string. @@ -127,7 +127,7 @@ char *BLI_string_join_array_by_sep_char_with_tableN(char sep, size_t BLI_string_flip_side_name(char *r_name, const char *from_name, bool strip_number, - const size_t name_len); + size_t name_len); /** * Ensures name is unique (according to criteria specified by caller in unique_check callback), diff --git a/source/blender/blenlib/BLI_timecode.h b/source/blender/blenlib/BLI_timecode.h index f0349e289ac..1cd18dc86ab 100644 --- a/source/blender/blenlib/BLI_timecode.h +++ b/source/blender/blenlib/BLI_timecode.h @@ -42,7 +42,7 @@ extern "C" { * \return length of \a str */ size_t BLI_timecode_string_from_time(char *str, - const size_t maxncpy, + size_t maxncpy, int brevity_level, float time_seconds, double fps, @@ -56,7 +56,7 @@ size_t BLI_timecode_string_from_time(char *str, * \param time_seconds: time total time in seconds * \return length of \a str */ -size_t BLI_timecode_string_from_time_simple(char *str, const size_t maxncpy, double time_seconds) +size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double time_seconds) ATTR_NONNULL(); /** @@ -72,7 +72,7 @@ size_t BLI_timecode_string_from_time_simple(char *str, const size_t maxncpy, dou * \note in some cases this is used to print non-seconds values. */ size_t BLI_timecode_string_from_time_seconds(char *str, - const size_t maxncpy, + size_t maxncpy, int brevity_level, float time_seconds) ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 9fe092fe525..35d4158de59 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -638,7 +638,7 @@ extern "C" { /** * Check if memory is zeroed, as with `memset(arr, 0, arr_size)`. */ -extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); +extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); #endif #define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member) \ @@ -840,15 +840,6 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); /** No-op for expressions we don't want to instantiate, but must remain valid. */ #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) -/** - * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for - * SFINAE in common cases. - * - * \note Often one has to invoke this macro with double parenthesis. That's because the condition - * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. - */ -#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr - /** \} */ #ifdef __cplusplus diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 90c6760019a..3958fd8e2d2 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -192,6 +192,8 @@ set(SRC BLI_dlrbTree.h BLI_dot_export.hh BLI_dot_export_attribute_enums.hh + BLI_double2.hh + BLI_double3.hh BLI_dynlib.h BLI_dynstr.h BLI_easing.h @@ -205,6 +207,9 @@ set(SRC BLI_fileops.hh BLI_fileops_types.h BLI_filereader.h + BLI_float2.hh + BLI_float3.hh + BLI_float4.hh BLI_float4x4.hh BLI_fnmatch.h BLI_function_ref.hh @@ -253,8 +258,6 @@ set(SRC BLI_math_statistics.h BLI_math_time.h BLI_math_vector.h - BLI_math_vec_types.hh - BLI_math_vec_mpq_types.hh BLI_memarena.h BLI_memblock.h BLI_memiter.h @@ -264,6 +267,8 @@ set(SRC BLI_mesh_boolean.hh BLI_mesh_intersect.hh BLI_mmap.h + BLI_mpq2.hh + BLI_mpq3.hh BLI_multi_value_map.hh BLI_noise.h BLI_noise.hh @@ -439,7 +444,6 @@ if(WITH_GTESTS) tests/BLI_math_rotation_test.cc tests/BLI_math_solvers_test.cc tests/BLI_math_time_test.cc - tests/BLI_math_vec_types_test.cc tests/BLI_math_vector_test.cc tests/BLI_memiter_test.cc tests/BLI_memory_utils_test.cc diff --git a/source/blender/blenlib/intern/BLI_mempool_private.h b/source/blender/blenlib/intern/BLI_mempool_private.h index 90569d87c41..03b0b11297b 100644 --- a/source/blender/blenlib/intern/BLI_mempool_private.h +++ b/source/blender/blenlib/intern/BLI_mempool_private.h @@ -54,8 +54,9 @@ typedef struct ParallelMempoolTaskData { * * See #BLI_task_parallel_mempool implementation for detailed usage example. */ -ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter) - ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, + size_t num_iter) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(); void mempool_iter_threadsafe_destroy(ParallelMempoolTaskData *iter_arr) ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc index 842e6cb6135..53e881a9fc7 100644 --- a/source/blender/blenlib/intern/delaunay_2d.cc +++ b/source/blender/blenlib/intern/delaunay_2d.cc @@ -25,10 +25,11 @@ #include #include "BLI_array.hh" +#include "BLI_double2.hh" #include "BLI_linklist.h" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_mpq_types.hh" +#include "BLI_mpq2.hh" #include "BLI_set.hh" #include "BLI_task.hh" #include "BLI_vector.hh" @@ -37,8 +38,6 @@ namespace blender::meshintersect { -using namespace blender::math; - /* Throughout this file, template argument T will be an * arithmetic-like type, like float, double, or mpq_class. */ @@ -789,11 +788,11 @@ bool in_line(const FatCo &a, } vec2 exact_ab = b.exact - a.exact; vec2 exact_ac = c.exact - a.exact; - if (dot(exact_ab, exact_ac) < 0) { + if (vec2::dot(exact_ab, exact_ac) < 0) { return false; } vec2 exact_bc = c.exact - b.exact; - return dot(exact_bc, exact_ac) >= 0; + return vec2::dot(exact_bc, exact_ac) >= 0; } #endif @@ -802,11 +801,11 @@ bool in_line(const FatCo &a, const FatCo &b, const FatCo { vec2 ab = b.approx - a.approx; vec2 ac = c.approx - a.approx; - if (dot(ab, ac) < 0) { + if (vec2::dot(ab, ac) < 0) { return false; } vec2 bc = c.approx - b.approx; - return dot(bc, ac) >= 0; + return vec2::dot(bc, ac) >= 0; } template<> CDTVert::CDTVert(const vec2 &pt) @@ -1082,7 +1081,7 @@ template CDTEdge *CDTArrangement::split_edge(SymEdge *se, T SymEdge *sesymprev = prev(sesym); SymEdge *sesymprevsym = sym(sesymprev); SymEdge *senext = se->next; - CDTVert *v = this->add_vert(interpolate(*a, *b, lambda)); + CDTVert *v = this->add_vert(vec2::interpolate(*a, *b, lambda)); CDTEdge *e = this->add_edge(v, se->next->vert, se->face, sesym->face); sesym->vert = v; SymEdge *newse = &e->symedges[0]; @@ -1705,16 +1704,16 @@ void fill_crossdata_for_intersect(const FatCo &curco, BLI_assert(se_vcva->vert == vc && se_vcva->next->vert == va); BLI_assert(se_vcvb->vert == vc && se_vcvb->next->vert == vb); UNUSED_VARS_NDEBUG(vc); - auto isect = isect_seg_seg>(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); + auto isect = vec2::isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); T &lambda = isect.lambda; switch (isect.kind) { - case isect_result>::LINE_LINE_CROSS: { + case vec2::isect_result::LINE_LINE_CROSS: { #ifdef WITH_GMP if (!std::is_same::value) { #else if (true) { #endif - double len_ab = distance(va->co.approx, vb->co.approx); + double len_ab = vec2::distance(va->co.approx, vb->co.approx); if (lambda * len_ab <= epsilon) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1736,7 +1735,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case isect_result>::LINE_LINE_EXACT: { + case vec2::isect_result::LINE_LINE_EXACT: { if (lambda == 0) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1751,7 +1750,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case isect_result>::LINE_LINE_NONE: { + case vec2::isect_result::LINE_LINE_NONE: { #ifdef WITH_GMP if (std::is_same::value) { BLI_assert(false); @@ -1767,9 +1766,9 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case isect_result>::LINE_LINE_COLINEAR: { - if (distance_squared(va->co.approx, v2->co.approx) <= - distance_squared(vb->co.approx, v2->co.approx)) { + case vec2::isect_result::LINE_LINE_COLINEAR: { + if (vec2::distance_squared(va->co.approx, v2->co.approx) <= + vec2::distance_squared(vb->co.approx, v2->co.approx)) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } else { @@ -1846,7 +1845,7 @@ void get_next_crossing_from_edge(CrossData *cd, { CDTVert *va = cd->in->vert; CDTVert *vb = cd->in->next->vert; - vec2 curco = interpolate(va->co.exact, vb->co.exact, cd->lambda); + vec2 curco = vec2::interpolate(va->co.exact, vb->co.exact, cd->lambda); FatCo fat_curco(curco); SymEdge *se_ac = sym(cd->in)->next; CDTVert *vc = se_ac->next->vert; @@ -2387,7 +2386,7 @@ template void remove_non_constraint_edges_leave_valid_bmesh(CDT_stat dissolvable_edges[i].e = e; const vec2 &co1 = e->symedges[0].vert->co.approx; const vec2 &co2 = e->symedges[1].vert->co.approx; - dissolvable_edges[i].len_squared = distance_squared(co1, co2); + dissolvable_edges[i].len_squared = vec2::distance_squared(co1, co2); i++; } } @@ -2570,18 +2569,18 @@ template void detect_holes(CDT_state *cdt_state) if (e->symedges[0].face->visit_index == e->symedges[1].face->visit_index) { continue; /* Don't count hits on edges between faces in same region. */ } - auto isect = isect_seg_seg>(ray_end.exact, + auto isect = vec2::isect_seg_seg(ray_end.exact, mid.exact, e->symedges[0].vert->co.exact, e->symedges[1].vert->co.exact); switch (isect.kind) { - case isect_result>::LINE_LINE_CROSS: { + case vec2::isect_result::LINE_LINE_CROSS: { hits++; break; } - case isect_result>::LINE_LINE_EXACT: - case isect_result>::LINE_LINE_NONE: - case isect_result>::LINE_LINE_COLINEAR: + case vec2::isect_result::LINE_LINE_EXACT: + case vec2::isect_result::LINE_LINE_NONE: + case vec2::isect_result::LINE_LINE_COLINEAR: break; } } diff --git a/source/blender/blenlib/intern/math_boolean.cc b/source/blender/blenlib/intern/math_boolean.cc index 0bae3c23f79..c16755868aa 100644 --- a/source/blender/blenlib/intern/math_boolean.cc +++ b/source/blender/blenlib/intern/math_boolean.cc @@ -18,10 +18,15 @@ * \ingroup bli */ +#include "BLI_double2.hh" +#include "BLI_double3.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_hash.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_mpq2.hh" +#include "BLI_mpq3.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc index 6fab6c9a383..223c0e273f0 100644 --- a/source/blender/blenlib/intern/math_vec.cc +++ b/source/blender/blenlib/intern/math_vec.cc @@ -18,83 +18,89 @@ * \ingroup bli */ +#include "BLI_double2.hh" +#include "BLI_double3.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_hash.hh" -#include "BLI_math_vec_mpq_types.hh" -#include "BLI_math_vector.hh" +#include "BLI_math_mpq.hh" +#include "BLI_mpq2.hh" +#include "BLI_mpq3.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" -namespace blender::math { +namespace blender { -template<> -isect_result isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4) +float2::isect_result float2::isect_seg_seg(const float2 &v1, + const float2 &v2, + const float2 &v3, + const float2 &v4) { - isect_result ans; + float2::isect_result ans; float div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0f) { ans.lambda = 0.0f; - ans.kind = isect_result::LINE_LINE_COLINEAR; + ans.mu = 0.0f; + ans.kind = float2::isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; - float mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; - if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) { - if (ans.lambda == 0.0f || ans.lambda == 1.0f || mu == 0.0f || mu == 1.0f) { - ans.kind = isect_result::LINE_LINE_EXACT; + ans.mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; + if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && ans.mu >= 0.0f && ans.mu <= 1.0f) { + if (ans.lambda == 0.0f || ans.lambda == 1.0f || ans.mu == 0.0f || ans.mu == 1.0f) { + ans.kind = float2::isect_result::LINE_LINE_EXACT; } else { - ans.kind = isect_result::LINE_LINE_CROSS; + ans.kind = float2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result::LINE_LINE_NONE; + ans.kind = float2::isect_result::LINE_LINE_NONE; } } return ans; } -template<> -isect_result isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4) +double2::isect_result double2::isect_seg_seg(const double2 &v1, + const double2 &v2, + const double2 &v3, + const double2 &v4) { - isect_result ans; + double2::isect_result ans; double div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = isect_result::LINE_LINE_COLINEAR; + ans.kind = double2::isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; double mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; if (ans.lambda >= 0.0 && ans.lambda <= 1.0 && mu >= 0.0 && mu <= 1.0) { if (ans.lambda == 0.0 || ans.lambda == 1.0 || mu == 0.0 || mu == 1.0) { - ans.kind = isect_result::LINE_LINE_EXACT; + ans.kind = double2::isect_result::LINE_LINE_EXACT; } else { - ans.kind = isect_result::LINE_LINE_CROSS; + ans.kind = double2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result::LINE_LINE_NONE; + ans.kind = double2::isect_result::LINE_LINE_NONE; } } return ans; } #ifdef WITH_GMP -template<> -isect_result isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4) +mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, + const mpq2 &v2, + const mpq2 &v3, + const mpq2 &v4) { - isect_result ans; + mpq2::isect_result ans; mpq_class div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = isect_result::LINE_LINE_COLINEAR; + ans.kind = mpq2::isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; @@ -103,21 +109,66 @@ isect_result isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, if (ans.lambda >= 0 && ans.lambda <= 1 && ((div > 0 && mudiv >= 0 && mudiv <= div) || (div < 0 && mudiv <= 0 && mudiv >= div))) { if (ans.lambda == 0 || ans.lambda == 1 || mudiv == 0 || mudiv == div) { - ans.kind = isect_result::LINE_LINE_EXACT; + ans.kind = mpq2::isect_result::LINE_LINE_EXACT; } else { - ans.kind = isect_result::LINE_LINE_CROSS; + ans.kind = mpq2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result::LINE_LINE_NONE; + ans.kind = mpq2::isect_result::LINE_LINE_NONE; } } return ans; } #endif +double3 double3::cross_poly(Span poly) +{ + /* Newell's Method. */ + int nv = static_cast(poly.size()); + if (nv < 3) { + return double3(0, 0, 0); + } + const double3 *v_prev = &poly[nv - 1]; + const double3 *v_curr = &poly[0]; + double3 n(0, 0, 0); + for (int i = 0; i < nv;) { + n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); + n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); + n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); + v_prev = v_curr; + ++i; + if (i < nv) { + v_curr = &poly[i]; + } + } + return n; +} + #ifdef WITH_GMP +mpq3 mpq3::cross_poly(Span poly) +{ + /* Newell's Method. */ + int nv = static_cast(poly.size()); + if (nv < 3) { + return mpq3(0); + } + const mpq3 *v_prev = &poly[nv - 1]; + const mpq3 *v_curr = &poly[0]; + mpq3 n(0); + for (int i = 0; i < nv;) { + n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); + n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); + n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); + v_prev = v_curr; + ++i; + if (i < nv) { + v_curr = &poly[i]; + } + } + return n; +} uint64_t hash_mpq_class(const mpq_class &value) { @@ -125,6 +176,20 @@ uint64_t hash_mpq_class(const mpq_class &value) return get_default_hash(static_cast(value.get_d())); } +uint64_t mpq2::hash() const +{ + uint64_t hashx = hash_mpq_class(this->x); + uint64_t hashy = hash_mpq_class(this->y); + return hashx ^ (hashy * 33); +} + +uint64_t mpq3::hash() const +{ + uint64_t hashx = hash_mpq_class(this->x); + uint64_t hashy = hash_mpq_class(this->y); + uint64_t hashz = hash_mpq_class(this->z); + return hashx ^ (hashy * 33) ^ (hashz * 33 * 37); +} #endif -} // namespace blender::math +} // namespace blender diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index a3eae1896d3..ce4db0c6b9d 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -28,6 +28,8 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" +# include "BLI_double3.hh" +# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" @@ -35,9 +37,8 @@ # include "BLI_math_boolean.hh" # include "BLI_math_geom.h" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" # include "BLI_mesh_intersect.hh" +# include "BLI_mpq3.hh" # include "BLI_set.hh" # include "BLI_span.hh" # include "BLI_stack.hh" @@ -1632,13 +1633,13 @@ static Edge find_good_sorting_edge(const Vert *testp, ordinate[axis_next] = -abscissa[axis]; ordinate[axis_next_next] = 0; /* By construction, dot(abscissa, ordinate) == 0, so they are perpendicular. */ - mpq3 normal = math::cross(abscissa, ordinate); + mpq3 normal = mpq3::cross(abscissa, ordinate); if (dbg_level > 0) { std::cout << "abscissa = " << abscissa << "\n"; std::cout << "ordinate = " << ordinate << "\n"; std::cout << "normal = " << normal << "\n"; } - mpq_class nlen2 = math::length_squared(normal); + mpq_class nlen2 = normal.length_squared(); mpq_class max_abs_slope = -1; Edge esort; const Vector &edges = tmtopo.vert_edges(closestp); @@ -1647,12 +1648,12 @@ static Edge find_good_sorting_edge(const Vert *testp, const mpq3 &co_other = v_other->co_exact; mpq3 evec = co_other - co_closest; /* Get projection of evec onto plane of abscissa and ordinate. */ - mpq3 proj_evec = evec - (math::dot(evec, normal) / nlen2) * normal; + mpq3 proj_evec = evec - (mpq3::dot(evec, normal) / nlen2) * normal; /* The projection calculations along the abscissa and ordinate should * be scaled by 1/abscissa and 1/ordinate respectively, * but we can skip: it won't affect which `evec` has the maximum slope. */ - mpq_class evec_a = math::dot(proj_evec, abscissa); - mpq_class evec_o = math::dot(proj_evec, ordinate); + mpq_class evec_a = mpq3::dot(proj_evec, abscissa); + mpq_class evec_o = mpq3::dot(proj_evec, ordinate); if (dbg_level > 0) { std::cout << "e = " << e << "\n"; std::cout << "v_other = " << v_other << "\n"; @@ -1790,8 +1791,8 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, ap = p; ap -= a; - mpq_class d1 = math::dot_with_buffer(ab, ap, m); - mpq_class d2 = math::dot_with_buffer(ac, ap, m); + mpq_class d1 = mpq3::dot_with_buffer(ab, ap, m); + mpq_class d2 = mpq3::dot_with_buffer(ac, ap, m); if (d1 <= 0 && d2 <= 0) { /* Barycentric coordinates (1,0,0). */ *r_edge = -1; @@ -1799,13 +1800,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = a\n"; } - return math::distance_squared_with_buffer(p, a, m); + return mpq3::distance_squared_with_buffer(p, a, m); } /* Check if p in vertex region outside b. */ bp = p; bp -= b; - mpq_class d3 = math::dot_with_buffer(ab, bp, m); - mpq_class d4 = math::dot_with_buffer(ac, bp, m); + mpq_class d3 = mpq3::dot_with_buffer(ab, bp, m); + mpq_class d4 = mpq3::dot_with_buffer(ac, bp, m); if (d3 >= 0 && d4 <= d3) { /* Barycentric coordinates (0,1,0). */ *r_edge = -1; @@ -1813,7 +1814,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = b\n"; } - return math::distance_squared_with_buffer(p, b, m); + return mpq3::distance_squared_with_buffer(p, b, m); } /* Check if p in region of ab. */ mpq_class vc = d1 * d4 - d3 * d2; @@ -1828,13 +1829,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ab at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* Check if p in vertex region outside c. */ cp = p; cp -= c; - mpq_class d5 = math::dot_with_buffer(ab, cp, m); - mpq_class d6 = math::dot_with_buffer(ac, cp, m); + mpq_class d5 = mpq3::dot_with_buffer(ab, cp, m); + mpq_class d6 = mpq3::dot_with_buffer(ac, cp, m); if (d6 >= 0 && d5 <= d6) { /* Barycentric coordinates (0,0,1). */ *r_edge = -1; @@ -1842,7 +1843,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = c\n"; } - return math::distance_squared_with_buffer(p, c, m); + return mpq3::distance_squared_with_buffer(p, c, m); } /* Check if p in edge region of ac. */ mpq_class vb = d5 * d2 - d1 * d6; @@ -1857,7 +1858,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ac at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* Check if p in edge region of bc. */ mpq_class va = d3 * d6 - d5 * d4; @@ -1873,7 +1874,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on bc at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* p inside face region. Compute barycentric coordinates (u,v,w). */ mpq_class denom = 1 / (va + vb + vc); @@ -1889,7 +1890,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = inside at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } static float closest_on_tri_to_point_float_dist_squared(const float3 &p, @@ -2609,7 +2610,7 @@ static void test_tri_inside_shapes(const IMesh &tm, double3 test_point = calc_point_inside_tri_db(tri_test); /* Offset the test point a tiny bit in the tri_test normal direction. */ tri_test.populate_plane(false); - double3 norm = math::normalize(tri_test.plane->norm); + double3 norm = tri_test.plane->norm.normalized(); const double offset_amount = 1e-5; double3 offset_test_point = test_point + offset_amount * norm; if (dbg_level > 0) { @@ -3001,7 +3002,7 @@ static void init_face_merge_state(FaceMergeState *fms, std::cout << "process tri = " << &tri << "\n"; } BLI_assert(tri.plane_populated()); - if (math::dot(norm, tri.plane->norm) <= 0.0) { + if (double3::dot(norm, tri.plane->norm) <= 0.0) { if (dbg_level > 0) { std::cout << "triangle has wrong orientation, skipping\n"; } @@ -3026,7 +3027,7 @@ static void init_face_merge_state(FaceMergeState *fms, } if (me_index == -1) { double3 vec = new_me.v2->co - new_me.v1->co; - new_me.len_squared = math::length_squared(vec); + new_me.len_squared = vec.length_squared(); new_me.orig = tri.edge_orig[i]; new_me.is_intersect = tri.is_intersect[i]; new_me.dissolvable = (new_me.orig == NO_INDEX && !new_me.is_intersect); @@ -3266,7 +3267,7 @@ static Vector merge_tris_for_face(Vector tris, bool done = false; double3 first_tri_normal = tm.face(tris[0])->plane->norm; double3 second_tri_normal = tm.face(tris[1])->plane->norm; - if (tris.size() == 2 && math::dot(first_tri_normal, second_tri_normal) > 0.0) { + if (tris.size() == 2 && double3::dot(first_tri_normal, second_tri_normal) > 0.0) { /* Is this a case where quad with one diagonal remained unchanged? * Worth special handling because this case will be very common. */ Face &tri1 = *tm.face(tris[0]); @@ -3331,7 +3332,7 @@ static bool approx_in_line(const double3 &a, const double3 &b, const double3 &c) { double3 vec1 = b - a; double3 vec2 = c - b; - double cos_ang = math::dot(math::normalize(vec1), math::normalize(vec2)); + double cos_ang = double3::dot(vec1.normalized(), vec2.normalized()); return fabs(cos_ang - 1.0) < 1e-4; } diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc index 982759ffcff..1f150137ba3 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -30,13 +30,15 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" +# include "BLI_double3.hh" +# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" # include "BLI_math_boolean.hh" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" +# include "BLI_mpq2.hh" +# include "BLI_mpq3.hh" # include "BLI_polyfill_2d.h" # include "BLI_set.hh" # include "BLI_span.hh" @@ -196,14 +198,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co_exact; } - normal_exact = math::cross_poly(co.as_span()); + normal_exact = mpq3::cross_poly(co); } else { mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact; mpq3 tr12 = vert[1]->co_exact - vert[2]->co_exact; - normal_exact = math::cross(tr02, tr12); + normal_exact = mpq3::cross(tr02, tr12); } - mpq_class d_exact = -math::dot(normal_exact, vert[0]->co_exact); + mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact); plane = new Plane(normal_exact, d_exact); } else { @@ -213,14 +215,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co; } - normal = math::cross_poly(co.as_span()); + normal = double3::cross_poly(co); } else { double3 tr02 = vert[0]->co - vert[2]->co; double3 tr12 = vert[1]->co - vert[2]->co; - normal = math::cross(tr02, tr12); + normal = double3::cross_high_precision(tr02, tr12); } - double d = -math::dot(normal, vert[0]->co); + double d = -double3::dot(normal, vert[0]->co); plane = new Plane(normal, d); } } @@ -1096,15 +1098,15 @@ static mpq2 project_3d_to_2d(const mpq3 &p3d, int proj_axis) */ static double supremum_dot_cross(const double3 &a, const double3 &b) { - double3 abs_a = math::abs(a); - double3 abs_b = math::abs(b); + double3 abs_a = double3::abs(a); + double3 abs_b = double3::abs(b); double3 c; /* This is dot(cross(a, b), cross(a,b)) but using absolute values for a and b * and always using + when operation is + or -. */ c[0] = abs_a[1] * abs_b[2] + abs_a[2] * abs_b[1]; c[1] = abs_a[2] * abs_b[0] + abs_a[0] * abs_b[2]; c[2] = abs_a[0] * abs_b[1] + abs_a[1] * abs_b[0]; - return math::dot(c, c); + return double3::dot(c, c); } /* The index of dot when inputs are plane_coords with index 1 is much higher. @@ -1141,11 +1143,11 @@ static int filter_plane_side(const double3 &p, const double3 &abs_plane_p, const double3 &abs_plane_no) { - double d = math::dot(p - plane_p, plane_no); + double d = double3::dot(p - plane_p, plane_no); if (d == 0.0) { return 0; } - double supremum = math::dot(abs_p + abs_plane_p, abs_plane_no); + double supremum = double3::dot(abs_p + abs_plane_p, abs_plane_no); double err_bound = supremum * index_plane_side * DBL_EPSILON; if (fabs(d) > err_bound) { return d > 0 ? 1 : -1; @@ -1176,9 +1178,9 @@ static inline mpq3 tti_interp( ab -= b; ac = a; ac -= c; - mpq_class den = math::dot_with_buffer(ab, n, dotbuf); + mpq_class den = mpq3::dot_with_buffer(ab, n, dotbuf); BLI_assert(den != 0); - mpq_class alpha = math::dot_with_buffer(ac, n, dotbuf) / den; + mpq_class alpha = mpq3::dot_with_buffer(ac, n, dotbuf) / den; return a - alpha * ab; } @@ -1207,7 +1209,7 @@ static inline int tti_above(const mpq3 &a, n.y = ba.z * ca.x - ba.x * ca.z; n.z = ba.x * ca.y - ba.y * ca.x; - return sgn(math::dot_with_buffer(ad, n, dotbuf)); + return sgn(mpq3::dot_with_buffer(ad, n, dotbuf)); } /** @@ -1426,11 +1428,11 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) const double3 &d_r2 = vr2->co; const double3 &d_n2 = tri2.plane->norm; - const double3 &abs_d_p1 = math::abs(d_p1); - const double3 &abs_d_q1 = math::abs(d_q1); - const double3 &abs_d_r1 = math::abs(d_r1); - const double3 &abs_d_r2 = math::abs(d_r2); - const double3 &abs_d_n2 = math::abs(d_n2); + const double3 &abs_d_p1 = double3::abs(d_p1); + const double3 &abs_d_q1 = double3::abs(d_q1); + const double3 &abs_d_r1 = double3::abs(d_r1); + const double3 &abs_d_r2 = double3::abs(d_r2); + const double3 &abs_d_n2 = double3::abs(d_n2); int sp1 = filter_plane_side(d_p1, d_r2, d_n2, abs_d_p1, abs_d_r2, abs_d_n2); int sq1 = filter_plane_side(d_q1, d_r2, d_n2, abs_d_q1, abs_d_r2, abs_d_n2); @@ -1446,9 +1448,9 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) } const double3 &d_n1 = tri1.plane->norm; - const double3 &abs_d_p2 = math::abs(d_p2); - const double3 &abs_d_q2 = math::abs(d_q2); - const double3 &abs_d_n1 = math::abs(d_n1); + const double3 &abs_d_p2 = double3::abs(d_p2); + const double3 &abs_d_q2 = double3::abs(d_q2); + const double3 &abs_d_n1 = double3::abs(d_n1); int sp2 = filter_plane_side(d_p2, d_r1, d_n1, abs_d_p2, abs_d_r1, abs_d_n1); int sq2 = filter_plane_side(d_q2, d_r1, d_n1, abs_d_q2, abs_d_r1, abs_d_n1); @@ -1475,17 +1477,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp1 == 0) { buf[0] = p1; buf[0] -= r2; - sp1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); + sp1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (sq1 == 0) { buf[0] = q1; buf[0] -= r2; - sq1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); + sq1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (sr1 == 0) { buf[0] = r1; buf[0] -= r2; - sr1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); + sr1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (dbg_level > 1) { @@ -1507,17 +1509,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp2 == 0) { buf[0] = p2; buf[0] -= r1; - sp2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); + sp2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (sq2 == 0) { buf[0] = q2; buf[0] -= r1; - sq2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); + sq2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (sr2 == 0) { buf[0] = r2; buf[0] -= r1; - sr2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); + sr2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (dbg_level > 1) { @@ -1719,7 +1721,7 @@ static CDT_data prepare_cdt_input(const IMesh &tm, int t, const Vectorplane_populated()); ans.t_plane = tm.face(t)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); prepare_need_tri(ans, tm, t); for (const ITT_value &itt : itts) { switch (itt.kind) { @@ -1755,7 +1757,7 @@ static CDT_data prepare_cdt_input_for_cluster(const IMesh &tm, BLI_assert(tm.face(t0)->plane_populated()); ans.t_plane = tm.face(t0)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); for (const int t : cl) { prepare_need_tri(ans, tm, t); } @@ -2002,9 +2004,9 @@ static bool is_quad_flip_first_third(const double3 &v1, const double3 &normal) { double3 dir_v3v1 = v3 - v1; - double3 tangent = math::cross(dir_v3v1, normal); - double dot = math::dot(v1, tangent); - return (math::dot(v4, tangent) >= dot) || (math::dot(v2, tangent) <= dot); + double3 tangent = double3::cross_high_precision(dir_v3v1, normal); + double dot = double3::dot(v1, tangent); + return (double3::dot(v4, tangent) >= dot) || (double3::dot(v2, tangent) <= dot); } /** @@ -2122,7 +2124,7 @@ static Array exact_triangulate_poly(Face *f, IMeshArena *arena) f->populate_plane(false); } const double3 &poly_normal = f->plane->norm; - int axis = math::dominant_axis(poly_normal); + int axis = double3::dominant_axis(poly_normal); /* If project down y axis as opposed to x or z, the orientation * of the polygon will be reversed. * Yet another reversal happens if the poly normal in the dominant @@ -2201,15 +2203,15 @@ static bool face_is_degenerate(const Face *f) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double3 dab = math::cross(da, db); - double dab_length_squared = math::length_squared(dab); + double3 dab = double3::cross_high_precision(da, db); + double dab_length_squared = dab.length_squared(); double err_bound = supremum_dot_cross(dab, dab) * index_dot_cross * DBL_EPSILON; if (dab_length_squared > err_bound) { return false; } mpq3 a = v2->co_exact - v0->co_exact; mpq3 b = v2->co_exact - v1->co_exact; - mpq3 ab = math::cross(a, b); + mpq3 ab = mpq3::cross(a, b); if (ab.x == 0 && ab.y == 0 && ab.z == 0) { return true; } @@ -2229,8 +2231,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double da_length_squared = math::length_squared(da); - double db_length_squared = math::length_squared(db); + double da_length_squared = da.length_squared(); + double db_length_squared = db.length_squared(); if (da_length_squared == 0.0 || db_length_squared == 0.0) { return true; } @@ -2238,8 +2240,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) * The triangle is almost degenerate if sin t is almost 0. * sin^2 t = |da x db|^2 / (|da|^2 |db|^2) */ - double3 dab = math::cross(da, db); - double dab_length_squared = math::length_squared(dab); + double3 dab = double3::cross_high_precision(da, db); + double dab_length_squared = dab.length_squared(); double sin_squared_t = dab_length_squared / (da_length_squared * db_length_squared); if (sin_squared_t < 1e-8) { return true; diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc index 3460c1284fc..a6ad18801fd 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -50,7 +50,9 @@ #include #include -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" +#include "BLI_float4.hh" #include "BLI_math_base_safe.h" #include "BLI_noise.hh" #include "BLI_utildefines.h" @@ -1467,7 +1469,7 @@ void voronoi_smooth_f1(const float w, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_w != nullptr) { smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor; @@ -1590,7 +1592,7 @@ static float voronoi_distance(const float2 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float2::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1613,7 +1615,7 @@ void voronoi_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1652,7 +1654,7 @@ void voronoi_smooth_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1674,10 +1676,11 @@ void voronoi_smooth_f1(const float2 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; + smoothPosition = float2::interpolate(smoothPosition, pointPosition, h) - + correctionFactor; } } } @@ -1701,7 +1704,7 @@ void voronoi_f2(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1745,7 +1748,7 @@ void voronoi_f2(const float2 coord, void voronoi_distance_to_edge(const float2 coord, const float randomness, float *r_distance) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float2 vectorToClosest = float2(0.0f, 0.0f); @@ -1774,7 +1777,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float const float2 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v2v2(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v2v2((vectorToClosest + vectorToPoint) / 2.0f, - math::normalize(perpendicularToEdge)); + perpendicularToEdge.normalized()); minDistance = std::min(minDistance, distanceToEdge); } } @@ -1784,7 +1787,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *r_radius) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float2 closestPoint = float2(0.0f, 0.0f); @@ -1795,7 +1798,7 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j); const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(pointPosition, localPosition); + const float distanceToPoint = float2::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -1814,14 +1817,14 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j) + closestPointOffset; const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float2::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float2::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 3D Voronoi **** */ @@ -1833,7 +1836,7 @@ static float voronoi_distance(const float3 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float3::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1857,7 +1860,7 @@ void voronoi_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1899,7 +1902,7 @@ void voronoi_smooth_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1922,10 +1925,10 @@ void voronoi_smooth_f1(const float3 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = float3::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -1951,7 +1954,7 @@ void voronoi_f2(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1997,7 +2000,7 @@ void voronoi_f2(const float3 coord, void voronoi_distance_to_edge(const float3 coord, const float randomness, float *r_distance) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float3 vectorToClosest = float3(0.0f, 0.0f, 0.0f); @@ -2029,7 +2032,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float const float3 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v3v3(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v3v3((vectorToClosest + vectorToPoint) / 2.0f, - math::normalize(perpendicularToEdge)); + perpendicularToEdge.normalized()); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2040,7 +2043,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *r_radius) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float3 closestPoint = float3(0.0f, 0.0f, 0.0f); @@ -2052,7 +2055,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k); const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(pointPosition, localPosition); + const float distanceToPoint = float3::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2073,7 +2076,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k) + closestPointOffset; const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float3::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2081,7 +2084,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float3::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 4D Voronoi **** */ @@ -2093,7 +2096,7 @@ static float voronoi_distance(const float4 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float4::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z) + fabsf(a.w - b.w); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -2118,7 +2121,7 @@ void voronoi_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -2163,7 +2166,7 @@ void voronoi_smooth_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -2188,10 +2191,10 @@ void voronoi_smooth_f1(const float4 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = float4::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -2218,7 +2221,7 @@ void voronoi_f2(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2267,7 +2270,7 @@ void voronoi_f2(const float4 coord, void voronoi_distance_to_edge(const float4 coord, const float randomness, float *r_distance) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float4 vectorToClosest = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2304,7 +2307,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float const float4 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v4v4(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v4v4((vectorToClosest + vectorToPoint) / 2.0f, - math::normalize(perpendicularToEdge)); + float4::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2316,7 +2319,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *r_radius) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float4 closestPoint = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2330,7 +2333,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(pointPosition, localPosition); + const float distanceToPoint = float4::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2354,7 +2357,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float4::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2363,7 +2366,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float4::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /** \} */ diff --git a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc index eac3faa6d15..70e3a99e57a 100644 --- a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc +++ b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc @@ -21,9 +21,10 @@ extern "C" { #define DO_RANDOM_TESTS 0 #include "BLI_array.hh" +#include "BLI_double2.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_mpq_types.hh" +#include "BLI_mpq2.hh" #include "BLI_vector.hh" #include "BLI_delaunay_2d.h" diff --git a/source/blender/blenlib/tests/BLI_math_vec_types_test.cc b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc deleted file mode 100644 index 8aa1f90fde2..00000000000 --- a/source/blender/blenlib/tests/BLI_math_vec_types_test.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* Apache License, Version 2.0 */ - -#include "testing/testing.h" - -#include "BLI_math_vec_types.hh" - -namespace blender::tests { - -using namespace blender::math; - -TEST(math_vec_types, ScalarConstructorUnsigned) -{ - float2 u(5u); - EXPECT_EQ(u[0], 5.0f); - EXPECT_EQ(u[1], 5.0f); -} - -TEST(math_vec_types, ScalarConstructorInt) -{ - float2 i(-5); - EXPECT_EQ(i[0], -5.0f); - EXPECT_EQ(i[1], -5.0f); -} - -TEST(math_vec_types, ScalarConstructorFloat) -{ - float2 f(5.2f); - EXPECT_FLOAT_EQ(f[0], 5.2f); - EXPECT_FLOAT_EQ(f[1], 5.2f); -} - -TEST(math_vec_types, ScalarConstructorDouble) -{ - float2 d(5.2); - EXPECT_FLOAT_EQ(d[0], 5.2f); - EXPECT_FLOAT_EQ(d[1], 5.2f); -} - -TEST(math_vec_types, MultiScalarConstructorVec2) -{ - int2 i(5.5f, -1.8); - EXPECT_EQ(i[0], 5); - EXPECT_EQ(i[1], -1); -} - -TEST(math_vec_types, MultiScalarConstructorVec3) -{ - int3 i(5.5f, -1.8, 6u); - EXPECT_EQ(i[0], 5); - EXPECT_EQ(i[1], -1); - EXPECT_EQ(i[2], 6); -} - -TEST(math_vec_types, MultiScalarConstructorVec4) -{ - int4 i(5.5f, -1.8, 6u, 0.888f); - EXPECT_EQ(i[0], 5); - EXPECT_EQ(i[1], -1); - EXPECT_EQ(i[2], 6); - EXPECT_EQ(i[3], 0); -} - -TEST(math_vec_types, MixedScalarVectorConstructorVec3) -{ - float3 fl_v2(float2(5.5f), 1.8f); - EXPECT_FLOAT_EQ(fl_v2[0], 5.5f); - EXPECT_FLOAT_EQ(fl_v2[1], 5.5f); - EXPECT_FLOAT_EQ(fl_v2[2], 1.8f); - - float3 v2_fl(1.8f, float2(5.5f)); - EXPECT_FLOAT_EQ(v2_fl[0], 1.8f); - EXPECT_FLOAT_EQ(v2_fl[1], 5.5f); - EXPECT_FLOAT_EQ(v2_fl[2], 5.5f); -} - -TEST(math_vec_types, MixedScalarVectorConstructorVec4) -{ - int4 v2_fl_fl(float2(1), 2, 3); - EXPECT_EQ(v2_fl_fl[0], 1); - EXPECT_EQ(v2_fl_fl[1], 1); - EXPECT_EQ(v2_fl_fl[2], 2); - EXPECT_EQ(v2_fl_fl[3], 3); - - float4 fl_v2_fl(1, int2(2), 3); - EXPECT_EQ(fl_v2_fl[0], 1); - EXPECT_EQ(fl_v2_fl[1], 2); - EXPECT_EQ(fl_v2_fl[2], 2); - EXPECT_EQ(fl_v2_fl[3], 3); - - double4 fl_fl_v2(1, 2, double2(3)); - EXPECT_EQ(fl_fl_v2[0], 1); - EXPECT_EQ(fl_fl_v2[1], 2); - EXPECT_EQ(fl_fl_v2[2], 3); - EXPECT_EQ(fl_fl_v2[3], 3); - - int4 v2_v2(float2(1), uint2(2)); - EXPECT_EQ(v2_v2[0], 1); - EXPECT_EQ(v2_v2[1], 1); - EXPECT_EQ(v2_v2[2], 2); - EXPECT_EQ(v2_v2[3], 2); - - float4 v3_fl(uint3(1), 2); - EXPECT_EQ(v3_fl[0], 1); - EXPECT_EQ(v3_fl[1], 1); - EXPECT_EQ(v3_fl[2], 1); - EXPECT_EQ(v3_fl[3], 2); - - uint4 fl_v3(1, float3(2)); - EXPECT_EQ(fl_v3[0], 1); - EXPECT_EQ(fl_v3[1], 2); - EXPECT_EQ(fl_v3[2], 2); - EXPECT_EQ(fl_v3[3], 2); -} - -TEST(math_vec_types, ComponentMasking) -{ - int4 i(0, 1, 2, 3); - float2 f2 = float2(i); - EXPECT_EQ(f2[0], 0.0f); - EXPECT_EQ(f2[1], 1.0f); -} - -TEST(math_vec_types, PointerConversion) -{ - float array[3] = {1.0f, 2.0f, 3.0f}; - float3 farray(array); - EXPECT_EQ(farray[0], 1.0f); - EXPECT_EQ(farray[1], 2.0f); - EXPECT_EQ(farray[2], 3.0f); -} - -TEST(math_vec_types, PointerArrayConversion) -{ - float array[1][3] = {{1.0f, 2.0f, 3.0f}}; - float(*ptr)[3] = array; - float3 fptr(ptr); - EXPECT_EQ(fptr[0], 1.0f); - EXPECT_EQ(fptr[1], 2.0f); - EXPECT_EQ(fptr[2], 3.0f); -} - -TEST(math_vec_types, VectorTypeConversion) -{ - double2 d(int2(float2(5.75f, -1.57f))); - EXPECT_EQ(d[0], 5.0); - EXPECT_EQ(d[1], -1.0); -} - -} // namespace blender::tests diff --git a/source/blender/blenlib/tests/BLI_memory_utils_test.cc b/source/blender/blenlib/tests/BLI_memory_utils_test.cc index 74e54151a06..207f310d902 100644 --- a/source/blender/blenlib/tests/BLI_memory_utils_test.cc +++ b/source/blender/blenlib/tests/BLI_memory_utils_test.cc @@ -1,6 +1,6 @@ /* Apache License, Version 2.0 */ -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_memory_utils.hh" #include "BLI_strict_flags.h" #include "testing/testing.h" diff --git a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc index 2b8fb3dbea4..d759f0c3be4 100644 --- a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc @@ -11,8 +11,8 @@ #include "BLI_array.hh" #include "BLI_map.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_boolean.hh" +#include "BLI_mpq3.hh" #include "BLI_vector.hh" #ifdef WITH_GMP diff --git a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc index d2d76593129..68111fb8eb1 100644 --- a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc @@ -10,8 +10,8 @@ #include "BLI_array.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_intersect.hh" +#include "BLI_mpq3.hh" #include "BLI_task.h" #include "BLI_vector.hh" diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 7865c79323d..85ea27b0f4e 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -1186,6 +1186,7 @@ static BMO_FlagSet bmo_enum_triangulate_quad_method[] = { {MOD_TRIANGULATE_QUAD_FIXED, "FIXED"}, {MOD_TRIANGULATE_QUAD_ALTERNATE, "ALTERNATE"}, {MOD_TRIANGULATE_QUAD_SHORTEDGE, "SHORT_EDGE"}, + {MOD_TRIANGULATE_QUAD_LONGEDGE, "LONG_EDGE"}, {0, NULL}, }; diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index e9eaf865e3c..e7280303c26 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -1007,6 +1007,7 @@ void BM_face_triangulate(BMesh *bm, break; } case MOD_TRIANGULATE_QUAD_SHORTEDGE: + case MOD_TRIANGULATE_QUAD_LONGEDGE: case MOD_TRIANGULATE_QUAD_BEAUTY: default: { BMLoop *l_v3, *l_v4; @@ -1023,6 +1024,12 @@ void BM_face_triangulate(BMesh *bm, d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); split_24 = ((d2 - d1) > 0.0f); } + else if (quad_method == MOD_TRIANGULATE_QUAD_LONGEDGE) { + float d1, d2; + d1 = len_squared_v3v3(l_v4->v->co, l_v2->v->co); + d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); + split_24 = ((d2 - d1) < 0.0f); + } else { /* first check if the quad is concave on either diagonal */ const int flip_flag = is_quad_flip_v3( diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 96dc17c2d1a..905d1443002 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -647,6 +647,15 @@ endif() blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +if(WITH_UNITY_BUILD) + set_target_properties(bf_compositor PROPERTIES UNITY_BUILD ON) + set_target_properties(bf_compositor PROPERTIES UNITY_BUILD_BATCH_SIZE 10) +endif() + +if(COMMAND target_precompile_headers) + target_precompile_headers(bf_compositor PRIVATE COM_precomp.h) +endif() + if(CXX_WARN_NO_SUGGEST_OVERRIDE) target_compile_options(bf_compositor PRIVATE "-Wsuggest-override") endif() diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index 794bf1b23bc..1c3a28670df 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -18,7 +18,7 @@ #pragma once -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" #include "DNA_vec_types.h" diff --git a/source/blender/compositor/COM_precomp.h b/source/blender/compositor/COM_precomp.h new file mode 100644 index 00000000000..4d2681ea0cd --- /dev/null +++ b/source/blender/compositor/COM_precomp.h @@ -0,0 +1,33 @@ +/* Pre-compiled headers, see: D13797. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "COM_ConstantOperation.h" +#include "COM_ConvertOperation.h" +#include "COM_Debug.h" +#include "COM_Enums.h" +#include "COM_ExecutionGroup.h" +#include "COM_ExecutionSystem.h" +#include "COM_MultiThreadedOperation.h" +#include "COM_Node.h" +#include "COM_NodeOperation.h" +#include "COM_OpenCLDevice.h" +#include "COM_SetAlphaMultiplyOperation.h" +#include "COM_SetColorOperation.h" +#include "COM_SetSamplerOperation.h" +#include "COM_SetValueOperation.h" +#include "COM_SetVectorOperation.h" +#include "COM_defines.h" diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 0e871f47b87..e601ebac4e1 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -136,7 +136,7 @@ void add_exr_channels(void *exrhandle, const char *layer_name, const DataType datatype, const char *view_name, - const size_t width, + size_t width, bool use_half_float, float *buf); void free_exr_channels(void *exrhandle, diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 1c09417e9ab..fcdc3fe58e8 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1475,6 +1475,17 @@ void DepsgraphRelationBuilder::build_animation_images(ID *id) id, NodeType::IMAGE_ANIMATION, OperationCode::IMAGE_ANIMATION); TimeSourceKey time_src_key; add_relation(time_src_key, image_animation_key, "TimeSrc -> Image Animation"); + + /* The image users of these ids may change during evaluation. Make sure that the image + * animation update happens after evaluation. */ + if (GS(id->name) == ID_MA) { + OperationKey material_update_key(id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE); + add_relation(material_update_key, image_animation_key, "Material Update -> Image Animation"); + } + else if (GS(id->name) == ID_WO) { + OperationKey world_update_key(id, NodeType::SHADING, OperationCode::WORLD_UPDATE); + add_relation(world_update_key, image_animation_key, "World Update -> Image Animation"); + } } } diff --git a/source/blender/depsgraph/intern/node/deg_node_factory.h b/source/blender/depsgraph/intern/node/deg_node_factory.h index 125f340a0fa..b3153a7ddfb 100644 --- a/source/blender/depsgraph/intern/node/deg_node_factory.h +++ b/source/blender/depsgraph/intern/node/deg_node_factory.h @@ -55,7 +55,7 @@ template struct DepsNodeFactoryImpl : public DepsNodeFacto void register_node_typeinfo(DepsNodeFactory *factory); /* Get typeinfo for specified type */ -DepsNodeFactory *type_get_factory(const NodeType type); +DepsNodeFactory *type_get_factory(NodeType type); } // namespace deg } // namespace blender diff --git a/source/blender/draw/intern/draw_cache_impl_curve.cc b/source/blender/draw/intern/draw_cache_impl_curve.cc index 33cf0e9a3cd..1108d40125b 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.cc +++ b/source/blender/draw/intern/draw_cache_impl_curve.cc @@ -26,8 +26,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc index b846da3f016..ea702e5efdd 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc @@ -25,7 +25,9 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" +#include "BLI_float4.hh" #include "BLI_string.h" #include "BKE_attribute.h" diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 73a94f066e3..79dda480a0a 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -54,6 +54,7 @@ #include "BKE_deform.h" #include "BKE_global.h" #include "BKE_gpencil.h" +#include "BKE_gpencil_curve.h" #include "BKE_gpencil_geom.h" #include "BKE_layer.h" #include "BKE_main.h" @@ -834,7 +835,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p, /* color strength */ if (brush_settings->flag & GP_BRUSH_USE_STRENGTH_PRESSURE) { pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); } /* Set vertex colors for buffer. */ @@ -918,6 +919,19 @@ static short gpencil_stroke_addpoint(tGPsdata *p, return GP_STROKEADD_INVALID; } +static void gpencil_stroke_unselect(bGPdata *gpd, bGPDstroke *gps) +{ + gps->flag &= ~GP_STROKE_SELECT; + BKE_gpencil_stroke_select_index_reset(gps); + for (int i = 0; i < gps->totpoints; i++) { + gps->points[i].flag &= ~GP_SPOINT_SELECT; + } + /* Update the selection from the stroke to the curve. */ + if (gps->editcurve) { + BKE_gpencil_editcurve_stroke_sync_selection(gpd, gps, gps->editcurve); + } +} + /* make a new stroke from the buffer data */ static void gpencil_stroke_newfrombuffer(tGPsdata *p) { @@ -928,6 +942,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) tGPspoint *ptc; MDeformVert *dvert = NULL; Brush *brush = p->brush; + BrushGpencilSettings *brush_settings = brush->gpencil_settings; ToolSettings *ts = p->scene->toolsettings; Depsgraph *depsgraph = p->depsgraph; Object *obact = (Object *)p->ownerPtr.data; @@ -1016,7 +1031,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; /* Apply the vertex color to point. */ @@ -1050,7 +1065,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); pt->time = ptc->time; /* Apply the vertex color to point. */ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); @@ -1175,7 +1190,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; pt->uv_fac = ptc->uv_fac; @@ -1300,7 +1315,12 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) ctrl2, GPENCIL_MINIMUM_JOIN_DIST, &pt_index); + if (gps_target != NULL) { + /* Unselect all points of source and destination strokes. This is required to avoid + * a change in the resolution of the original strokes during the join. */ + gpencil_stroke_unselect(gpd, gps); + gpencil_stroke_unselect(gpd, gps_target); gps = ED_gpencil_stroke_join_and_trim(p->gpd, p->gpf, gps, gps_target, pt_index); } else { diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h index 8a669a2afc2..6bcddfa631a 100644 --- a/source/blender/editors/include/ED_util.h +++ b/source/blender/editors/include/ED_util.h @@ -102,7 +102,7 @@ void ED_slider_destroy(struct bContext *C, struct tSlider *slider); */ void ED_slider_status_string_get(const struct tSlider *slider, char *status_string, - const size_t size_of_status_string); + size_t size_of_status_string); float ED_slider_factor_get(struct tSlider *slider); void ED_slider_factor_set(struct tSlider *slider, float factor); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index f01b8318e98..9ce07cd2e07 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -495,7 +495,7 @@ float UI_text_clip_middle_ex(const struct uiFontStyle *fstyle, char *str, float okwidth, float minwidth, - const size_t max_len, + size_t max_len, char rpart_sep); /** @@ -2957,15 +2957,17 @@ void UI_fontstyle_set(const struct uiFontStyle *fs); void UI_fontstyle_draw_ex(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, + size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, - size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info); + void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, + size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params); /** diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 027f03d05c7..923f741e3ae 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -688,11 +688,11 @@ extern void ui_hsvcube_pos_from_vals( */ extern void ui_but_string_get_ex(uiBut *but, char *str, - const size_t maxlen, + size_t maxlen, int float_precision, bool use_exp_float, bool *r_use_exp_float) ATTR_NONNULL(1, 2); -extern void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) ATTR_NONNULL(); +extern void ui_but_string_get(uiBut *but, char *str, size_t maxlen) ATTR_NONNULL(); /** * A version of #ui_but_string_get_ex for dynamic buffer sizes * (where #ui_but_string_get_max_length returns 0). diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index bc1d3387ad7..135cef5fe53 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1146,6 +1146,7 @@ static void panel_draw_aligned_widgets(const uiStyle *style, UI_fontstyle_draw(fontstyle, &title_rect, panel->drawname, + sizeof(panel->drawname), title_color, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index e146443faaa..fe58a6a05ae 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -74,6 +74,8 @@ #define UI_TIP_PADDING (int)(UI_TIP_PAD_FAC * UI_UNIT_Y) #define UI_TIP_MAXWIDTH 600 +#define UI_TIP_STR_MAX 1024 + typedef struct uiTooltipFormat { enum { UI_TIP_STYLE_NORMAL = 0, @@ -214,7 +216,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw header and active data (is done here to be able to change color) */ rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_MAIN]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); /* offset to the end of the last line */ if (field->text_suffix) { @@ -224,7 +226,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.ymax -= yofs; rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_ACTIVE]); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text_suffix, drawcol, &fs_params); + UI_fontstyle_draw( + &data->fstyle, &bbox, field->text_suffix, UI_TIP_STR_MAX, drawcol, &fs_params); /* undo offset */ bbox.xmin -= xofs; @@ -243,7 +246,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* XXX, needed because we don't have mono in 'U.uifonts' */ BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); - UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); } else { BLI_assert(field->format.style == UI_TIP_STYLE_NORMAL); @@ -255,7 +258,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw remaining data */ rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); } bbox.ymax -= data->lineh * field->geom.lines; @@ -1215,12 +1218,12 @@ static ARegion *ui_tooltip_create_with_data(bContext *C, BLI_assert(ELEM(field->format.style, UI_TIP_STYLE_NORMAL, UI_TIP_STYLE_HEADER)); font_id = data->fstyle.uifont_id; } - w = BLF_width_ex(font_id, field->text, BLF_DRAW_STR_DUMMY_MAX, &info); + w = BLF_width_ex(font_id, field->text, UI_TIP_STR_MAX, &info); /* check for suffix (enum label) */ if (field->text_suffix && field->text_suffix[0]) { x_pos = info.width; - w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, BLF_DRAW_STR_DUMMY_MAX)); + w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, UI_TIP_STR_MAX)); } fontw = max_ii(fontw, w); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index c28769a4951..44942d508ca 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -140,9 +140,9 @@ static uiFont *uifont_to_blfont(int id) void UI_fontstyle_draw_ex(const uiFontStyle *fs, const rcti *rect, const char *str, + const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, - size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info) @@ -183,10 +183,10 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, } if (fs_params->align == UI_STYLE_TEXT_CENTER) { - xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); + xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len))); } else if (fs_params->align == UI_STYLE_TEXT_RIGHT) { - xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len); + xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len); } yofs = MAX2(0, yofs); @@ -196,7 +196,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_color4ubv(fs->uifont_id, col); - BLF_draw_ex(fs->uifont_id, str, len, r_info); + BLF_draw_ex(fs->uifont_id, str, str_len, r_info); BLF_disable(fs->uifont_id, font_flag); @@ -211,12 +211,11 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, + const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params) { - int xofs, yofs; - - UI_fontstyle_draw_ex(fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, NULL); + UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, NULL, NULL, NULL); } void UI_fontstyle_draw_rotated(const uiFontStyle *fs, diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ad8c0842657..b44496731f7 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2130,11 +2130,11 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, + drawlen, wcol->text, &(struct uiFontStyleDraw_Params){ .align = align, }, - drawlen, &font_xofs, &font_yofs, NULL); @@ -2194,6 +2194,7 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, drawstr_right, + UI_MAX_DRAW_STR, col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5417,11 +5418,11 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr, + sizeof(drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, }, - BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, &info); @@ -5468,6 +5469,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, hint_drawstr, + sizeof(hint_drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5523,6 +5525,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, &trect, drawstr, + sizeof(drawstr), text_col, &(struct uiFontStyleDraw_Params){ .align = text_align, diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index b9943d13b19..06e21f91d04 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -3527,6 +3527,8 @@ static int object_add_named_exec(bContext *C, wmOperator *op) } basen->object->visibility_flag &= ~OB_HIDE_VIEWPORT; + /* Do immediately, as #copy_object_set_idnew() below operates on visible objects. */ + BKE_base_eval_flags(basen); /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or * BKE_view_layer_base_deselect_all(). */ diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 16e83395401..4f94927533b 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -722,7 +722,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r SpaceProperties *sbuts = CTX_wm_space_properties(C); ShaderPreview *sp = static_cast(WM_jobs_customdata(wm, area)); rcti newrect; - int ok; + bool ok; int newx = BLI_rcti_size_x(rect); int newy = BLI_rcti_size_y(rect); diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 44e9735866d..dd1b4e10e60 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -240,6 +240,7 @@ static void file_draw_string(int sx, UI_fontstyle_draw(&fs, &rect, fname, + sizeof(fname), col, &(struct uiFontStyleDraw_Params){ .align = align, @@ -289,12 +290,12 @@ static void file_draw_string_multiline(int sx, UI_fontstyle_draw_ex(&style->widget, &rect, string, + len, text_col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, .word_wrap = true, }, - len, NULL, NULL, &result); diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 2d3c42b16d1..e9a385c525b 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2452,7 +2452,7 @@ static void frame_node_draw_label(const bNodeTree &ntree, const bool has_label = node.label[0] != '\0'; if (has_label) { BLF_position(fontid, x, y, 0); - BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, label, sizeof(label)); } /* draw text body */ diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 02d68189997..4834ca3174a 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -28,9 +28,9 @@ #include "DNA_anim_types.h" #include "DNA_node_types.h" +#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_vector.hh" diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index 740d1fbb6f9..0f542734f66 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -23,7 +23,7 @@ #pragma once -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" #include "BLI_vector.hh" #include "BKE_node.h" @@ -43,6 +43,9 @@ struct bNodeLink; struct bNodeSocket; struct wmGizmoGroupType; struct wmKeyConfig; +namespace blender { +struct float2; +} struct wmWindow; /** Temporary data used in node link drag modal operator. */ diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index 803cf38c53a..334ca1f76ee 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -111,13 +111,11 @@ static bNode *node_under_mouse_select(bNodeTree &ntree, int mx, int my) static bNode *node_under_mouse_tweak(bNodeTree &ntree, const float2 &mouse) { - using namespace blender::math; - LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) { if (node->type == NODE_REROUTE) { bNodeSocket *socket = (bNodeSocket *)node->inputs.first; const float2 location{socket->locx, socket->locy}; - if (distance(mouse, location) < 24.0f) { + if (float2::distance(mouse, location) < 24.0f) { return node; } } diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index e814530d1e2..6dffc0bc2a4 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -2262,28 +2262,15 @@ void sequencer_draw_preview(const bContext *C, seq_prefetch_wm_notify(C, scene); } -/* Draw backdrop in sequencer timeline. */ -static void draw_seq_backdrop(View2D *v2d) +static void draw_seq_timeline_channels(View2D *v2d) { - int i; - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - /* View backdrop. */ - immUniformThemeColor(TH_BACK); - immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax); - - /* Darker overlay over the view backdrop. */ - immUniformThemeColorShade(TH_BACK, -10); - immRectf(pos, v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0); - - /* Alternating horizontal stripes. */ - i = max_ii(1, ((int)v2d->cur.ymin) - 1); - GPU_blend(GPU_BLEND_ALPHA); immUniformThemeColor(TH_ROW_ALTERNATE); + /* Alternating horizontal stripes. */ + int i = max_ii(1, ((int)v2d->cur.ymin) - 1); while (i < v2d->cur.ymax) { if (i & 1) { immRectf(pos, v2d->cur.xmin, i, v2d->cur.xmax, i + 1); @@ -2295,6 +2282,14 @@ static void draw_seq_backdrop(View2D *v2d) immUnbindProgram(); } +static void draw_seq_timeline_channel_numbers(ARegion *region) +{ + View2D *v2d = ®ion->v2d; + rcti rect; + BLI_rcti_init(&rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); + UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); +} + static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *region) { Scene *scene = CTX_data_scene(C); @@ -2718,7 +2713,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region) } UI_view2d_view_ortho(v2d); - draw_seq_backdrop(v2d); + draw_seq_timeline_channels(v2d); if ((sseq->flag & SEQ_SHOW_OVERLAY) && (sseq->timeline_overlay.flag & SEQ_TIMELINE_SHOW_GRID)) { U.v2d_min_gridsize *= 3; UI_view2d_draw_lines_x__discrete_frames_or_seconds( @@ -2776,13 +2771,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region) UI_view2d_view_restore(C); ED_time_scrub_draw(region, scene, !(sseq->flag & SEQ_DRAWFRAMES), true); - /* Draw channel numbers. */ - { - rcti rect; - BLI_rcti_init( - &rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); - UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); - } + draw_seq_timeline_channel_numbers(region); } void draw_timeline_seq_display(const bContext *C, ARegion *region) diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc index ede8756a9da..ee623083db7 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc @@ -19,8 +19,9 @@ #include "MEM_guardedalloc.h" #include "BLI_color.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_hash.hh" -#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index f4b5ff819ed..7cc2d8d0b48 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -17,7 +17,8 @@ #include #include -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BKE_geometry_set.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc index 556c0b0d5ca..36c7f1057df 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc @@ -123,7 +123,9 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float2 cell) { return math::distance_squared(cell, value) > threshold_sq; }, + [&](const float2 cell) { + return float2::distance_squared(cell, value) > threshold_sq; + }, prev_mask, new_indices); break; @@ -153,7 +155,9 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float3 cell) { return math::distance_squared(cell, value) > threshold_sq; }, + [&](const float3 cell) { + return float3::distance_squared(cell, value) > threshold_sq; + }, prev_mask, new_indices); break; diff --git a/source/blender/editors/util/ed_draw.c b/source/blender/editors/util/ed_draw.c index ccbde07f5b1..3e85862a847 100644 --- a/source/blender/editors/util/ed_draw.c +++ b/source/blender/editors/util/ed_draw.c @@ -599,9 +599,9 @@ static void metadata_custom_draw_fields(const char *field, const char *value, vo } MetadataCustomDrawContext *ctx = (MetadataCustomDrawContext *)ctx_v; char temp_str[MAX_METADATA_STR]; - BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: %s", field, value); + SNPRINTF(temp_str, "%s: %s", field, value); BLF_position(ctx->fontid, ctx->xmin, ctx->ymin + ctx->current_y, 0.0f); - BLF_draw(ctx->fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(ctx->fontid, temp_str, sizeof(temp_str)); ctx->current_y += ctx->vertical_offset; } @@ -625,18 +625,18 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const /* first line */ if (i == 0) { bool do_newline = false; - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[0]); if (metadata_is_valid(ibuf, temp_str, 0, len)) { BLF_position(fontid, xmin, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); do_newline = true; } - len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]); + len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[1]); if (metadata_is_valid(ibuf, temp_str, 1, len)) { - int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); BLF_position(fontid, xmax - line_width, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); do_newline = true; } @@ -645,32 +645,32 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const } } /* Strip */ else if (ELEM(i, 1, 2)) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); ofs_y += vertical_offset; } } /* Note (wrapped) */ else if (i == 3) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { struct ResultBLF info; BLF_enable(fontid, BLF_WORD_WRAP); BLF_wordwrap(fontid, ibuf->x - (margin * 2)); BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw_ex(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX, &info); + BLF_draw_ex(fontid, temp_str, sizeof(temp_str), &info); BLF_wordwrap(fontid, 0); BLF_disable(fontid, BLF_WORD_WRAP); ofs_y += vertical_offset * info.lines; } } else { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { - int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); BLF_position(fontid, xmax - line_width, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); ofs_y += vertical_offset; } } @@ -687,12 +687,12 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const int ofs_x = 0; ofs_y = ctx.current_y; for (int i = 5; i < 10; i++) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i]); if (metadata_is_valid(ibuf, temp_str, i, len)) { BLF_position(fontid, xmin + ofs_x, ymin + ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); - ofs_x += BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX) + UI_UNIT_X; + ofs_x += BLF_width(fontid, temp_str, sizeof(temp_str)) + UI_UNIT_X; } } } diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt index b7eaf018dba..47da6bc55f6 100644 --- a/source/blender/freestyle/CMakeLists.txt +++ b/source/blender/freestyle/CMakeLists.txt @@ -594,4 +594,7 @@ if(WIN32) endif() blender_add_lib(bf_freestyle "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") -blender_precompile_headers(bf_freestyle FRS_precomp.cpp FRS_precomp.h) + +if(COMMAND target_precompile_headers) + target_precompile_headers(bf_freestyle PRIVATE FRS_precomp.h) +endif() diff --git a/source/blender/freestyle/FRS_precomp.cpp b/source/blender/freestyle/FRS_precomp.cpp deleted file mode 100644 index 7e50a47f45b..00000000000 --- a/source/blender/freestyle/FRS_precomp.cpp +++ /dev/null @@ -1,2 +0,0 @@ -/* Pre-compiled headers, see: D2606. */ -#include "FRS_precomp.h" diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc index 0bbfbc8cb10..058fb76af2b 100644 --- a/source/blender/functions/intern/cpp_types.cc +++ b/source/blender/functions/intern/cpp_types.cc @@ -18,8 +18,9 @@ #include "FN_field_cpp_type.hh" #include "BLI_color.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" -#include "BLI_math_vec_types.hh" namespace blender::fn { diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index c7481c6ea67..65d7631445d 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -544,7 +544,7 @@ bool IMB_prepare_write_ImBuf(bool isfloat, struct ImBuf *ibuf); */ bool IMB_ispic(const char *filepath); bool IMB_ispic_type_matches(const char *filepath, int filetype); -int IMB_ispic_type_from_memory(const unsigned char *buf, const size_t buf_size); +int IMB_ispic_type_from_memory(const unsigned char *buf, size_t buf_size); int IMB_ispic_type(const char *filepath); /** @@ -972,28 +972,20 @@ void IMB_update_gpu_texture_sub(struct GPUTexture *tex, /** * \attention defined in stereoimbuf.c */ -void IMB_stereo3d_write_dimensions(char mode, - bool is_squeezed, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); -void IMB_stereo3d_read_dimensions(char mode, - bool is_squeezed, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); +void IMB_stereo3d_write_dimensions( + char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); +void IMB_stereo3d_read_dimensions( + char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); int *IMB_stereo3d_from_rect(struct ImageFormatData *im_format, - const size_t x, - const size_t y, - const size_t channels, + size_t x, + size_t y, + size_t channels, int *rect_left, int *rect_right); float *IMB_stereo3d_from_rectf(struct ImageFormatData *im_format, - const size_t x, - const size_t y, - const size_t channels, + size_t x, + size_t y, + size_t channels, float *rectf_left, float *rectf_right); /** diff --git a/source/blender/imbuf/IMB_metadata.h b/source/blender/imbuf/IMB_metadata.h index 652ce913ee5..50982d08c3e 100644 --- a/source/blender/imbuf/IMB_metadata.h +++ b/source/blender/imbuf/IMB_metadata.h @@ -58,10 +58,7 @@ void IMB_metadata_free(struct IDProperty *metadata); * \param len: length of value buffer allocated by user. * \return 1 (true) if metadata is present and value for the key found, 0 (false) otherwise. */ -bool IMB_metadata_get_field(struct IDProperty *metadata, - const char *key, - char *value, - const size_t len); +bool IMB_metadata_get_field(struct IDProperty *metadata, const char *key, char *value, size_t len); /** * Set user data in the metadata. diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h index 104458ffa7a..bf6aef3ecd3 100644 --- a/source/blender/imbuf/intern/IMB_filetype.h +++ b/source/blender/imbuf/intern/IMB_filetype.h @@ -41,7 +41,7 @@ typedef struct ImFileType { * \note that this may only read in a small part of the files header, * see: #IMB_ispic_type for details. */ - bool (*is_a)(const unsigned char *buf, const size_t size); + bool (*is_a)(const unsigned char *buf, size_t size); /** Load an image from memory. */ struct ImBuf *(*load)(const unsigned char *mem, @@ -93,7 +93,7 @@ void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty); /** \name Format: PNG (#IMB_FTYPE_PNG) * \{ */ -bool imb_is_a_png(const unsigned char *mem, const size_t size); +bool imb_is_a_png(const unsigned char *mem, size_t size); struct ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, @@ -106,7 +106,7 @@ bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: TARGA (#IMB_FTYPE_TGA) * \{ */ -bool imb_is_a_targa(const unsigned char *buf, const size_t size); +bool imb_is_a_targa(const unsigned char *buf, size_t size); struct ImBuf *imb_loadtarga(const unsigned char *mem, size_t size, int flags, @@ -119,7 +119,7 @@ bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: IRIS (#IMB_FTYPE_IMAGIC) * \{ */ -bool imb_is_a_iris(const unsigned char *mem, const size_t size); +bool imb_is_a_iris(const unsigned char *mem, size_t size); /** * Read in a B/W RGB or RGBA iris image file and return an image buffer. */ @@ -135,7 +135,7 @@ bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JP2 (#IMB_FTYPE_JP2) * \{ */ -bool imb_is_a_jp2(const unsigned char *buf, const size_t size); +bool imb_is_a_jp2(const unsigned char *buf, size_t size); struct ImBuf *imb_load_jp2(const unsigned char *mem, size_t size, int flags, @@ -151,7 +151,7 @@ bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JPEG (#IMB_FTYPE_JPG) * \{ */ -bool imb_is_a_jpeg(const unsigned char *mem, const size_t size); +bool imb_is_a_jpeg(const unsigned char *mem, size_t size); bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags); struct ImBuf *imb_load_jpeg(const unsigned char *buffer, size_t size, @@ -164,7 +164,7 @@ struct ImBuf *imb_load_jpeg(const unsigned char *buffer, /** \name Format: BMP (#IMB_FTYPE_BMP) * \{ */ -bool imb_is_a_bmp(const unsigned char *buf, const size_t size); +bool imb_is_a_bmp(const unsigned char *buf, size_t size); struct ImBuf *imb_bmp_decode(const unsigned char *mem, size_t size, int flags, @@ -178,7 +178,7 @@ bool imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: CINEON (#IMB_FTYPE_CINEON) * \{ */ -bool imb_is_a_cineon(const unsigned char *buf, const size_t size); +bool imb_is_a_cineon(const unsigned char *buf, size_t size); bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_cineon(const unsigned char *mem, size_t size, @@ -191,7 +191,7 @@ struct ImBuf *imb_load_cineon(const unsigned char *mem, /** \name Format: DPX (#IMB_FTYPE_DPX) * \{ */ -bool imb_is_a_dpx(const unsigned char *buf, const size_t size); +bool imb_is_a_dpx(const unsigned char *buf, size_t size); bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_dpx(const unsigned char *mem, size_t size, @@ -204,7 +204,7 @@ struct ImBuf *imb_load_dpx(const unsigned char *mem, /** \name Format: HDR (#IMB_FTYPE_RADHDR) * \{ */ -bool imb_is_a_hdr(const unsigned char *buf, const size_t size); +bool imb_is_a_hdr(const unsigned char *buf, size_t size); struct ImBuf *imb_loadhdr(const unsigned char *mem, size_t size, int flags, @@ -218,7 +218,7 @@ bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags); * \{ */ void imb_inittiff(void); -bool imb_is_a_tiff(const unsigned char *buf, const size_t size); +bool imb_is_a_tiff(const unsigned char *buf, size_t size); /** * Loads a TIFF file. * \param mem: Memory containing the TIFF file. diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 1d81653c7cd..6a05b681c88 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -879,7 +879,7 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); # else - /* Scale with swscale then flip image over Y axis. */ + /* Scale with swscale. */ int *dstStride = anim->pFrameRGB->linesize; uint8_t **dst = anim->pFrameRGB->data; const int dstStride2[4] = {dstStride[0], 0, 0, 0}; @@ -896,11 +896,12 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); - bottom = (unsigned char *)ibuf->rect; - top = bottom + ibuf->x * (ibuf->y - 1) * 4; + /* Flip destination image buffer over Y axis. */ + bottom = (unsigned char *)dst[0]; + top = bottom + anim->x * (anim->y - 1) * 4; - h = (ibuf->y + 1) / 2; - w = ibuf->x; + h = (anim->y + 1) / 2; + w = anim->x; for (y = 0; y < h; y++) { unsigned char tmp[4]; diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index 931c4f267f9..2d540f13a52 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -26,7 +26,7 @@ extern "C" { #endif -bool imb_is_a_dds(const unsigned char *mem, const size_t size); +bool imb_is_a_dds(const unsigned char *mem, size_t size); bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_dds(const unsigned char *mem, size_t size, diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index 659050cdb00..1201bd1b5e0 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -31,7 +31,7 @@ extern "C" { struct ImBuf; -bool imb_is_a_photoshop(const unsigned char *mem, const size_t size); +bool imb_is_a_photoshop(const unsigned char *mem, size_t size); int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h index 14336620926..4321c95db30 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.h +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -36,7 +36,7 @@ void imb_exitopenexr(void); * Test presence of OpenEXR file. * \param mem: pointer to loaded OpenEXR bit-stream. */ -bool imb_is_a_openexr(const unsigned char *mem, const size_t size); +bool imb_is_a_openexr(const unsigned char *mem, size_t size); bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 7f4e4dd31df..925ef0a8502 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -77,7 +77,7 @@ static const unsigned char *oldreadcolrs(RGBE *scan, scan[0][BLU] = *mem++; scan[0][EXP] = *mem++; if (scan[0][RED] == 1 && scan[0][GRN] == 1 && scan[0][BLU] == 1) { - for (i = scan[0][EXP] << rshift; i > 0; i--) { + for (i = scan[0][EXP] << rshift; i > 0 && len > 0; i--) { COPY_RGBE(scan[-1], scan[0]); scan++; len--; @@ -227,7 +227,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, int found = 0; int width = 0, height = 0; const unsigned char *ptr, *mem_eof = mem + size; - char oriY[80], oriX[80]; + char oriY[3], oriX[3]; if (!imb_is_a_hdr(mem, size)) { return NULL; @@ -244,22 +244,33 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, } } - if ((found && (x < (size + 2))) == 0) { + if ((found && (x < (size - 1))) == 0) { /* Data not found! */ return NULL; } - if (sscanf((const char *)&mem[x + 1], - "%79s %d %79s %d", - (char *)&oriY, - &height, - (char *)&oriX, - &width) != 4) { + x++; + + /* sscanf requires a null-terminated buffer argument */ + char buf[32] = {0}; + memcpy(buf, &mem[x], MIN2(sizeof(buf) - 1, size - x)); + + if (sscanf(buf, "%2s %d %2s %d", (char *)&oriY, &height, (char *)&oriX, &width) != 4) { + return NULL; + } + + if (width < 1 || height < 1) { return NULL; } + /* Checking that width x height does not extend past mem_eof is not easily possible + * since the format uses RLE compression. Can cause excessive memory allocation to occur. */ + /* find end of this line, data right behind it */ - ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n'); + ptr = (const unsigned char *)strchr((const char *)&mem[x], '\n'); + if (ptr == NULL || ptr >= mem_eof) { + return NULL; + } ptr++; if (flags & IB_test) { diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc index 4a359c49d26..86fa580bf1f 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.cc +++ b/source/blender/io/alembic/intern/abc_reader_object.cc @@ -120,29 +120,10 @@ static Imath::M44d blend_matrices(const Imath::M44d &m0, const Imath::M44d &m1, * the matrices manually. */ - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - mat0[i][j] = static_cast(m0[i][j]); - } - } - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - mat1[i][j] = static_cast(m1[i][j]); - } - } - + convert_matrix_datatype(m0, mat0); + convert_matrix_datatype(m1, mat1); interp_m4_m4m4(ret, mat0, mat1, weight); - - Imath::M44d m; - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - m[i][j] = ret[i][j]; - } - } - - return m; + return convert_matrix_datatype(ret); } Imath::M44d get_matrix(const IXformSchema &schema, const float time) diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc index 7868bade8c1..f031648d2ed 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc @@ -23,8 +23,9 @@ * \ingroup bgpencil */ +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" -#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_span.hh" @@ -282,7 +283,7 @@ float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, bGPDstroke *gps) const float2 screen_ex = gpencil_3D_point_to_2D(&pt->x); const float2 v1 = screen_co - screen_ex; - float radius = math::length(v1); + float radius = v1.length(); BKE_gpencil_free_stroke(gps_perimeter); return MAX2(radius, 1.0f); diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.hh b/source/blender/io/gpencil/intern/gpencil_io_base.hh index ae54d5056dc..09557cd7a4d 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.hh +++ b/source/blender/io/gpencil/intern/gpencil_io_base.hh @@ -22,8 +22,9 @@ * \ingroup bgpencil */ +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" -#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "DNA_space_types.h" /* for FILE_MAX */ diff --git a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc index 455ebb7c3cb..941d1137f4d 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc @@ -21,8 +21,8 @@ * \ingroup bgpencil */ +#include "BLI_float3.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_gpencil_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh index e6d2853d040..9a4dfe3efe3 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh @@ -22,7 +22,7 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_utility_mixins.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index 5b710939e00..b99d41e0c72 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -21,8 +21,8 @@ #include "BKE_image.h" #include "BKE_node.h" +#include "BLI_float3.hh" #include "BLI_map.hh" -#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "DNA_material_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh index a84dcb80a48..2f62d189bd1 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh @@ -20,8 +20,8 @@ #pragma once +#include "BLI_float3.hh" #include "BLI_map.hh" -#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc index ec690115115..91aabd8fa76 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc @@ -18,9 +18,9 @@ * \ingroup obj */ +#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index 0feca806f35..f9151bb97f8 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -236,7 +236,7 @@ TEST(obj_exporter_writer, mtllib) static bool strings_equal_after_first_lines(const std::string &a, const std::string &b) { /* If `dbg_level > 0` then a failing test will print context around the first mismatch. */ - const bool dbg_level = 0; + const int dbg_level = 0; const size_t a_len = a.size(); const size_t b_len = b.size(); const size_t a_next = a.find_first_of('\n'); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index fc041e257b0..1d0796bda8b 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1852,6 +1852,7 @@ enum { MOD_TRIANGULATE_QUAD_FIXED = 1, MOD_TRIANGULATE_QUAD_ALTERNATE = 2, MOD_TRIANGULATE_QUAD_SHORTEDGE = 3, + MOD_TRIANGULATE_QUAD_LONGEDGE = 4, }; typedef struct LaplacianSmoothModifierData { diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 29d61bcf2ff..114e350b582 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -2118,6 +2118,7 @@ typedef enum GeometryNodeTriangulateQuads { GEO_NODE_TRIANGULATE_QUAD_FIXED = 1, GEO_NODE_TRIANGULATE_QUAD_ALTERNATE = 2, GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE = 3, + GEO_NODE_TRIANGULATE_QUAD_LONGEDGE = 4, } GeometryNodeTriangulateQuads; typedef enum GeometryNodePointInstanceType { diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 77c0db81b37..b32d98e3cb1 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -1743,7 +1743,7 @@ bool RNA_struct_override_matches(struct Main *bmain, struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, const char *root_path, - const size_t root_path_len, + size_t root_path_len, struct IDOverrideLibrary *override, eRNAOverrideMatch flags, eRNAOverrideMatchResult *r_report_flags); diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 20e6e931b4b..95ad184c6b9 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -544,7 +544,7 @@ int rna_property_override_diff_default(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - const size_t rna_path_len, + size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index f0e32a19d04..723ae384fdf 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -214,7 +214,7 @@ typedef int (*RNAPropOverrideDiff)(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - const size_t rna_path_len, + size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index d46ae13b482..0f0734c8448 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -331,7 +331,12 @@ const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[] = { "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads based on the distance between the vertices"}, + "Split the quads along their shortest diagonal"}, + {MOD_TRIANGULATE_QUAD_LONGEDGE, + "LONGEST_DIAGONAL", + 0, + "Longest Diagonal", + "Split the quads along their longest diagonal"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index e7307e6e058..ecbeadf1fa4 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -9488,7 +9488,12 @@ static void def_geo_triangulate(StructRNA *srna) "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads based on the distance between the vertices"}, + "Split the quads along their shortest diagonal"}, + {GEO_NODE_TRIANGULATE_QUAD_LONGEDGE, + "LONGEST_DIAGONAL", + 0, + "Longest Diagonal", + "Split the quads along their longest diagonal"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc index 910b52dea67..778b5746471 100644 --- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc +++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc @@ -197,8 +197,8 @@ static float compute_voxel_size(const ModifierEvalContext *ctx, /* Compute the voxel size based on the desired number of voxels and the approximated bounding box * of the volume. */ const BoundBox *bb = BKE_object_boundbox_get(mvmd->object); - const float diagonal = math::distance(transform * float3(bb->vec[6]), - transform * float3(bb->vec[0])); + const float diagonal = float3::distance(transform * float3(bb->vec[6]), + transform * float3(bb->vec[0])); const float approximate_volume_side_length = diagonal + mvmd->exterior_band_width * 2.0f; const float voxel_size = approximate_volume_side_length / mvmd->voxel_amount / volume_simplify; return voxel_size; diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 49528845197..cee5d0be65d 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -28,8 +28,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_multi_value_map.hh" #include "BLI_set.hh" #include "BLI_string.h" diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh index 6ea89beee2e..a0a2e6f81f8 100644 --- a/source/blender/nodes/NOD_math_functions.hh +++ b/source/blender/nodes/NOD_math_functions.hh @@ -18,9 +18,9 @@ #include "DNA_node_types.h" +#include "BLI_float3.hh" #include "BLI_math_base_safe.h" #include "BLI_math_rotation.h" -#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" namespace blender::nodes { @@ -240,8 +240,6 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -261,21 +259,40 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation case NODE_VECTOR_MATH_MULTIPLY: return dispatch([](float3 a, float3 b) { return a * b; }); case NODE_VECTOR_MATH_DIVIDE: - return dispatch([](float3 a, float3 b) { return safe_divide(a, b); }); + return dispatch([](float3 a, float3 b) { + return float3(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z)); + }); case NODE_VECTOR_MATH_CROSS_PRODUCT: - return dispatch([](float3 a, float3 b) { return cross_high_precision(a, b); }); + return dispatch([](float3 a, float3 b) { return float3::cross_high_precision(a, b); }); case NODE_VECTOR_MATH_PROJECT: - return dispatch([](float3 a, float3 b) { return project(a, b); }); + return dispatch([](float3 a, float3 b) { + float length_squared = b.length_squared(); + return (length_squared != 0.0) ? (float3::dot(a, b) / length_squared) * b : float3(0.0f); + }); case NODE_VECTOR_MATH_REFLECT: - return dispatch([](float3 a, float3 b) { return reflect(a, normalize(b)); }); + return dispatch([](float3 a, float3 b) { + b.normalize(); + return a.reflected(b); + }); case NODE_VECTOR_MATH_SNAP: - return dispatch([](float3 a, float3 b) { return floor(safe_divide(a, b)) * b; }); + return dispatch([](float3 a, float3 b) { + return float3(floor(safe_divide(a.x, b.x)), + floor(safe_divide(a.y, b.y)), + floor(safe_divide(a.z, b.z))) * + b; + }); case NODE_VECTOR_MATH_MODULO: - return dispatch([](float3 a, float3 b) { return mod(a, b); }); + return dispatch([](float3 a, float3 b) { + return float3(safe_modf(a.x, b.x), safe_modf(a.y, b.y), safe_modf(a.z, b.z)); + }); case NODE_VECTOR_MATH_MINIMUM: - return dispatch([](float3 a, float3 b) { return min(a, b); }); + return dispatch([](float3 a, float3 b) { + return float3(min_ff(a.x, b.x), min_ff(a.y, b.y), min_ff(a.z, b.z)); + }); case NODE_VECTOR_MATH_MAXIMUM: - return dispatch([](float3 a, float3 b) { return max(a, b); }); + return dispatch([](float3 a, float3 b) { + return float3(max_ff(a.x, b.x), max_ff(a.y, b.y), max_ff(a.z, b.z)); + }); default: return false; } @@ -289,8 +306,6 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -304,9 +319,9 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation switch (operation) { case NODE_VECTOR_MATH_DOT_PRODUCT: - return dispatch([](float3 a, float3 b) { return dot(a, b); }); + return dispatch([](float3 a, float3 b) { return float3::dot(a, b); }); case NODE_VECTOR_MATH_DISTANCE: - return dispatch([](float3 a, float3 b) { return distance(a, b); }); + return dispatch([](float3 a, float3 b) { return float3::distance(a, b); }); default: return false; } @@ -320,8 +335,6 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -341,7 +354,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOpera return float3(wrapf(a.x, b.x, c.x), wrapf(a.y, b.y, c.y), wrapf(a.z, b.z, c.z)); }); case NODE_VECTOR_MATH_FACEFORWARD: - return dispatch([](float3 a, float3 b, float3 c) { return faceforward(a, b, c); }); + return dispatch([](float3 a, float3 b, float3 c) { return float3::faceforward(a, b, c); }); default: return false; } @@ -355,8 +368,6 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -370,7 +381,8 @@ inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperat switch (operation) { case NODE_VECTOR_MATH_REFRACT: - return dispatch([](float3 a, float3 b, float c) { return refract(a, normalize(b), c); }); + return dispatch( + [](float3 a, float3 b, float c) { return float3::refract(a, b.normalized(), c); }); default: return false; } @@ -384,8 +396,6 @@ template inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -399,7 +409,7 @@ inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation oper switch (operation) { case NODE_VECTOR_MATH_LENGTH: - return dispatch([](float3 in) { return length(in); }); + return dispatch([](float3 in) { return in.length(); }); default: return false; } @@ -440,8 +450,6 @@ template inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -455,15 +463,20 @@ inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation ope switch (operation) { case NODE_VECTOR_MATH_NORMALIZE: - return dispatch([](float3 in) { return normalize(in); }); /* Should be safe. */ + return dispatch([](float3 in) { + float3 out = in; + out.normalize(); + return out; + }); /* Should be safe. */ case NODE_VECTOR_MATH_FLOOR: - return dispatch([](float3 in) { return floor(in); }); + return dispatch([](float3 in) { return float3(floor(in.x), floor(in.y), floor(in.z)); }); case NODE_VECTOR_MATH_CEIL: - return dispatch([](float3 in) { return ceil(in); }); + return dispatch([](float3 in) { return float3(ceil(in.x), ceil(in.y), ceil(in.z)); }); case NODE_VECTOR_MATH_FRACTION: - return dispatch([](float3 in) { return fract(in); }); + return dispatch( + [](float3 in) { return in - float3(floor(in.x), floor(in.y), floor(in.z)); }); case NODE_VECTOR_MATH_ABSOLUTE: - return dispatch([](float3 in) { return abs(in); }); + return dispatch([](float3 in) { return float3::abs(in); }); case NODE_VECTOR_MATH_SINE: return dispatch([](float3 in) { return float3(sinf(in.x), sinf(in.y), sinf(in.z)); }); case NODE_VECTOR_MATH_COSINE: diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh index a1972c66ca2..c0580a2c919 100644 --- a/source/blender/nodes/NOD_socket_declarations.hh +++ b/source/blender/nodes/NOD_socket_declarations.hh @@ -21,7 +21,7 @@ #include "RNA_types.h" #include "BLI_color.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" namespace blender::nodes::decl { diff --git a/source/blender/nodes/composite/node_composite_tree.cc b/source/blender/nodes/composite/node_composite_tree.cc index 08dbd4ad6f0..c54382cc1ad 100644 --- a/source/blender/nodes/composite/node_composite_tree.cc +++ b/source/blender/nodes/composite/node_composite_tree.cc @@ -249,23 +249,6 @@ void ntreeCompositUpdateRLayers(bNodeTree *ntree) } } -void ntreeCompositRegisterPass(bNodeTree *ntree, - Scene *scene, - ViewLayer *view_layer, - const char *name, - eNodeSocketDatatype type) -{ - if (ntree == nullptr) { - return; - } - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node->type == CMP_NODE_R_LAYERS) { - node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type); - } - } -} - void ntreeCompositTagRender(Scene *scene) { /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes, diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index 6f4f9d7e597..f2b9fbc2215 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -269,7 +269,12 @@ void node_cmp_rlayers_register_pass(bNodeTree *ntree, } } -static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), +struct CreateOutputUserData { + bNodeTree &ntree; + bNode &node; +}; + +static void cmp_node_rlayer_create_outputs_cb(void *userdata, Scene *scene, ViewLayer *view_layer, const char *name, @@ -277,18 +282,8 @@ static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), const char *UNUSED(chanid), eNodeSocketDatatype type) { - /* Register the pass in all scenes that have a render layer node for this layer. - * Since multiple scenes can be used in the compositor, the code must loop over all scenes - * and check whether their nodetree has a node that needs to be updated. */ - /* NOTE: using G_MAIN seems valid here, - * unless we want to register that for every other temp Main we could generate??? */ - ntreeCompositRegisterPass(scene->nodetree, scene, view_layer, name, type); - - for (Scene *sce = (Scene *)G_MAIN->scenes.first; sce; sce = (Scene *)sce->id.next) { - if (sce->nodetree && sce != scene) { - ntreeCompositRegisterPass(sce->nodetree, scene, view_layer, name, type); - } - } + CreateOutputUserData &data = *(CreateOutputUserData *)userdata; + node_cmp_rlayers_register_pass(&data.ntree, &data.node, scene, view_layer, name, type); } static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, @@ -308,14 +303,17 @@ static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, data->prev_index = -1; node->storage = data; + CreateOutputUserData userdata = {*ntree, *node}; + RenderEngine *engine = RE_engine_create(engine_type); RE_engine_update_render_passes( - engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, nullptr); + engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, &userdata); RE_engine_free(engine); if ((scene->r.mode & R_EDGE_FRS) && (view_layer->freestyle_config.flags & FREESTYLE_AS_RENDER_PASS)) { - ntreeCompositRegisterPass(ntree, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); + node_cmp_rlayers_register_pass( + ntree, node, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); } MEM_freeN(data); diff --git a/source/blender/nodes/function/node_function_util.hh b/source/blender/nodes/function/node_function_util.hh index 69c617b4f01..acde9c4b55b 100644 --- a/source/blender/nodes/function/node_function_util.hh +++ b/source/blender/nodes/function/node_function_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc index bcc035e6ede..f4ce8d2f35a 100644 --- a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc +++ b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc @@ -69,14 +69,14 @@ static void align_rotations_auto_pivot(IndexMask mask, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = math::normalize(vector); - float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); + const float3 new_axis = vector.normalized(); + float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc index 7c09bace756..3bb46511eeb 100644 --- a/source/blender/nodes/function/nodes/node_fn_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_compare.cc @@ -265,7 +265,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Than - Dot Product", - [](float3 a, float3 b, float comp) { return math::dot(a, b) < comp; }}; + [](float3 a, float3 b, float comp) { return float3::dot(a, b) < comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -283,7 +283,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Than - Length", - [](float3 a, float3 b) { return math::length(a) < math::length(b); }}; + [](float3 a, float3 b) { return a.length() < b.length(); }}; return &fn; } } @@ -299,7 +299,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Equal - Dot Product", - [](float3 a, float3 b, float comp) { return math::dot(a, b) <= comp; }}; + [](float3 a, float3 b, float comp) { return float3::dot(a, b) <= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -317,7 +317,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Equal - Length", - [](float3 a, float3 b) { return math::length(a) <= math::length(b); }}; + [](float3 a, float3 b) { return a.length() <= b.length(); }}; return &fn; } } @@ -333,7 +333,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Than - Dot Product", - [](float3 a, float3 b, float comp) { return math::dot(a, b) > comp; }}; + [](float3 a, float3 b, float comp) { return float3::dot(a, b) > comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -351,7 +351,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Than - Length", - [](float3 a, float3 b) { return math::length(a) > math::length(b); }}; + [](float3 a, float3 b) { return a.length() > b.length(); }}; return &fn; } } @@ -367,7 +367,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Equal - Dot Product", - [](float3 a, float3 b, float comp) { return math::dot(a, b) >= comp; }}; + [](float3 a, float3 b, float comp) { return float3::dot(a, b) >= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -385,7 +385,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Equal - Length", - [](float3 a, float3 b) { return math::length(a) >= math::length(b); }}; + [](float3 a, float3 b) { return a.length() >= b.length(); }}; return &fn; } } @@ -402,7 +402,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(math::dot(a, b) - comp) <= epsilon; + return abs(float3::dot(a, b) - comp) <= epsilon; }}; return &fn; } @@ -424,7 +424,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(math::length(a) - math::length(b)) <= epsilon; + return abs(a.length() - b.length()) <= epsilon; }}; return &fn; } @@ -442,7 +442,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Not Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(math::dot(a, b) - comp) >= epsilon; + return abs(float3::dot(a, b) - comp) >= epsilon; }}; return &fn; } @@ -464,7 +464,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Not Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(math::length(a) - math::length(b)) > epsilon; + return abs(a.length() - b.length()) > epsilon; }}; return &fn; } diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh index e063be62987..1c2a8f521c0 100644 --- a/source/blender/nodes/geometry/node_geometry_util.hh +++ b/source/blender/nodes/geometry/node_geometry_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" @@ -83,7 +83,7 @@ Mesh *create_cylinder_or_cone_mesh(float radius_top, int circle_segments, int side_segments, int fill_segments, - const GeometryNodeMeshCircleFillType fill_type, + GeometryNodeMeshCircleFillType fill_type, ConeAttributeOutputs &attribute_outputs); Mesh *create_cuboid_mesh(float3 size, int verts_x, int verts_y, int verts_z); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc index 1d064586238..36ad4605a4b 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc @@ -90,14 +90,14 @@ static void align_rotations_auto_pivot(const VArray &vectors, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = math::normalize(vector); - float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); + const float3 new_axis = vector.normalized(); + float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc index 20f500b1bd8..74dac73f255 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc @@ -81,7 +81,7 @@ static void calculate_mesh_proximity(const VArray &positions, for (int i : range) { /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[i]); + nearest.dist_sq = float3::distance_squared(nearest.co, positions[i]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[i], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc index a85a7c56cb9..b0210f2eb94 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc @@ -229,7 +229,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = math::distance_squared(position, float3(mvert.co)); + const float distance_sq = float3::distance_squared(position, mvert.co); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc index 1e6b7f92a77..8555d7cc8a3 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc @@ -241,13 +241,13 @@ static void copy_uniform_sample_point_attributes(Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent = math::normalize(tangent); + tangent.normalize(); } spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals = math::normalize(normals); + normals.normalize(); } } }); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc index c712e82ca18..29eff373d15 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc @@ -321,7 +321,7 @@ BLI_NOINLINE static void interpolate_existing_attributes( continue; } - for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { + for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { const int offset = instance_start_offsets[i_instance]; Span bary_coords = bary_coords_array[i_instance]; Span looptri_indices = looptri_indices_array[i_instance]; @@ -516,7 +516,7 @@ static void distribute_points_poisson_disk(Span set_group const VArray density_factors = component.attribute_get_for_read( density_attribute_name, ATTR_DOMAIN_CORNER, use_one_default ? 1.0f : 0.0f); - for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { + for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { Vector &positions = positions_all[i_instance]; Vector &bary_coords = bary_coords_all[i_instance]; Vector &looptri_indices = looptri_indices_all[i_instance]; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc index f54ffc53a6e..7b1bbed8ae4 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc @@ -161,7 +161,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = math::distance(min, max); + const float diagonal = float3::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc index cfae88e0625..dd03092a594 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc @@ -107,7 +107,7 @@ static void raycast_to_mesh(const Mesh &mesh, for (const int i : ray_origins.index_range()) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = math::normalize(ray_directions[i]); + const float3 ray_direction = ray_directions[i].normalized(); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc index 929d9046f98..7e09721273a 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc @@ -16,7 +16,7 @@ #include "BLI_array.hh" #include "BLI_delaunay_2d.h" -#include "BLI_math_vec_types.hh" +#include "BLI_double2.hh" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc index 68b609f8045..1a44fce86a6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc @@ -122,9 +122,9 @@ static Array calculate_directions(const Span positions) Array directions(size); for (const int i : IndexRange(size - 1)) { - directions[i] = math::normalize(positions[i + 1] - positions[i]); + directions[i] = (positions[i + 1] - positions[i]).normalized(); } - directions[size - 1] = math::normalize(positions[0] - positions[size - 1]); + directions[size - 1] = (positions[0] - positions[size - 1]).normalized(); return directions; } @@ -135,9 +135,9 @@ static Array calculate_axes(const Span directions) const int size = directions.size(); Array axes(size); - axes[0] = math::normalize(math::cross(-directions[size - 1], directions[0])); + axes[0] = float3::cross(-directions[size - 1], directions[0]).normalized(); for (const int i : IndexRange(1, size - 1)) { - axes[i] = math::normalize(math::cross(-directions[i - 1], directions[i])); + axes[i] = float3::cross(-directions[i - 1], directions[i]).normalized(); } return axes; @@ -248,8 +248,8 @@ static void limit_radii(FilletData &fd, const bool cyclic) if (cyclic) { /* Calculate lengths between adjacent control points. */ - const float len_prev = math::distance(positions[0], positions[size - 1]); - const float len_next = math::distance(positions[0], positions[1]); + const float len_prev = float3::distance(positions[0], positions[size - 1]); + const float len_next = float3::distance(positions[0], positions[1]); /* Calculate tangent lengths of fillets in control points. */ const float tan_len = radii[0] * tan(angles[0] / 2.0f); @@ -271,16 +271,16 @@ static void limit_radii(FilletData &fd, const bool cyclic) } /* Initialize max_radii to largest possible radii. */ - float prev_dist = math::distance(positions[1], positions[0]); + float prev_dist = float3::distance(positions[1], positions[0]); for (const int i : IndexRange(1, size - 2)) { - const float temp_dist = math::distance(positions[i], positions[i + 1]); + const float temp_dist = float3::distance(positions[i], positions[i + 1]); max_radii[i] = std::min(prev_dist, temp_dist) / tan(angles[i] / 2.0f); prev_dist = temp_dist; } /* Max radii calculations for each index. */ for (const int i : IndexRange(start, fillet_count - 1)) { - const float len_next = math::distance(positions[i], positions[i + 1]); + const float len_next = float3::distance(positions[i], positions[i + 1]); const float tan_len = radii[i] * tan(angles[i] / 2.0f); const float tan_len_next = radii[i + 1] * tan(angles[i + 1] / 2.0f); @@ -415,8 +415,7 @@ static void update_bezier_positions(const FilletData &fd, const float3 center = get_center(dst_spline.positions()[i_dst] - positions[i_src], fd, i_src); /* Calculate the vector of the radius formed by the first vertex. */ float3 radius_vec = dst_spline.positions()[i_dst] - center; - float radius; - radius_vec = math::normalize_and_get_length(radius_vec, radius); + const float radius = radius_vec.normalize_and_get_length(); dst_spline.handle_types_right().slice(1, count - 2).fill(BezierSpline::HandleType::Align); dst_spline.handle_types_left().slice(1, count - 2).fill(BezierSpline::HandleType::Align); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc index 7b5d1a1dc80..a7fb493c7d7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc @@ -101,8 +101,8 @@ static void node_update(bNodeTree *ntree, bNode *node) static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3) { - const float3 a = math::normalize(p2 - p1); - const float3 b = math::normalize(p3 - p1); + const float3 a = (p2 - p1).normalized(); + const float3 b = (p3 - p1).normalized(); return (ELEM(a, b, b * -1.0f)); } @@ -122,18 +122,18 @@ static std::unique_ptr create_point_circle_curve( float3 center; /* Midpoints of `P1->P2` and `P2->P3`. */ - const float3 q1 = math::interpolate(p1, p2, 0.5f); - const float3 q2 = math::interpolate(p2, p3, 0.5f); + const float3 q1 = float3::interpolate(p1, p2, 0.5f); + const float3 q2 = float3::interpolate(p2, p3, 0.5f); /* Normal Vectors of `P1->P2` and `P2->P3` */ - const float3 v1 = math::normalize(p2 - p1); - const float3 v2 = math::normalize(p3 - p2); + const float3 v1 = (p2 - p1).normalized(); + const float3 v2 = (p3 - p2).normalized(); /* Normal of plane of main 2 segments P1->P2 and `P2->P3`. */ - const float3 v3 = math::normalize(math::cross(v1, v2)); + const float3 v3 = float3::cross(v1, v2).normalized(); /* Normal of plane of first perpendicular bisector and `P1->P2`. */ - const float3 v4 = math::normalize(math::cross(v3, v1)); + const float3 v4 = float3::cross(v3, v1).normalized(); /* Determine Center-point from the intersection of 3 planes. */ float plane_1[4], plane_2[4], plane_3[4]; @@ -148,7 +148,7 @@ static std::unique_ptr create_point_circle_curve( } /* Get the radius from the center-point to p1. */ - const float r = math::distance(p1, center); + const float r = float3::distance(p1, center); const float theta_step = ((2 * M_PI) / (float)resolution); for (const int i : IndexRange(resolution)) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc index d35fa0a2fdc..ff9218b1ac2 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc @@ -100,7 +100,7 @@ static std::unique_ptr create_direction_line_curve(const float3 start spline->resize(2); MutableSpan positions = spline->positions(); positions[0] = start; - positions[1] = math::normalize(direction) * length + start; + positions[1] = direction.normalized() * length + start; spline->radii().fill(1.0f); spline->tilts().fill(0.0f); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc index 885d92a111b..084d27e9d24 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc @@ -58,9 +58,9 @@ static std::unique_ptr create_quadratic_bezier_curve(const float3 p1, const float step = 1.0f / resolution; for (const int i : IndexRange(resolution + 1)) { const float factor = step * i; - const float3 q1 = math::interpolate(p1, p2, factor); - const float3 q2 = math::interpolate(p2, p3, factor); - positions[i] = math::interpolate(q1, q2, factor); + const float3 q1 = float3::interpolate(p1, p2, factor); + const float3 q2 = float3::interpolate(p2, p3, factor); + positions[i] = float3::interpolate(q1, q2, factor); } curve->add_spline(std::move(spline)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc index 56fbc50f033..038f7625825 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc @@ -185,7 +185,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_tangents = splines[spline_indices[i]]->evaluated_tangents(); - sampled_tangents[i] = math::normalize(sample_with_lookup(lookup, evaluated_tangents)); + sampled_tangents[i] = sample_with_lookup(lookup, evaluated_tangents).normalized(); } } @@ -193,7 +193,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_normals = splines[spline_indices[i]]->evaluated_normals(); - sampled_normals[i] = math::normalize(sample_with_lookup(lookup, evaluated_normals)); + sampled_normals[i] = sample_with_lookup(lookup, evaluated_normals).normalized(); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc index 257a5b8df00..40dde645756 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc @@ -96,7 +96,7 @@ static void calculate_nurbs_lengths(const NURBSpline &spline, MutableSpan float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { lengths[i] = length; - length += math::distance(positions[i], positions[i + 1]); + length += float3::distance(positions[i], positions[i + 1]); } lengths.last() = length; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc index 19efd4b7508..a8553b636a4 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc @@ -285,7 +285,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent = math::normalize(tangent); + tangent.normalize(); } } @@ -293,7 +293,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals = math::normalize(normals); + normals.normalize(); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc index 624a8b6b0f6..28a8fb80294 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc @@ -21,7 +21,7 @@ #include "BKE_image.h" -#include "BLI_math_vec_types.hh" +#include "BLI_float4.hh" #include "BLI_threads.h" #include "BLI_timeit.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc index e90a9eb393b..5b67258a947 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc @@ -155,7 +155,7 @@ static void calculate_polys(const CuboidConfig &config, /* Calculate polys for Bottom faces. */ int vert_1_start = 0; - for (const int UNUSED(y) : IndexRange(config.edges_y)) { + for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { const int vert_1 = vert_1_start + x; const int vert_2 = vert_1_start + config.verts_x + x; @@ -173,7 +173,7 @@ static void calculate_polys(const CuboidConfig &config, vert_1_start = 0; int vert_2_start = config.verts_x * config.verts_y; - for (const int UNUSED(z) : IndexRange(config.edges_z)) { + for ([[maybe_unused]] const int z : IndexRange(config.edges_z)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, @@ -196,7 +196,7 @@ static void calculate_polys(const CuboidConfig &config, (config.verts_x - 2) * (config.verts_y - 2)); vert_2_start = vert_1_start + config.verts_x; - for (const int UNUSED(y) : IndexRange(config.edges_y)) { + for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc index 8a2b054ece0..5116e78fdda 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc @@ -155,8 +155,8 @@ static void node_geo_exec(GeoNodeExecParams params) if (count_mode == GEO_NODE_MESH_LINE_COUNT_RESOLUTION) { /* Don't allow asymptotic count increase for low resolution values. */ const float resolution = std::max(params.extract_input("Resolution"), 0.0001f); - const int count = math::length(total_delta) / resolution + 1; - const float3 delta = math::normalize(total_delta) * resolution; + const int count = total_delta.length() / resolution + 1; + const float3 delta = total_delta.normalized() * resolution; mesh = create_line_mesh(start, delta, count); } else if (count_mode == GEO_NODE_MESH_LINE_COUNT_TOTAL) { @@ -204,7 +204,7 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count) MutableSpan edges{mesh->medge, mesh->totedge}; short normal[3]; - normal_float_to_short_v3(normal, math::normalize(delta)); + normal_float_to_short_v3(normal, delta.normalized()); for (const int i : verts.index_range()) { copy_v3_v3(verts[i].co, start + delta * i); diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc index 373e6bfdd18..41178d5c4e6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc @@ -178,7 +178,7 @@ static void calculate_sphere_faces(MutableSpan loops, int ring_vert_index_start = 1; int ring_edge_index_start = segments; - for (const int UNUSED(ring) : IndexRange(1, rings - 2)) { + for ([[maybe_unused]] const int ring : IndexRange(1, rings - 2)) { const int next_ring_vert_index_start = ring_vert_index_start + segments; const int next_ring_edge_index_start = ring_edge_index_start + segments * 2; const int ring_vertical_edge_index_start = ring_edge_index_start + segments; diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc index c165bcf8e35..dda4543d5e1 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc @@ -166,7 +166,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = math::distance(min, max); + const float diagonal = float3::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc index 772638ef240..e0117c4726d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc @@ -85,7 +85,7 @@ static bool calculate_mesh_proximity(const VArray &positions, for (int i : range) { const int index = mask[i]; /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[index]); + nearest.dist_sq = float3::distance_squared(nearest.co, positions[index]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[index], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc index c38503f688c..2c35ca0afc9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc @@ -163,7 +163,7 @@ static void raycast_to_mesh(IndexMask mask, for (const int i : mask) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = math::normalize(ray_directions[i]); + const float3 ray_direction = ray_directions[i].normalized(); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc index feab0a6743f..82d09bbc208 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc @@ -106,7 +106,7 @@ static void set_position_in_component(const GeometryNodeCurveHandleMode mode, } } else { - for (int UNUSED(i) : spline->positions().index_range()) { + for ([[maybe_unused]] int i : spline->positions().index_range()) { if (current_mask < selection.size() && selection[current_mask] == current_point) { current_mask++; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc index 6867051ecfe..331460296a6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc @@ -296,7 +296,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = math::distance_squared(position, float3(mvert.co)); + const float distance_sq = float3::distance_squared(position, mvert.co); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc index 6187a2eacf9..7f866ea6f4a 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc @@ -37,7 +37,7 @@ namespace blender::nodes { static bool use_translate(const float3 rotation, const float3 scale) { - if (compare_ff(math::length_squared(rotation), 0.0f, 1e-9f) != 1) { + if (compare_ff(rotation.length_squared(), 0.0f, 1e-9f) != 1) { return false; } if (compare_ff(scale.x, 1.0f, 1e-9f) != 1 || compare_ff(scale.y, 1.0f, 1e-9f) != 1 || @@ -49,7 +49,7 @@ static bool use_translate(const float3 rotation, const float3 scale) static void translate_mesh(Mesh &mesh, const float3 translation) { - if (!math::is_zero(translation)) { + if (!translation.is_zero()) { BKE_mesh_translate(&mesh, translation, false); } } diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc index ed72580ccf1..6a6b6e3d3cc 100644 --- a/source/blender/nodes/intern/node_socket.cc +++ b/source/blender/nodes/intern/node_socket.cc @@ -26,8 +26,8 @@ #include "DNA_node_types.h" #include "BLI_color.hh" +#include "BLI_float3.hh" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/node_shader_util.hh b/source/blender/nodes/shader/node_shader_util.hh index 5a5b4f613f3..9d4d57d01dd 100644 --- a/source/blender/nodes/shader/node_shader_util.hh +++ b/source/blender/nodes/shader/node_shader_util.hh @@ -29,9 +29,9 @@ #include "BLI_blenlib.h" #include "BLI_color.hh" +#include "BLI_float3.hh" #include "BLI_math.h" #include "BLI_math_base_safe.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_threads.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc index bc7ca661a77..3276a1bfd72 100644 --- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc +++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc @@ -272,7 +272,7 @@ class MapRangeVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -315,8 +315,8 @@ class MapRangeSteppedVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(6, "Vector"); for (int64_t i : mask) { - float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); - factor = math::safe_divide(math::floor(factor * (steps[i] + 1.0f)), steps[i]); + float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + factor = float3::safe_divide(float3::floor(factor * (steps[i] + 1.0f)), steps[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -355,7 +355,7 @@ class MapRangeSmoothstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = (float3(3.0f) - 2.0f * factor) * (factor * factor); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; @@ -390,7 +390,7 @@ class MapRangeSmootherstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc index 81a69ef18da..61b1613c11a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc @@ -19,7 +19,8 @@ #include "node_shader_util.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float4.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc index 53be5bc09d9..85e0f262ca7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc @@ -130,7 +130,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - const float r = std::max(0.999999f - math::length(vector[i]), 0.0f); + const float r = std::max(0.999999f - vector[i].length(), 0.0f); fac[i] = r * r; } break; @@ -140,7 +140,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - fac[i] = std::max(0.999999f - math::length(vector[i]), 0.0f); + fac[i] = std::max(0.999999f - vector[i].length(), 0.0f); } break; } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc index 1c703313edf..0e549859a39 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc @@ -176,14 +176,14 @@ class NoiseFunction : public fn::MultiFunction { const VArray &vector = params.readonly_single_input(0, "Vector"); if (compute_factor) { for (int64_t i : mask) { - const float2 position = float2(vector[i] * scale[i]); + const float2 position = vector[i] * scale[i]; r_factor[i] = noise::perlin_fractal_distorted( position, detail[i], roughness[i], distortion[i]); } } if (compute_color) { for (int64_t i : mask) { - const float2 position = float2(vector[i] * scale[i]); + const float2 position = vector[i] * scale[i]; const float3 c = noise::perlin_float3_fractal_distorted( position, detail[i], roughness[i], distortion[i]); r_color[i] = ColorGeometry4f(c[0], c[1], c[2], 1.0f); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc index 209f96449cd..2b5c1ddfe21 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc @@ -313,7 +313,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -345,7 +345,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -380,7 +380,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -416,7 +416,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -446,7 +446,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -479,7 +479,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -519,7 +519,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -560,7 +560,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -604,7 +604,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -837,7 +837,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -868,7 +868,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -902,7 +902,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -937,7 +937,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -966,7 +966,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -999,7 +999,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } } @@ -1040,7 +1040,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1080,7 +1080,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1123,7 +1123,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 604792389fa..f08665d75e7 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -57,20 +57,20 @@ void PyC_Err_PrintWithFunc(PyObject *py_func); void PyC_FileAndNum(const char **r_filename, int *r_lineno); void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno); /* checks python is running */ int PyC_AsArray_FAST(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value_fast, - const Py_ssize_t length, + Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value, - const Py_ssize_t length, + Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray_Multi_FAST(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value_fast, const int *dims, int dims_len, @@ -78,7 +78,7 @@ int PyC_AsArray_Multi_FAST(void *array, const char *error_prefix); int PyC_AsArray_Multi(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value, const int *dims, int dims_len, diff --git a/source/blender/render/RE_bake.h b/source/blender/render/RE_bake.h index 43d3b5b323c..b7ce3da71ff 100644 --- a/source/blender/render/RE_bake.h +++ b/source/blender/render/RE_bake.h @@ -96,7 +96,7 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, BakePixel pixel_array_to[], BakeHighPolyData highpoly[], int tot_highpoly, - const size_t num_pixels, + size_t num_pixels, bool is_custom_cage, float cage_extrusion, float max_ray_distance, @@ -106,16 +106,16 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, void RE_bake_pixels_populate(struct Mesh *me, struct BakePixel *pixel_array, - const size_t num_pixels, + size_t num_pixels, const struct BakeTargets *targets, const char *uv_layer); -void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask); +void RE_bake_mask_fill(const BakePixel pixel_array[], size_t num_pixels, char *mask); void RE_bake_margin(struct ImBuf *ibuf, char *mask, int margin); void RE_bake_normal_world_to_object(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], struct Object *ob, @@ -125,14 +125,14 @@ void RE_bake_normal_world_to_object(const BakePixel pixel_array[], * to a tangent space normal map for a given low poly mesh. */ void RE_bake_normal_world_to_tangent(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], struct Mesh *me, const eBakeNormalSwizzle normal_swizzle[3], float mat[4][4]); void RE_bake_normal_world_to_world(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], const eBakeNormalSwizzle normal_swizzle[3]); diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index 8776bc63cf0..a35e83a8632 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -3344,12 +3344,12 @@ static ImBuf *do_text_effect(const SeqRenderData *context, fonty = line_height; BLF_position(font, x + max_ii(fontx / 55, 1), y - max_ii(fonty / 30, 1), 0.0f); BLF_buffer_col(font, data->shadow_color); - BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(font, data->text, sizeof(data->text)); } BLF_position(font, x, y, 0.0f); BLF_buffer_col(font, data->color); - BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(font, data->text, sizeof(data->text)); BLF_buffer(font, NULL, NULL, 0, 0, 0, NULL); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 9a8a6a3a3ac..2e305c0bf3c 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -607,7 +607,7 @@ int WM_operator_confirm_message_ex(struct bContext *C, const char *title, int icon, const char *message, - const wmOperatorCallContext opcontext); + wmOperatorCallContext opcontext); int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message); /* Operator API. */ diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 99bab3ae23d..344f4959a93 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -193,7 +193,6 @@ bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWind static void wm_window_match_init(bContext *C, ListBase *wmlist) { *wmlist = G_MAIN->wm; - BLI_listbase_clear(&G_MAIN->wm); wmWindow *active_win = CTX_wm_window(C); @@ -220,6 +219,8 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist) } } + BLI_listbase_clear(&G_MAIN->wm); + /* reset active window */ CTX_wm_window_set(C, active_win); -- cgit v1.2.3 From 46e049d0ce2bce2f53ddc41a0dbbea2969d00a5d Mon Sep 17 00:00:00 2001 From: Clment Foucault Date: Wed, 12 Jan 2022 12:46:52 +0100 Subject: BLI: Refactor vector types & functions to use templates This patch implements the vector types (i.e:`float2`) by making heavy usage of templating. All vector functions are now outside of the vector classes (inside the `blender::math` namespace) and are not vector size dependent for the most part. In the ongoing effort to make shaders less GL centric, we are aiming to share more code between GLSL and C++ to avoid code duplication. ####Motivations: - We are aiming to share UBO and SSBO structures between GLSL and C++. This means we will use many of the existing vector types and others we currently don't have (uintX, intX). All these variations were asking for many more code duplication. - Deduplicate existing code which is duplicated for each vector size. - We also want to share small functions. Which means that vector functions should be static and not in the class namespace. - Reduce friction to use these types in new projects due to their incompleteness. - The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a bit of a let down. Most clases are incomplete, out of sync with each others with different codestyles, and some functions that should be static are not (i.e: `float3::reflect()`). ####Upsides: - Still support `.x, .y, .z, .w` for readability. - Compact, readable and easilly extendable. - All of the vector functions are available for all the vectors types and can be restricted to certain types. Also template specialization let us define exception for special class (like mpq). - With optimization ON, the compiler unroll the loops and performance is the same. ####Downsides: - Might impact debugability. Though I would arge that the bugs are rarelly caused by the vector class itself (since the operations are quite trivial) but by the type conversions. - Might impact compile time. I did not saw a significant impact since the usage is not really widespread. - Functions needs to be rewritten to support arbitrary vector length. For instance, one can't call `len_squared_v3v3` in `math::length_squared()` and call it a day. - Type cast does not work with the template version of the `math::` vector functions. Meaning you need to manually cast `float *` and `(float *)[3]` to `float3` for the function calls. i.e: `math::distance_squared(float3(nearest.co), positions[i]);` - Some parts might loose in readability: `float3::dot(v1.normalized(), v2.normalized())` becoming `math::dot(math::normalize(v1), math::normalize(v2))` But I propose, when appropriate, to use `using namespace blender::math;` on function local or file scope to increase readability. `dot(normalize(v1), normalize(v2))` ####Consideration: - Include back `.length()` method. It is quite handy and is more C++ oriented. - I considered the GLM library as a candidate for replacement. It felt like too much for what we need and would be difficult to extend / modify to our needs. - I used Macros to reduce code in operators declaration and potential copy paste bugs. This could reduce debugability and could be reverted. - This touches `delaunay_2d.cc` and the intersection code. I would like to know @howardt opinion on the matter. - The `noexcept` on the copy constructor of `mpq(2|3)` is being removed. But according to @JacquesLucke it is not a real problem for now. I would like to give a huge thanks to @JacquesLucke who helped during this and pushed me to reduce the duplication further. Reviewed By: brecht, sergey, JacquesLucke Differential Revision: https://developer.blender.org/D13791 --- source/blender/blenfont/BLF_api.h | 2 +- source/blender/blenfont/intern/blf_internal.h | 4 +- source/blender/blenkernel/BKE_appdir.h | 2 +- source/blender/blenkernel/BKE_attribute.h | 2 +- source/blender/blenkernel/BKE_attribute_access.hh | 3 +- source/blender/blenkernel/BKE_attribute_math.hh | 7 +- source/blender/blenkernel/BKE_bvhutils.h | 18 +- source/blender/blenkernel/BKE_customdata.h | 4 +- source/blender/blenkernel/BKE_geometry_set.hh | 2 +- source/blender/blenkernel/BKE_image.h | 2 +- source/blender/blenkernel/BKE_mesh_sample.hh | 2 +- source/blender/blenkernel/BKE_node.h | 8 +- source/blender/blenkernel/BKE_scene.h | 7 +- source/blender/blenkernel/BKE_spline.hh | 2 +- source/blender/blenkernel/BKE_vfont.h | 2 +- source/blender/blenkernel/BKE_volume.h | 2 +- source/blender/blenkernel/intern/DerivedMesh.cc | 2 +- .../blender/blenkernel/intern/attribute_access.cc | 2 +- .../blenkernel/intern/data_transfer_intern.h | 6 +- .../blenkernel/intern/geometry_component_mesh.cc | 5 +- source/blender/blenkernel/intern/gpencil_geom.cc | 2 +- source/blender/blenkernel/intern/hair.cc | 2 +- source/blender/blenkernel/intern/image.c | 26 +- source/blender/blenkernel/intern/mesh.cc | 10 +- .../blenkernel/intern/mesh_boolean_convert.cc | 2 +- .../blender/blenkernel/intern/mesh_remesh_voxel.cc | 2 +- source/blender/blenkernel/intern/object_dupli.cc | 8 +- source/blender/blenkernel/intern/pointcloud.cc | 24 +- source/blender/blenkernel/intern/simulation.cc | 2 +- source/blender/blenkernel/intern/spline_base.cc | 41 +- source/blender/blenkernel/intern/spline_bezier.cc | 37 +- source/blender/blenkernel/intern/tracking_test.cc | 2 +- .../blender/blenkernel/intern/type_conversions.cc | 3 +- source/blender/blenkernel/intern/volume.cc | 2 +- source/blender/blenkernel/intern/volume_render.cc | 2 +- source/blender/blenkernel/intern/volume_to_mesh.cc | 2 +- source/blender/blenlib/BLI_array_store.h | 2 +- source/blender/blenlib/BLI_array_utils.h | 4 +- source/blender/blenlib/BLI_buffer.h | 4 +- source/blender/blenlib/BLI_delaunay_2d.h | 4 +- source/blender/blenlib/BLI_double2.hh | 143 ------ source/blender/blenlib/BLI_double3.hh | 246 --------- source/blender/blenlib/BLI_fileops.h | 3 +- source/blender/blenlib/BLI_float2.hh | 218 -------- source/blender/blenlib/BLI_float3.hh | 320 ------------ source/blender/blenlib/BLI_float4.hh | 138 ----- source/blender/blenlib/BLI_float4x4.hh | 5 +- source/blender/blenlib/BLI_gsqueue.h | 2 +- source/blender/blenlib/BLI_listbase.h | 6 +- source/blender/blenlib/BLI_math_boolean.hh | 6 +- source/blender/blenlib/BLI_math_vec_mpq_types.hh | 91 ++++ source/blender/blenlib/BLI_math_vec_types.hh | 566 +++++++++++++++++++++ source/blender/blenlib/BLI_math_vector.hh | 399 +++++++++++++++ source/blender/blenlib/BLI_memarena.h | 4 +- source/blender/blenlib/BLI_memory_utils.h | 2 +- source/blender/blenlib/BLI_memory_utils.hh | 9 - source/blender/blenlib/BLI_mesh_intersect.hh | 5 +- source/blender/blenlib/BLI_mpq2.hh | 184 ------- source/blender/blenlib/BLI_mpq3.hh | 297 ----------- source/blender/blenlib/BLI_noise.hh | 4 +- source/blender/blenlib/BLI_path_util.h | 19 +- source/blender/blenlib/BLI_rand.hh | 3 +- source/blender/blenlib/BLI_stack.h | 6 +- source/blender/blenlib/BLI_string.h | 26 +- source/blender/blenlib/BLI_string_utf8.h | 19 +- source/blender/blenlib/BLI_string_utils.h | 6 +- source/blender/blenlib/BLI_timecode.h | 6 +- source/blender/blenlib/BLI_utildefines.h | 11 +- source/blender/blenlib/CMakeLists.txt | 10 +- .../blender/blenlib/intern/BLI_mempool_private.h | 5 +- source/blender/blenlib/intern/delaunay_2d.cc | 45 +- source/blender/blenlib/intern/math_boolean.cc | 7 +- source/blender/blenlib/intern/math_vec.cc | 133 ++--- source/blender/blenlib/intern/mesh_boolean.cc | 51 +- source/blender/blenlib/intern/mesh_intersect.cc | 88 ++-- source/blender/blenlib/intern/noise.cc | 79 ++- .../blender/blenlib/tests/BLI_delaunay_2d_test.cc | 3 +- .../blenlib/tests/BLI_math_vec_types_test.cc | 149 ++++++ .../blender/blenlib/tests/BLI_memory_utils_test.cc | 2 +- .../blender/blenlib/tests/BLI_mesh_boolean_test.cc | 2 +- .../blenlib/tests/BLI_mesh_intersect_test.cc | 2 +- source/blender/bmesh/intern/bmesh_opdefines.c | 1 - source/blender/bmesh/intern/bmesh_polygon.c | 7 - source/blender/compositor/CMakeLists.txt | 9 - source/blender/compositor/COM_defines.h | 2 +- source/blender/compositor/COM_precomp.h | 33 -- .../operations/COM_OutputFileOperation.h | 2 +- .../intern/builder/deg_builder_relations.cc | 11 - .../depsgraph/intern/node/deg_node_factory.h | 2 +- .../blender/draw/intern/draw_cache_impl_curve.cc | 2 +- .../mesh_extractors/extract_mesh_vbo_attributes.cc | 4 +- source/blender/editors/gpencil/gpencil_paint.c | 28 +- source/blender/editors/include/ED_util.h | 2 +- source/blender/editors/include/UI_interface.h | 6 +- .../blender/editors/interface/interface_intern.h | 4 +- source/blender/editors/interface/interface_panel.c | 1 - .../editors/interface/interface_region_tooltip.c | 15 +- source/blender/editors/interface/interface_style.c | 13 +- .../blender/editors/interface/interface_widgets.c | 7 +- source/blender/editors/object/object_add.c | 2 - source/blender/editors/render/render_preview.cc | 2 +- source/blender/editors/space_file/file_draw.c | 3 +- source/blender/editors/space_node/node_draw.cc | 2 +- source/blender/editors/space_node/node_group.cc | 2 +- source/blender/editors/space_node/node_intern.hh | 5 +- source/blender/editors/space_node/node_select.cc | 4 +- .../editors/space_sequencer/sequencer_draw.c | 37 +- .../space_spreadsheet/spreadsheet_column.cc | 3 +- .../space_spreadsheet/spreadsheet_layout.cc | 3 +- .../space_spreadsheet/spreadsheet_row_filter.cc | 8 +- source/blender/editors/util/ed_draw.c | 34 +- source/blender/freestyle/CMakeLists.txt | 5 +- source/blender/freestyle/FRS_precomp.cpp | 2 + source/blender/functions/intern/cpp_types.cc | 3 +- source/blender/imbuf/IMB_imbuf.h | 30 +- source/blender/imbuf/IMB_metadata.h | 5 +- source/blender/imbuf/intern/IMB_filetype.h | 22 +- source/blender/imbuf/intern/anim_movie.c | 11 +- source/blender/imbuf/intern/dds/dds_api.h | 2 +- source/blender/imbuf/intern/oiio/openimageio_api.h | 2 +- source/blender/imbuf/intern/openexr/openexr_api.h | 2 +- source/blender/imbuf/intern/radiance_hdr.c | 31 +- .../blender/io/alembic/intern/abc_reader_object.cc | 25 +- .../blender/io/gpencil/intern/gpencil_io_base.cc | 5 +- .../blender/io/gpencil/intern/gpencil_io_base.hh | 3 +- .../io/gpencil/intern/gpencil_io_import_svg.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mesh.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_nurbs.cc | 2 +- .../io/wavefront_obj/tests/obj_exporter_tests.cc | 2 +- source/blender/makesdna/DNA_modifier_types.h | 1 - source/blender/makesdna/DNA_node_types.h | 1 - source/blender/makesrna/RNA_access.h | 2 +- source/blender/makesrna/intern/rna_internal.h | 2 +- .../blender/makesrna/intern/rna_internal_types.h | 2 +- source/blender/makesrna/intern/rna_modifier.c | 7 +- source/blender/makesrna/intern/rna_nodetree.c | 7 +- .../blender/modifiers/intern/MOD_mesh_to_volume.cc | 4 +- source/blender/modifiers/intern/MOD_nodes.cc | 2 +- source/blender/nodes/NOD_math_functions.hh | 75 ++- source/blender/nodes/NOD_socket_declarations.hh | 2 +- .../blender/nodes/composite/node_composite_tree.cc | 17 + .../nodes/composite/nodes/node_composite_image.cc | 28 +- .../blender/nodes/function/node_function_util.hh | 2 +- .../nodes/node_fn_align_euler_to_vector.cc | 8 +- .../nodes/function/nodes/node_fn_compare.cc | 24 +- .../blender/nodes/geometry/node_geometry_util.hh | 4 +- .../node_geo_legacy_align_rotation_to_vector.cc | 8 +- .../legacy/node_geo_legacy_attribute_proximity.cc | 2 +- .../legacy/node_geo_legacy_attribute_transfer.cc | 2 +- .../legacy/node_geo_legacy_curve_to_points.cc | 4 +- .../legacy/node_geo_legacy_point_distribute.cc | 4 +- .../legacy/node_geo_legacy_points_to_volume.cc | 2 +- .../nodes/legacy/node_geo_legacy_raycast.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fill.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fillet.cc | 21 +- .../nodes/node_geo_curve_primitive_circle.cc | 18 +- .../nodes/node_geo_curve_primitive_line.cc | 2 +- .../node_geo_curve_primitive_quadratic_bezier.cc | 6 +- .../nodes/geometry/nodes/node_geo_curve_sample.cc | 4 +- .../nodes/node_geo_curve_spline_parameter.cc | 2 +- .../geometry/nodes/node_geo_curve_to_points.cc | 4 +- .../nodes/geometry/nodes/node_geo_image_texture.cc | 2 +- .../geometry/nodes/node_geo_mesh_primitive_cube.cc | 6 +- .../geometry/nodes/node_geo_mesh_primitive_line.cc | 6 +- .../nodes/node_geo_mesh_primitive_uv_sphere.cc | 2 +- .../geometry/nodes/node_geo_points_to_volume.cc | 2 +- .../nodes/geometry/nodes/node_geo_proximity.cc | 2 +- .../nodes/geometry/nodes/node_geo_raycast.cc | 2 +- .../geometry/nodes/node_geo_set_curve_handles.cc | 2 +- .../geometry/nodes/node_geo_transfer_attribute.cc | 2 +- .../nodes/geometry/nodes/node_geo_transform.cc | 4 +- source/blender/nodes/intern/node_socket.cc | 2 +- source/blender/nodes/shader/node_shader_util.hh | 2 +- .../nodes/shader/nodes/node_shader_map_range.cc | 10 +- .../nodes/shader/nodes/node_shader_tex_brick.cc | 3 +- .../nodes/shader/nodes/node_shader_tex_gradient.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_noise.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_voronoi.cc | 36 +- source/blender/python/generic/py_capi_utils.h | 12 +- source/blender/render/RE_bake.h | 12 +- source/blender/sequencer/intern/effects.c | 4 +- source/blender/windowmanager/WM_api.h | 2 +- source/blender/windowmanager/intern/wm_files.c | 3 +- 185 files changed, 1961 insertions(+), 2433 deletions(-) delete mode 100644 source/blender/blenlib/BLI_double2.hh delete mode 100644 source/blender/blenlib/BLI_double3.hh delete mode 100644 source/blender/blenlib/BLI_float2.hh delete mode 100644 source/blender/blenlib/BLI_float3.hh delete mode 100644 source/blender/blenlib/BLI_float4.hh create mode 100644 source/blender/blenlib/BLI_math_vec_mpq_types.hh create mode 100644 source/blender/blenlib/BLI_math_vec_types.hh create mode 100644 source/blender/blenlib/BLI_math_vector.hh delete mode 100644 source/blender/blenlib/BLI_mpq2.hh delete mode 100644 source/blender/blenlib/BLI_mpq3.hh create mode 100644 source/blender/blenlib/tests/BLI_math_vec_types_test.cc delete mode 100644 source/blender/compositor/COM_precomp.h create mode 100644 source/blender/freestyle/FRS_precomp.cpp (limited to 'source/blender') diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 169107b19cb..76a6135baaf 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -122,7 +122,7 @@ void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth) ATTR_NONNULL(2); typedef bool (*BLF_GlyphBoundsFn)(const char *str, - size_t str_step_ofs, + const size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 4e36f522981..23e42ec777f 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -121,7 +121,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, const char *str, size_t str_len, bool (*user_fn)(const char *str, - size_t str_step_ofs, + const size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, @@ -132,7 +132,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, int blf_font_count_missing_chars(struct FontBLF *font, const char *str, - size_t str_len, + const size_t str_len, int *r_tot_chars); void blf_font_free(struct FontBLF *font); diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index a7baaed141f..e92909fb3ca 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -140,7 +140,7 @@ bool BKE_appdir_font_folder_default(char *dir); * Find Python executable. */ bool BKE_appdir_program_python_search(char *fullpath, - size_t fullpath_len, + const size_t fullpath_len, int version_major, int version_minor); diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index 6020da08f51..db8f3759bf8 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -73,7 +73,7 @@ bool BKE_id_attribute_rename(struct ID *id, const char *new_name, struct ReportList *reports); -int BKE_id_attributes_length(struct ID *id, CustomDataMask mask); +int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask); struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id); void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer); diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index f69ba79e23f..3ffdcee05eb 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -26,9 +26,8 @@ #include "BKE_attribute.h" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_function_ref.hh" +#include "BLI_math_vec_types.hh" /** * This file defines classes that help to provide access to attribute data on a #GeometryComponent. diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh index 802c744972c..a7bdca06790 100644 --- a/source/blender/blenkernel/BKE_attribute_math.hh +++ b/source/blender/blenkernel/BKE_attribute_math.hh @@ -18,8 +18,7 @@ #include "BLI_array.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "DNA_customdata_types.h" @@ -160,12 +159,12 @@ template<> inline float mix2(const float factor, const float &a, const float &b) template<> inline float2 mix2(const float factor, const float2 &a, const float2 &b) { - return float2::interpolate(a, b, factor); + return math::interpolate(a, b, factor); } template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b) { - return float3::interpolate(a, b, factor); + return math::interpolate(a, b, factor); } template<> diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 146e6394fd6..42c8a5dae5d 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -128,7 +128,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -148,7 +148,7 @@ BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -165,7 +165,7 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -188,7 +188,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -212,7 +212,7 @@ BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -229,7 +229,7 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -251,7 +251,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -263,7 +263,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, */ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, const struct Mesh *mesh, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, int tree_type); /** @@ -272,7 +272,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, BVHTree *BKE_bvhtree_from_editmesh_get(BVHTreeFromEditMesh *data, struct BMEditMesh *em, int tree_type, - BVHCacheType bvh_cache_type, + const BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 17a44274712..b5b6296a0fa 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -323,7 +323,7 @@ void CustomData_bmesh_copy_data_exclude_by_type(const struct CustomData *source, struct CustomData *dest, void *src_block, void **dest_block, - CustomDataMask mask_exclude); + const CustomDataMask mask_exclude); /** * Copies data of a single layer of a given type. @@ -496,7 +496,7 @@ void CustomData_bmesh_free_block_data(struct CustomData *data, void *block); */ void CustomData_bmesh_free_block_data_exclude_by_type(struct CustomData *data, void *block, - CustomDataMask mask_exclude); + const CustomDataMask mask_exclude); /** * Copy custom data to/from layers as in mesh/derived-mesh, to edit-mesh diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index acb89637f20..f92f33b2776 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -23,11 +23,11 @@ #include #include -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_function_ref.hh" #include "BLI_hash.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_set.hh" #include "BLI_user_counter.hh" #include "BLI_vector_set.hh" diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 80c6b155be0..7b87189a13f 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -367,7 +367,7 @@ void BKE_image_packfiles(struct ReportList *reports, struct Image *ima, const ch void BKE_image_packfiles_from_mem(struct ReportList *reports, struct Image *ima, char *data, - size_t data_len); + const size_t data_len); /** * Prints memory statistics for images. diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh index 238b6f4dcae..738b768d906 100644 --- a/source/blender/blenkernel/BKE_mesh_sample.hh +++ b/source/blender/blenkernel/BKE_mesh_sample.hh @@ -22,7 +22,7 @@ #include "FN_generic_virtual_array.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BKE_attribute.h" diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index a76fe2f83e0..5f8222e33d4 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1374,12 +1374,18 @@ void ntreeCompositTagRender(struct Scene *scene); * - Each render layer node calls the update function of the * render engine that's used for its scene. * - The render engine calls RE_engine_register_pass for each pass. - * - #RE_engine_register_pass calls #node_cmp_rlayers_register_pass. + * - #RE_engine_register_pass calls #ntreeCompositRegisterPass, + * which calls #node_cmp_rlayers_register_pass for every render layer node. * * TODO: This is *not* part of `blenkernel`, it's defined under "source/blender/nodes/". * This declaration should be moved out of BKE. */ void ntreeCompositUpdateRLayers(struct bNodeTree *ntree); +void ntreeCompositRegisterPass(struct bNodeTree *ntree, + struct Scene *scene, + struct ViewLayer *view_layer, + const char *name, + eNodeSocketDatatype type); void ntreeCompositClearTags(struct bNodeTree *ntree); struct bNodeSocket *ntreeCompositOutputFileAddSocket(struct bNodeTree *ntree, diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index a40359e8650..8610bc09a92 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -317,8 +317,11 @@ void BKE_scene_multiview_view_prefix_get(struct Scene *scene, const char *name, char *r_prefix, const char **r_ext); -void BKE_scene_multiview_videos_dimensions_get( - const struct RenderData *rd, size_t width, size_t height, size_t *r_width, size_t *r_height); +void BKE_scene_multiview_videos_dimensions_get(const struct RenderData *rd, + const size_t width, + const size_t height, + size_t *r_width, + size_t *r_height); int BKE_scene_multiview_num_videos_get(const struct RenderData *rd); /* depsgraph */ diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh index 2c14880978f..a87f76da8da 100644 --- a/source/blender/blenkernel/BKE_spline.hh +++ b/source/blender/blenkernel/BKE_spline.hh @@ -24,8 +24,8 @@ #include "FN_generic_virtual_array.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BKE_attribute_access.hh" diff --git a/source/blender/blenkernel/BKE_vfont.h b/source/blender/blenkernel/BKE_vfont.h index 3397f2ef82a..d0a44ce4e47 100644 --- a/source/blender/blenkernel/BKE_vfont.h +++ b/source/blender/blenkernel/BKE_vfont.h @@ -104,7 +104,7 @@ void BKE_vfont_select_clamp(struct Object *ob); void BKE_vfont_clipboard_free(void); void BKE_vfont_clipboard_set(const char32_t *text_buf, const struct CharInfo *info_buf, - size_t len); + const size_t len); void BKE_vfont_clipboard_get(char32_t **r_text_buf, struct CharInfo **r_info_buf, size_t *r_len_utf8, diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h index 2b551a76d73..b40facc3572 100644 --- a/source/blender/blenkernel/BKE_volume.h +++ b/source/blender/blenkernel/BKE_volume.h @@ -163,8 +163,8 @@ bool BKE_volume_save(const struct Volume *volume, * file or copy shared grids to make them writeable. */ #ifdef __cplusplus -# include "BLI_float3.hh" # include "BLI_float4x4.hh" +# include "BLI_math_vec_types.hh" # include "BLI_string_ref.hh" bool BKE_volume_min_max(const Volume *volume, blender::float3 &r_min, blender::float3 &r_max); diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 4bfd71ba932..73785e2ee2b 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -38,9 +38,9 @@ #include "BLI_array.h" #include "BLI_bitmap.h" #include "BLI_blenlib.h" -#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_task.h" #include "BLI_task.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 1a4265d936b..cc43a3e26a8 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -30,7 +30,7 @@ #include "DNA_pointcloud_types.h" #include "BLI_color.hh" -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLT_translation.h" diff --git a/source/blender/blenkernel/intern/data_transfer_intern.h b/source/blender/blenkernel/intern/data_transfer_intern.h index b5b3db31fbf..e5218415df9 100644 --- a/source/blender/blenkernel/intern/data_transfer_intern.h +++ b/source/blender/blenkernel/intern/data_transfer_intern.h @@ -44,9 +44,9 @@ void data_transfer_layersmapping_add_item(struct ListBase *r_map, void *data_dst, int data_src_n, int data_dst_n, - size_t elem_size, - size_t data_size, - size_t data_offset, + const size_t elem_size, + const size_t data_size, + const size_t data_offset, uint64_t data_flag, cd_datatransfer_interp interp, void *interp_data); diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 2b4238d26bb..88a58220b23 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -217,9 +217,8 @@ VArray mesh_normals_varray(const MeshComponent &mesh_component, * calculating unnecessary values and to allow normalizing the result much more simply. */ for (const int i : mask) { const MEdge &edge = edges[i]; - edge_normals[i] = float3::interpolate( - vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f) - .normalized(); + edge_normals[i] = math::normalize( + math::interpolate(vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f)); } return VArray::ForContainer(std::move(edge_normals)); diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc index f8681647a77..116d77f1a2a 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.cc +++ b/source/blender/blenkernel/intern/gpencil_geom.cc @@ -33,10 +33,10 @@ #include "BLI_array_utils.h" #include "BLI_blenlib.h" -#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_heap.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_polyfill_2d.h" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/hair.cc b/source/blender/blenkernel/intern/hair.cc index c5b154c9a4b..b7ba159f631 100644 --- a/source/blender/blenkernel/intern/hair.cc +++ b/source/blender/blenkernel/intern/hair.cc @@ -28,9 +28,9 @@ #include "DNA_material_types.h" #include "DNA_object_types.h" -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math_base.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 23b1054f814..4899c3671aa 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -2446,7 +2446,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and draw the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.file, sizeof(stamp_data.file)); + BLF_draw_buffer(mono, stamp_data.file, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2469,7 +2469,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.date, sizeof(stamp_data.date)); + BLF_draw_buffer(mono, stamp_data.date, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2492,7 +2492,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.rendertime, sizeof(stamp_data.rendertime)); + BLF_draw_buffer(mono, stamp_data.rendertime, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2515,7 +2515,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.memory, sizeof(stamp_data.memory)); + BLF_draw_buffer(mono, stamp_data.memory, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2538,7 +2538,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.hostname, sizeof(stamp_data.hostname)); + BLF_draw_buffer(mono, stamp_data.hostname, BLF_DRAW_STR_DUMMY_MAX); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2562,7 +2562,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs + (h - h_fixed), 0.0); - BLF_draw_buffer(mono, stamp_data.note, sizeof(stamp_data.note)); + BLF_draw_buffer(mono, stamp_data.note, BLF_DRAW_STR_DUMMY_MAX); } BLF_disable(mono, BLF_WORD_WRAP); @@ -2586,7 +2586,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.marker, sizeof(stamp_data.marker)); + BLF_draw_buffer(mono, stamp_data.marker, BLF_DRAW_STR_DUMMY_MAX); /* space width. */ x += w + pad; @@ -2609,7 +2609,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.time, sizeof(stamp_data.time)); + BLF_draw_buffer(mono, stamp_data.time, BLF_DRAW_STR_DUMMY_MAX); /* space width. */ x += w + pad; @@ -2631,7 +2631,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.frame, sizeof(stamp_data.frame)); + BLF_draw_buffer(mono, stamp_data.frame, BLF_DRAW_STR_DUMMY_MAX); /* space width. */ x += w + pad; @@ -2651,7 +2651,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.camera, sizeof(stamp_data.camera)); + BLF_draw_buffer(mono, stamp_data.camera, BLF_DRAW_STR_DUMMY_MAX); /* space width. */ x += w + pad; @@ -2671,7 +2671,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.cameralens, sizeof(stamp_data.cameralens)); + BLF_draw_buffer(mono, stamp_data.cameralens, BLF_DRAW_STR_DUMMY_MAX); } if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) { @@ -2693,7 +2693,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.scene, sizeof(stamp_data.scene)); + BLF_draw_buffer(mono, stamp_data.scene, BLF_DRAW_STR_DUMMY_MAX); } if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) { @@ -2715,7 +2715,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.strip, sizeof(stamp_data.strip)); + BLF_draw_buffer(mono, stamp_data.strip, BLF_DRAW_STR_DUMMY_MAX); } /* cleanup the buffer. */ diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 12c63ab0523..8ceaced1972 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -36,13 +36,13 @@ #include "BLI_bitmap.h" #include "BLI_edgehash.h" #include "BLI_endian_switch.h" -#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_index_range.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_memarena.h" #include "BLI_string.h" #include "BLI_task.hh" @@ -1597,16 +1597,16 @@ bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3]) [&](IndexRange range, const Result &init) { Result result = init; for (const int i : range) { - float3::min_max(me->mvert[i].co, result.min, result.max); + math::min_max(float3(me->mvert[i].co), result.min, result.max); } return result; }, [](const Result &a, const Result &b) { - return Result{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return Result{math::min(a.min, b.min), math::max(a.max, b.max)}; }); - copy_v3_v3(r_min, float3::min(minmax.min, r_min)); - copy_v3_v3(r_max, float3::max(minmax.max, r_max)); + copy_v3_v3(r_min, math::min(minmax.min, float3(r_min))); + copy_v3_v3(r_max, math::max(minmax.max, float3(r_max))); return true; } diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc index 771d79a0445..a4a5fe2be2e 100644 --- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc +++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc @@ -32,9 +32,9 @@ #include "BLI_alloca.h" #include "BLI_array.hh" -#include "BLI_float2.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_mesh_boolean.hh" #include "BLI_mesh_intersect.hh" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc index 3447185089d..50464da86e9 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc @@ -31,8 +31,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_index_range.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_mesh_types.h" diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc index e682486390c..20fdda8bdc7 100644 --- a/source/blender/blenkernel/intern/object_dupli.cc +++ b/source/blender/blenkernel/intern/object_dupli.cc @@ -31,9 +31,9 @@ #include "BLI_string_utf8.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_vector.hh" @@ -1026,6 +1026,8 @@ static void get_dupliface_transform_from_coords(Span coords, const float scale_fac, float r_mat[4][4]) { + using namespace blender::math; + /* Location. */ float3 location(0); for (const float3 &coord : coords) { @@ -1036,9 +1038,7 @@ static void get_dupliface_transform_from_coords(Span coords, /* Rotation. */ float quat[4]; - float3 f_no; - cross_poly_v3(f_no, (const float(*)[3])coords.data(), (uint)coords.size()); - f_no.normalize(); + float3 f_no = normalize(cross_poly(coords)); tri_to_quat_ex(quat, coords[0], coords[1], coords[2], f_no); /* Scale. */ diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc index a041e04bf71..b5f016e4d76 100644 --- a/source/blender/blenkernel/intern/pointcloud.cc +++ b/source/blender/blenkernel/intern/pointcloud.cc @@ -25,9 +25,9 @@ #include "DNA_object_types.h" #include "DNA_pointcloud_types.h" -#include "BLI_float3.hh" #include "BLI_index_range.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" @@ -275,6 +275,8 @@ struct MinMaxResult { static MinMaxResult min_max_no_radii(Span positions) { + using namespace blender::math; + return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -282,17 +284,19 @@ static MinMaxResult min_max_no_radii(Span positions) [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - float3::min_max(positions[i], result.min, result.max); + min_max(positions[i], result.min, result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; }); } static MinMaxResult min_max_with_radii(Span positions, Span radii) { + using namespace blender::math; + return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -300,18 +304,20 @@ static MinMaxResult min_max_with_radii(Span positions, Span radii [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - result.min = float3::min(positions[i] - radii[i], result.min); - result.max = float3::max(positions[i] + radii[i], result.max); + result.min = min(positions[i] - radii[i], result.min); + result.max = max(positions[i] + radii[i], result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; }); } bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r_max[3]) { + using namespace blender::math; + if (!pointcloud->totpoint) { return false; } @@ -322,8 +328,8 @@ bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r {pointcloud->radius, pointcloud->totpoint}) : min_max_no_radii(positions); - copy_v3_v3(r_min, float3::min(min_max.min, r_min)); - copy_v3_v3(r_max, float3::max(min_max.max, r_max)); + copy_v3_v3(r_min, min(min_max.min, float3(r_min))); + copy_v3_v3(r_max, max(min_max.max, float3(r_max))); return true; } @@ -340,7 +346,7 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob) ob->runtime.bb = static_cast(MEM_callocN(sizeof(BoundBox), "pointcloud boundbox")); } - blender::float3 min, max; + float3 min, max; INIT_MINMAX(min, max); if (ob->runtime.geometry_set_eval != nullptr) { ob->runtime.geometry_set_eval->compute_boundbox_without_instances(&min, &max); diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index b0f9de5963a..ec4b0e8d51d 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -28,9 +28,9 @@ #include "DNA_simulation_types.h" #include "BLI_compiler_compat.h" -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 857022345f3..3262d768b6c 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -166,13 +166,15 @@ static void accumulate_lengths(Span positions, const bool is_cyclic, MutableSpan lengths) { + using namespace blender::math; + float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { - length += float3::distance(positions[i], positions[i + 1]); + length += distance(positions[i], positions[i + 1]); lengths[i] = length; } if (is_cyclic) { - lengths.last() = length + float3::distance(positions.last(), positions.first()); + lengths.last() = length + distance(positions.last(), positions.first()); } } @@ -200,11 +202,13 @@ Span Spline::evaluated_lengths() const static float3 direction_bisect(const float3 &prev, const float3 &middle, const float3 &next) { - const float3 dir_prev = (middle - prev).normalized(); - const float3 dir_next = (next - middle).normalized(); + using namespace blender::math; + + const float3 dir_prev = normalize(middle - prev); + const float3 dir_next = normalize(next - middle); - const float3 result = (dir_prev + dir_next).normalized(); - if (UNLIKELY(result.is_zero())) { + const float3 result = normalize(dir_prev + dir_next); + if (UNLIKELY(is_zero(result))) { return float3(0.0f, 0.0f, 1.0f); } return result; @@ -214,6 +218,8 @@ static void calculate_tangents(Span positions, const bool is_cyclic, MutableSpan tangents) { + using namespace blender::math; + if (positions.size() == 1) { tangents.first() = float3(0.0f, 0.0f, 1.0f); return; @@ -232,8 +238,8 @@ static void calculate_tangents(Span positions, tangents.last() = direction_bisect(second_to_last, last, first); } else { - tangents.first() = (positions[1] - positions[0]).normalized(); - tangents.last() = (positions.last() - positions[positions.size() - 2]).normalized(); + tangents.first() = normalize(positions[1] - positions[0]); + tangents.last() = normalize(positions.last() - positions[positions.size() - 2]); } } @@ -264,18 +270,22 @@ static float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, const float angle) { + using namespace blender::math; + BLI_ASSERT_UNIT_V3(direction); BLI_ASSERT_UNIT_V3(axis); - const float3 axis_scaled = axis * float3::dot(direction, axis); + const float3 axis_scaled = axis * dot(direction, axis); const float3 diff = direction - axis_scaled; - const float3 cross = float3::cross(axis, diff); + const float3 cross = blender::math::cross(axis, diff); return axis_scaled + diff * std::cos(angle) + cross * std::sin(angle); } static void calculate_normals_z_up(Span tangents, MutableSpan r_normals) { + using namespace blender::math; + BLI_assert(r_normals.size() == tangents.size()); /* Same as in `vec_to_quat`. */ @@ -286,7 +296,7 @@ static void calculate_normals_z_up(Span tangents, MutableSpan r_ r_normals[i] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[i] = float3(tangent.y, -tangent.x, 0.0f).normalized(); + r_normals[i] = normalize(float3(tangent.y, -tangent.x, 0.0f)); } } } @@ -298,12 +308,14 @@ static float3 calculate_next_normal(const float3 &last_normal, const float3 &last_tangent, const float3 ¤t_tangent) { - if (last_tangent.is_zero() || current_tangent.is_zero()) { + using namespace blender::math; + + if (is_zero(last_tangent) || is_zero(current_tangent)) { return last_normal; } const float angle = angle_normalized_v3v3(last_tangent, current_tangent); if (angle != 0.0) { - const float3 axis = float3::cross(last_tangent, current_tangent).normalized(); + const float3 axis = normalize(cross(last_tangent, current_tangent)); return rotate_direction_around_axis(last_normal, axis, angle); } return last_normal; @@ -313,6 +325,7 @@ static void calculate_normals_minimum(Span tangents, const bool cyclic, MutableSpan r_normals) { + using namespace blender::math; BLI_assert(r_normals.size() == tangents.size()); if (r_normals.is_empty()) { @@ -327,7 +340,7 @@ static void calculate_normals_minimum(Span tangents, r_normals[0] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[0] = float3(first_tangent.y, -first_tangent.x, 0.0f).normalized(); + r_normals[0] = normalize(float3(first_tangent.y, -first_tangent.x, 0.0f)); } /* Forward normal with minimum twist along the entire spline. */ diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc index b24c8960857..980437014b1 100644 --- a/source/blender/blenkernel/intern/spline_bezier.cc +++ b/source/blender/blenkernel/intern/spline_bezier.cc @@ -199,11 +199,13 @@ void BezierSpline::ensure_auto_handles() const } for (const int i : IndexRange(this->size())) { + using namespace blender; + if (ELEM(HandleType::Auto, handle_types_left_[i], handle_types_right_[i])) { const float3 prev_diff = positions_[i] - previous_position(positions_, is_cyclic_, i); const float3 next_diff = next_position(positions_, is_cyclic_, i) - positions_[i]; - float prev_len = prev_diff.length(); - float next_len = next_diff.length(); + float prev_len = math::length(prev_diff); + float next_len = math::length(next_diff); if (prev_len == 0.0f) { prev_len = 1.0f; } @@ -213,7 +215,7 @@ void BezierSpline::ensure_auto_handles() const const float3 dir = next_diff / next_len + prev_diff / prev_len; /* This magic number is unfortunate, but comes from elsewhere in Blender. */ - const float len = dir.length() * 2.5614f; + const float len = math::length(dir) * 2.5614f; if (len != 0.0f) { if (handle_types_left_[i] == HandleType::Auto) { const float prev_len_clamped = std::min(prev_len, next_len * 5.0f); @@ -228,12 +230,12 @@ void BezierSpline::ensure_auto_handles() const if (handle_types_left_[i] == HandleType::Vector) { const float3 prev = previous_position(positions_, is_cyclic_, i); - handle_positions_left_[i] = float3::interpolate(positions_[i], prev, 1.0f / 3.0f); + handle_positions_left_[i] = math::interpolate(positions_[i], prev, 1.0f / 3.0f); } if (handle_types_right_[i] == HandleType::Vector) { const float3 next = next_position(positions_, is_cyclic_, i); - handle_positions_right_[i] = float3::interpolate(positions_[i], next, 1.0f / 3.0f); + handle_positions_right_[i] = math::interpolate(positions_[i], next, 1.0f / 3.0f); } } @@ -275,6 +277,8 @@ static void set_handle_position(const float3 &position, float3 &handle, float3 &handle_other) { + using namespace blender::math; + /* Don't bother when the handle positions are calculated automatically anyway. */ if (ELEM(type, BezierSpline::HandleType::Auto, BezierSpline::HandleType::Vector)) { return; @@ -283,9 +287,9 @@ static void set_handle_position(const float3 &position, handle = new_value; if (type_other == BezierSpline::HandleType::Align) { /* Keep track of the old length of the opposite handle. */ - const float length = float3::distance(handle_other, position); + const float length = distance(handle_other, position); /* Set the other handle to directly opposite from the current handle. */ - const float3 dir = (handle - position).normalized(); + const float3 dir = normalize(handle - position); handle_other = position - dir * length; } } @@ -353,6 +357,7 @@ int BezierSpline::evaluated_points_size() const void BezierSpline::correct_end_tangents() const { + using namespace blender::math; if (is_cyclic_) { return; } @@ -360,10 +365,10 @@ void BezierSpline::correct_end_tangents() const MutableSpan tangents(evaluated_tangents_cache_); if (handle_positions_right_.first() != positions_.first()) { - tangents.first() = (handle_positions_right_.first() - positions_.first()).normalized(); + tangents.first() = normalize(handle_positions_right_.first() - positions_.first()); } if (handle_positions_left_.last() != positions_.last()) { - tangents.last() = (positions_.last() - handle_positions_left_.last()).normalized(); + tangents.last() = normalize(positions_.last() - handle_positions_left_.last()); } } @@ -371,20 +376,22 @@ BezierSpline::InsertResult BezierSpline::calculate_segment_insertion(const int i const int next_index, const float parameter) { + using namespace blender::math; + BLI_assert(parameter <= 1.0f && parameter >= 0.0f); BLI_assert(next_index == 0 || next_index == index + 1); const float3 &point_prev = positions_[index]; const float3 &handle_prev = handle_positions_right_[index]; const float3 &handle_next = handle_positions_left_[next_index]; const float3 &point_next = positions_[next_index]; - const float3 center_point = float3::interpolate(handle_prev, handle_next, parameter); + const float3 center_point = interpolate(handle_prev, handle_next, parameter); BezierSpline::InsertResult result; - result.handle_prev = float3::interpolate(point_prev, handle_prev, parameter); - result.handle_next = float3::interpolate(handle_next, point_next, parameter); - result.left_handle = float3::interpolate(result.handle_prev, center_point, parameter); - result.right_handle = float3::interpolate(center_point, result.handle_next, parameter); - result.position = float3::interpolate(result.left_handle, result.right_handle, parameter); + result.handle_prev = interpolate(point_prev, handle_prev, parameter); + result.handle_next = interpolate(handle_next, point_next, parameter); + result.left_handle = interpolate(result.handle_prev, center_point, parameter); + result.right_handle = interpolate(center_point, result.handle_next, parameter); + result.position = interpolate(result.left_handle, result.right_handle, parameter); return result; } diff --git a/source/blender/blenkernel/intern/tracking_test.cc b/source/blender/blenkernel/intern/tracking_test.cc index a3845dcad8f..d85d71b7c86 100644 --- a/source/blender/blenkernel/intern/tracking_test.cc +++ b/source/blender/blenkernel/intern/tracking_test.cc @@ -5,7 +5,7 @@ #include "DNA_tracking_types.h" #include "BKE_tracking.h" -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" namespace blender { diff --git a/source/blender/blenkernel/intern/type_conversions.cc b/source/blender/blenkernel/intern/type_conversions.cc index b23220286e6..cb05337ef2a 100644 --- a/source/blender/blenkernel/intern/type_conversions.cc +++ b/source/blender/blenkernel/intern/type_conversions.cc @@ -19,8 +19,7 @@ #include "FN_multi_function_builder.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" namespace blender::bke { diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index 4b71c98339b..c17706dc216 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -28,12 +28,12 @@ #include "BLI_compiler_compat.h" #include "BLI_fileops.h" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_ghash.h" #include "BLI_index_range.hh" #include "BLI_map.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc index 6dc497bb616..c0a205b5673 100644 --- a/source/blender/blenkernel/intern/volume_render.cc +++ b/source/blender/blenkernel/intern/volume_render.cc @@ -21,8 +21,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_math_matrix.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_vector.hh" diff --git a/source/blender/blenkernel/intern/volume_to_mesh.cc b/source/blender/blenkernel/intern/volume_to_mesh.cc index 6e465b2fdf0..733549c0022 100644 --- a/source/blender/blenkernel/intern/volume_to_mesh.cc +++ b/source/blender/blenkernel/intern/volume_to_mesh.cc @@ -16,7 +16,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_array_store.h b/source/blender/blenlib/BLI_array_store.h index 68928f53e55..0be361d4ab9 100644 --- a/source/blender/blenlib/BLI_array_store.h +++ b/source/blender/blenlib/BLI_array_store.h @@ -84,7 +84,7 @@ size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs); */ BArrayState *BLI_array_store_state_add(BArrayStore *bs, const void *data, - size_t data_len, + const size_t data_len, const BArrayState *state_reference); /** * Remove a state and free any unused #BChunk data. diff --git a/source/blender/blenlib/BLI_array_utils.h b/source/blender/blenlib/BLI_array_utils.h index 202ae9a9786..50fc2ce909b 100644 --- a/source/blender/blenlib/BLI_array_utils.h +++ b/source/blender/blenlib/BLI_array_utils.h @@ -52,7 +52,7 @@ void _bli_array_wrap(void *arr, uint arr_len, size_t arr_stride, int dir); * Access via #BLI_array_wrap */ void _bli_array_permute( - void *arr, uint arr_len, size_t arr_stride, const uint *order, void *arr_temp); + void *arr, uint arr_len, const size_t arr_stride, const uint *order, void *arr_temp); #define BLI_array_permute(arr, arr_len, order) \ _bli_array_permute(arr, arr_len, sizeof(*(arr)), order, NULL) #define BLI_array_permute_ex(arr, arr_len, order, arr_temp) \ @@ -152,7 +152,7 @@ bool _bli_array_is_zeroed(const void *arr, uint arr_len, size_t arr_stride); */ bool _bli_array_iter_spiral_square(const void *arr_v, const int arr_shape[2], - size_t elem_size, + const size_t elem_size, const int center[2], bool (*test_fn)(const void *arr_item, void *user_data), void *user_data); diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h index e79d44fd934..7f577443cf7 100644 --- a/source/blender/blenlib/BLI_buffer.h +++ b/source/blender/blenlib/BLI_buffer.h @@ -74,7 +74,7 @@ enum { /** * \note Never decreases the amount of memory allocated. */ -void BLI_buffer_resize(BLI_Buffer *buffer, size_t new_count); +void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); /** * Ensure size, throwing away old data, respecting #BLI_BUFFER_USE_CALLOC. @@ -83,7 +83,7 @@ void BLI_buffer_resize(BLI_Buffer *buffer, size_t new_count); * - Ignored (malloc'd). * - Cleared (when #BLI_BUFFER_USE_CALLOC is set). */ -void BLI_buffer_reinit(BLI_Buffer *buffer, size_t new_count); +void BLI_buffer_reinit(BLI_Buffer *buffer, const size_t new_count); /** * Append an array of elements. diff --git a/source/blender/blenlib/BLI_delaunay_2d.h b/source/blender/blenlib/BLI_delaunay_2d.h index db0df95499f..1ee0be64cee 100644 --- a/source/blender/blenlib/BLI_delaunay_2d.h +++ b/source/blender/blenlib/BLI_delaunay_2d.h @@ -215,9 +215,9 @@ void BLI_delaunay_2d_cdt_free(CDT_result *result); /* C++ Interface. */ # include "BLI_array.hh" -# include "BLI_double2.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_vector.hh" namespace blender::meshintersect { diff --git a/source/blender/blenlib/BLI_double2.hh b/source/blender/blenlib/BLI_double2.hh deleted file mode 100644 index 0abff01ab2f..00000000000 --- a/source/blender/blenlib/BLI_double2.hh +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include "BLI_double3.hh" - -namespace blender { - -struct double2 { - double x, y; - - double2() = default; - - double2(const double *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - double2(double x, double y) : x(x), y(y) - { - } - - double2(const double3 &other) : x(other.x), y(other.y) - { - } - - operator double *() - { - return &x; - } - - operator const double *() const - { - return &x; - } - - double length() const - { - return len_v2_db(*this); - } - - friend double2 operator+(const double2 &a, const double2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend double2 operator-(const double2 &a, const double2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend double2 operator*(const double2 &a, double b) - { - return {a.x * b, a.y * b}; - } - - friend double2 operator/(const double2 &a, double b) - { - BLI_assert(b != 0.0); - return {a.x / b, a.y / b}; - } - - friend double2 operator*(double a, const double2 &b) - { - return b * a; - } - - friend bool operator==(const double2 &a, const double2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const double2 &a, const double2 &b) - { - return a.x != b.x || a.y != b.y; - } - - friend std::ostream &operator<<(std::ostream &stream, const double2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static double dot(const double2 &a, const double2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static double2 interpolate(const double2 &a, const double2 &b, double t) - { - return a * (1 - t) + b * t; - } - - static double2 abs(const double2 &a) - { - return double2(fabs(a.x), fabs(a.y)); - } - - static double distance(const double2 &a, const double2 &b) - { - return (a - b).length(); - } - - static double distance_squared(const double2 &a, const double2 &b) - { - double2 diff = a - b; - return double2::dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - double lambda; - }; - - static isect_result isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4); -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_double3.hh b/source/blender/blenlib/BLI_double3.hh deleted file mode 100644 index ab258c9121b..00000000000 --- a/source/blender/blenlib/BLI_double3.hh +++ /dev/null @@ -1,246 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include - -#include "BLI_math_vector.h" -#include "BLI_span.hh" - -namespace blender { - -struct double3 { - double x, y, z; - - double3() = default; - - double3(const double *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - double3(const double (*ptr)[3]) : double3((const double *)ptr) - { - } - - explicit double3(double value) : x(value), y(value), z(value) - { - } - - explicit double3(int value) : x(value), y(value), z(value) - { - } - - double3(double x, double y, double z) : x{x}, y{y}, z{z} - { - } - - operator const double *() const - { - return &x; - } - - operator double *() - { - return &x; - } - - double normalize_and_get_length() - { - return normalize_v3_db(*this); - } - - double3 normalized() const - { - double3 result; - normalize_v3_v3_db(result, *this); - return result; - } - - double length() const - { - return len_v3_db(*this); - } - - double length_squared() const - { - return len_squared_v3_db(*this); - } - - void reflect(const double3 &normal) - { - *this = this->reflected(normal); - } - - double3 reflected(const double3 &normal) const - { - double3 result; - reflect_v3_v3v3_db(result, *this, normal); - return result; - } - - static double3 safe_divide(const double3 &a, const double3 &b) - { - double3 result; - result.x = (b.x == 0.0) ? 0.0 : a.x / b.x; - result.y = (b.y == 0.0) ? 0.0 : a.y / b.y; - result.z = (b.z == 0.0) ? 0.0 : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - friend double3 operator+(const double3 &a, const double3 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z}; - } - - void operator+=(const double3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - } - - friend double3 operator-(const double3 &a, const double3 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z}; - } - - friend double3 operator-(const double3 &a) - { - return {-a.x, -a.y, -a.z}; - } - - void operator-=(const double3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - } - - void operator*=(const double &scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - } - - void operator*=(const double3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - } - - friend double3 operator*(const double3 &a, const double3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend double3 operator*(const double3 &a, const double &b) - { - return {a.x * b, a.y * b, a.z * b}; - } - - friend double3 operator*(const double &a, const double3 &b) - { - return b * a; - } - - friend double3 operator/(const double3 &a, const double &b) - { - BLI_assert(b != 0.0); - return {a.x / b, a.y / b, a.z / b}; - } - - friend bool operator==(const double3 &a, const double3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const double3 &a, const double3 &b) - { - return a.x != b.x || a.y != b.y || a.z != b.z; - } - - friend std::ostream &operator<<(std::ostream &stream, const double3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - static double dot(const double3 &a, const double3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static double3 cross_high_precision(const double3 &a, const double3 &b) - { - double3 result; - cross_v3_v3v3_db(result, a, b); - return result; - } - - static double3 project(const double3 &a, const double3 &b) - { - double3 result; - project_v3_v3v3_db(result, a, b); - return result; - } - - static double distance(const double3 &a, const double3 &b) - { - return (a - b).length(); - } - - static double distance_squared(const double3 &a, const double3 &b) - { - double3 diff = a - b; - return double3::dot(diff, diff); - } - - static double3 interpolate(const double3 &a, const double3 &b, double t) - { - return a * (1 - t) + b * t; - } - - static double3 abs(const double3 &a) - { - return double3(fabs(a.x), fabs(a.y), fabs(a.z)); - } - - static int dominant_axis(const double3 &a) - { - double x = (a.x >= 0) ? a.x : -a.x; - double y = (a.y >= 0) ? a.y : -a.y; - double z = (a.z >= 0) ? a.z : -a.z; - return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); - } - - static double3 cross_poly(Span poly); -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index 28cb5f6d84b..0022823b3de 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -155,7 +155,8 @@ double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL( * * \note can return NULL when the size is not big enough */ -char *BLI_current_working_dir(char *dir, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +char *BLI_current_working_dir(char *dir, const size_t maxncpy) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(); eFileAttributes BLI_file_attributes(const char *path); /** \} */ diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh deleted file mode 100644 index bb4229db86e..00000000000 --- a/source/blender/blenlib/BLI_float2.hh +++ /dev/null @@ -1,218 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include "BLI_float3.hh" - -namespace blender { - -struct float2 { - float x, y; - - float2() = default; - - float2(const float *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - explicit float2(float value) : x(value), y(value) - { - } - - explicit float2(int value) : x(value), y(value) - { - } - - float2(float x, float y) : x(x), y(y) - { - } - - float2(const float3 &other) : x(other.x), y(other.y) - { - } - - operator float *() - { - return &x; - } - - operator const float *() const - { - return &x; - } - - float length() const - { - return len_v2(*this); - } - - float length_squared() const - { - return len_squared_v2(*this); - } - - bool is_zero() const - { - return this->x == 0.0f && this->y == 0.0f; - } - - float2 &operator+=(const float2 &other) - { - x += other.x; - y += other.y; - return *this; - } - - float2 &operator-=(const float2 &other) - { - x -= other.x; - y -= other.y; - return *this; - } - - float2 &operator*=(float factor) - { - x *= factor; - y *= factor; - return *this; - } - - float2 &operator/=(float divisor) - { - x /= divisor; - y /= divisor; - return *this; - } - - uint64_t hash() const - { - uint64_t x1 = *reinterpret_cast(&x); - uint64_t x2 = *reinterpret_cast(&y); - return (x1 * 812519) ^ (x2 * 707951); - } - - friend float2 operator+(const float2 &a, const float2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend float2 operator-(const float2 &a, const float2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend float2 operator-(const float2 &a, const float &b) - { - return {a.x - b, a.y - b}; - } - - friend float2 operator*(const float2 &a, float b) - { - return {a.x * b, a.y * b}; - } - - friend float2 operator/(const float2 &a, float b) - { - BLI_assert(b != 0.0f); - return {a.x / b, a.y / b}; - } - - friend float2 operator*(float a, const float2 &b) - { - return b * a; - } - - friend std::ostream &operator<<(std::ostream &stream, const float2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static float2 safe_divide(const float2 &a, const float b) - { - return (b != 0.0f) ? a / b : float2(0.0f); - } - - static float2 floor(const float2 &a) - { - return float2(floorf(a.x), floorf(a.y)); - } - - /** - * Returns a normalized vector. The original vector is not changed. - */ - float2 normalized() const - { - float2 result; - normalize_v2_v2(result, *this); - return result; - } - - static float dot(const float2 &a, const float2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static float2 interpolate(const float2 &a, const float2 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float2 abs(const float2 &a) - { - return float2(fabsf(a.x), fabsf(a.y)); - } - - static float distance(const float2 &a, const float2 &b) - { - return (a - b).length(); - } - - static float distance_squared(const float2 &a, const float2 &b) - { - float2 diff = a - b; - return float2::dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - float lambda; - float mu; - }; - - static isect_result isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4); - - friend bool operator==(const float2 &a, const float2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const float2 &a, const float2 &b) - { - return !(a == b); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh deleted file mode 100644 index 765f524fb31..00000000000 --- a/source/blender/blenlib/BLI_float3.hh +++ /dev/null @@ -1,320 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include - -#include "BLI_math_vector.h" - -namespace blender { - -struct float3 { - float x, y, z; - - float3() = default; - - float3(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - float3(const float (*ptr)[3]) : float3(static_cast(ptr[0])) - { - } - - explicit float3(float value) : x(value), y(value), z(value) - { - } - - explicit float3(int value) : x(value), y(value), z(value) - { - } - - float3(float x, float y, float z) : x{x}, y{y}, z{z} - { - } - - operator const float *() const - { - return &x; - } - - operator float *() - { - return &x; - } - - friend float3 operator+(const float3 &a, const float3 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z}; - } - - friend float3 operator+(const float3 &a, const float &b) - { - return {a.x + b, a.y + b, a.z + b}; - } - - float3 &operator+=(const float3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - return *this; - } - - friend float3 operator-(const float3 &a, const float3 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z}; - } - - friend float3 operator-(const float3 &a) - { - return {-a.x, -a.y, -a.z}; - } - - friend float3 operator-(const float3 &a, const float &b) - { - return {a.x - b, a.y - b, a.z - b}; - } - - float3 &operator-=(const float3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - return *this; - } - - float3 &operator*=(float scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - return *this; - } - - float3 &operator*=(const float3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - return *this; - } - - friend float3 operator*(const float3 &a, const float3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend float3 operator*(const float3 &a, float b) - { - return {a.x * b, a.y * b, a.z * b}; - } - - friend float3 operator*(float a, const float3 &b) - { - return b * a; - } - - friend float3 operator/(const float3 &a, float b) - { - BLI_assert(b != 0.0f); - return {a.x / b, a.y / b, a.z / b}; - } - - friend std::ostream &operator<<(std::ostream &stream, const float3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - friend bool operator==(const float3 &a, const float3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const float3 &a, const float3 &b) - { - return !(a == b); - } - - float normalize_and_get_length() - { - return normalize_v3(*this); - } - - /** - * Normalizes the vector in place. - */ - void normalize() - { - normalize_v3(*this); - } - - /** - * Returns a normalized vector. The original vector is not changed. - */ - float3 normalized() const - { - float3 result; - normalize_v3_v3(result, *this); - return result; - } - - float length() const - { - return len_v3(*this); - } - - float length_squared() const - { - return len_squared_v3(*this); - } - - bool is_zero() const - { - return this->x == 0.0f && this->y == 0.0f && this->z == 0.0f; - } - - void reflect(const float3 &normal) - { - *this = this->reflected(normal); - } - - float3 reflected(const float3 &normal) const - { - float3 result; - reflect_v3_v3v3(result, *this, normal); - return result; - } - - static float3 refract(const float3 &incident, const float3 &normal, const float eta) - { - float3 result; - float k = 1.0f - eta * eta * (1.0f - dot(normal, incident) * dot(normal, incident)); - if (k < 0.0f) { - result = float3(0.0f); - } - else { - result = eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal; - } - return result; - } - - static float3 faceforward(const float3 &vector, const float3 &incident, const float3 &reference) - { - return dot(reference, incident) < 0.0f ? vector : -vector; - } - - static float3 safe_divide(const float3 &a, const float3 &b) - { - float3 result; - result.x = (b.x == 0.0f) ? 0.0f : a.x / b.x; - result.y = (b.y == 0.0f) ? 0.0f : a.y / b.y; - result.z = (b.z == 0.0f) ? 0.0f : a.z / b.z; - return result; - } - - static float3 min(const float3 &a, const float3 &b) - { - return {a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z}; - } - - static float3 max(const float3 &a, const float3 &b) - { - return {a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z}; - } - - static void min_max(const float3 &vector, float3 &min, float3 &max) - { - min = float3::min(vector, min); - max = float3::max(vector, max); - } - - static float3 safe_divide(const float3 &a, const float b) - { - return (b != 0.0f) ? a / b : float3(0.0f); - } - - static float3 floor(const float3 &a) - { - return float3(floorf(a.x), floorf(a.y), floorf(a.z)); - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - uint64_t hash() const - { - uint64_t x1 = *reinterpret_cast(&x); - uint64_t x2 = *reinterpret_cast(&y); - uint64_t x3 = *reinterpret_cast(&z); - return (x1 * 435109) ^ (x2 * 380867) ^ (x3 * 1059217); - } - - static float dot(const float3 &a, const float3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static float3 cross_high_precision(const float3 &a, const float3 &b) - { - float3 result; - cross_v3_v3v3_hi_prec(result, a, b); - return result; - } - - static float3 cross(const float3 &a, const float3 &b) - { - float3 result; - cross_v3_v3v3(result, a, b); - return result; - } - - static float3 project(const float3 &a, const float3 &b) - { - float3 result; - project_v3_v3v3(result, a, b); - return result; - } - - static float distance(const float3 &a, const float3 &b) - { - return (a - b).length(); - } - - static float distance_squared(const float3 &a, const float3 &b) - { - float3 diff = a - b; - return float3::dot(diff, diff); - } - - static float3 interpolate(const float3 &a, const float3 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float3 abs(const float3 &a) - { - return float3(fabsf(a.x), fabsf(a.y), fabsf(a.z)); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float4.hh b/source/blender/blenlib/BLI_float4.hh deleted file mode 100644 index 5b487f6d029..00000000000 --- a/source/blender/blenlib/BLI_float4.hh +++ /dev/null @@ -1,138 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -namespace blender { - -struct float4 { - float x, y, z, w; - - float4() = default; - - float4(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]}, w{ptr[3]} - { - } - - explicit float4(float value) : x(value), y(value), z(value), w(value) - { - } - - explicit float4(int value) : x(value), y(value), z(value), w(value) - { - } - - float4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) - { - } - - operator float *() - { - return &x; - } - - friend float4 operator+(const float4 &a, const float &b) - { - return {a.x + b, a.y + b, a.z + b, a.w + b}; - } - - operator const float *() const - { - return &x; - } - - float4 &operator+=(const float4 &other) - { - x += other.x; - y += other.y; - z += other.z; - w += other.w; - return *this; - } - - friend float4 operator-(const float4 &a, const float4 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; - } - - friend float4 operator-(const float4 &a, const float &b) - { - return {a.x - b, a.y - b, a.z - b, a.w - b}; - } - - friend float4 operator+(const float4 &a, const float4 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; - } - - friend float4 operator/(const float4 &a, float f) - { - BLI_assert(f != 0.0f); - return a * (1.0f / f); - } - - float4 &operator*=(float factor) - { - x *= factor; - y *= factor; - z *= factor; - w *= factor; - return *this; - } - - friend float4 operator*(const float4 &a, float b) - { - return {a.x * b, a.y * b, a.z * b, a.w * b}; - } - - friend float4 operator*(float a, const float4 &b) - { - return b * a; - } - - float length() const - { - return len_v4(*this); - } - - static float distance(const float4 &a, const float4 &b) - { - return (a - b).length(); - } - - static float4 safe_divide(const float4 &a, const float b) - { - return (b != 0.0f) ? a / b : float4(0.0f); - } - - static float4 interpolate(const float4 &a, const float4 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float4 floor(const float4 &a) - { - return float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w)); - } - - static float4 normalize(const float4 &a) - { - const float t = len_v4(a); - return (t != 0.0f) ? a / t : float4(0.0f); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float4x4.hh b/source/blender/blenlib/BLI_float4x4.hh index b7f839f4ddf..81c969d02d0 100644 --- a/source/blender/blenlib/BLI_float4x4.hh +++ b/source/blender/blenlib/BLI_float4x4.hh @@ -16,8 +16,9 @@ #pragma once -#include "BLI_float3.hh" #include "BLI_math_matrix.h" +#include "BLI_math_vec_types.hh" +#include "BLI_math_vector.h" namespace blender { @@ -63,7 +64,7 @@ struct float4x4 { * Without the negation, the result would be a so called improper rotation. That means it * contains a reflection. Such an improper rotation matrix could not be converted to another * representation of a rotation such as euler angles. */ - const float3 cross = -float3::cross(forward, up); + const float3 cross = -math::cross(forward, up); float4x4 matrix; matrix.values[0][0] = forward.x; diff --git a/source/blender/blenlib/BLI_gsqueue.h b/source/blender/blenlib/BLI_gsqueue.h index a35c743c80b..8b32c09b56b 100644 --- a/source/blender/blenlib/BLI_gsqueue.h +++ b/source/blender/blenlib/BLI_gsqueue.h @@ -31,7 +31,7 @@ extern "C" { typedef struct _GSQueue GSQueue; -GSQueue *BLI_gsqueue_new(size_t elem_size); +GSQueue *BLI_gsqueue_new(const size_t elem_size); /** * Returns true if the queue is empty, false otherwise. */ diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index f73d1f22502..64852b95ae4 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -85,7 +85,7 @@ void *BLI_findptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, - size_t bytes_size, + const size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** * Find the first item in the list that matches the given string, or the given index as fallback. @@ -96,7 +96,7 @@ void *BLI_listbase_bytes_find(const ListBase *listbase, */ void *BLI_listbase_string_or_index_find(const struct ListBase *listbase, const char *string, - size_t string_offset, + const size_t string_offset, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /* Find backwards. */ @@ -133,7 +133,7 @@ void *BLI_rfindptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_rfind(const ListBase *listbase, const void *bytes, - size_t bytes_size, + const size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** diff --git a/source/blender/blenlib/BLI_math_boolean.hh b/source/blender/blenlib/BLI_math_boolean.hh index 20fd00b2aa4..8cf93c82dec 100644 --- a/source/blender/blenlib/BLI_math_boolean.hh +++ b/source/blender/blenlib/BLI_math_boolean.hh @@ -21,13 +21,11 @@ * \brief Math vector functions needed specifically for mesh intersect and boolean. */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" +#include "BLI_math_vec_types.hh" #ifdef WITH_GMP # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" #endif namespace blender { diff --git a/source/blender/blenlib/BLI_math_vec_mpq_types.hh b/source/blender/blenlib/BLI_math_vec_mpq_types.hh new file mode 100644 index 00000000000..36eb0cac83c --- /dev/null +++ b/source/blender/blenlib/BLI_math_vec_mpq_types.hh @@ -0,0 +1,91 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#ifdef WITH_GMP + +# include "BLI_math_mpq.hh" +# include "BLI_math_vec_types.hh" + +namespace blender { + +using mpq2 = vec_base; +using mpq3 = vec_base; + +namespace math { + +uint64_t hash_mpq_class(const mpq_class &value); + +template<> inline uint64_t vector_hash(const mpq2 &vec) +{ + return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33); +} + +template<> inline uint64_t vector_hash(const mpq3 &vec) +{ + return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33) ^ (hash_mpq_class(vec.z) * 33 * 37); +} + +/** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ +template<> inline mpq_class length(const mpq2 &a) +{ + return mpq_class(sqrt(length_squared(a).get_d())); +} + +/** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ +template<> inline mpq_class length(const mpq3 &a) +{ + return mpq_class(sqrt(length_squared(a).get_d())); +} + +/** + * The buffer avoids allocating a temporary variable. + */ +inline mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) +{ + buffer = a; + buffer -= b; + return dot(buffer, buffer); +} + +/** + * The buffer avoids allocating a temporary variable. + */ +inline mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) +{ + buffer = a; + buffer *= b; + buffer.x += buffer.y; + buffer.x += buffer.z; + return buffer.x; +} + +} // namespace math + +} // namespace blender + +#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh new file mode 100644 index 00000000000..52aacd294e4 --- /dev/null +++ b/source/blender/blenlib/BLI_math_vec_types.hh @@ -0,0 +1,566 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include +#include +#include +#include + +#include "BLI_math_vector.hh" +#include "BLI_utildefines.h" + +namespace blender { + +/* clang-format off */ +template +using as_uint_type = std::conditional_t>>>; +/* clang-format on */ + +template struct vec_struct_base { + std::array values; +}; + +template struct vec_struct_base { + T x, y; +}; + +template struct vec_struct_base { + T x, y, z; +}; + +template struct vec_struct_base { + T x, y, z, w; +}; + +template struct vec_base : public vec_struct_base { + + static constexpr int type_length = Size; + + using base_type = T; + using uint_type = vec_base, Size>; + + vec_base() = default; + + explicit vec_base(uint value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(int value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(float value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(double value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + +/* Workaround issue with template BLI_ENABLE_IF((Size == 2)) not working. */ +#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test)) + + template vec_base(T _x, T _y) + { + (*this)[0] = _x; + (*this)[1] = _y; + } + + template vec_base(T _x, T _y, T _z) + { + (*this)[0] = _x; + (*this)[1] = _y; + (*this)[2] = _z; + } + + template vec_base(T _x, T _y, T _z, T _w) + { + (*this)[0] = _x; + (*this)[1] = _y; + (*this)[2] = _z; + (*this)[3] = _w; + } + + /** Mixed scalar-vector constructors. */ + + template + constexpr vec_base(const vec_base &xy, T z) + : vec_base(static_cast(xy.x), static_cast(xy.y), z) + { + } + + template + constexpr vec_base(T x, const vec_base &yz) + : vec_base(x, static_cast(yz.x), static_cast(yz.y)) + { + } + + template + vec_base(vec_base xyz, T w) + : vec_base( + static_cast(xyz.x), static_cast(xyz.y), static_cast(xyz.z), static_cast(w)) + { + } + + template + vec_base(T x, vec_base yzw) + : vec_base( + static_cast(x), static_cast(yzw.x), static_cast(yzw.y), static_cast(yzw.z)) + { + } + + template + vec_base(vec_base xy, vec_base zw) + : vec_base( + static_cast(xy.x), static_cast(xy.y), static_cast(zw.x), static_cast(zw.y)) + { + } + + template + vec_base(vec_base xy, T z, T w) + : vec_base(static_cast(xy.x), static_cast(xy.y), static_cast(z), static_cast(w)) + { + } + + template + vec_base(T x, vec_base yz, T w) + : vec_base(static_cast(x), static_cast(yz.x), static_cast(yz.y), static_cast(w)) + { + } + + template + vec_base(T x, T y, vec_base zw) + : vec_base(static_cast(x), static_cast(y), static_cast(zw.x), static_cast(zw.y)) + { + } + + /** Masking. */ + + template Size)> + explicit vec_base(const vec_base &other) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(other[i]); + } + } + +#undef BLI_ENABLE_IF_VEC + + /** Conversion from pointers (from C-style vectors). */ + + vec_base(const T *ptr) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = ptr[i]; + } + } + + vec_base(const T (*ptr)[Size]) : vec_base(static_cast(ptr[0])) + { + } + + /** Conversion from other vector types. */ + + template explicit vec_base(const vec_base &vec) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(vec[i]); + } + } + + /** C-style pointer dereference. */ + + operator const T *() const + { + return reinterpret_cast(this); + } + + operator T *() + { + return reinterpret_cast(this); + } + + /** Array access. */ + + const T &operator[](int index) const + { + BLI_assert(index >= 0); + BLI_assert(index < Size); + return reinterpret_cast(this)[index]; + } + + T &operator[](int index) + { + BLI_assert(index >= 0); + BLI_assert(index < Size); + return reinterpret_cast(this)[index]; + } + + /** Internal Operators Macro. */ + +#define BLI_INT_OP(_T) template))> + +#define BLI_VEC_OP_IMPL(_result, _i, _op) \ + vec_base _result; \ + for (int _i = 0; _i < Size; _i++) { \ + _op; \ + } \ + return _result; + +#define BLI_VEC_OP_IMPL_SELF(_i, _op) \ + for (int _i = 0; _i < Size; _i++) { \ + _op; \ + } \ + return *this; + + /** Arithmetic operators. */ + + friend vec_base operator+(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b[i]); + } + + friend vec_base operator+(const vec_base &a, const T &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b); + } + + friend vec_base operator+(const T &a, const vec_base &b) + { + return b + a; + } + + vec_base &operator+=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b[i]); + } + + vec_base &operator+=(const T &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b); + } + + friend vec_base operator-(const vec_base &a) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = -a[i]); + } + + friend vec_base operator-(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b[i]); + } + + friend vec_base operator-(const vec_base &a, const T &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b); + } + + friend vec_base operator-(const T &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a - b[i]); + } + + vec_base &operator-=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b[i]); + } + + vec_base &operator-=(const T &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b); + } + + friend vec_base operator*(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b[i]); + } + + friend vec_base operator*(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b); + } + + friend vec_base operator*(T a, const vec_base &b) + { + return b * a; + } + + vec_base &operator*=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b); + } + + vec_base &operator*=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b[i]); + } + + friend vec_base operator/(const vec_base &a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b[i]); + } + + friend vec_base operator/(const vec_base &a, T b) + { + BLI_assert(b != T(0)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b); + } + + friend vec_base operator/(T a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a / b[i]); + } + + vec_base &operator/=(T b) + { + BLI_assert(b != T(0)); + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b); + } + + vec_base &operator/=(const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b[i]); + } + + /** Binary operators. */ + + BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b[i]); + } + + BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b); + } + + BLI_INT_OP(T) friend vec_base operator&(T a, const vec_base &b) + { + return b & a; + } + + BLI_INT_OP(T) vec_base &operator&=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b); + } + + BLI_INT_OP(T) vec_base &operator&=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b[i]); + } + + BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b); + } + + BLI_INT_OP(T) friend vec_base operator|(T a, const vec_base &b) + { + return b | a; + } + + BLI_INT_OP(T) vec_base &operator|=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b); + } + + BLI_INT_OP(T) vec_base &operator|=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b[i]); + } + + BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b); + } + + BLI_INT_OP(T) friend vec_base operator^(T a, const vec_base &b) + { + return b ^ a; + } + + BLI_INT_OP(T) vec_base &operator^=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b); + } + + BLI_INT_OP(T) vec_base &operator^=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator~(const vec_base &a) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = ~a[i]); + } + + /** Bit-shift operators. */ + + BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b[i]); + } + + BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b); + } + + BLI_INT_OP(T) vec_base &operator<<=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b); + } + + BLI_INT_OP(T) vec_base &operator<<=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b[i]); + } + + BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b); + } + + BLI_INT_OP(T) vec_base &operator>>=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b); + } + + BLI_INT_OP(T) vec_base &operator>>=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b[i]); + } + + /** Modulo operators. */ + + BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b[i]); + } + + BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, T b) + { + BLI_assert(b != 0); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b); + } + + BLI_INT_OP(T) friend vec_base operator%(T a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a % b[i]); + } + +#undef BLI_INT_OP +#undef BLI_VEC_OP_IMPL +#undef BLI_VEC_OP_IMPL_SELF + + /** Compare. */ + + friend bool operator==(const vec_base &a, const vec_base &b) + { + for (int i = 0; i < Size; i++) { + if (a[i] != b[i]) { + return false; + } + } + return true; + } + + friend bool operator!=(const vec_base &a, const vec_base &b) + { + return !(a == b); + } + + /** Misc. */ + + uint64_t hash() const + { + return math::vector_hash(*this); + } + + friend std::ostream &operator<<(std::ostream &stream, const vec_base &v) + { + stream << "("; + for (int i = 0; i < Size; i++) { + stream << v[i]; + if (i != Size - 1) { + stream << ", "; + } + } + stream << ")"; + return stream; + } +}; + +using int2 = vec_base; +using int3 = vec_base; +using int4 = vec_base; + +using uint2 = vec_base; +using uint3 = vec_base; +using uint4 = vec_base; + +using float2 = vec_base; +using float3 = vec_base; +using float4 = vec_base; + +using double2 = vec_base; +using double3 = vec_base; +using double4 = vec_base; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_math_vector.hh b/source/blender/blenlib/BLI_math_vector.hh new file mode 100644 index 00000000000..e7d765df842 --- /dev/null +++ b/source/blender/blenlib/BLI_math_vector.hh @@ -0,0 +1,399 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include +#include + +#include "BLI_math_base_safe.h" +#include "BLI_math_vector.h" +#include "BLI_span.hh" +#include "BLI_utildefines.h" + +#ifdef WITH_GMP +# include "BLI_math_mpq.hh" +#endif + +namespace blender::math { + +#ifndef NDEBUG +# define BLI_ASSERT_UNIT(v) \ + { \ + const float _test_unit = length_squared(v); \ + BLI_assert(!(std::abs(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \ + !(std::abs(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \ + } \ + (void)0 +#else +# define BLI_ASSERT_UNIT(v) (void)(v) +#endif + +#define bT typename T::base_type + +#ifdef WITH_GMP +# define BLI_ENABLE_IF_FLT_VEC(T) \ + BLI_ENABLE_IF((std::is_floating_point_v || \ + std::is_same_v)) +#else +# define BLI_ENABLE_IF_FLT_VEC(T) BLI_ENABLE_IF((std::is_floating_point_v)) +#endif + +#define BLI_ENABLE_IF_INT_VEC(T) BLI_ENABLE_IF((std::is_integral_v)) + +template inline bool is_zero(const T &a) +{ + for (int i = 0; i < T::type_length; i++) { + if (a[i] != bT(0)) { + return false; + } + } + return true; +} + +template inline bool is_any_zero(const T &a) +{ + for (int i = 0; i < T::type_length; i++) { + if (a[i] == bT(0)) { + return true; + } + } + return false; +} + +template inline T abs(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] >= 0 ? a[i] : -a[i]; + } + return result; +} + +template inline T min(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] < b[i] ? a[i] : b[i]; + } + return result; +} + +template inline T max(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] > b[i] ? a[i] : b[i]; + } + return result; +} + +template inline T clamp(const T &a, const T &min_v, const T &max_v) +{ + T result = a; + for (int i = 0; i < T::type_length; i++) { + CLAMP(result[i], min_v[i], max_v[i]); + } + return result; +} + +template inline T clamp(const T &a, const bT &min_v, const bT &max_v) +{ + T result = a; + for (int i = 0; i < T::type_length; i++) { + CLAMP(result[i], min_v, max_v); + } + return result; +} + +template inline T mod(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + BLI_assert(b[i] != 0); + result[i] = std::fmod(a[i], b[i]); + } + return result; +} + +template inline T mod(const T &a, bT b) +{ + BLI_assert(b != 0); + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::fmod(a[i], b); + } + return result; +} + +template inline T safe_mod(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = (b[i] != 0) ? std::fmod(a[i], b[i]) : 0; + } + return result; +} + +template inline T safe_mod(const T &a, bT b) +{ + if (b == 0) { + return T(0.0f); + } + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::fmod(a[i], b); + } + return result; +} + +template inline void min_max(const T &vector, T &min_vec, T &max_vec) +{ + min_vec = min(vector, min_vec); + max_vec = max(vector, max_vec); +} + +template inline T safe_divide(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = (b[i] == 0) ? 0 : a[i] / b[i]; + } + return result; +} + +template inline T safe_divide(const T &a, const bT b) +{ + return (b != 0) ? a / b : T(0.0f); +} + +template inline T floor(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::floor(a[i]); + } + return result; +} + +template inline T ceil(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::ceil(a[i]); + } + return result; +} + +template inline T fract(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] - std::floor(a[i]); + } + return result; +} + +template inline bT dot(const T &a, const T &b) +{ + bT result = a[0] * b[0]; + for (int i = 1; i < T::type_length; i++) { + result += a[i] * b[i]; + } + return result; +} + +template inline bT length_manhattan(const T &a) +{ + bT result = std::abs(a[0]); + for (int i = 1; i < T::type_length; i++) { + result += std::abs(a[i]); + } + return result; +} + +template inline bT length_squared(const T &a) +{ + return dot(a, a); +} + +template inline bT length(const T &a) +{ + return std::sqrt(length_squared(a)); +} + +template inline bT distance_manhattan(const T &a, const T &b) +{ + return length_manhattan(a - b); +} + +template inline bT distance_squared(const T &a, const T &b) +{ + return length_squared(a - b); +} + +template inline bT distance(const T &a, const T &b) +{ + return length(a - b); +} + +template uint64_t vector_hash(const T &vec) +{ + BLI_STATIC_ASSERT(T::type_length <= 4, "Longer types need to implement vector_hash themself."); + const typename T::uint_type &uvec = *reinterpret_cast(&vec); + uint64_t result; + result = uvec[0] * uint64_t(435109); + if constexpr (T::type_length > 1) { + result ^= uvec[1] * uint64_t(380867); + } + if constexpr (T::type_length > 2) { + result ^= uvec[2] * uint64_t(1059217); + } + if constexpr (T::type_length > 3) { + result ^= uvec[3] * uint64_t(2002613); + } + return result; +} + +template inline T reflect(const T &incident, const T &normal) +{ + BLI_ASSERT_UNIT(normal); + return incident - 2.0 * dot(normal, incident) * normal; +} + +template +inline T refract(const T &incident, const T &normal, const bT eta) +{ + float dot_ni = dot(normal, incident); + float k = 1.0f - eta * eta * (1.0f - dot_ni * dot_ni); + if (k < 0.0f) { + return T(0.0f); + } + return eta * incident - (eta * dot_ni + sqrt(k)) * normal; +} + +template inline T project(const T &p, const T &v_proj) +{ + if (UNLIKELY(is_zero(v_proj))) { + return T(0.0f); + } + return v_proj * (dot(p, v_proj) / dot(v_proj, v_proj)); +} + +template +inline T normalize_and_get_length(const T &v, bT &out_length) +{ + out_length = length_squared(v); + /* A larger value causes normalize errors in a scaled down models with camera extreme close. */ + constexpr bT threshold = std::is_same_v ? 1.0e-70 : 1.0e-35f; + if (out_length > threshold) { + out_length = sqrt(out_length); + return v / out_length; + } + /* Either the vector is small or one of it's values contained `nan`. */ + out_length = 0.0; + return T(0.0); +} + +template inline T normalize(const T &v) +{ + bT len; + return normalize_and_get_length(v, len); +} + +template +inline T cross(const T &a, const T &b) +{ + return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; +} + +template)), + BLI_ENABLE_IF((T::type_length == 3))> +inline T cross_high_precision(const T &a, const T &b) +{ + return {(float)((double)a.y * b.z - (double)a.z * b.y), + (float)((double)a.z * b.x - (double)a.x * b.z), + (float)((double)a.x * b.y - (double)a.y * b.x)}; +} + +template +inline T cross_poly(Span poly) +{ + /* Newell's Method. */ + int nv = static_cast(poly.size()); + if (nv < 3) { + return T(0, 0, 0); + } + const T *v_prev = &poly[nv - 1]; + const T *v_curr = &poly[0]; + T n(0, 0, 0); + for (int i = 0; i < nv;) { + n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); + n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); + n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); + v_prev = v_curr; + ++i; + if (i < nv) { + v_curr = &poly[i]; + } + } + return n; +} + +template inline T interpolate(const T &a, const T &b, bT t) +{ + return a * (1 - t) + b * t; +} + +template +inline T faceforward(const T &vector, const T &incident, const T &reference) +{ + return (dot(reference, incident) < 0) ? vector : -vector; +} + +template inline int dominant_axis(const T &a) +{ + T b = abs(a); + return ((b.x > b.y) ? ((b.x > b.z) ? 0 : 2) : ((b.y > b.z) ? 1 : 2)); +} + +/** Intersections. */ + +template struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + bT lambda; +}; + +template +isect_result isect_seg_seg(const T &v1, const T &v2, const T &v3, const T &v4); + +#undef BLI_ENABLE_IF_FLT_VEC +#undef BLI_ENABLE_IF_INT_VEC +#undef bT + +} // namespace blender::math diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h index bcfe2efc5e5..4ac4712bc8c 100644 --- a/source/blender/blenlib/BLI_memarena.h +++ b/source/blender/blenlib/BLI_memarena.h @@ -38,13 +38,13 @@ extern "C" { struct MemArena; typedef struct MemArena MemArena; -struct MemArena *BLI_memarena_new(size_t bufsize, +struct MemArena *BLI_memarena_new(const size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC; void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_malloc(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_calloc(struct MemArena *ma) ATTR_NONNULL(1); -void BLI_memarena_use_align(struct MemArena *ma, size_t align) ATTR_NONNULL(1); +void BLI_memarena_use_align(struct MemArena *ma, const size_t align) ATTR_NONNULL(1); void *BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2); void *BLI_memarena_calloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT diff --git a/source/blender/blenlib/BLI_memory_utils.h b/source/blender/blenlib/BLI_memory_utils.h index 09d8f646905..79e25e26040 100644 --- a/source/blender/blenlib/BLI_memory_utils.h +++ b/source/blender/blenlib/BLI_memory_utils.h @@ -29,7 +29,7 @@ extern "C" { /* it may be defined already */ #ifndef __BLI_UTILDEFINES_H__ -bool BLI_memory_is_zero(const void *arr, size_t size); +bool BLI_memory_is_zero(const void *arr, const size_t size); #endif #ifdef __cplusplus diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh index 37691017c12..9a5be79b61e 100644 --- a/source/blender/blenlib/BLI_memory_utils.hh +++ b/source/blender/blenlib/BLI_memory_utils.hh @@ -557,13 +557,4 @@ Container &move_assign_container(Container &dst, Container &&src) noexcept( return dst; } -/** - * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for - * SFINAE in common cases. - * - * \note Often one has to invoke this macro with double parenthesis. That's because the condition - * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. - */ -#define BLI_ENABLE_IF(condition) typename std::enable_if_t * = nullptr - } // namespace blender diff --git a/source/blender/blenlib/BLI_mesh_intersect.hh b/source/blender/blenlib/BLI_mesh_intersect.hh index 71a8abb822f..0ebee6f16a8 100644 --- a/source/blender/blenlib/BLI_mesh_intersect.hh +++ b/source/blender/blenlib/BLI_mesh_intersect.hh @@ -28,12 +28,11 @@ # include # include "BLI_array.hh" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_index_range.hh" # include "BLI_map.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_span.hh" # include "BLI_utility_mixins.hh" # include "BLI_vector.hh" diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh deleted file mode 100644 index 18bc8821d9c..00000000000 --- a/source/blender/blenlib/BLI_mpq2.hh +++ /dev/null @@ -1,184 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#ifdef WITH_GMP - -# include "BLI_math_mpq.hh" -# include "BLI_mpq3.hh" - -namespace blender { - -struct mpq2 { - mpq_class x, y; - - mpq2() = default; - - mpq2(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - mpq2(mpq_class x, mpq_class y) : x(x), y(y) - { - } - - mpq2(const mpq2 &other) : x(other.x), y(other.y) - { - } - - mpq2(mpq2 &&other) noexcept : x(std::move(other.x)), y(std::move(other.y)) - { - } - - ~mpq2() = default; - - mpq2 &operator=(const mpq2 &other) - { - if (this != &other) { - x = other.x; - y = other.y; - } - return *this; - } - - mpq2 &operator=(mpq2 &&other) noexcept - { - x = std::move(other.x); - y = std::move(other.y); - return *this; - } - - mpq2(const mpq3 &other) : x(other.x), y(other.y) - { - } - - operator mpq_class *() - { - return &x; - } - - operator const mpq_class *() const - { - return &x; - } - - /** - * Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ - mpq_class length() const - { - mpq_class lsquared = dot(*this, *this); - return mpq_class(sqrt(lsquared.get_d())); - } - - friend mpq2 operator+(const mpq2 &a, const mpq2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend mpq2 operator-(const mpq2 &a, const mpq2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend mpq2 operator*(const mpq2 &a, mpq_class b) - { - return {a.x * b, a.y * b}; - } - - friend mpq2 operator/(const mpq2 &a, mpq_class b) - { - BLI_assert(b != 0); - return {a.x / b, a.y / b}; - } - - friend mpq2 operator*(mpq_class a, const mpq2 &b) - { - return b * a; - } - - friend bool operator==(const mpq2 &a, const mpq2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const mpq2 &a, const mpq2 &b) - { - return a.x != b.x || a.y != b.y; - } - - friend std::ostream &operator<<(std::ostream &stream, const mpq2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static mpq_class dot(const mpq2 &a, const mpq2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static mpq2 interpolate(const mpq2 &a, const mpq2 &b, mpq_class t) - { - return a * (1 - t) + b * t; - } - - static mpq2 abs(const mpq2 &a) - { - mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; - mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; - return mpq2(abs_x, abs_y); - } - - static mpq_class distance(const mpq2 &a, const mpq2 &b) - { - return (a - b).length(); - } - - static mpq_class distance_squared(const mpq2 &a, const mpq2 &b) - { - mpq2 diff = a - b; - return dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - mpq_class lambda; - }; - - static isect_result isect_seg_seg(const mpq2 &v1, - const mpq2 &v2, - const mpq2 &v3, - const mpq2 &v4); - - /** There is a sensible use for hashing on exact arithmetic types. */ - uint64_t hash() const; -}; - -} // namespace blender - -#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_mpq3.hh b/source/blender/blenlib/BLI_mpq3.hh deleted file mode 100644 index b9eda2ad7e1..00000000000 --- a/source/blender/blenlib/BLI_mpq3.hh +++ /dev/null @@ -1,297 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#ifdef WITH_GMP - -# include - -# include "BLI_math.h" -# include "BLI_math_mpq.hh" -# include "BLI_span.hh" - -namespace blender { - -struct mpq3 { - mpq_class x, y, z; - - mpq3() = default; - - mpq3(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - mpq3(const mpq_class (*ptr)[3]) : mpq3((const mpq_class *)ptr) - { - } - - explicit mpq3(mpq_class value) : x(value), y(value), z(value) - { - } - - explicit mpq3(int value) : x(value), y(value), z(value) - { - } - - mpq3(mpq_class x, mpq_class y, mpq_class z) : x{x}, y{y}, z{z} - { - } - - operator const mpq_class *() const - { - return &x; - } - - operator mpq_class *() - { - return &x; - } - - /* Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ - mpq_class normalize_and_get_length() - { - double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; - double len = normalize_v3_db(dv); - this->x = mpq_class(dv[0]); - this->y = mpq_class(dv[1]); - this->z = mpq_class(dv[2]); - return len; - } - - mpq3 normalized() const - { - double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; - double dr[3]; - normalize_v3_v3_db(dr, dv); - return mpq3(mpq_class(dr[0]), mpq_class(dr[1]), mpq_class(dr[2])); - } - - /* Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of double. - */ - mpq_class length() const - { - mpq_class lsquared = this->length_squared(); - double dsquared = lsquared.get_d(); - double d = sqrt(dsquared); - return mpq_class(d); - } - - mpq_class length_squared() const - { - return x * x + y * y + z * z; - } - - void reflect(const mpq3 &normal) - { - *this = this->reflected(normal); - } - - mpq3 reflected(const mpq3 &normal) const - { - mpq3 result; - const mpq_class dot2 = 2 * dot(*this, normal); - result.x = this->x - (dot2 * normal.x); - result.y = this->y - (dot2 * normal.y); - result.z = this->z - (dot2 * normal.z); - return result; - } - - static mpq3 safe_divide(const mpq3 &a, const mpq3 &b) - { - mpq3 result; - result.x = (b.x == 0) ? mpq_class(0) : a.x / b.x; - result.y = (b.y == 0) ? mpq_class(0) : a.y / b.y; - result.z = (b.z == 0) ? mpq_class(0) : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - friend mpq3 operator+(const mpq3 &a, const mpq3 &b) - { - return mpq3(a.x + b.x, a.y + b.y, a.z + b.z); - } - - void operator+=(const mpq3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - } - - friend mpq3 operator-(const mpq3 &a, const mpq3 &b) - { - return mpq3(a.x - b.x, a.y - b.y, a.z - b.z); - } - - friend mpq3 operator-(const mpq3 &a) - { - return mpq3(-a.x, -a.y, -a.z); - } - - void operator-=(const mpq3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - } - - void operator*=(mpq_class scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - } - - void operator*=(const mpq3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - } - - friend mpq3 operator*(const mpq3 &a, const mpq3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend mpq3 operator*(const mpq3 &a, const mpq_class &b) - { - return mpq3(a.x * b, a.y * b, a.z * b); - } - - friend mpq3 operator*(const mpq_class &a, const mpq3 &b) - { - return mpq3(a * b.x, a * b.y, a * b.z); - } - - friend mpq3 operator/(const mpq3 &a, const mpq_class &b) - { - BLI_assert(b != 0); - return mpq3(a.x / b, a.y / b, a.z / b); - } - - friend bool operator==(const mpq3 &a, const mpq3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const mpq3 &a, const mpq3 &b) - { - return a.x != b.x || a.y != b.y || a.z != b.z; - } - - friend std::ostream &operator<<(std::ostream &stream, const mpq3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - static mpq_class dot(const mpq3 &a, const mpq3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) - { - buffer = a; - buffer *= b; - buffer.x += buffer.y; - buffer.x += buffer.z; - return buffer.x; - } - - static mpq3 cross(const mpq3 &a, const mpq3 &b) - { - return mpq3(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]); - } - - static mpq3 cross_high_precision(const mpq3 &a, const mpq3 &b) - { - return cross(a, b); - } - - static mpq3 project(const mpq3 &a, const mpq3 &b) - { - const mpq_class mul = mpq3::dot(a, b) / mpq3::dot(b, b); - return mpq3(mul * b[0], mul * b[1], mul * b[2]); - } - - static mpq_class distance(const mpq3 &a, const mpq3 &b) - { - mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); - return diff.length(); - } - - static mpq_class distance_squared(const mpq3 &a, const mpq3 &b) - { - mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); - return mpq3::dot(diff, diff); - } - - static mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) - { - buffer = a; - buffer -= b; - return mpq3::dot(buffer, buffer); - } - - static mpq3 interpolate(const mpq3 &a, const mpq3 &b, mpq_class t) - { - mpq_class s = 1 - t; - return mpq3(a.x * s + b.x * t, a.y * s + b.y * t, a.z * s + b.z * t); - } - - static mpq3 abs(const mpq3 &a) - { - mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; - mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; - mpq_class abs_z = (a.z >= 0) ? a.z : -a.z; - return mpq3(abs_x, abs_y, abs_z); - } - - static int dominant_axis(const mpq3 &a) - { - mpq_class x = (a.x >= 0) ? a.x : -a.x; - mpq_class y = (a.y >= 0) ? a.y : -a.y; - mpq_class z = (a.z >= 0) ? a.z : -a.z; - return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); - } - - static mpq3 cross_poly(Span poly); - - /** There is a sensible use for hashing on exact arithmetic types. */ - uint64_t hash() const; -}; - -uint64_t hash_mpq_class(const mpq_class &value); - -} // namespace blender - -#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_noise.hh b/source/blender/blenlib/BLI_noise.hh index 4f68ef17ca2..297c65c250a 100644 --- a/source/blender/blenlib/BLI_noise.hh +++ b/source/blender/blenlib/BLI_noise.hh @@ -16,9 +16,7 @@ #pragma once -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" namespace blender::noise { diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 658cc0c3825..16f479cb3b8 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -75,15 +75,16 @@ bool BLI_make_existing_file(const char *name); * - Doesn't use CWD, or deal with relative paths. * - Only fill's in \a dir and \a file when they are non NULL. */ -void BLI_split_dirfile(const char *string, char *dir, char *file, size_t dirlen, size_t filelen); +void BLI_split_dirfile( + const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen); /** * Copies the parent directory part of string into `dir`, max length `dirlen`. */ -void BLI_split_dir_part(const char *string, char *dir, size_t dirlen); +void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen); /** * Copies the leaf filename part of string into `file`, max length `filelen`. */ -void BLI_split_file_part(const char *string, char *file, size_t filelen); +void BLI_split_file_part(const char *string, char *file, const size_t filelen); /** * Returns a pointer to the last extension (e.g. the position of the last period). * Returns NULL if there is no extension. @@ -93,7 +94,7 @@ const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(); /** * Append a filename to a dir, ensuring slash separates. */ -void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict file) +void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__restrict file) ATTR_NONNULL(); /** * Simple appending of filename to dir, does not check for valid path! @@ -103,7 +104,7 @@ void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict * that de-duplicates separators and can handle an arbitrary number of paths. */ void BLI_join_dirfile(char *__restrict dst, - size_t maxlen, + const size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL(); /** @@ -113,7 +114,7 @@ void BLI_join_dirfile(char *__restrict dst, * \note If you want a trailing slash, add `SEP_STR` as the last path argument, * duplicate slashes will be cleaned up. */ -size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first, ...) +size_t BLI_path_join(char *__restrict dst, const size_t dst_len, const char *path_first, ...) ATTR_NONNULL(1, 3) ATTR_SENTINEL(0); /** * Like Python's `os.path.basename()` @@ -163,12 +164,12 @@ void BLI_path_slash_rstrip(char *string) ATTR_NONNULL(); void BLI_path_slash_native(char *path) ATTR_NONNULL(); #ifdef _WIN32 -bool BLI_path_program_extensions_add_win32(char *name, size_t maxlen); +bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen); #endif /** * Search for a binary (executable) */ -bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name); +bool BLI_path_program_search(char *fullname, const size_t maxlen, const char *name); /** * \return true when `str` end with `ext` (case insensitive). @@ -352,7 +353,7 @@ bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(); * This is _not_ something Blender's internal paths support, instead they use the "//" prefix. * In most cases #BLI_path_abs should be used instead. */ -bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL(); +bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) ATTR_NONNULL(); /** * Replaces `file` with a relative version (prefixed by "//") such that #BLI_path_abs, given * the same `relfile`, will convert it back to its original value. diff --git a/source/blender/blenlib/BLI_rand.hh b/source/blender/blenlib/BLI_rand.hh index cc9e9b374d7..667d6df8996 100644 --- a/source/blender/blenlib/BLI_rand.hh +++ b/source/blender/blenlib/BLI_rand.hh @@ -20,9 +20,8 @@ #pragma once -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h index eb4e69a42d4..653f5f61c9e 100644 --- a/source/blender/blenlib/BLI_stack.h +++ b/source/blender/blenlib/BLI_stack.h @@ -28,13 +28,13 @@ extern "C" { typedef struct BLI_Stack BLI_Stack; -BLI_Stack *BLI_stack_new_ex(size_t elem_size, +BLI_Stack *BLI_stack_new_ex(const size_t elem_size, const char *description, - size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + const size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** * Create a new homogeneous stack with elements of 'elem_size' bytes. */ -BLI_Stack *BLI_stack_new(size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT +BLI_Stack *BLI_stack_new(const size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 8177545911c..a82e97914db 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -42,7 +42,8 @@ extern "C" { * \param len: The number of bytes to duplicate * \retval Returns the duplicated string */ -char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +char *BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(); /** * Duplicates the cstring \a str into a newly mallocN'd @@ -73,7 +74,8 @@ char *BLI_strdupcat(const char *__restrict str1, * the size of dst) * \retval Returns dst */ -char *BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(); +char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) + ATTR_NONNULL(); /** * Like BLI_strncpy but ensures dst is always padded by given char, @@ -105,7 +107,7 @@ char *BLI_strncpy_ensure_pad(char *__restrict dst, */ size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, - size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + const size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); @@ -184,7 +186,7 @@ void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL(); * \note Larger tables should use a hash table. */ bool BLI_str_replace_table_exact(char *string, - size_t string_len, + const size_t string_len, const char *replace_table[][2], int replace_table_len); @@ -233,7 +235,7 @@ char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT * * \note This is used for creating animation paths in blend files. */ -size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) +size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) ATTR_NONNULL(); /** * This roughly matches C and Python's string escaping with double quotes - `"`. @@ -249,9 +251,9 @@ size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t d */ size_t BLI_str_unescape_ex(char *__restrict dst, const char *__restrict src, - size_t src_maxncpy, + const size_t src_maxncpy, /* Additional arguments. */ - size_t dst_maxncpy, + const size_t dst_maxncpy, bool *r_is_complete) ATTR_NONNULL(); /** * See #BLI_str_unescape_ex doc-string. @@ -263,7 +265,7 @@ size_t BLI_str_unescape_ex(char *__restrict dst, * * \note This is used for parsing animation paths in blend files (runs often). */ -size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_maxncpy) +size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy) ATTR_NONNULL(); /** @@ -357,10 +359,10 @@ int BLI_strcmp_ignore_pad(const char *str1, const char *str2, char pad) ATTR_WAR /** * Determine the length of a fixed-size string. */ -size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(); -void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(); +void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL(); +void BLI_str_toupper_ascii(char *str, const size_t len) ATTR_NONNULL(); /** * Strip white-space from end of the string. */ @@ -477,7 +479,7 @@ bool BLI_string_all_words_matched(const char *name, * \return The number of words found in \a str */ int BLI_string_find_split_words(const char *str, - size_t len, + const size_t len, char delim, int r_words[][2], int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 108a2f5fc7d..82622d442fb 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -110,12 +110,14 @@ size_t BLI_str_utf8_from_unicode_len(unsigned int c) ATTR_WARN_UNUSED_RESULT; * * \return number of bytes written. */ -size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, size_t outbuf_len) ATTR_NONNULL(2); +size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, const size_t outbuf_len) + ATTR_NONNULL(2); size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, - size_t maxncpy) ATTR_NONNULL(1, 2); -size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, size_t maxncpy) - ATTR_NONNULL(1, 2); + const size_t maxncpy) ATTR_NONNULL(1, 2); +size_t BLI_str_utf32_as_utf8(char *__restrict dst, + const char32_t *__restrict src, + const size_t maxncpy) ATTR_NONNULL(1, 2); /** * \return The UTF-32 len in UTF-8. */ @@ -160,20 +162,21 @@ size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RES size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; -size_t BLI_strnlen_utf8_ex(const char *strc, size_t maxlen, size_t *r_len_bytes) +size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes) ATTR_NONNULL(1, 3); /** * \param strc: the string to measure the length. * \param maxlen: the string length (in bytes) * \return the unicode length (not in bytes!) */ -size_t BLI_strnlen_utf8(const char *strc, size_t maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) + ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, - size_t maxncpy) ATTR_NONNULL(1, 2); + const size_t maxncpy) ATTR_NONNULL(1, 2); size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, - size_t maxncpy) ATTR_NONNULL(1, 2); + const size_t maxncpy) ATTR_NONNULL(1, 2); /** * Count columns that character/string occupies (based on `wcwidth.co`). diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index 818bfe8182b..fd3918ff217 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -57,11 +57,11 @@ bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(); * Based on `BLI_split_dirfile()` / `os.path.splitext()`, * `"a.b.c"` -> (`"a.b"`, `".c"`). */ -void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, size_t str_len); +void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len); /** * `"a.b.c"` -> (`"a."`, `"b.c"`). */ -void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size_t str_len); +void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len); /** * Join strings, return newly allocated string. @@ -127,7 +127,7 @@ char *BLI_string_join_array_by_sep_char_with_tableN(char sep, size_t BLI_string_flip_side_name(char *r_name, const char *from_name, bool strip_number, - size_t name_len); + const size_t name_len); /** * Ensures name is unique (according to criteria specified by caller in unique_check callback), diff --git a/source/blender/blenlib/BLI_timecode.h b/source/blender/blenlib/BLI_timecode.h index 1cd18dc86ab..f0349e289ac 100644 --- a/source/blender/blenlib/BLI_timecode.h +++ b/source/blender/blenlib/BLI_timecode.h @@ -42,7 +42,7 @@ extern "C" { * \return length of \a str */ size_t BLI_timecode_string_from_time(char *str, - size_t maxncpy, + const size_t maxncpy, int brevity_level, float time_seconds, double fps, @@ -56,7 +56,7 @@ size_t BLI_timecode_string_from_time(char *str, * \param time_seconds: time total time in seconds * \return length of \a str */ -size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double time_seconds) +size_t BLI_timecode_string_from_time_simple(char *str, const size_t maxncpy, double time_seconds) ATTR_NONNULL(); /** @@ -72,7 +72,7 @@ size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double ti * \note in some cases this is used to print non-seconds values. */ size_t BLI_timecode_string_from_time_seconds(char *str, - size_t maxncpy, + const size_t maxncpy, int brevity_level, float time_seconds) ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 35d4158de59..9fe092fe525 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -638,7 +638,7 @@ extern "C" { /** * Check if memory is zeroed, as with `memset(arr, 0, arr_size)`. */ -extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); +extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); #endif #define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member) \ @@ -840,6 +840,15 @@ extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); /** No-op for expressions we don't want to instantiate, but must remain valid. */ #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) +/** + * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for + * SFINAE in common cases. + * + * \note Often one has to invoke this macro with double parenthesis. That's because the condition + * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. + */ +#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr + /** \} */ #ifdef __cplusplus diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 3958fd8e2d2..90c6760019a 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -192,8 +192,6 @@ set(SRC BLI_dlrbTree.h BLI_dot_export.hh BLI_dot_export_attribute_enums.hh - BLI_double2.hh - BLI_double3.hh BLI_dynlib.h BLI_dynstr.h BLI_easing.h @@ -207,9 +205,6 @@ set(SRC BLI_fileops.hh BLI_fileops_types.h BLI_filereader.h - BLI_float2.hh - BLI_float3.hh - BLI_float4.hh BLI_float4x4.hh BLI_fnmatch.h BLI_function_ref.hh @@ -258,6 +253,8 @@ set(SRC BLI_math_statistics.h BLI_math_time.h BLI_math_vector.h + BLI_math_vec_types.hh + BLI_math_vec_mpq_types.hh BLI_memarena.h BLI_memblock.h BLI_memiter.h @@ -267,8 +264,6 @@ set(SRC BLI_mesh_boolean.hh BLI_mesh_intersect.hh BLI_mmap.h - BLI_mpq2.hh - BLI_mpq3.hh BLI_multi_value_map.hh BLI_noise.h BLI_noise.hh @@ -444,6 +439,7 @@ if(WITH_GTESTS) tests/BLI_math_rotation_test.cc tests/BLI_math_solvers_test.cc tests/BLI_math_time_test.cc + tests/BLI_math_vec_types_test.cc tests/BLI_math_vector_test.cc tests/BLI_memiter_test.cc tests/BLI_memory_utils_test.cc diff --git a/source/blender/blenlib/intern/BLI_mempool_private.h b/source/blender/blenlib/intern/BLI_mempool_private.h index 03b0b11297b..90569d87c41 100644 --- a/source/blender/blenlib/intern/BLI_mempool_private.h +++ b/source/blender/blenlib/intern/BLI_mempool_private.h @@ -54,9 +54,8 @@ typedef struct ParallelMempoolTaskData { * * See #BLI_task_parallel_mempool implementation for detailed usage example. */ -ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, - size_t num_iter) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); +ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter) + ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void mempool_iter_threadsafe_destroy(ParallelMempoolTaskData *iter_arr) ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc index 53e881a9fc7..842e6cb6135 100644 --- a/source/blender/blenlib/intern/delaunay_2d.cc +++ b/source/blender/blenlib/intern/delaunay_2d.cc @@ -25,11 +25,10 @@ #include #include "BLI_array.hh" -#include "BLI_double2.hh" #include "BLI_linklist.h" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_set.hh" #include "BLI_task.hh" #include "BLI_vector.hh" @@ -38,6 +37,8 @@ namespace blender::meshintersect { +using namespace blender::math; + /* Throughout this file, template argument T will be an * arithmetic-like type, like float, double, or mpq_class. */ @@ -788,11 +789,11 @@ bool in_line(const FatCo &a, } vec2 exact_ab = b.exact - a.exact; vec2 exact_ac = c.exact - a.exact; - if (vec2::dot(exact_ab, exact_ac) < 0) { + if (dot(exact_ab, exact_ac) < 0) { return false; } vec2 exact_bc = c.exact - b.exact; - return vec2::dot(exact_bc, exact_ac) >= 0; + return dot(exact_bc, exact_ac) >= 0; } #endif @@ -801,11 +802,11 @@ bool in_line(const FatCo &a, const FatCo &b, const FatCo { vec2 ab = b.approx - a.approx; vec2 ac = c.approx - a.approx; - if (vec2::dot(ab, ac) < 0) { + if (dot(ab, ac) < 0) { return false; } vec2 bc = c.approx - b.approx; - return vec2::dot(bc, ac) >= 0; + return dot(bc, ac) >= 0; } template<> CDTVert::CDTVert(const vec2 &pt) @@ -1081,7 +1082,7 @@ template CDTEdge *CDTArrangement::split_edge(SymEdge *se, T SymEdge *sesymprev = prev(sesym); SymEdge *sesymprevsym = sym(sesymprev); SymEdge *senext = se->next; - CDTVert *v = this->add_vert(vec2::interpolate(*a, *b, lambda)); + CDTVert *v = this->add_vert(interpolate(*a, *b, lambda)); CDTEdge *e = this->add_edge(v, se->next->vert, se->face, sesym->face); sesym->vert = v; SymEdge *newse = &e->symedges[0]; @@ -1704,16 +1705,16 @@ void fill_crossdata_for_intersect(const FatCo &curco, BLI_assert(se_vcva->vert == vc && se_vcva->next->vert == va); BLI_assert(se_vcvb->vert == vc && se_vcvb->next->vert == vb); UNUSED_VARS_NDEBUG(vc); - auto isect = vec2::isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); + auto isect = isect_seg_seg>(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); T &lambda = isect.lambda; switch (isect.kind) { - case vec2::isect_result::LINE_LINE_CROSS: { + case isect_result>::LINE_LINE_CROSS: { #ifdef WITH_GMP if (!std::is_same::value) { #else if (true) { #endif - double len_ab = vec2::distance(va->co.approx, vb->co.approx); + double len_ab = distance(va->co.approx, vb->co.approx); if (lambda * len_ab <= epsilon) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1735,7 +1736,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_EXACT: { + case isect_result>::LINE_LINE_EXACT: { if (lambda == 0) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1750,7 +1751,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_NONE: { + case isect_result>::LINE_LINE_NONE: { #ifdef WITH_GMP if (std::is_same::value) { BLI_assert(false); @@ -1766,9 +1767,9 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_COLINEAR: { - if (vec2::distance_squared(va->co.approx, v2->co.approx) <= - vec2::distance_squared(vb->co.approx, v2->co.approx)) { + case isect_result>::LINE_LINE_COLINEAR: { + if (distance_squared(va->co.approx, v2->co.approx) <= + distance_squared(vb->co.approx, v2->co.approx)) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } else { @@ -1845,7 +1846,7 @@ void get_next_crossing_from_edge(CrossData *cd, { CDTVert *va = cd->in->vert; CDTVert *vb = cd->in->next->vert; - vec2 curco = vec2::interpolate(va->co.exact, vb->co.exact, cd->lambda); + vec2 curco = interpolate(va->co.exact, vb->co.exact, cd->lambda); FatCo fat_curco(curco); SymEdge *se_ac = sym(cd->in)->next; CDTVert *vc = se_ac->next->vert; @@ -2386,7 +2387,7 @@ template void remove_non_constraint_edges_leave_valid_bmesh(CDT_stat dissolvable_edges[i].e = e; const vec2 &co1 = e->symedges[0].vert->co.approx; const vec2 &co2 = e->symedges[1].vert->co.approx; - dissolvable_edges[i].len_squared = vec2::distance_squared(co1, co2); + dissolvable_edges[i].len_squared = distance_squared(co1, co2); i++; } } @@ -2569,18 +2570,18 @@ template void detect_holes(CDT_state *cdt_state) if (e->symedges[0].face->visit_index == e->symedges[1].face->visit_index) { continue; /* Don't count hits on edges between faces in same region. */ } - auto isect = vec2::isect_seg_seg(ray_end.exact, + auto isect = isect_seg_seg>(ray_end.exact, mid.exact, e->symedges[0].vert->co.exact, e->symedges[1].vert->co.exact); switch (isect.kind) { - case vec2::isect_result::LINE_LINE_CROSS: { + case isect_result>::LINE_LINE_CROSS: { hits++; break; } - case vec2::isect_result::LINE_LINE_EXACT: - case vec2::isect_result::LINE_LINE_NONE: - case vec2::isect_result::LINE_LINE_COLINEAR: + case isect_result>::LINE_LINE_EXACT: + case isect_result>::LINE_LINE_NONE: + case isect_result>::LINE_LINE_COLINEAR: break; } } diff --git a/source/blender/blenlib/intern/math_boolean.cc b/source/blender/blenlib/intern/math_boolean.cc index c16755868aa..0bae3c23f79 100644 --- a/source/blender/blenlib/intern/math_boolean.cc +++ b/source/blender/blenlib/intern/math_boolean.cc @@ -18,15 +18,10 @@ * \ingroup bli */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" -#include "BLI_mpq3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc index 223c0e273f0..6fab6c9a383 100644 --- a/source/blender/blenlib/intern/math_vec.cc +++ b/source/blender/blenlib/intern/math_vec.cc @@ -18,89 +18,83 @@ * \ingroup bli */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" -#include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" -#include "BLI_mpq3.hh" +#include "BLI_math_vec_mpq_types.hh" +#include "BLI_math_vector.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" -namespace blender { +namespace blender::math { -float2::isect_result float2::isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4) +template<> +isect_result isect_seg_seg(const float2 &v1, + const float2 &v2, + const float2 &v3, + const float2 &v4) { - float2::isect_result ans; + isect_result ans; float div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0f) { ans.lambda = 0.0f; - ans.mu = 0.0f; - ans.kind = float2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; - ans.mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; - if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && ans.mu >= 0.0f && ans.mu <= 1.0f) { - if (ans.lambda == 0.0f || ans.lambda == 1.0f || ans.mu == 0.0f || ans.mu == 1.0f) { - ans.kind = float2::isect_result::LINE_LINE_EXACT; + float mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; + if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) { + if (ans.lambda == 0.0f || ans.lambda == 1.0f || mu == 0.0f || mu == 1.0f) { + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = float2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = float2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } -double2::isect_result double2::isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4) +template<> +isect_result isect_seg_seg(const double2 &v1, + const double2 &v2, + const double2 &v3, + const double2 &v4) { - double2::isect_result ans; + isect_result ans; double div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = double2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; double mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; if (ans.lambda >= 0.0 && ans.lambda <= 1.0 && mu >= 0.0 && mu <= 1.0) { if (ans.lambda == 0.0 || ans.lambda == 1.0 || mu == 0.0 || mu == 1.0) { - ans.kind = double2::isect_result::LINE_LINE_EXACT; + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = double2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = double2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } #ifdef WITH_GMP -mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, - const mpq2 &v2, - const mpq2 &v3, - const mpq2 &v4) +template<> +isect_result isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4) { - mpq2::isect_result ans; + isect_result ans; mpq_class div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = mpq2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; @@ -109,66 +103,21 @@ mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, if (ans.lambda >= 0 && ans.lambda <= 1 && ((div > 0 && mudiv >= 0 && mudiv <= div) || (div < 0 && mudiv <= 0 && mudiv >= div))) { if (ans.lambda == 0 || ans.lambda == 1 || mudiv == 0 || mudiv == div) { - ans.kind = mpq2::isect_result::LINE_LINE_EXACT; + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = mpq2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = mpq2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } #endif -double3 double3::cross_poly(Span poly) -{ - /* Newell's Method. */ - int nv = static_cast(poly.size()); - if (nv < 3) { - return double3(0, 0, 0); - } - const double3 *v_prev = &poly[nv - 1]; - const double3 *v_curr = &poly[0]; - double3 n(0, 0, 0); - for (int i = 0; i < nv;) { - n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); - n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); - n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); - v_prev = v_curr; - ++i; - if (i < nv) { - v_curr = &poly[i]; - } - } - return n; -} - #ifdef WITH_GMP -mpq3 mpq3::cross_poly(Span poly) -{ - /* Newell's Method. */ - int nv = static_cast(poly.size()); - if (nv < 3) { - return mpq3(0); - } - const mpq3 *v_prev = &poly[nv - 1]; - const mpq3 *v_curr = &poly[0]; - mpq3 n(0); - for (int i = 0; i < nv;) { - n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); - n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); - n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); - v_prev = v_curr; - ++i; - if (i < nv) { - v_curr = &poly[i]; - } - } - return n; -} uint64_t hash_mpq_class(const mpq_class &value) { @@ -176,20 +125,6 @@ uint64_t hash_mpq_class(const mpq_class &value) return get_default_hash(static_cast(value.get_d())); } -uint64_t mpq2::hash() const -{ - uint64_t hashx = hash_mpq_class(this->x); - uint64_t hashy = hash_mpq_class(this->y); - return hashx ^ (hashy * 33); -} - -uint64_t mpq3::hash() const -{ - uint64_t hashx = hash_mpq_class(this->x); - uint64_t hashy = hash_mpq_class(this->y); - uint64_t hashz = hash_mpq_class(this->z); - return hashx ^ (hashy * 33) ^ (hashz * 33 * 37); -} #endif -} // namespace blender +} // namespace blender::math diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index ce4db0c6b9d..a3eae1896d3 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -28,8 +28,6 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" @@ -37,8 +35,9 @@ # include "BLI_math_boolean.hh" # include "BLI_math_geom.h" # include "BLI_math_mpq.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_mesh_intersect.hh" -# include "BLI_mpq3.hh" # include "BLI_set.hh" # include "BLI_span.hh" # include "BLI_stack.hh" @@ -1633,13 +1632,13 @@ static Edge find_good_sorting_edge(const Vert *testp, ordinate[axis_next] = -abscissa[axis]; ordinate[axis_next_next] = 0; /* By construction, dot(abscissa, ordinate) == 0, so they are perpendicular. */ - mpq3 normal = mpq3::cross(abscissa, ordinate); + mpq3 normal = math::cross(abscissa, ordinate); if (dbg_level > 0) { std::cout << "abscissa = " << abscissa << "\n"; std::cout << "ordinate = " << ordinate << "\n"; std::cout << "normal = " << normal << "\n"; } - mpq_class nlen2 = normal.length_squared(); + mpq_class nlen2 = math::length_squared(normal); mpq_class max_abs_slope = -1; Edge esort; const Vector &edges = tmtopo.vert_edges(closestp); @@ -1648,12 +1647,12 @@ static Edge find_good_sorting_edge(const Vert *testp, const mpq3 &co_other = v_other->co_exact; mpq3 evec = co_other - co_closest; /* Get projection of evec onto plane of abscissa and ordinate. */ - mpq3 proj_evec = evec - (mpq3::dot(evec, normal) / nlen2) * normal; + mpq3 proj_evec = evec - (math::dot(evec, normal) / nlen2) * normal; /* The projection calculations along the abscissa and ordinate should * be scaled by 1/abscissa and 1/ordinate respectively, * but we can skip: it won't affect which `evec` has the maximum slope. */ - mpq_class evec_a = mpq3::dot(proj_evec, abscissa); - mpq_class evec_o = mpq3::dot(proj_evec, ordinate); + mpq_class evec_a = math::dot(proj_evec, abscissa); + mpq_class evec_o = math::dot(proj_evec, ordinate); if (dbg_level > 0) { std::cout << "e = " << e << "\n"; std::cout << "v_other = " << v_other << "\n"; @@ -1791,8 +1790,8 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, ap = p; ap -= a; - mpq_class d1 = mpq3::dot_with_buffer(ab, ap, m); - mpq_class d2 = mpq3::dot_with_buffer(ac, ap, m); + mpq_class d1 = math::dot_with_buffer(ab, ap, m); + mpq_class d2 = math::dot_with_buffer(ac, ap, m); if (d1 <= 0 && d2 <= 0) { /* Barycentric coordinates (1,0,0). */ *r_edge = -1; @@ -1800,13 +1799,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = a\n"; } - return mpq3::distance_squared_with_buffer(p, a, m); + return math::distance_squared_with_buffer(p, a, m); } /* Check if p in vertex region outside b. */ bp = p; bp -= b; - mpq_class d3 = mpq3::dot_with_buffer(ab, bp, m); - mpq_class d4 = mpq3::dot_with_buffer(ac, bp, m); + mpq_class d3 = math::dot_with_buffer(ab, bp, m); + mpq_class d4 = math::dot_with_buffer(ac, bp, m); if (d3 >= 0 && d4 <= d3) { /* Barycentric coordinates (0,1,0). */ *r_edge = -1; @@ -1814,7 +1813,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = b\n"; } - return mpq3::distance_squared_with_buffer(p, b, m); + return math::distance_squared_with_buffer(p, b, m); } /* Check if p in region of ab. */ mpq_class vc = d1 * d4 - d3 * d2; @@ -1829,13 +1828,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ab at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* Check if p in vertex region outside c. */ cp = p; cp -= c; - mpq_class d5 = mpq3::dot_with_buffer(ab, cp, m); - mpq_class d6 = mpq3::dot_with_buffer(ac, cp, m); + mpq_class d5 = math::dot_with_buffer(ab, cp, m); + mpq_class d6 = math::dot_with_buffer(ac, cp, m); if (d6 >= 0 && d5 <= d6) { /* Barycentric coordinates (0,0,1). */ *r_edge = -1; @@ -1843,7 +1842,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = c\n"; } - return mpq3::distance_squared_with_buffer(p, c, m); + return math::distance_squared_with_buffer(p, c, m); } /* Check if p in edge region of ac. */ mpq_class vb = d5 * d2 - d1 * d6; @@ -1858,7 +1857,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ac at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* Check if p in edge region of bc. */ mpq_class va = d3 * d6 - d5 * d4; @@ -1874,7 +1873,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on bc at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* p inside face region. Compute barycentric coordinates (u,v,w). */ mpq_class denom = 1 / (va + vb + vc); @@ -1890,7 +1889,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = inside at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } static float closest_on_tri_to_point_float_dist_squared(const float3 &p, @@ -2610,7 +2609,7 @@ static void test_tri_inside_shapes(const IMesh &tm, double3 test_point = calc_point_inside_tri_db(tri_test); /* Offset the test point a tiny bit in the tri_test normal direction. */ tri_test.populate_plane(false); - double3 norm = tri_test.plane->norm.normalized(); + double3 norm = math::normalize(tri_test.plane->norm); const double offset_amount = 1e-5; double3 offset_test_point = test_point + offset_amount * norm; if (dbg_level > 0) { @@ -3002,7 +3001,7 @@ static void init_face_merge_state(FaceMergeState *fms, std::cout << "process tri = " << &tri << "\n"; } BLI_assert(tri.plane_populated()); - if (double3::dot(norm, tri.plane->norm) <= 0.0) { + if (math::dot(norm, tri.plane->norm) <= 0.0) { if (dbg_level > 0) { std::cout << "triangle has wrong orientation, skipping\n"; } @@ -3027,7 +3026,7 @@ static void init_face_merge_state(FaceMergeState *fms, } if (me_index == -1) { double3 vec = new_me.v2->co - new_me.v1->co; - new_me.len_squared = vec.length_squared(); + new_me.len_squared = math::length_squared(vec); new_me.orig = tri.edge_orig[i]; new_me.is_intersect = tri.is_intersect[i]; new_me.dissolvable = (new_me.orig == NO_INDEX && !new_me.is_intersect); @@ -3267,7 +3266,7 @@ static Vector merge_tris_for_face(Vector tris, bool done = false; double3 first_tri_normal = tm.face(tris[0])->plane->norm; double3 second_tri_normal = tm.face(tris[1])->plane->norm; - if (tris.size() == 2 && double3::dot(first_tri_normal, second_tri_normal) > 0.0) { + if (tris.size() == 2 && math::dot(first_tri_normal, second_tri_normal) > 0.0) { /* Is this a case where quad with one diagonal remained unchanged? * Worth special handling because this case will be very common. */ Face &tri1 = *tm.face(tris[0]); @@ -3332,7 +3331,7 @@ static bool approx_in_line(const double3 &a, const double3 &b, const double3 &c) { double3 vec1 = b - a; double3 vec2 = c - b; - double cos_ang = double3::dot(vec1.normalized(), vec2.normalized()); + double cos_ang = math::dot(math::normalize(vec1), math::normalize(vec2)); return fabs(cos_ang - 1.0) < 1e-4; } diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc index 1f150137ba3..982759ffcff 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -30,15 +30,13 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" # include "BLI_math_boolean.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_polyfill_2d.h" # include "BLI_set.hh" # include "BLI_span.hh" @@ -198,14 +196,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co_exact; } - normal_exact = mpq3::cross_poly(co); + normal_exact = math::cross_poly(co.as_span()); } else { mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact; mpq3 tr12 = vert[1]->co_exact - vert[2]->co_exact; - normal_exact = mpq3::cross(tr02, tr12); + normal_exact = math::cross(tr02, tr12); } - mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact); + mpq_class d_exact = -math::dot(normal_exact, vert[0]->co_exact); plane = new Plane(normal_exact, d_exact); } else { @@ -215,14 +213,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co; } - normal = double3::cross_poly(co); + normal = math::cross_poly(co.as_span()); } else { double3 tr02 = vert[0]->co - vert[2]->co; double3 tr12 = vert[1]->co - vert[2]->co; - normal = double3::cross_high_precision(tr02, tr12); + normal = math::cross(tr02, tr12); } - double d = -double3::dot(normal, vert[0]->co); + double d = -math::dot(normal, vert[0]->co); plane = new Plane(normal, d); } } @@ -1098,15 +1096,15 @@ static mpq2 project_3d_to_2d(const mpq3 &p3d, int proj_axis) */ static double supremum_dot_cross(const double3 &a, const double3 &b) { - double3 abs_a = double3::abs(a); - double3 abs_b = double3::abs(b); + double3 abs_a = math::abs(a); + double3 abs_b = math::abs(b); double3 c; /* This is dot(cross(a, b), cross(a,b)) but using absolute values for a and b * and always using + when operation is + or -. */ c[0] = abs_a[1] * abs_b[2] + abs_a[2] * abs_b[1]; c[1] = abs_a[2] * abs_b[0] + abs_a[0] * abs_b[2]; c[2] = abs_a[0] * abs_b[1] + abs_a[1] * abs_b[0]; - return double3::dot(c, c); + return math::dot(c, c); } /* The index of dot when inputs are plane_coords with index 1 is much higher. @@ -1143,11 +1141,11 @@ static int filter_plane_side(const double3 &p, const double3 &abs_plane_p, const double3 &abs_plane_no) { - double d = double3::dot(p - plane_p, plane_no); + double d = math::dot(p - plane_p, plane_no); if (d == 0.0) { return 0; } - double supremum = double3::dot(abs_p + abs_plane_p, abs_plane_no); + double supremum = math::dot(abs_p + abs_plane_p, abs_plane_no); double err_bound = supremum * index_plane_side * DBL_EPSILON; if (fabs(d) > err_bound) { return d > 0 ? 1 : -1; @@ -1178,9 +1176,9 @@ static inline mpq3 tti_interp( ab -= b; ac = a; ac -= c; - mpq_class den = mpq3::dot_with_buffer(ab, n, dotbuf); + mpq_class den = math::dot_with_buffer(ab, n, dotbuf); BLI_assert(den != 0); - mpq_class alpha = mpq3::dot_with_buffer(ac, n, dotbuf) / den; + mpq_class alpha = math::dot_with_buffer(ac, n, dotbuf) / den; return a - alpha * ab; } @@ -1209,7 +1207,7 @@ static inline int tti_above(const mpq3 &a, n.y = ba.z * ca.x - ba.x * ca.z; n.z = ba.x * ca.y - ba.y * ca.x; - return sgn(mpq3::dot_with_buffer(ad, n, dotbuf)); + return sgn(math::dot_with_buffer(ad, n, dotbuf)); } /** @@ -1428,11 +1426,11 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) const double3 &d_r2 = vr2->co; const double3 &d_n2 = tri2.plane->norm; - const double3 &abs_d_p1 = double3::abs(d_p1); - const double3 &abs_d_q1 = double3::abs(d_q1); - const double3 &abs_d_r1 = double3::abs(d_r1); - const double3 &abs_d_r2 = double3::abs(d_r2); - const double3 &abs_d_n2 = double3::abs(d_n2); + const double3 &abs_d_p1 = math::abs(d_p1); + const double3 &abs_d_q1 = math::abs(d_q1); + const double3 &abs_d_r1 = math::abs(d_r1); + const double3 &abs_d_r2 = math::abs(d_r2); + const double3 &abs_d_n2 = math::abs(d_n2); int sp1 = filter_plane_side(d_p1, d_r2, d_n2, abs_d_p1, abs_d_r2, abs_d_n2); int sq1 = filter_plane_side(d_q1, d_r2, d_n2, abs_d_q1, abs_d_r2, abs_d_n2); @@ -1448,9 +1446,9 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) } const double3 &d_n1 = tri1.plane->norm; - const double3 &abs_d_p2 = double3::abs(d_p2); - const double3 &abs_d_q2 = double3::abs(d_q2); - const double3 &abs_d_n1 = double3::abs(d_n1); + const double3 &abs_d_p2 = math::abs(d_p2); + const double3 &abs_d_q2 = math::abs(d_q2); + const double3 &abs_d_n1 = math::abs(d_n1); int sp2 = filter_plane_side(d_p2, d_r1, d_n1, abs_d_p2, abs_d_r1, abs_d_n1); int sq2 = filter_plane_side(d_q2, d_r1, d_n1, abs_d_q2, abs_d_r1, abs_d_n1); @@ -1477,17 +1475,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp1 == 0) { buf[0] = p1; buf[0] -= r2; - sp1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sp1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (sq1 == 0) { buf[0] = q1; buf[0] -= r2; - sq1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sq1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (sr1 == 0) { buf[0] = r1; buf[0] -= r2; - sr1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sr1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (dbg_level > 1) { @@ -1509,17 +1507,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp2 == 0) { buf[0] = p2; buf[0] -= r1; - sp2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sp2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (sq2 == 0) { buf[0] = q2; buf[0] -= r1; - sq2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sq2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (sr2 == 0) { buf[0] = r2; buf[0] -= r1; - sr2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sr2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (dbg_level > 1) { @@ -1721,7 +1719,7 @@ static CDT_data prepare_cdt_input(const IMesh &tm, int t, const Vectorplane_populated()); ans.t_plane = tm.face(t)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); prepare_need_tri(ans, tm, t); for (const ITT_value &itt : itts) { switch (itt.kind) { @@ -1757,7 +1755,7 @@ static CDT_data prepare_cdt_input_for_cluster(const IMesh &tm, BLI_assert(tm.face(t0)->plane_populated()); ans.t_plane = tm.face(t0)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); for (const int t : cl) { prepare_need_tri(ans, tm, t); } @@ -2004,9 +2002,9 @@ static bool is_quad_flip_first_third(const double3 &v1, const double3 &normal) { double3 dir_v3v1 = v3 - v1; - double3 tangent = double3::cross_high_precision(dir_v3v1, normal); - double dot = double3::dot(v1, tangent); - return (double3::dot(v4, tangent) >= dot) || (double3::dot(v2, tangent) <= dot); + double3 tangent = math::cross(dir_v3v1, normal); + double dot = math::dot(v1, tangent); + return (math::dot(v4, tangent) >= dot) || (math::dot(v2, tangent) <= dot); } /** @@ -2124,7 +2122,7 @@ static Array exact_triangulate_poly(Face *f, IMeshArena *arena) f->populate_plane(false); } const double3 &poly_normal = f->plane->norm; - int axis = double3::dominant_axis(poly_normal); + int axis = math::dominant_axis(poly_normal); /* If project down y axis as opposed to x or z, the orientation * of the polygon will be reversed. * Yet another reversal happens if the poly normal in the dominant @@ -2203,15 +2201,15 @@ static bool face_is_degenerate(const Face *f) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double3 dab = double3::cross_high_precision(da, db); - double dab_length_squared = dab.length_squared(); + double3 dab = math::cross(da, db); + double dab_length_squared = math::length_squared(dab); double err_bound = supremum_dot_cross(dab, dab) * index_dot_cross * DBL_EPSILON; if (dab_length_squared > err_bound) { return false; } mpq3 a = v2->co_exact - v0->co_exact; mpq3 b = v2->co_exact - v1->co_exact; - mpq3 ab = mpq3::cross(a, b); + mpq3 ab = math::cross(a, b); if (ab.x == 0 && ab.y == 0 && ab.z == 0) { return true; } @@ -2231,8 +2229,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double da_length_squared = da.length_squared(); - double db_length_squared = db.length_squared(); + double da_length_squared = math::length_squared(da); + double db_length_squared = math::length_squared(db); if (da_length_squared == 0.0 || db_length_squared == 0.0) { return true; } @@ -2240,8 +2238,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) * The triangle is almost degenerate if sin t is almost 0. * sin^2 t = |da x db|^2 / (|da|^2 |db|^2) */ - double3 dab = double3::cross_high_precision(da, db); - double dab_length_squared = dab.length_squared(); + double3 dab = math::cross(da, db); + double dab_length_squared = math::length_squared(dab); double sin_squared_t = dab_length_squared / (da_length_squared * db_length_squared); if (sin_squared_t < 1e-8) { return true; diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc index a6ad18801fd..3460c1284fc 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -50,9 +50,7 @@ #include #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_math_base_safe.h" #include "BLI_noise.hh" #include "BLI_utildefines.h" @@ -1469,7 +1467,7 @@ void voronoi_smooth_f1(const float w, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_w != nullptr) { smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor; @@ -1592,7 +1590,7 @@ static float voronoi_distance(const float2 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float2::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1615,7 +1613,7 @@ void voronoi_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1654,7 +1652,7 @@ void voronoi_smooth_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1676,11 +1674,10 @@ void voronoi_smooth_f1(const float2 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float2::interpolate(smoothPosition, pointPosition, h) - - correctionFactor; + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } } @@ -1704,7 +1701,7 @@ void voronoi_f2(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1748,7 +1745,7 @@ void voronoi_f2(const float2 coord, void voronoi_distance_to_edge(const float2 coord, const float randomness, float *r_distance) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float2 vectorToClosest = float2(0.0f, 0.0f); @@ -1777,7 +1774,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float const float2 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v2v2(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v2v2((vectorToClosest + vectorToPoint) / 2.0f, - perpendicularToEdge.normalized()); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -1787,7 +1784,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *r_radius) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float2 closestPoint = float2(0.0f, 0.0f); @@ -1798,7 +1795,7 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j); const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float2::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -1817,14 +1814,14 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j) + closestPointOffset; const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float2::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; } } } - *r_radius = float2::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 3D Voronoi **** */ @@ -1836,7 +1833,7 @@ static float voronoi_distance(const float3 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float3::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1860,7 +1857,7 @@ void voronoi_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1902,7 +1899,7 @@ void voronoi_smooth_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1925,10 +1922,10 @@ void voronoi_smooth_f1(const float3 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float3::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -1954,7 +1951,7 @@ void voronoi_f2(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2000,7 +1997,7 @@ void voronoi_f2(const float3 coord, void voronoi_distance_to_edge(const float3 coord, const float randomness, float *r_distance) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float3 vectorToClosest = float3(0.0f, 0.0f, 0.0f); @@ -2032,7 +2029,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float const float3 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v3v3(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v3v3((vectorToClosest + vectorToPoint) / 2.0f, - perpendicularToEdge.normalized()); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2043,7 +2040,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *r_radius) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float3 closestPoint = float3(0.0f, 0.0f, 0.0f); @@ -2055,7 +2052,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k); const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float3::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2076,7 +2073,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k) + closestPointOffset; const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float3::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2084,7 +2081,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * } } } - *r_radius = float3::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 4D Voronoi **** */ @@ -2096,7 +2093,7 @@ static float voronoi_distance(const float4 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float4::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z) + fabsf(a.w - b.w); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -2121,7 +2118,7 @@ void voronoi_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -2166,7 +2163,7 @@ void voronoi_smooth_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -2191,10 +2188,10 @@ void voronoi_smooth_f1(const float4 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float4::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -2221,7 +2218,7 @@ void voronoi_f2(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2270,7 +2267,7 @@ void voronoi_f2(const float4 coord, void voronoi_distance_to_edge(const float4 coord, const float randomness, float *r_distance) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float4 vectorToClosest = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2307,7 +2304,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float const float4 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v4v4(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v4v4((vectorToClosest + vectorToPoint) / 2.0f, - float4::normalize(perpendicularToEdge)); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2319,7 +2316,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *r_radius) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float4 closestPoint = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2333,7 +2330,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float4::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2357,7 +2354,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float4::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2366,7 +2363,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * } } } - *r_radius = float4::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /** \} */ diff --git a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc index 70e3a99e57a..eac3faa6d15 100644 --- a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc +++ b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc @@ -21,10 +21,9 @@ extern "C" { #define DO_RANDOM_TESTS 0 #include "BLI_array.hh" -#include "BLI_double2.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_vector.hh" #include "BLI_delaunay_2d.h" diff --git a/source/blender/blenlib/tests/BLI_math_vec_types_test.cc b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc new file mode 100644 index 00000000000..8aa1f90fde2 --- /dev/null +++ b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc @@ -0,0 +1,149 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +#include "BLI_math_vec_types.hh" + +namespace blender::tests { + +using namespace blender::math; + +TEST(math_vec_types, ScalarConstructorUnsigned) +{ + float2 u(5u); + EXPECT_EQ(u[0], 5.0f); + EXPECT_EQ(u[1], 5.0f); +} + +TEST(math_vec_types, ScalarConstructorInt) +{ + float2 i(-5); + EXPECT_EQ(i[0], -5.0f); + EXPECT_EQ(i[1], -5.0f); +} + +TEST(math_vec_types, ScalarConstructorFloat) +{ + float2 f(5.2f); + EXPECT_FLOAT_EQ(f[0], 5.2f); + EXPECT_FLOAT_EQ(f[1], 5.2f); +} + +TEST(math_vec_types, ScalarConstructorDouble) +{ + float2 d(5.2); + EXPECT_FLOAT_EQ(d[0], 5.2f); + EXPECT_FLOAT_EQ(d[1], 5.2f); +} + +TEST(math_vec_types, MultiScalarConstructorVec2) +{ + int2 i(5.5f, -1.8); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); +} + +TEST(math_vec_types, MultiScalarConstructorVec3) +{ + int3 i(5.5f, -1.8, 6u); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); + EXPECT_EQ(i[2], 6); +} + +TEST(math_vec_types, MultiScalarConstructorVec4) +{ + int4 i(5.5f, -1.8, 6u, 0.888f); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); + EXPECT_EQ(i[2], 6); + EXPECT_EQ(i[3], 0); +} + +TEST(math_vec_types, MixedScalarVectorConstructorVec3) +{ + float3 fl_v2(float2(5.5f), 1.8f); + EXPECT_FLOAT_EQ(fl_v2[0], 5.5f); + EXPECT_FLOAT_EQ(fl_v2[1], 5.5f); + EXPECT_FLOAT_EQ(fl_v2[2], 1.8f); + + float3 v2_fl(1.8f, float2(5.5f)); + EXPECT_FLOAT_EQ(v2_fl[0], 1.8f); + EXPECT_FLOAT_EQ(v2_fl[1], 5.5f); + EXPECT_FLOAT_EQ(v2_fl[2], 5.5f); +} + +TEST(math_vec_types, MixedScalarVectorConstructorVec4) +{ + int4 v2_fl_fl(float2(1), 2, 3); + EXPECT_EQ(v2_fl_fl[0], 1); + EXPECT_EQ(v2_fl_fl[1], 1); + EXPECT_EQ(v2_fl_fl[2], 2); + EXPECT_EQ(v2_fl_fl[3], 3); + + float4 fl_v2_fl(1, int2(2), 3); + EXPECT_EQ(fl_v2_fl[0], 1); + EXPECT_EQ(fl_v2_fl[1], 2); + EXPECT_EQ(fl_v2_fl[2], 2); + EXPECT_EQ(fl_v2_fl[3], 3); + + double4 fl_fl_v2(1, 2, double2(3)); + EXPECT_EQ(fl_fl_v2[0], 1); + EXPECT_EQ(fl_fl_v2[1], 2); + EXPECT_EQ(fl_fl_v2[2], 3); + EXPECT_EQ(fl_fl_v2[3], 3); + + int4 v2_v2(float2(1), uint2(2)); + EXPECT_EQ(v2_v2[0], 1); + EXPECT_EQ(v2_v2[1], 1); + EXPECT_EQ(v2_v2[2], 2); + EXPECT_EQ(v2_v2[3], 2); + + float4 v3_fl(uint3(1), 2); + EXPECT_EQ(v3_fl[0], 1); + EXPECT_EQ(v3_fl[1], 1); + EXPECT_EQ(v3_fl[2], 1); + EXPECT_EQ(v3_fl[3], 2); + + uint4 fl_v3(1, float3(2)); + EXPECT_EQ(fl_v3[0], 1); + EXPECT_EQ(fl_v3[1], 2); + EXPECT_EQ(fl_v3[2], 2); + EXPECT_EQ(fl_v3[3], 2); +} + +TEST(math_vec_types, ComponentMasking) +{ + int4 i(0, 1, 2, 3); + float2 f2 = float2(i); + EXPECT_EQ(f2[0], 0.0f); + EXPECT_EQ(f2[1], 1.0f); +} + +TEST(math_vec_types, PointerConversion) +{ + float array[3] = {1.0f, 2.0f, 3.0f}; + float3 farray(array); + EXPECT_EQ(farray[0], 1.0f); + EXPECT_EQ(farray[1], 2.0f); + EXPECT_EQ(farray[2], 3.0f); +} + +TEST(math_vec_types, PointerArrayConversion) +{ + float array[1][3] = {{1.0f, 2.0f, 3.0f}}; + float(*ptr)[3] = array; + float3 fptr(ptr); + EXPECT_EQ(fptr[0], 1.0f); + EXPECT_EQ(fptr[1], 2.0f); + EXPECT_EQ(fptr[2], 3.0f); +} + +TEST(math_vec_types, VectorTypeConversion) +{ + double2 d(int2(float2(5.75f, -1.57f))); + EXPECT_EQ(d[0], 5.0); + EXPECT_EQ(d[1], -1.0); +} + +} // namespace blender::tests diff --git a/source/blender/blenlib/tests/BLI_memory_utils_test.cc b/source/blender/blenlib/tests/BLI_memory_utils_test.cc index 207f310d902..74e54151a06 100644 --- a/source/blender/blenlib/tests/BLI_memory_utils_test.cc +++ b/source/blender/blenlib/tests/BLI_memory_utils_test.cc @@ -1,6 +1,6 @@ /* Apache License, Version 2.0 */ -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_memory_utils.hh" #include "BLI_strict_flags.h" #include "testing/testing.h" diff --git a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc index d759f0c3be4..2b8fb3dbea4 100644 --- a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc @@ -11,8 +11,8 @@ #include "BLI_array.hh" #include "BLI_map.hh" #include "BLI_math_mpq.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_boolean.hh" -#include "BLI_mpq3.hh" #include "BLI_vector.hh" #ifdef WITH_GMP diff --git a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc index 68111fb8eb1..d2d76593129 100644 --- a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc @@ -10,8 +10,8 @@ #include "BLI_array.hh" #include "BLI_math_mpq.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_intersect.hh" -#include "BLI_mpq3.hh" #include "BLI_task.h" #include "BLI_vector.hh" diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 85ea27b0f4e..7865c79323d 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -1186,7 +1186,6 @@ static BMO_FlagSet bmo_enum_triangulate_quad_method[] = { {MOD_TRIANGULATE_QUAD_FIXED, "FIXED"}, {MOD_TRIANGULATE_QUAD_ALTERNATE, "ALTERNATE"}, {MOD_TRIANGULATE_QUAD_SHORTEDGE, "SHORT_EDGE"}, - {MOD_TRIANGULATE_QUAD_LONGEDGE, "LONG_EDGE"}, {0, NULL}, }; diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index e7280303c26..e9eaf865e3c 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -1007,7 +1007,6 @@ void BM_face_triangulate(BMesh *bm, break; } case MOD_TRIANGULATE_QUAD_SHORTEDGE: - case MOD_TRIANGULATE_QUAD_LONGEDGE: case MOD_TRIANGULATE_QUAD_BEAUTY: default: { BMLoop *l_v3, *l_v4; @@ -1024,12 +1023,6 @@ void BM_face_triangulate(BMesh *bm, d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); split_24 = ((d2 - d1) > 0.0f); } - else if (quad_method == MOD_TRIANGULATE_QUAD_LONGEDGE) { - float d1, d2; - d1 = len_squared_v3v3(l_v4->v->co, l_v2->v->co); - d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); - split_24 = ((d2 - d1) < 0.0f); - } else { /* first check if the quad is concave on either diagonal */ const int flip_flag = is_quad_flip_v3( diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 905d1443002..96dc17c2d1a 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -647,15 +647,6 @@ endif() blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") -if(WITH_UNITY_BUILD) - set_target_properties(bf_compositor PROPERTIES UNITY_BUILD ON) - set_target_properties(bf_compositor PROPERTIES UNITY_BUILD_BATCH_SIZE 10) -endif() - -if(COMMAND target_precompile_headers) - target_precompile_headers(bf_compositor PRIVATE COM_precomp.h) -endif() - if(CXX_WARN_NO_SUGGEST_OVERRIDE) target_compile_options(bf_compositor PRIVATE "-Wsuggest-override") endif() diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index 1c3a28670df..794bf1b23bc 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -18,7 +18,7 @@ #pragma once -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "DNA_vec_types.h" diff --git a/source/blender/compositor/COM_precomp.h b/source/blender/compositor/COM_precomp.h deleted file mode 100644 index 4d2681ea0cd..00000000000 --- a/source/blender/compositor/COM_precomp.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Pre-compiled headers, see: D13797. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "COM_ConstantOperation.h" -#include "COM_ConvertOperation.h" -#include "COM_Debug.h" -#include "COM_Enums.h" -#include "COM_ExecutionGroup.h" -#include "COM_ExecutionSystem.h" -#include "COM_MultiThreadedOperation.h" -#include "COM_Node.h" -#include "COM_NodeOperation.h" -#include "COM_OpenCLDevice.h" -#include "COM_SetAlphaMultiplyOperation.h" -#include "COM_SetColorOperation.h" -#include "COM_SetSamplerOperation.h" -#include "COM_SetValueOperation.h" -#include "COM_SetVectorOperation.h" -#include "COM_defines.h" diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index e601ebac4e1..0e871f47b87 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -136,7 +136,7 @@ void add_exr_channels(void *exrhandle, const char *layer_name, const DataType datatype, const char *view_name, - size_t width, + const size_t width, bool use_half_float, float *buf); void free_exr_channels(void *exrhandle, diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index fcdc3fe58e8..1c09417e9ab 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1475,17 +1475,6 @@ void DepsgraphRelationBuilder::build_animation_images(ID *id) id, NodeType::IMAGE_ANIMATION, OperationCode::IMAGE_ANIMATION); TimeSourceKey time_src_key; add_relation(time_src_key, image_animation_key, "TimeSrc -> Image Animation"); - - /* The image users of these ids may change during evaluation. Make sure that the image - * animation update happens after evaluation. */ - if (GS(id->name) == ID_MA) { - OperationKey material_update_key(id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE); - add_relation(material_update_key, image_animation_key, "Material Update -> Image Animation"); - } - else if (GS(id->name) == ID_WO) { - OperationKey world_update_key(id, NodeType::SHADING, OperationCode::WORLD_UPDATE); - add_relation(world_update_key, image_animation_key, "World Update -> Image Animation"); - } } } diff --git a/source/blender/depsgraph/intern/node/deg_node_factory.h b/source/blender/depsgraph/intern/node/deg_node_factory.h index b3153a7ddfb..125f340a0fa 100644 --- a/source/blender/depsgraph/intern/node/deg_node_factory.h +++ b/source/blender/depsgraph/intern/node/deg_node_factory.h @@ -55,7 +55,7 @@ template struct DepsNodeFactoryImpl : public DepsNodeFacto void register_node_typeinfo(DepsNodeFactory *factory); /* Get typeinfo for specified type */ -DepsNodeFactory *type_get_factory(NodeType type); +DepsNodeFactory *type_get_factory(const NodeType type); } // namespace deg } // namespace blender diff --git a/source/blender/draw/intern/draw_cache_impl_curve.cc b/source/blender/draw/intern/draw_cache_impl_curve.cc index 1108d40125b..33cf0e9a3cd 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.cc +++ b/source/blender/draw/intern/draw_cache_impl_curve.cc @@ -26,8 +26,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc index ea702e5efdd..b846da3f016 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc @@ -25,9 +25,7 @@ #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BKE_attribute.h" diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 79dda480a0a..73a94f066e3 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -54,7 +54,6 @@ #include "BKE_deform.h" #include "BKE_global.h" #include "BKE_gpencil.h" -#include "BKE_gpencil_curve.h" #include "BKE_gpencil_geom.h" #include "BKE_layer.h" #include "BKE_main.h" @@ -835,7 +834,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p, /* color strength */ if (brush_settings->flag & GP_BRUSH_USE_STRENGTH_PRESSURE) { pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); } /* Set vertex colors for buffer. */ @@ -919,19 +918,6 @@ static short gpencil_stroke_addpoint(tGPsdata *p, return GP_STROKEADD_INVALID; } -static void gpencil_stroke_unselect(bGPdata *gpd, bGPDstroke *gps) -{ - gps->flag &= ~GP_STROKE_SELECT; - BKE_gpencil_stroke_select_index_reset(gps); - for (int i = 0; i < gps->totpoints; i++) { - gps->points[i].flag &= ~GP_SPOINT_SELECT; - } - /* Update the selection from the stroke to the curve. */ - if (gps->editcurve) { - BKE_gpencil_editcurve_stroke_sync_selection(gpd, gps, gps->editcurve); - } -} - /* make a new stroke from the buffer data */ static void gpencil_stroke_newfrombuffer(tGPsdata *p) { @@ -942,7 +928,6 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) tGPspoint *ptc; MDeformVert *dvert = NULL; Brush *brush = p->brush; - BrushGpencilSettings *brush_settings = brush->gpencil_settings; ToolSettings *ts = p->scene->toolsettings; Depsgraph *depsgraph = p->depsgraph; Object *obact = (Object *)p->ownerPtr.data; @@ -1031,7 +1016,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; /* Apply the vertex color to point. */ @@ -1065,7 +1050,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); pt->time = ptc->time; /* Apply the vertex color to point. */ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); @@ -1190,7 +1175,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); + CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; pt->uv_fac = ptc->uv_fac; @@ -1315,12 +1300,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) ctrl2, GPENCIL_MINIMUM_JOIN_DIST, &pt_index); - if (gps_target != NULL) { - /* Unselect all points of source and destination strokes. This is required to avoid - * a change in the resolution of the original strokes during the join. */ - gpencil_stroke_unselect(gpd, gps); - gpencil_stroke_unselect(gpd, gps_target); gps = ED_gpencil_stroke_join_and_trim(p->gpd, p->gpf, gps, gps_target, pt_index); } else { diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h index 6bcddfa631a..8a669a2afc2 100644 --- a/source/blender/editors/include/ED_util.h +++ b/source/blender/editors/include/ED_util.h @@ -102,7 +102,7 @@ void ED_slider_destroy(struct bContext *C, struct tSlider *slider); */ void ED_slider_status_string_get(const struct tSlider *slider, char *status_string, - size_t size_of_status_string); + const size_t size_of_status_string); float ED_slider_factor_get(struct tSlider *slider); void ED_slider_factor_set(struct tSlider *slider, float factor); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 9ce07cd2e07..f01b8318e98 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -495,7 +495,7 @@ float UI_text_clip_middle_ex(const struct uiFontStyle *fstyle, char *str, float okwidth, float minwidth, - size_t max_len, + const size_t max_len, char rpart_sep); /** @@ -2957,17 +2957,15 @@ void UI_fontstyle_set(const struct uiFontStyle *fs); void UI_fontstyle_draw_ex(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, - size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, + size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info); - void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, - size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params); /** diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 923f741e3ae..027f03d05c7 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -688,11 +688,11 @@ extern void ui_hsvcube_pos_from_vals( */ extern void ui_but_string_get_ex(uiBut *but, char *str, - size_t maxlen, + const size_t maxlen, int float_precision, bool use_exp_float, bool *r_use_exp_float) ATTR_NONNULL(1, 2); -extern void ui_but_string_get(uiBut *but, char *str, size_t maxlen) ATTR_NONNULL(); +extern void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) ATTR_NONNULL(); /** * A version of #ui_but_string_get_ex for dynamic buffer sizes * (where #ui_but_string_get_max_length returns 0). diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 135cef5fe53..bc1d3387ad7 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1146,7 +1146,6 @@ static void panel_draw_aligned_widgets(const uiStyle *style, UI_fontstyle_draw(fontstyle, &title_rect, panel->drawname, - sizeof(panel->drawname), title_color, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index fe58a6a05ae..e146443faaa 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -74,8 +74,6 @@ #define UI_TIP_PADDING (int)(UI_TIP_PAD_FAC * UI_UNIT_Y) #define UI_TIP_MAXWIDTH 600 -#define UI_TIP_STR_MAX 1024 - typedef struct uiTooltipFormat { enum { UI_TIP_STYLE_NORMAL = 0, @@ -216,7 +214,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw header and active data (is done here to be able to change color) */ rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_MAIN]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); /* offset to the end of the last line */ if (field->text_suffix) { @@ -226,8 +224,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.ymax -= yofs; rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_ACTIVE]); - UI_fontstyle_draw( - &data->fstyle, &bbox, field->text_suffix, UI_TIP_STR_MAX, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text_suffix, drawcol, &fs_params); /* undo offset */ bbox.xmin -= xofs; @@ -246,7 +243,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* XXX, needed because we don't have mono in 'U.uifonts' */ BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); - UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); + UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol, &fs_params); } else { BLI_assert(field->format.style == UI_TIP_STYLE_NORMAL); @@ -258,7 +255,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw remaining data */ rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); } bbox.ymax -= data->lineh * field->geom.lines; @@ -1218,12 +1215,12 @@ static ARegion *ui_tooltip_create_with_data(bContext *C, BLI_assert(ELEM(field->format.style, UI_TIP_STYLE_NORMAL, UI_TIP_STYLE_HEADER)); font_id = data->fstyle.uifont_id; } - w = BLF_width_ex(font_id, field->text, UI_TIP_STR_MAX, &info); + w = BLF_width_ex(font_id, field->text, BLF_DRAW_STR_DUMMY_MAX, &info); /* check for suffix (enum label) */ if (field->text_suffix && field->text_suffix[0]) { x_pos = info.width; - w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, UI_TIP_STR_MAX)); + w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, BLF_DRAW_STR_DUMMY_MAX)); } fontw = max_ii(fontw, w); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 44942d508ca..c28769a4951 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -140,9 +140,9 @@ static uiFont *uifont_to_blfont(int id) void UI_fontstyle_draw_ex(const uiFontStyle *fs, const rcti *rect, const char *str, - const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, + size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info) @@ -183,10 +183,10 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, } if (fs_params->align == UI_STYLE_TEXT_CENTER) { - xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len))); + xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); } else if (fs_params->align == UI_STYLE_TEXT_RIGHT) { - xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len); + xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len); } yofs = MAX2(0, yofs); @@ -196,7 +196,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_color4ubv(fs->uifont_id, col); - BLF_draw_ex(fs->uifont_id, str, str_len, r_info); + BLF_draw_ex(fs->uifont_id, str, len, r_info); BLF_disable(fs->uifont_id, font_flag); @@ -211,11 +211,12 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, - const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params) { - UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, NULL, NULL, NULL); + int xofs, yofs; + + UI_fontstyle_draw_ex(fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, NULL); } void UI_fontstyle_draw_rotated(const uiFontStyle *fs, diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index b44496731f7..ad8c0842657 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2130,11 +2130,11 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, - drawlen, wcol->text, &(struct uiFontStyleDraw_Params){ .align = align, }, + drawlen, &font_xofs, &font_yofs, NULL); @@ -2194,7 +2194,6 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, drawstr_right, - UI_MAX_DRAW_STR, col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5418,11 +5417,11 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr, - sizeof(drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, }, + BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, &info); @@ -5469,7 +5468,6 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, hint_drawstr, - sizeof(hint_drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5525,7 +5523,6 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, &trect, drawstr, - sizeof(drawstr), text_col, &(struct uiFontStyleDraw_Params){ .align = text_align, diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 06e21f91d04..b9943d13b19 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -3527,8 +3527,6 @@ static int object_add_named_exec(bContext *C, wmOperator *op) } basen->object->visibility_flag &= ~OB_HIDE_VIEWPORT; - /* Do immediately, as #copy_object_set_idnew() below operates on visible objects. */ - BKE_base_eval_flags(basen); /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or * BKE_view_layer_base_deselect_all(). */ diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 4f94927533b..16e83395401 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -722,7 +722,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r SpaceProperties *sbuts = CTX_wm_space_properties(C); ShaderPreview *sp = static_cast(WM_jobs_customdata(wm, area)); rcti newrect; - bool ok; + int ok; int newx = BLI_rcti_size_x(rect); int newy = BLI_rcti_size_y(rect); diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index dd1b4e10e60..44e9735866d 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -240,7 +240,6 @@ static void file_draw_string(int sx, UI_fontstyle_draw(&fs, &rect, fname, - sizeof(fname), col, &(struct uiFontStyleDraw_Params){ .align = align, @@ -290,12 +289,12 @@ static void file_draw_string_multiline(int sx, UI_fontstyle_draw_ex(&style->widget, &rect, string, - len, text_col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, .word_wrap = true, }, + len, NULL, NULL, &result); diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index e9a385c525b..2d3c42b16d1 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2452,7 +2452,7 @@ static void frame_node_draw_label(const bNodeTree &ntree, const bool has_label = node.label[0] != '\0'; if (has_label) { BLF_position(fontid, x, y, 0); - BLF_draw(fontid, label, sizeof(label)); + BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX); } /* draw text body */ diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 4834ca3174a..02d68189997 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -28,9 +28,9 @@ #include "DNA_anim_types.h" #include "DNA_node_types.h" -#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_vector.hh" diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index 0f542734f66..740d1fbb6f9 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -23,7 +23,7 @@ #pragma once -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BKE_node.h" @@ -43,9 +43,6 @@ struct bNodeLink; struct bNodeSocket; struct wmGizmoGroupType; struct wmKeyConfig; -namespace blender { -struct float2; -} struct wmWindow; /** Temporary data used in node link drag modal operator. */ diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index 334ca1f76ee..803cf38c53a 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -111,11 +111,13 @@ static bNode *node_under_mouse_select(bNodeTree &ntree, int mx, int my) static bNode *node_under_mouse_tweak(bNodeTree &ntree, const float2 &mouse) { + using namespace blender::math; + LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) { if (node->type == NODE_REROUTE) { bNodeSocket *socket = (bNodeSocket *)node->inputs.first; const float2 location{socket->locx, socket->locy}; - if (float2::distance(mouse, location) < 24.0f) { + if (distance(mouse, location) < 24.0f) { return node; } } diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 6dffc0bc2a4..e814530d1e2 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -2262,15 +2262,28 @@ void sequencer_draw_preview(const bContext *C, seq_prefetch_wm_notify(C, scene); } -static void draw_seq_timeline_channels(View2D *v2d) +/* Draw backdrop in sequencer timeline. */ +static void draw_seq_backdrop(View2D *v2d) { + int i; + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + /* View backdrop. */ + immUniformThemeColor(TH_BACK); + immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax); + + /* Darker overlay over the view backdrop. */ + immUniformThemeColorShade(TH_BACK, -10); + immRectf(pos, v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0); + + /* Alternating horizontal stripes. */ + i = max_ii(1, ((int)v2d->cur.ymin) - 1); + GPU_blend(GPU_BLEND_ALPHA); immUniformThemeColor(TH_ROW_ALTERNATE); - /* Alternating horizontal stripes. */ - int i = max_ii(1, ((int)v2d->cur.ymin) - 1); while (i < v2d->cur.ymax) { if (i & 1) { immRectf(pos, v2d->cur.xmin, i, v2d->cur.xmax, i + 1); @@ -2282,14 +2295,6 @@ static void draw_seq_timeline_channels(View2D *v2d) immUnbindProgram(); } -static void draw_seq_timeline_channel_numbers(ARegion *region) -{ - View2D *v2d = ®ion->v2d; - rcti rect; - BLI_rcti_init(&rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); - UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); -} - static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *region) { Scene *scene = CTX_data_scene(C); @@ -2713,7 +2718,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region) } UI_view2d_view_ortho(v2d); - draw_seq_timeline_channels(v2d); + draw_seq_backdrop(v2d); if ((sseq->flag & SEQ_SHOW_OVERLAY) && (sseq->timeline_overlay.flag & SEQ_TIMELINE_SHOW_GRID)) { U.v2d_min_gridsize *= 3; UI_view2d_draw_lines_x__discrete_frames_or_seconds( @@ -2771,7 +2776,13 @@ void draw_timeline_seq(const bContext *C, ARegion *region) UI_view2d_view_restore(C); ED_time_scrub_draw(region, scene, !(sseq->flag & SEQ_DRAWFRAMES), true); - draw_seq_timeline_channel_numbers(region); + /* Draw channel numbers. */ + { + rcti rect; + BLI_rcti_init( + &rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); + UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); + } } void draw_timeline_seq_display(const bContext *C, ARegion *region) diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc index ee623083db7..ede8756a9da 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc @@ -19,9 +19,8 @@ #include "MEM_guardedalloc.h" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index 7cc2d8d0b48..f4b5ff819ed 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -17,8 +17,7 @@ #include #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BKE_geometry_set.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc index 36c7f1057df..556c0b0d5ca 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc @@ -123,9 +123,7 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float2 cell) { - return float2::distance_squared(cell, value) > threshold_sq; - }, + [&](const float2 cell) { return math::distance_squared(cell, value) > threshold_sq; }, prev_mask, new_indices); break; @@ -155,9 +153,7 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float3 cell) { - return float3::distance_squared(cell, value) > threshold_sq; - }, + [&](const float3 cell) { return math::distance_squared(cell, value) > threshold_sq; }, prev_mask, new_indices); break; diff --git a/source/blender/editors/util/ed_draw.c b/source/blender/editors/util/ed_draw.c index 3e85862a847..ccbde07f5b1 100644 --- a/source/blender/editors/util/ed_draw.c +++ b/source/blender/editors/util/ed_draw.c @@ -599,9 +599,9 @@ static void metadata_custom_draw_fields(const char *field, const char *value, vo } MetadataCustomDrawContext *ctx = (MetadataCustomDrawContext *)ctx_v; char temp_str[MAX_METADATA_STR]; - SNPRINTF(temp_str, "%s: %s", field, value); + BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: %s", field, value); BLF_position(ctx->fontid, ctx->xmin, ctx->ymin + ctx->current_y, 0.0f); - BLF_draw(ctx->fontid, temp_str, sizeof(temp_str)); + BLF_draw(ctx->fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); ctx->current_y += ctx->vertical_offset; } @@ -625,18 +625,18 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const /* first line */ if (i == 0) { bool do_newline = false; - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[0]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]); if (metadata_is_valid(ibuf, temp_str, 0, len)) { BLF_position(fontid, xmin, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); do_newline = true; } - len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[1]); + len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]); if (metadata_is_valid(ibuf, temp_str, 1, len)) { - int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); + int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); BLF_position(fontid, xmax - line_width, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); do_newline = true; } @@ -645,32 +645,32 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const } } /* Strip */ else if (ELEM(i, 1, 2)) { - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); ofs_y += vertical_offset; } } /* Note (wrapped) */ else if (i == 3) { - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { struct ResultBLF info; BLF_enable(fontid, BLF_WORD_WRAP); BLF_wordwrap(fontid, ibuf->x - (margin * 2)); BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw_ex(fontid, temp_str, sizeof(temp_str), &info); + BLF_draw_ex(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX, &info); BLF_wordwrap(fontid, 0); BLF_disable(fontid, BLF_WORD_WRAP); ofs_y += vertical_offset * info.lines; } } else { - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { - int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); + int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); BLF_position(fontid, xmax - line_width, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); ofs_y += vertical_offset; } } @@ -687,12 +687,12 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const int ofs_x = 0; ofs_y = ctx.current_y; for (int i = 5; i < 10; i++) { - int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); if (metadata_is_valid(ibuf, temp_str, i, len)) { BLF_position(fontid, xmin + ofs_x, ymin + ofs_y, 0.0f); - BLF_draw(fontid, temp_str, sizeof(temp_str)); + BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); - ofs_x += BLF_width(fontid, temp_str, sizeof(temp_str)) + UI_UNIT_X; + ofs_x += BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX) + UI_UNIT_X; } } } diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt index 47da6bc55f6..b7eaf018dba 100644 --- a/source/blender/freestyle/CMakeLists.txt +++ b/source/blender/freestyle/CMakeLists.txt @@ -594,7 +594,4 @@ if(WIN32) endif() blender_add_lib(bf_freestyle "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") - -if(COMMAND target_precompile_headers) - target_precompile_headers(bf_freestyle PRIVATE FRS_precomp.h) -endif() +blender_precompile_headers(bf_freestyle FRS_precomp.cpp FRS_precomp.h) diff --git a/source/blender/freestyle/FRS_precomp.cpp b/source/blender/freestyle/FRS_precomp.cpp new file mode 100644 index 00000000000..7e50a47f45b --- /dev/null +++ b/source/blender/freestyle/FRS_precomp.cpp @@ -0,0 +1,2 @@ +/* Pre-compiled headers, see: D2606. */ +#include "FRS_precomp.h" diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc index 058fb76af2b..0bbfbc8cb10 100644 --- a/source/blender/functions/intern/cpp_types.cc +++ b/source/blender/functions/intern/cpp_types.cc @@ -18,9 +18,8 @@ #include "FN_field_cpp_type.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" namespace blender::fn { diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 65d7631445d..c7481c6ea67 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -544,7 +544,7 @@ bool IMB_prepare_write_ImBuf(bool isfloat, struct ImBuf *ibuf); */ bool IMB_ispic(const char *filepath); bool IMB_ispic_type_matches(const char *filepath, int filetype); -int IMB_ispic_type_from_memory(const unsigned char *buf, size_t buf_size); +int IMB_ispic_type_from_memory(const unsigned char *buf, const size_t buf_size); int IMB_ispic_type(const char *filepath); /** @@ -972,20 +972,28 @@ void IMB_update_gpu_texture_sub(struct GPUTexture *tex, /** * \attention defined in stereoimbuf.c */ -void IMB_stereo3d_write_dimensions( - char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); -void IMB_stereo3d_read_dimensions( - char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); +void IMB_stereo3d_write_dimensions(char mode, + bool is_squeezed, + const size_t width, + const size_t height, + size_t *r_width, + size_t *r_height); +void IMB_stereo3d_read_dimensions(char mode, + bool is_squeezed, + const size_t width, + const size_t height, + size_t *r_width, + size_t *r_height); int *IMB_stereo3d_from_rect(struct ImageFormatData *im_format, - size_t x, - size_t y, - size_t channels, + const size_t x, + const size_t y, + const size_t channels, int *rect_left, int *rect_right); float *IMB_stereo3d_from_rectf(struct ImageFormatData *im_format, - size_t x, - size_t y, - size_t channels, + const size_t x, + const size_t y, + const size_t channels, float *rectf_left, float *rectf_right); /** diff --git a/source/blender/imbuf/IMB_metadata.h b/source/blender/imbuf/IMB_metadata.h index 50982d08c3e..652ce913ee5 100644 --- a/source/blender/imbuf/IMB_metadata.h +++ b/source/blender/imbuf/IMB_metadata.h @@ -58,7 +58,10 @@ void IMB_metadata_free(struct IDProperty *metadata); * \param len: length of value buffer allocated by user. * \return 1 (true) if metadata is present and value for the key found, 0 (false) otherwise. */ -bool IMB_metadata_get_field(struct IDProperty *metadata, const char *key, char *value, size_t len); +bool IMB_metadata_get_field(struct IDProperty *metadata, + const char *key, + char *value, + const size_t len); /** * Set user data in the metadata. diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h index bf6aef3ecd3..104458ffa7a 100644 --- a/source/blender/imbuf/intern/IMB_filetype.h +++ b/source/blender/imbuf/intern/IMB_filetype.h @@ -41,7 +41,7 @@ typedef struct ImFileType { * \note that this may only read in a small part of the files header, * see: #IMB_ispic_type for details. */ - bool (*is_a)(const unsigned char *buf, size_t size); + bool (*is_a)(const unsigned char *buf, const size_t size); /** Load an image from memory. */ struct ImBuf *(*load)(const unsigned char *mem, @@ -93,7 +93,7 @@ void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty); /** \name Format: PNG (#IMB_FTYPE_PNG) * \{ */ -bool imb_is_a_png(const unsigned char *mem, size_t size); +bool imb_is_a_png(const unsigned char *mem, const size_t size); struct ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, @@ -106,7 +106,7 @@ bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: TARGA (#IMB_FTYPE_TGA) * \{ */ -bool imb_is_a_targa(const unsigned char *buf, size_t size); +bool imb_is_a_targa(const unsigned char *buf, const size_t size); struct ImBuf *imb_loadtarga(const unsigned char *mem, size_t size, int flags, @@ -119,7 +119,7 @@ bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: IRIS (#IMB_FTYPE_IMAGIC) * \{ */ -bool imb_is_a_iris(const unsigned char *mem, size_t size); +bool imb_is_a_iris(const unsigned char *mem, const size_t size); /** * Read in a B/W RGB or RGBA iris image file and return an image buffer. */ @@ -135,7 +135,7 @@ bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JP2 (#IMB_FTYPE_JP2) * \{ */ -bool imb_is_a_jp2(const unsigned char *buf, size_t size); +bool imb_is_a_jp2(const unsigned char *buf, const size_t size); struct ImBuf *imb_load_jp2(const unsigned char *mem, size_t size, int flags, @@ -151,7 +151,7 @@ bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JPEG (#IMB_FTYPE_JPG) * \{ */ -bool imb_is_a_jpeg(const unsigned char *mem, size_t size); +bool imb_is_a_jpeg(const unsigned char *mem, const size_t size); bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags); struct ImBuf *imb_load_jpeg(const unsigned char *buffer, size_t size, @@ -164,7 +164,7 @@ struct ImBuf *imb_load_jpeg(const unsigned char *buffer, /** \name Format: BMP (#IMB_FTYPE_BMP) * \{ */ -bool imb_is_a_bmp(const unsigned char *buf, size_t size); +bool imb_is_a_bmp(const unsigned char *buf, const size_t size); struct ImBuf *imb_bmp_decode(const unsigned char *mem, size_t size, int flags, @@ -178,7 +178,7 @@ bool imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: CINEON (#IMB_FTYPE_CINEON) * \{ */ -bool imb_is_a_cineon(const unsigned char *buf, size_t size); +bool imb_is_a_cineon(const unsigned char *buf, const size_t size); bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_cineon(const unsigned char *mem, size_t size, @@ -191,7 +191,7 @@ struct ImBuf *imb_load_cineon(const unsigned char *mem, /** \name Format: DPX (#IMB_FTYPE_DPX) * \{ */ -bool imb_is_a_dpx(const unsigned char *buf, size_t size); +bool imb_is_a_dpx(const unsigned char *buf, const size_t size); bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_dpx(const unsigned char *mem, size_t size, @@ -204,7 +204,7 @@ struct ImBuf *imb_load_dpx(const unsigned char *mem, /** \name Format: HDR (#IMB_FTYPE_RADHDR) * \{ */ -bool imb_is_a_hdr(const unsigned char *buf, size_t size); +bool imb_is_a_hdr(const unsigned char *buf, const size_t size); struct ImBuf *imb_loadhdr(const unsigned char *mem, size_t size, int flags, @@ -218,7 +218,7 @@ bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags); * \{ */ void imb_inittiff(void); -bool imb_is_a_tiff(const unsigned char *buf, size_t size); +bool imb_is_a_tiff(const unsigned char *buf, const size_t size); /** * Loads a TIFF file. * \param mem: Memory containing the TIFF file. diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 6a05b681c88..1d81653c7cd 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -879,7 +879,7 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); # else - /* Scale with swscale. */ + /* Scale with swscale then flip image over Y axis. */ int *dstStride = anim->pFrameRGB->linesize; uint8_t **dst = anim->pFrameRGB->data; const int dstStride2[4] = {dstStride[0], 0, 0, 0}; @@ -896,12 +896,11 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); - /* Flip destination image buffer over Y axis. */ - bottom = (unsigned char *)dst[0]; - top = bottom + anim->x * (anim->y - 1) * 4; + bottom = (unsigned char *)ibuf->rect; + top = bottom + ibuf->x * (ibuf->y - 1) * 4; - h = (anim->y + 1) / 2; - w = anim->x; + h = (ibuf->y + 1) / 2; + w = ibuf->x; for (y = 0; y < h; y++) { unsigned char tmp[4]; diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index 2d540f13a52..931c4f267f9 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -26,7 +26,7 @@ extern "C" { #endif -bool imb_is_a_dds(const unsigned char *mem, size_t size); +bool imb_is_a_dds(const unsigned char *mem, const size_t size); bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_dds(const unsigned char *mem, size_t size, diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index 1201bd1b5e0..659050cdb00 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -31,7 +31,7 @@ extern "C" { struct ImBuf; -bool imb_is_a_photoshop(const unsigned char *mem, size_t size); +bool imb_is_a_photoshop(const unsigned char *mem, const size_t size); int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h index 4321c95db30..14336620926 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.h +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -36,7 +36,7 @@ void imb_exitopenexr(void); * Test presence of OpenEXR file. * \param mem: pointer to loaded OpenEXR bit-stream. */ -bool imb_is_a_openexr(const unsigned char *mem, size_t size); +bool imb_is_a_openexr(const unsigned char *mem, const size_t size); bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 925ef0a8502..7f4e4dd31df 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -77,7 +77,7 @@ static const unsigned char *oldreadcolrs(RGBE *scan, scan[0][BLU] = *mem++; scan[0][EXP] = *mem++; if (scan[0][RED] == 1 && scan[0][GRN] == 1 && scan[0][BLU] == 1) { - for (i = scan[0][EXP] << rshift; i > 0 && len > 0; i--) { + for (i = scan[0][EXP] << rshift; i > 0; i--) { COPY_RGBE(scan[-1], scan[0]); scan++; len--; @@ -227,7 +227,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, int found = 0; int width = 0, height = 0; const unsigned char *ptr, *mem_eof = mem + size; - char oriY[3], oriX[3]; + char oriY[80], oriX[80]; if (!imb_is_a_hdr(mem, size)) { return NULL; @@ -244,33 +244,22 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, } } - if ((found && (x < (size - 1))) == 0) { + if ((found && (x < (size + 2))) == 0) { /* Data not found! */ return NULL; } - x++; - - /* sscanf requires a null-terminated buffer argument */ - char buf[32] = {0}; - memcpy(buf, &mem[x], MIN2(sizeof(buf) - 1, size - x)); - - if (sscanf(buf, "%2s %d %2s %d", (char *)&oriY, &height, (char *)&oriX, &width) != 4) { - return NULL; - } - - if (width < 1 || height < 1) { + if (sscanf((const char *)&mem[x + 1], + "%79s %d %79s %d", + (char *)&oriY, + &height, + (char *)&oriX, + &width) != 4) { return NULL; } - /* Checking that width x height does not extend past mem_eof is not easily possible - * since the format uses RLE compression. Can cause excessive memory allocation to occur. */ - /* find end of this line, data right behind it */ - ptr = (const unsigned char *)strchr((const char *)&mem[x], '\n'); - if (ptr == NULL || ptr >= mem_eof) { - return NULL; - } + ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n'); ptr++; if (flags & IB_test) { diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc index 86fa580bf1f..4a359c49d26 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.cc +++ b/source/blender/io/alembic/intern/abc_reader_object.cc @@ -120,10 +120,29 @@ static Imath::M44d blend_matrices(const Imath::M44d &m0, const Imath::M44d &m1, * the matrices manually. */ - convert_matrix_datatype(m0, mat0); - convert_matrix_datatype(m1, mat1); + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + mat0[i][j] = static_cast(m0[i][j]); + } + } + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + mat1[i][j] = static_cast(m1[i][j]); + } + } + interp_m4_m4m4(ret, mat0, mat1, weight); - return convert_matrix_datatype(ret); + + Imath::M44d m; + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + m[i][j] = ret[i][j]; + } + } + + return m; } Imath::M44d get_matrix(const IXformSchema &schema, const float time) diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc index f031648d2ed..7868bade8c1 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc @@ -23,9 +23,8 @@ * \ingroup bgpencil */ -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_span.hh" @@ -283,7 +282,7 @@ float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, bGPDstroke *gps) const float2 screen_ex = gpencil_3D_point_to_2D(&pt->x); const float2 v1 = screen_co - screen_ex; - float radius = v1.length(); + float radius = math::length(v1); BKE_gpencil_free_stroke(gps_perimeter); return MAX2(radius, 1.0f); diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.hh b/source/blender/io/gpencil/intern/gpencil_io_base.hh index 09557cd7a4d..ae54d5056dc 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.hh +++ b/source/blender/io/gpencil/intern/gpencil_io_base.hh @@ -22,9 +22,8 @@ * \ingroup bgpencil */ -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "DNA_space_types.h" /* for FILE_MAX */ diff --git a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc index 941d1137f4d..455ebb7c3cb 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc @@ -21,8 +21,8 @@ * \ingroup bgpencil */ -#include "BLI_float3.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_gpencil_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh index 9a4dfe3efe3..e6d2853d040 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh @@ -22,7 +22,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utility_mixins.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index b99d41e0c72..5b710939e00 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -21,8 +21,8 @@ #include "BKE_image.h" #include "BKE_node.h" -#include "BLI_float3.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "DNA_material_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh index 2f62d189bd1..a84dcb80a48 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh @@ -20,8 +20,8 @@ #pragma once -#include "BLI_float3.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc index 91aabd8fa76..ec690115115 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc @@ -18,9 +18,9 @@ * \ingroup obj */ -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index f9151bb97f8..0feca806f35 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -236,7 +236,7 @@ TEST(obj_exporter_writer, mtllib) static bool strings_equal_after_first_lines(const std::string &a, const std::string &b) { /* If `dbg_level > 0` then a failing test will print context around the first mismatch. */ - const int dbg_level = 0; + const bool dbg_level = 0; const size_t a_len = a.size(); const size_t b_len = b.size(); const size_t a_next = a.find_first_of('\n'); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 1d0796bda8b..fc041e257b0 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1852,7 +1852,6 @@ enum { MOD_TRIANGULATE_QUAD_FIXED = 1, MOD_TRIANGULATE_QUAD_ALTERNATE = 2, MOD_TRIANGULATE_QUAD_SHORTEDGE = 3, - MOD_TRIANGULATE_QUAD_LONGEDGE = 4, }; typedef struct LaplacianSmoothModifierData { diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 114e350b582..29d61bcf2ff 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -2118,7 +2118,6 @@ typedef enum GeometryNodeTriangulateQuads { GEO_NODE_TRIANGULATE_QUAD_FIXED = 1, GEO_NODE_TRIANGULATE_QUAD_ALTERNATE = 2, GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE = 3, - GEO_NODE_TRIANGULATE_QUAD_LONGEDGE = 4, } GeometryNodeTriangulateQuads; typedef enum GeometryNodePointInstanceType { diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index b32d98e3cb1..77c0db81b37 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -1743,7 +1743,7 @@ bool RNA_struct_override_matches(struct Main *bmain, struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, const char *root_path, - size_t root_path_len, + const size_t root_path_len, struct IDOverrideLibrary *override, eRNAOverrideMatch flags, eRNAOverrideMatchResult *r_report_flags); diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 95ad184c6b9..20e6e931b4b 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -544,7 +544,7 @@ int rna_property_override_diff_default(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - size_t rna_path_len, + const size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 723ae384fdf..f0e32a19d04 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -214,7 +214,7 @@ typedef int (*RNAPropOverrideDiff)(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - size_t rna_path_len, + const size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 0f0734c8448..d46ae13b482 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -331,12 +331,7 @@ const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[] = { "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads along their shortest diagonal"}, - {MOD_TRIANGULATE_QUAD_LONGEDGE, - "LONGEST_DIAGONAL", - 0, - "Longest Diagonal", - "Split the quads along their longest diagonal"}, + "Split the quads based on the distance between the vertices"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index ecbeadf1fa4..e7307e6e058 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -9488,12 +9488,7 @@ static void def_geo_triangulate(StructRNA *srna) "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads along their shortest diagonal"}, - {GEO_NODE_TRIANGULATE_QUAD_LONGEDGE, - "LONGEST_DIAGONAL", - 0, - "Longest Diagonal", - "Split the quads along their longest diagonal"}, + "Split the quads based on the distance between the vertices"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc index 778b5746471..910b52dea67 100644 --- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc +++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc @@ -197,8 +197,8 @@ static float compute_voxel_size(const ModifierEvalContext *ctx, /* Compute the voxel size based on the desired number of voxels and the approximated bounding box * of the volume. */ const BoundBox *bb = BKE_object_boundbox_get(mvmd->object); - const float diagonal = float3::distance(transform * float3(bb->vec[6]), - transform * float3(bb->vec[0])); + const float diagonal = math::distance(transform * float3(bb->vec[6]), + transform * float3(bb->vec[0])); const float approximate_volume_side_length = diagonal + mvmd->exterior_band_width * 2.0f; const float voxel_size = approximate_volume_side_length / mvmd->voxel_amount / volume_simplify; return voxel_size; diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index cee5d0be65d..49528845197 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -28,8 +28,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_multi_value_map.hh" #include "BLI_set.hh" #include "BLI_string.h" diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh index a0a2e6f81f8..6ea89beee2e 100644 --- a/source/blender/nodes/NOD_math_functions.hh +++ b/source/blender/nodes/NOD_math_functions.hh @@ -18,9 +18,9 @@ #include "DNA_node_types.h" -#include "BLI_float3.hh" #include "BLI_math_base_safe.h" #include "BLI_math_rotation.h" +#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" namespace blender::nodes { @@ -240,6 +240,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -259,40 +261,21 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation case NODE_VECTOR_MATH_MULTIPLY: return dispatch([](float3 a, float3 b) { return a * b; }); case NODE_VECTOR_MATH_DIVIDE: - return dispatch([](float3 a, float3 b) { - return float3(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return safe_divide(a, b); }); case NODE_VECTOR_MATH_CROSS_PRODUCT: - return dispatch([](float3 a, float3 b) { return float3::cross_high_precision(a, b); }); + return dispatch([](float3 a, float3 b) { return cross_high_precision(a, b); }); case NODE_VECTOR_MATH_PROJECT: - return dispatch([](float3 a, float3 b) { - float length_squared = b.length_squared(); - return (length_squared != 0.0) ? (float3::dot(a, b) / length_squared) * b : float3(0.0f); - }); + return dispatch([](float3 a, float3 b) { return project(a, b); }); case NODE_VECTOR_MATH_REFLECT: - return dispatch([](float3 a, float3 b) { - b.normalize(); - return a.reflected(b); - }); + return dispatch([](float3 a, float3 b) { return reflect(a, normalize(b)); }); case NODE_VECTOR_MATH_SNAP: - return dispatch([](float3 a, float3 b) { - return float3(floor(safe_divide(a.x, b.x)), - floor(safe_divide(a.y, b.y)), - floor(safe_divide(a.z, b.z))) * - b; - }); + return dispatch([](float3 a, float3 b) { return floor(safe_divide(a, b)) * b; }); case NODE_VECTOR_MATH_MODULO: - return dispatch([](float3 a, float3 b) { - return float3(safe_modf(a.x, b.x), safe_modf(a.y, b.y), safe_modf(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return mod(a, b); }); case NODE_VECTOR_MATH_MINIMUM: - return dispatch([](float3 a, float3 b) { - return float3(min_ff(a.x, b.x), min_ff(a.y, b.y), min_ff(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return min(a, b); }); case NODE_VECTOR_MATH_MAXIMUM: - return dispatch([](float3 a, float3 b) { - return float3(max_ff(a.x, b.x), max_ff(a.y, b.y), max_ff(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return max(a, b); }); default: return false; } @@ -306,6 +289,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -319,9 +304,9 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation switch (operation) { case NODE_VECTOR_MATH_DOT_PRODUCT: - return dispatch([](float3 a, float3 b) { return float3::dot(a, b); }); + return dispatch([](float3 a, float3 b) { return dot(a, b); }); case NODE_VECTOR_MATH_DISTANCE: - return dispatch([](float3 a, float3 b) { return float3::distance(a, b); }); + return dispatch([](float3 a, float3 b) { return distance(a, b); }); default: return false; } @@ -335,6 +320,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -354,7 +341,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOpera return float3(wrapf(a.x, b.x, c.x), wrapf(a.y, b.y, c.y), wrapf(a.z, b.z, c.z)); }); case NODE_VECTOR_MATH_FACEFORWARD: - return dispatch([](float3 a, float3 b, float3 c) { return float3::faceforward(a, b, c); }); + return dispatch([](float3 a, float3 b, float3 c) { return faceforward(a, b, c); }); default: return false; } @@ -368,6 +355,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -381,8 +370,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperat switch (operation) { case NODE_VECTOR_MATH_REFRACT: - return dispatch( - [](float3 a, float3 b, float c) { return float3::refract(a, b.normalized(), c); }); + return dispatch([](float3 a, float3 b, float c) { return refract(a, normalize(b), c); }); default: return false; } @@ -396,6 +384,8 @@ template inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -409,7 +399,7 @@ inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation oper switch (operation) { case NODE_VECTOR_MATH_LENGTH: - return dispatch([](float3 in) { return in.length(); }); + return dispatch([](float3 in) { return length(in); }); default: return false; } @@ -450,6 +440,8 @@ template inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -463,20 +455,15 @@ inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation ope switch (operation) { case NODE_VECTOR_MATH_NORMALIZE: - return dispatch([](float3 in) { - float3 out = in; - out.normalize(); - return out; - }); /* Should be safe. */ + return dispatch([](float3 in) { return normalize(in); }); /* Should be safe. */ case NODE_VECTOR_MATH_FLOOR: - return dispatch([](float3 in) { return float3(floor(in.x), floor(in.y), floor(in.z)); }); + return dispatch([](float3 in) { return floor(in); }); case NODE_VECTOR_MATH_CEIL: - return dispatch([](float3 in) { return float3(ceil(in.x), ceil(in.y), ceil(in.z)); }); + return dispatch([](float3 in) { return ceil(in); }); case NODE_VECTOR_MATH_FRACTION: - return dispatch( - [](float3 in) { return in - float3(floor(in.x), floor(in.y), floor(in.z)); }); + return dispatch([](float3 in) { return fract(in); }); case NODE_VECTOR_MATH_ABSOLUTE: - return dispatch([](float3 in) { return float3::abs(in); }); + return dispatch([](float3 in) { return abs(in); }); case NODE_VECTOR_MATH_SINE: return dispatch([](float3 in) { return float3(sinf(in.x), sinf(in.y), sinf(in.z)); }); case NODE_VECTOR_MATH_COSINE: diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh index c0580a2c919..a1972c66ca2 100644 --- a/source/blender/nodes/NOD_socket_declarations.hh +++ b/source/blender/nodes/NOD_socket_declarations.hh @@ -21,7 +21,7 @@ #include "RNA_types.h" #include "BLI_color.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" namespace blender::nodes::decl { diff --git a/source/blender/nodes/composite/node_composite_tree.cc b/source/blender/nodes/composite/node_composite_tree.cc index c54382cc1ad..08dbd4ad6f0 100644 --- a/source/blender/nodes/composite/node_composite_tree.cc +++ b/source/blender/nodes/composite/node_composite_tree.cc @@ -249,6 +249,23 @@ void ntreeCompositUpdateRLayers(bNodeTree *ntree) } } +void ntreeCompositRegisterPass(bNodeTree *ntree, + Scene *scene, + ViewLayer *view_layer, + const char *name, + eNodeSocketDatatype type) +{ + if (ntree == nullptr) { + return; + } + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type == CMP_NODE_R_LAYERS) { + node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type); + } + } +} + void ntreeCompositTagRender(Scene *scene) { /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes, diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index f2b9fbc2215..6f4f9d7e597 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -269,12 +269,7 @@ void node_cmp_rlayers_register_pass(bNodeTree *ntree, } } -struct CreateOutputUserData { - bNodeTree &ntree; - bNode &node; -}; - -static void cmp_node_rlayer_create_outputs_cb(void *userdata, +static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), Scene *scene, ViewLayer *view_layer, const char *name, @@ -282,8 +277,18 @@ static void cmp_node_rlayer_create_outputs_cb(void *userdata, const char *UNUSED(chanid), eNodeSocketDatatype type) { - CreateOutputUserData &data = *(CreateOutputUserData *)userdata; - node_cmp_rlayers_register_pass(&data.ntree, &data.node, scene, view_layer, name, type); + /* Register the pass in all scenes that have a render layer node for this layer. + * Since multiple scenes can be used in the compositor, the code must loop over all scenes + * and check whether their nodetree has a node that needs to be updated. */ + /* NOTE: using G_MAIN seems valid here, + * unless we want to register that for every other temp Main we could generate??? */ + ntreeCompositRegisterPass(scene->nodetree, scene, view_layer, name, type); + + for (Scene *sce = (Scene *)G_MAIN->scenes.first; sce; sce = (Scene *)sce->id.next) { + if (sce->nodetree && sce != scene) { + ntreeCompositRegisterPass(sce->nodetree, scene, view_layer, name, type); + } + } } static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, @@ -303,17 +308,14 @@ static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, data->prev_index = -1; node->storage = data; - CreateOutputUserData userdata = {*ntree, *node}; - RenderEngine *engine = RE_engine_create(engine_type); RE_engine_update_render_passes( - engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, &userdata); + engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, nullptr); RE_engine_free(engine); if ((scene->r.mode & R_EDGE_FRS) && (view_layer->freestyle_config.flags & FREESTYLE_AS_RENDER_PASS)) { - node_cmp_rlayers_register_pass( - ntree, node, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); + ntreeCompositRegisterPass(ntree, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); } MEM_freeN(data); diff --git a/source/blender/nodes/function/node_function_util.hh b/source/blender/nodes/function/node_function_util.hh index acde9c4b55b..69c617b4f01 100644 --- a/source/blender/nodes/function/node_function_util.hh +++ b/source/blender/nodes/function/node_function_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc index f4ce8d2f35a..bcc035e6ede 100644 --- a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc +++ b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc @@ -69,14 +69,14 @@ static void align_rotations_auto_pivot(IndexMask mask, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = vector.normalized(); - float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); + const float3 new_axis = math::normalize(vector); + float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc index 3bb46511eeb..7c09bace756 100644 --- a/source/blender/nodes/function/nodes/node_fn_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_compare.cc @@ -265,7 +265,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Than - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) < comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) < comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -283,7 +283,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Than - Length", - [](float3 a, float3 b) { return a.length() < b.length(); }}; + [](float3 a, float3 b) { return math::length(a) < math::length(b); }}; return &fn; } } @@ -299,7 +299,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Equal - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) <= comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) <= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -317,7 +317,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Equal - Length", - [](float3 a, float3 b) { return a.length() <= b.length(); }}; + [](float3 a, float3 b) { return math::length(a) <= math::length(b); }}; return &fn; } } @@ -333,7 +333,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Than - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) > comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) > comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -351,7 +351,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Than - Length", - [](float3 a, float3 b) { return a.length() > b.length(); }}; + [](float3 a, float3 b) { return math::length(a) > math::length(b); }}; return &fn; } } @@ -367,7 +367,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Equal - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) >= comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) >= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -385,7 +385,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Equal - Length", - [](float3 a, float3 b) { return a.length() >= b.length(); }}; + [](float3 a, float3 b) { return math::length(a) >= math::length(b); }}; return &fn; } } @@ -402,7 +402,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(float3::dot(a, b) - comp) <= epsilon; + return abs(math::dot(a, b) - comp) <= epsilon; }}; return &fn; } @@ -424,7 +424,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(a.length() - b.length()) <= epsilon; + return abs(math::length(a) - math::length(b)) <= epsilon; }}; return &fn; } @@ -442,7 +442,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Not Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(float3::dot(a, b) - comp) >= epsilon; + return abs(math::dot(a, b) - comp) >= epsilon; }}; return &fn; } @@ -464,7 +464,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Not Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(a.length() - b.length()) > epsilon; + return abs(math::length(a) - math::length(b)) > epsilon; }}; return &fn; } diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh index 1c2a8f521c0..e063be62987 100644 --- a/source/blender/nodes/geometry/node_geometry_util.hh +++ b/source/blender/nodes/geometry/node_geometry_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" @@ -83,7 +83,7 @@ Mesh *create_cylinder_or_cone_mesh(float radius_top, int circle_segments, int side_segments, int fill_segments, - GeometryNodeMeshCircleFillType fill_type, + const GeometryNodeMeshCircleFillType fill_type, ConeAttributeOutputs &attribute_outputs); Mesh *create_cuboid_mesh(float3 size, int verts_x, int verts_y, int verts_z); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc index 36ad4605a4b..1d064586238 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc @@ -90,14 +90,14 @@ static void align_rotations_auto_pivot(const VArray &vectors, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = vector.normalized(); - float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); + const float3 new_axis = math::normalize(vector); + float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc index 74dac73f255..20f500b1bd8 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc @@ -81,7 +81,7 @@ static void calculate_mesh_proximity(const VArray &positions, for (int i : range) { /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = float3::distance_squared(nearest.co, positions[i]); + nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[i]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[i], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc index b0210f2eb94..a85a7c56cb9 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc @@ -229,7 +229,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = float3::distance_squared(position, mvert.co); + const float distance_sq = math::distance_squared(position, float3(mvert.co)); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc index 8555d7cc8a3..1e6b7f92a77 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc @@ -241,13 +241,13 @@ static void copy_uniform_sample_point_attributes(Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent.normalize(); + tangent = math::normalize(tangent); } spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals.normalize(); + normals = math::normalize(normals); } } }); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc index 29eff373d15..c712e82ca18 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc @@ -321,7 +321,7 @@ BLI_NOINLINE static void interpolate_existing_attributes( continue; } - for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { + for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { const int offset = instance_start_offsets[i_instance]; Span bary_coords = bary_coords_array[i_instance]; Span looptri_indices = looptri_indices_array[i_instance]; @@ -516,7 +516,7 @@ static void distribute_points_poisson_disk(Span set_group const VArray density_factors = component.attribute_get_for_read( density_attribute_name, ATTR_DOMAIN_CORNER, use_one_default ? 1.0f : 0.0f); - for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { + for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { Vector &positions = positions_all[i_instance]; Vector &bary_coords = bary_coords_all[i_instance]; Vector &looptri_indices = looptri_indices_all[i_instance]; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc index 7b1bbed8ae4..f54ffc53a6e 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc @@ -161,7 +161,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = float3::distance(min, max); + const float diagonal = math::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc index dd03092a594..cfae88e0625 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc @@ -107,7 +107,7 @@ static void raycast_to_mesh(const Mesh &mesh, for (const int i : ray_origins.index_range()) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = ray_directions[i].normalized(); + const float3 ray_direction = math::normalize(ray_directions[i]); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc index 7e09721273a..929d9046f98 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc @@ -16,7 +16,7 @@ #include "BLI_array.hh" #include "BLI_delaunay_2d.h" -#include "BLI_double2.hh" +#include "BLI_math_vec_types.hh" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc index 1a44fce86a6..68b609f8045 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc @@ -122,9 +122,9 @@ static Array calculate_directions(const Span positions) Array directions(size); for (const int i : IndexRange(size - 1)) { - directions[i] = (positions[i + 1] - positions[i]).normalized(); + directions[i] = math::normalize(positions[i + 1] - positions[i]); } - directions[size - 1] = (positions[0] - positions[size - 1]).normalized(); + directions[size - 1] = math::normalize(positions[0] - positions[size - 1]); return directions; } @@ -135,9 +135,9 @@ static Array calculate_axes(const Span directions) const int size = directions.size(); Array axes(size); - axes[0] = float3::cross(-directions[size - 1], directions[0]).normalized(); + axes[0] = math::normalize(math::cross(-directions[size - 1], directions[0])); for (const int i : IndexRange(1, size - 1)) { - axes[i] = float3::cross(-directions[i - 1], directions[i]).normalized(); + axes[i] = math::normalize(math::cross(-directions[i - 1], directions[i])); } return axes; @@ -248,8 +248,8 @@ static void limit_radii(FilletData &fd, const bool cyclic) if (cyclic) { /* Calculate lengths between adjacent control points. */ - const float len_prev = float3::distance(positions[0], positions[size - 1]); - const float len_next = float3::distance(positions[0], positions[1]); + const float len_prev = math::distance(positions[0], positions[size - 1]); + const float len_next = math::distance(positions[0], positions[1]); /* Calculate tangent lengths of fillets in control points. */ const float tan_len = radii[0] * tan(angles[0] / 2.0f); @@ -271,16 +271,16 @@ static void limit_radii(FilletData &fd, const bool cyclic) } /* Initialize max_radii to largest possible radii. */ - float prev_dist = float3::distance(positions[1], positions[0]); + float prev_dist = math::distance(positions[1], positions[0]); for (const int i : IndexRange(1, size - 2)) { - const float temp_dist = float3::distance(positions[i], positions[i + 1]); + const float temp_dist = math::distance(positions[i], positions[i + 1]); max_radii[i] = std::min(prev_dist, temp_dist) / tan(angles[i] / 2.0f); prev_dist = temp_dist; } /* Max radii calculations for each index. */ for (const int i : IndexRange(start, fillet_count - 1)) { - const float len_next = float3::distance(positions[i], positions[i + 1]); + const float len_next = math::distance(positions[i], positions[i + 1]); const float tan_len = radii[i] * tan(angles[i] / 2.0f); const float tan_len_next = radii[i + 1] * tan(angles[i + 1] / 2.0f); @@ -415,7 +415,8 @@ static void update_bezier_positions(const FilletData &fd, const float3 center = get_center(dst_spline.positions()[i_dst] - positions[i_src], fd, i_src); /* Calculate the vector of the radius formed by the first vertex. */ float3 radius_vec = dst_spline.positions()[i_dst] - center; - const float radius = radius_vec.normalize_and_get_length(); + float radius; + radius_vec = math::normalize_and_get_length(radius_vec, radius); dst_spline.handle_types_right().slice(1, count - 2).fill(BezierSpline::HandleType::Align); dst_spline.handle_types_left().slice(1, count - 2).fill(BezierSpline::HandleType::Align); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc index a7fb493c7d7..7b5d1a1dc80 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc @@ -101,8 +101,8 @@ static void node_update(bNodeTree *ntree, bNode *node) static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3) { - const float3 a = (p2 - p1).normalized(); - const float3 b = (p3 - p1).normalized(); + const float3 a = math::normalize(p2 - p1); + const float3 b = math::normalize(p3 - p1); return (ELEM(a, b, b * -1.0f)); } @@ -122,18 +122,18 @@ static std::unique_ptr create_point_circle_curve( float3 center; /* Midpoints of `P1->P2` and `P2->P3`. */ - const float3 q1 = float3::interpolate(p1, p2, 0.5f); - const float3 q2 = float3::interpolate(p2, p3, 0.5f); + const float3 q1 = math::interpolate(p1, p2, 0.5f); + const float3 q2 = math::interpolate(p2, p3, 0.5f); /* Normal Vectors of `P1->P2` and `P2->P3` */ - const float3 v1 = (p2 - p1).normalized(); - const float3 v2 = (p3 - p2).normalized(); + const float3 v1 = math::normalize(p2 - p1); + const float3 v2 = math::normalize(p3 - p2); /* Normal of plane of main 2 segments P1->P2 and `P2->P3`. */ - const float3 v3 = float3::cross(v1, v2).normalized(); + const float3 v3 = math::normalize(math::cross(v1, v2)); /* Normal of plane of first perpendicular bisector and `P1->P2`. */ - const float3 v4 = float3::cross(v3, v1).normalized(); + const float3 v4 = math::normalize(math::cross(v3, v1)); /* Determine Center-point from the intersection of 3 planes. */ float plane_1[4], plane_2[4], plane_3[4]; @@ -148,7 +148,7 @@ static std::unique_ptr create_point_circle_curve( } /* Get the radius from the center-point to p1. */ - const float r = float3::distance(p1, center); + const float r = math::distance(p1, center); const float theta_step = ((2 * M_PI) / (float)resolution); for (const int i : IndexRange(resolution)) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc index ff9218b1ac2..d35fa0a2fdc 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc @@ -100,7 +100,7 @@ static std::unique_ptr create_direction_line_curve(const float3 start spline->resize(2); MutableSpan positions = spline->positions(); positions[0] = start; - positions[1] = direction.normalized() * length + start; + positions[1] = math::normalize(direction) * length + start; spline->radii().fill(1.0f); spline->tilts().fill(0.0f); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc index 084d27e9d24..885d92a111b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc @@ -58,9 +58,9 @@ static std::unique_ptr create_quadratic_bezier_curve(const float3 p1, const float step = 1.0f / resolution; for (const int i : IndexRange(resolution + 1)) { const float factor = step * i; - const float3 q1 = float3::interpolate(p1, p2, factor); - const float3 q2 = float3::interpolate(p2, p3, factor); - positions[i] = float3::interpolate(q1, q2, factor); + const float3 q1 = math::interpolate(p1, p2, factor); + const float3 q2 = math::interpolate(p2, p3, factor); + positions[i] = math::interpolate(q1, q2, factor); } curve->add_spline(std::move(spline)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc index 038f7625825..56fbc50f033 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc @@ -185,7 +185,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_tangents = splines[spline_indices[i]]->evaluated_tangents(); - sampled_tangents[i] = sample_with_lookup(lookup, evaluated_tangents).normalized(); + sampled_tangents[i] = math::normalize(sample_with_lookup(lookup, evaluated_tangents)); } } @@ -193,7 +193,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_normals = splines[spline_indices[i]]->evaluated_normals(); - sampled_normals[i] = sample_with_lookup(lookup, evaluated_normals).normalized(); + sampled_normals[i] = math::normalize(sample_with_lookup(lookup, evaluated_normals)); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc index 40dde645756..257a5b8df00 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc @@ -96,7 +96,7 @@ static void calculate_nurbs_lengths(const NURBSpline &spline, MutableSpan float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { lengths[i] = length; - length += float3::distance(positions[i], positions[i + 1]); + length += math::distance(positions[i], positions[i + 1]); } lengths.last() = length; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc index a8553b636a4..19efd4b7508 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc @@ -285,7 +285,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent.normalize(); + tangent = math::normalize(tangent); } } @@ -293,7 +293,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals.normalize(); + normals = math::normalize(normals); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc index 28a8fb80294..624a8b6b0f6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc @@ -21,7 +21,7 @@ #include "BKE_image.h" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_threads.h" #include "BLI_timeit.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc index 5b67258a947..e90a9eb393b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc @@ -155,7 +155,7 @@ static void calculate_polys(const CuboidConfig &config, /* Calculate polys for Bottom faces. */ int vert_1_start = 0; - for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { + for (const int UNUSED(y) : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { const int vert_1 = vert_1_start + x; const int vert_2 = vert_1_start + config.verts_x + x; @@ -173,7 +173,7 @@ static void calculate_polys(const CuboidConfig &config, vert_1_start = 0; int vert_2_start = config.verts_x * config.verts_y; - for ([[maybe_unused]] const int z : IndexRange(config.edges_z)) { + for (const int UNUSED(z) : IndexRange(config.edges_z)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, @@ -196,7 +196,7 @@ static void calculate_polys(const CuboidConfig &config, (config.verts_x - 2) * (config.verts_y - 2)); vert_2_start = vert_1_start + config.verts_x; - for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { + for (const int UNUSED(y) : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc index 5116e78fdda..8a2b054ece0 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc @@ -155,8 +155,8 @@ static void node_geo_exec(GeoNodeExecParams params) if (count_mode == GEO_NODE_MESH_LINE_COUNT_RESOLUTION) { /* Don't allow asymptotic count increase for low resolution values. */ const float resolution = std::max(params.extract_input("Resolution"), 0.0001f); - const int count = total_delta.length() / resolution + 1; - const float3 delta = total_delta.normalized() * resolution; + const int count = math::length(total_delta) / resolution + 1; + const float3 delta = math::normalize(total_delta) * resolution; mesh = create_line_mesh(start, delta, count); } else if (count_mode == GEO_NODE_MESH_LINE_COUNT_TOTAL) { @@ -204,7 +204,7 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count) MutableSpan edges{mesh->medge, mesh->totedge}; short normal[3]; - normal_float_to_short_v3(normal, delta.normalized()); + normal_float_to_short_v3(normal, math::normalize(delta)); for (const int i : verts.index_range()) { copy_v3_v3(verts[i].co, start + delta * i); diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc index 41178d5c4e6..373e6bfdd18 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc @@ -178,7 +178,7 @@ static void calculate_sphere_faces(MutableSpan loops, int ring_vert_index_start = 1; int ring_edge_index_start = segments; - for ([[maybe_unused]] const int ring : IndexRange(1, rings - 2)) { + for (const int UNUSED(ring) : IndexRange(1, rings - 2)) { const int next_ring_vert_index_start = ring_vert_index_start + segments; const int next_ring_edge_index_start = ring_edge_index_start + segments * 2; const int ring_vertical_edge_index_start = ring_edge_index_start + segments; diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc index dda4543d5e1..c165bcf8e35 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc @@ -166,7 +166,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = float3::distance(min, max); + const float diagonal = math::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc index e0117c4726d..772638ef240 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc @@ -85,7 +85,7 @@ static bool calculate_mesh_proximity(const VArray &positions, for (int i : range) { const int index = mask[i]; /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = float3::distance_squared(nearest.co, positions[index]); + nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[index]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[index], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc index 2c35ca0afc9..c38503f688c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc @@ -163,7 +163,7 @@ static void raycast_to_mesh(IndexMask mask, for (const int i : mask) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = ray_directions[i].normalized(); + const float3 ray_direction = math::normalize(ray_directions[i]); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc index 82d09bbc208..feab0a6743f 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc @@ -106,7 +106,7 @@ static void set_position_in_component(const GeometryNodeCurveHandleMode mode, } } else { - for ([[maybe_unused]] int i : spline->positions().index_range()) { + for (int UNUSED(i) : spline->positions().index_range()) { if (current_mask < selection.size() && selection[current_mask] == current_point) { current_mask++; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc index 331460296a6..6867051ecfe 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc @@ -296,7 +296,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = float3::distance_squared(position, mvert.co); + const float distance_sq = math::distance_squared(position, float3(mvert.co)); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc index 7f866ea6f4a..6187a2eacf9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc @@ -37,7 +37,7 @@ namespace blender::nodes { static bool use_translate(const float3 rotation, const float3 scale) { - if (compare_ff(rotation.length_squared(), 0.0f, 1e-9f) != 1) { + if (compare_ff(math::length_squared(rotation), 0.0f, 1e-9f) != 1) { return false; } if (compare_ff(scale.x, 1.0f, 1e-9f) != 1 || compare_ff(scale.y, 1.0f, 1e-9f) != 1 || @@ -49,7 +49,7 @@ static bool use_translate(const float3 rotation, const float3 scale) static void translate_mesh(Mesh &mesh, const float3 translation) { - if (!translation.is_zero()) { + if (!math::is_zero(translation)) { BKE_mesh_translate(&mesh, translation, false); } } diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc index 6a6b6e3d3cc..ed72580ccf1 100644 --- a/source/blender/nodes/intern/node_socket.cc +++ b/source/blender/nodes/intern/node_socket.cc @@ -26,8 +26,8 @@ #include "DNA_node_types.h" #include "BLI_color.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/node_shader_util.hh b/source/blender/nodes/shader/node_shader_util.hh index 9d4d57d01dd..5a5b4f613f3 100644 --- a/source/blender/nodes/shader/node_shader_util.hh +++ b/source/blender/nodes/shader/node_shader_util.hh @@ -29,9 +29,9 @@ #include "BLI_blenlib.h" #include "BLI_color.hh" -#include "BLI_float3.hh" #include "BLI_math.h" #include "BLI_math_base_safe.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_threads.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc index 3276a1bfd72..bc7ca661a77 100644 --- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc +++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc @@ -272,7 +272,7 @@ class MapRangeVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -315,8 +315,8 @@ class MapRangeSteppedVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(6, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); - factor = float3::safe_divide(float3::floor(factor * (steps[i] + 1.0f)), steps[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + factor = math::safe_divide(math::floor(factor * (steps[i] + 1.0f)), steps[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -355,7 +355,7 @@ class MapRangeSmoothstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = (float3(3.0f) - 2.0f * factor) * (factor * factor); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; @@ -390,7 +390,7 @@ class MapRangeSmootherstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc index 61b1613c11a..81a69ef18da 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc @@ -19,8 +19,7 @@ #include "node_shader_util.hh" -#include "BLI_float2.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc index 85e0f262ca7..53be5bc09d9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc @@ -130,7 +130,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - const float r = std::max(0.999999f - vector[i].length(), 0.0f); + const float r = std::max(0.999999f - math::length(vector[i]), 0.0f); fac[i] = r * r; } break; @@ -140,7 +140,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - fac[i] = std::max(0.999999f - vector[i].length(), 0.0f); + fac[i] = std::max(0.999999f - math::length(vector[i]), 0.0f); } break; } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc index 0e549859a39..1c703313edf 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc @@ -176,14 +176,14 @@ class NoiseFunction : public fn::MultiFunction { const VArray &vector = params.readonly_single_input(0, "Vector"); if (compute_factor) { for (int64_t i : mask) { - const float2 position = vector[i] * scale[i]; + const float2 position = float2(vector[i] * scale[i]); r_factor[i] = noise::perlin_fractal_distorted( position, detail[i], roughness[i], distortion[i]); } } if (compute_color) { for (int64_t i : mask) { - const float2 position = vector[i] * scale[i]; + const float2 position = float2(vector[i] * scale[i]); const float3 c = noise::perlin_float3_fractal_distorted( position, detail[i], roughness[i], distortion[i]); r_color[i] = ColorGeometry4f(c[0], c[1], c[2], 1.0f); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc index 2b5c1ddfe21..209f96449cd 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc @@ -313,7 +313,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -345,7 +345,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -380,7 +380,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -416,7 +416,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -446,7 +446,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -479,7 +479,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -519,7 +519,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -560,7 +560,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -604,7 +604,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -837,7 +837,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -868,7 +868,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -902,7 +902,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -937,7 +937,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -966,7 +966,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -999,7 +999,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } } @@ -1040,7 +1040,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1080,7 +1080,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1123,7 +1123,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index f08665d75e7..604792389fa 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -57,20 +57,20 @@ void PyC_Err_PrintWithFunc(PyObject *py_func); void PyC_FileAndNum(const char **r_filename, int *r_lineno); void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno); /* checks python is running */ int PyC_AsArray_FAST(void *array, - size_t array_item_size, + const size_t array_item_size, PyObject *value_fast, - Py_ssize_t length, + const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray(void *array, - size_t array_item_size, + const size_t array_item_size, PyObject *value, - Py_ssize_t length, + const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray_Multi_FAST(void *array, - size_t array_item_size, + const size_t array_item_size, PyObject *value_fast, const int *dims, int dims_len, @@ -78,7 +78,7 @@ int PyC_AsArray_Multi_FAST(void *array, const char *error_prefix); int PyC_AsArray_Multi(void *array, - size_t array_item_size, + const size_t array_item_size, PyObject *value, const int *dims, int dims_len, diff --git a/source/blender/render/RE_bake.h b/source/blender/render/RE_bake.h index b7ce3da71ff..43d3b5b323c 100644 --- a/source/blender/render/RE_bake.h +++ b/source/blender/render/RE_bake.h @@ -96,7 +96,7 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, BakePixel pixel_array_to[], BakeHighPolyData highpoly[], int tot_highpoly, - size_t num_pixels, + const size_t num_pixels, bool is_custom_cage, float cage_extrusion, float max_ray_distance, @@ -106,16 +106,16 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, void RE_bake_pixels_populate(struct Mesh *me, struct BakePixel *pixel_array, - size_t num_pixels, + const size_t num_pixels, const struct BakeTargets *targets, const char *uv_layer); -void RE_bake_mask_fill(const BakePixel pixel_array[], size_t num_pixels, char *mask); +void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask); void RE_bake_margin(struct ImBuf *ibuf, char *mask, int margin); void RE_bake_normal_world_to_object(const BakePixel pixel_array[], - size_t num_pixels, + const size_t num_pixels, int depth, float result[], struct Object *ob, @@ -125,14 +125,14 @@ void RE_bake_normal_world_to_object(const BakePixel pixel_array[], * to a tangent space normal map for a given low poly mesh. */ void RE_bake_normal_world_to_tangent(const BakePixel pixel_array[], - size_t num_pixels, + const size_t num_pixels, int depth, float result[], struct Mesh *me, const eBakeNormalSwizzle normal_swizzle[3], float mat[4][4]); void RE_bake_normal_world_to_world(const BakePixel pixel_array[], - size_t num_pixels, + const size_t num_pixels, int depth, float result[], const eBakeNormalSwizzle normal_swizzle[3]); diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index a35e83a8632..8776bc63cf0 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -3344,12 +3344,12 @@ static ImBuf *do_text_effect(const SeqRenderData *context, fonty = line_height; BLF_position(font, x + max_ii(fontx / 55, 1), y - max_ii(fonty / 30, 1), 0.0f); BLF_buffer_col(font, data->shadow_color); - BLF_draw_buffer(font, data->text, sizeof(data->text)); + BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); } BLF_position(font, x, y, 0.0f); BLF_buffer_col(font, data->color); - BLF_draw_buffer(font, data->text, sizeof(data->text)); + BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); BLF_buffer(font, NULL, NULL, 0, 0, 0, NULL); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 2e305c0bf3c..9a8a6a3a3ac 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -607,7 +607,7 @@ int WM_operator_confirm_message_ex(struct bContext *C, const char *title, int icon, const char *message, - wmOperatorCallContext opcontext); + const wmOperatorCallContext opcontext); int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message); /* Operator API. */ diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 344f4959a93..99bab3ae23d 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -193,6 +193,7 @@ bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWind static void wm_window_match_init(bContext *C, ListBase *wmlist) { *wmlist = G_MAIN->wm; + BLI_listbase_clear(&G_MAIN->wm); wmWindow *active_win = CTX_wm_window(C); @@ -219,8 +220,6 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist) } } - BLI_listbase_clear(&G_MAIN->wm); - /* reset active window */ CTX_wm_window_set(C, active_win); -- cgit v1.2.3 From fb6bd8864411ee27db05ceadcb80f690f44e48dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 12 Jan 2022 12:49:36 +0100 Subject: Revert "BLI: Refactor vector types & functions to use templates" Includes unwanted changes This reverts commit 46e049d0ce2bce2f53ddc41a0dbbea2969d00a5d. --- source/blender/blenfont/BLF_api.h | 2 +- source/blender/blenfont/intern/blf_internal.h | 4 +- source/blender/blenkernel/BKE_appdir.h | 2 +- source/blender/blenkernel/BKE_attribute.h | 2 +- source/blender/blenkernel/BKE_attribute_access.hh | 3 +- source/blender/blenkernel/BKE_attribute_math.hh | 7 +- source/blender/blenkernel/BKE_bvhutils.h | 18 +- source/blender/blenkernel/BKE_customdata.h | 4 +- source/blender/blenkernel/BKE_geometry_set.hh | 2 +- source/blender/blenkernel/BKE_image.h | 2 +- source/blender/blenkernel/BKE_mesh_sample.hh | 2 +- source/blender/blenkernel/BKE_node.h | 8 +- source/blender/blenkernel/BKE_scene.h | 7 +- source/blender/blenkernel/BKE_spline.hh | 2 +- source/blender/blenkernel/BKE_vfont.h | 2 +- source/blender/blenkernel/BKE_volume.h | 2 +- source/blender/blenkernel/intern/DerivedMesh.cc | 2 +- .../blender/blenkernel/intern/attribute_access.cc | 2 +- .../blenkernel/intern/data_transfer_intern.h | 6 +- .../blenkernel/intern/geometry_component_mesh.cc | 5 +- source/blender/blenkernel/intern/gpencil_geom.cc | 2 +- source/blender/blenkernel/intern/hair.cc | 2 +- source/blender/blenkernel/intern/image.c | 26 +- source/blender/blenkernel/intern/mesh.cc | 10 +- .../blenkernel/intern/mesh_boolean_convert.cc | 2 +- .../blender/blenkernel/intern/mesh_remesh_voxel.cc | 2 +- source/blender/blenkernel/intern/object_dupli.cc | 8 +- source/blender/blenkernel/intern/pointcloud.cc | 24 +- source/blender/blenkernel/intern/simulation.cc | 2 +- source/blender/blenkernel/intern/spline_base.cc | 41 +- source/blender/blenkernel/intern/spline_bezier.cc | 37 +- source/blender/blenkernel/intern/tracking_test.cc | 2 +- .../blender/blenkernel/intern/type_conversions.cc | 3 +- source/blender/blenkernel/intern/volume.cc | 2 +- source/blender/blenkernel/intern/volume_render.cc | 2 +- source/blender/blenkernel/intern/volume_to_mesh.cc | 2 +- source/blender/blenlib/BLI_array_store.h | 2 +- source/blender/blenlib/BLI_array_utils.h | 4 +- source/blender/blenlib/BLI_buffer.h | 4 +- source/blender/blenlib/BLI_delaunay_2d.h | 4 +- source/blender/blenlib/BLI_double2.hh | 143 ++++++ source/blender/blenlib/BLI_double3.hh | 246 +++++++++ source/blender/blenlib/BLI_fileops.h | 3 +- source/blender/blenlib/BLI_float2.hh | 218 ++++++++ source/blender/blenlib/BLI_float3.hh | 320 ++++++++++++ source/blender/blenlib/BLI_float4.hh | 138 +++++ source/blender/blenlib/BLI_float4x4.hh | 5 +- source/blender/blenlib/BLI_gsqueue.h | 2 +- source/blender/blenlib/BLI_listbase.h | 6 +- source/blender/blenlib/BLI_math_boolean.hh | 6 +- source/blender/blenlib/BLI_math_vec_mpq_types.hh | 91 ---- source/blender/blenlib/BLI_math_vec_types.hh | 566 --------------------- source/blender/blenlib/BLI_math_vector.hh | 399 --------------- source/blender/blenlib/BLI_memarena.h | 4 +- source/blender/blenlib/BLI_memory_utils.h | 2 +- source/blender/blenlib/BLI_memory_utils.hh | 9 + source/blender/blenlib/BLI_mesh_intersect.hh | 5 +- source/blender/blenlib/BLI_mpq2.hh | 184 +++++++ source/blender/blenlib/BLI_mpq3.hh | 297 +++++++++++ source/blender/blenlib/BLI_noise.hh | 4 +- source/blender/blenlib/BLI_path_util.h | 19 +- source/blender/blenlib/BLI_rand.hh | 3 +- source/blender/blenlib/BLI_stack.h | 6 +- source/blender/blenlib/BLI_string.h | 26 +- source/blender/blenlib/BLI_string_utf8.h | 19 +- source/blender/blenlib/BLI_string_utils.h | 6 +- source/blender/blenlib/BLI_timecode.h | 6 +- source/blender/blenlib/BLI_utildefines.h | 11 +- source/blender/blenlib/CMakeLists.txt | 10 +- .../blender/blenlib/intern/BLI_mempool_private.h | 5 +- source/blender/blenlib/intern/delaunay_2d.cc | 45 +- source/blender/blenlib/intern/math_boolean.cc | 7 +- source/blender/blenlib/intern/math_vec.cc | 133 +++-- source/blender/blenlib/intern/mesh_boolean.cc | 51 +- source/blender/blenlib/intern/mesh_intersect.cc | 88 ++-- source/blender/blenlib/intern/noise.cc | 79 +-- .../blender/blenlib/tests/BLI_delaunay_2d_test.cc | 3 +- .../blenlib/tests/BLI_math_vec_types_test.cc | 149 ------ .../blender/blenlib/tests/BLI_memory_utils_test.cc | 2 +- .../blender/blenlib/tests/BLI_mesh_boolean_test.cc | 2 +- .../blenlib/tests/BLI_mesh_intersect_test.cc | 2 +- source/blender/bmesh/intern/bmesh_opdefines.c | 1 + source/blender/bmesh/intern/bmesh_polygon.c | 7 + source/blender/compositor/CMakeLists.txt | 9 + source/blender/compositor/COM_defines.h | 2 +- source/blender/compositor/COM_precomp.h | 33 ++ .../operations/COM_OutputFileOperation.h | 2 +- .../intern/builder/deg_builder_relations.cc | 11 + .../depsgraph/intern/node/deg_node_factory.h | 2 +- .../blender/draw/intern/draw_cache_impl_curve.cc | 2 +- .../mesh_extractors/extract_mesh_vbo_attributes.cc | 4 +- source/blender/editors/gpencil/gpencil_paint.c | 28 +- source/blender/editors/include/ED_util.h | 2 +- source/blender/editors/include/UI_interface.h | 6 +- .../blender/editors/interface/interface_intern.h | 4 +- source/blender/editors/interface/interface_panel.c | 1 + .../editors/interface/interface_region_tooltip.c | 15 +- source/blender/editors/interface/interface_style.c | 13 +- .../blender/editors/interface/interface_widgets.c | 7 +- source/blender/editors/object/object_add.c | 2 + source/blender/editors/render/render_preview.cc | 2 +- source/blender/editors/space_file/file_draw.c | 3 +- source/blender/editors/space_node/node_draw.cc | 2 +- source/blender/editors/space_node/node_group.cc | 2 +- source/blender/editors/space_node/node_intern.hh | 5 +- source/blender/editors/space_node/node_select.cc | 4 +- .../editors/space_sequencer/sequencer_draw.c | 37 +- .../space_spreadsheet/spreadsheet_column.cc | 3 +- .../space_spreadsheet/spreadsheet_layout.cc | 3 +- .../space_spreadsheet/spreadsheet_row_filter.cc | 8 +- source/blender/editors/util/ed_draw.c | 34 +- source/blender/freestyle/CMakeLists.txt | 5 +- source/blender/freestyle/FRS_precomp.cpp | 2 - source/blender/functions/intern/cpp_types.cc | 3 +- source/blender/imbuf/IMB_imbuf.h | 30 +- source/blender/imbuf/IMB_metadata.h | 5 +- source/blender/imbuf/intern/IMB_filetype.h | 22 +- source/blender/imbuf/intern/anim_movie.c | 11 +- source/blender/imbuf/intern/dds/dds_api.h | 2 +- source/blender/imbuf/intern/oiio/openimageio_api.h | 2 +- source/blender/imbuf/intern/openexr/openexr_api.h | 2 +- source/blender/imbuf/intern/radiance_hdr.c | 31 +- .../blender/io/alembic/intern/abc_reader_object.cc | 25 +- .../blender/io/gpencil/intern/gpencil_io_base.cc | 5 +- .../blender/io/gpencil/intern/gpencil_io_base.hh | 3 +- .../io/gpencil/intern/gpencil_io_import_svg.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mesh.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_nurbs.cc | 2 +- .../io/wavefront_obj/tests/obj_exporter_tests.cc | 2 +- source/blender/makesdna/DNA_modifier_types.h | 1 + source/blender/makesdna/DNA_node_types.h | 1 + source/blender/makesrna/RNA_access.h | 2 +- source/blender/makesrna/intern/rna_internal.h | 2 +- .../blender/makesrna/intern/rna_internal_types.h | 2 +- source/blender/makesrna/intern/rna_modifier.c | 7 +- source/blender/makesrna/intern/rna_nodetree.c | 7 +- .../blender/modifiers/intern/MOD_mesh_to_volume.cc | 4 +- source/blender/modifiers/intern/MOD_nodes.cc | 2 +- source/blender/nodes/NOD_math_functions.hh | 75 +-- source/blender/nodes/NOD_socket_declarations.hh | 2 +- .../blender/nodes/composite/node_composite_tree.cc | 17 - .../nodes/composite/nodes/node_composite_image.cc | 28 +- .../blender/nodes/function/node_function_util.hh | 2 +- .../nodes/node_fn_align_euler_to_vector.cc | 8 +- .../nodes/function/nodes/node_fn_compare.cc | 24 +- .../blender/nodes/geometry/node_geometry_util.hh | 4 +- .../node_geo_legacy_align_rotation_to_vector.cc | 8 +- .../legacy/node_geo_legacy_attribute_proximity.cc | 2 +- .../legacy/node_geo_legacy_attribute_transfer.cc | 2 +- .../legacy/node_geo_legacy_curve_to_points.cc | 4 +- .../legacy/node_geo_legacy_point_distribute.cc | 4 +- .../legacy/node_geo_legacy_points_to_volume.cc | 2 +- .../nodes/legacy/node_geo_legacy_raycast.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fill.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fillet.cc | 21 +- .../nodes/node_geo_curve_primitive_circle.cc | 18 +- .../nodes/node_geo_curve_primitive_line.cc | 2 +- .../node_geo_curve_primitive_quadratic_bezier.cc | 6 +- .../nodes/geometry/nodes/node_geo_curve_sample.cc | 4 +- .../nodes/node_geo_curve_spline_parameter.cc | 2 +- .../geometry/nodes/node_geo_curve_to_points.cc | 4 +- .../nodes/geometry/nodes/node_geo_image_texture.cc | 2 +- .../geometry/nodes/node_geo_mesh_primitive_cube.cc | 6 +- .../geometry/nodes/node_geo_mesh_primitive_line.cc | 6 +- .../nodes/node_geo_mesh_primitive_uv_sphere.cc | 2 +- .../geometry/nodes/node_geo_points_to_volume.cc | 2 +- .../nodes/geometry/nodes/node_geo_proximity.cc | 2 +- .../nodes/geometry/nodes/node_geo_raycast.cc | 2 +- .../geometry/nodes/node_geo_set_curve_handles.cc | 2 +- .../geometry/nodes/node_geo_transfer_attribute.cc | 2 +- .../nodes/geometry/nodes/node_geo_transform.cc | 4 +- source/blender/nodes/intern/node_socket.cc | 2 +- source/blender/nodes/shader/node_shader_util.hh | 2 +- .../nodes/shader/nodes/node_shader_map_range.cc | 10 +- .../nodes/shader/nodes/node_shader_tex_brick.cc | 3 +- .../nodes/shader/nodes/node_shader_tex_gradient.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_noise.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_voronoi.cc | 36 +- source/blender/python/generic/py_capi_utils.h | 12 +- source/blender/render/RE_bake.h | 12 +- source/blender/sequencer/intern/effects.c | 4 +- source/blender/windowmanager/WM_api.h | 2 +- source/blender/windowmanager/intern/wm_files.c | 3 +- 185 files changed, 2433 insertions(+), 1961 deletions(-) create mode 100644 source/blender/blenlib/BLI_double2.hh create mode 100644 source/blender/blenlib/BLI_double3.hh create mode 100644 source/blender/blenlib/BLI_float2.hh create mode 100644 source/blender/blenlib/BLI_float3.hh create mode 100644 source/blender/blenlib/BLI_float4.hh delete mode 100644 source/blender/blenlib/BLI_math_vec_mpq_types.hh delete mode 100644 source/blender/blenlib/BLI_math_vec_types.hh delete mode 100644 source/blender/blenlib/BLI_math_vector.hh create mode 100644 source/blender/blenlib/BLI_mpq2.hh create mode 100644 source/blender/blenlib/BLI_mpq3.hh delete mode 100644 source/blender/blenlib/tests/BLI_math_vec_types_test.cc create mode 100644 source/blender/compositor/COM_precomp.h delete mode 100644 source/blender/freestyle/FRS_precomp.cpp (limited to 'source/blender') diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 76a6135baaf..169107b19cb 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -122,7 +122,7 @@ void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth) ATTR_NONNULL(2); typedef bool (*BLF_GlyphBoundsFn)(const char *str, - const size_t str_step_ofs, + size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 23e42ec777f..4e36f522981 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -121,7 +121,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, const char *str, size_t str_len, bool (*user_fn)(const char *str, - const size_t str_step_ofs, + size_t str_step_ofs, const struct rcti *glyph_step_bounds, int glyph_advance_x, const struct rctf *glyph_bounds, @@ -132,7 +132,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, int blf_font_count_missing_chars(struct FontBLF *font, const char *str, - const size_t str_len, + size_t str_len, int *r_tot_chars); void blf_font_free(struct FontBLF *font); diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index e92909fb3ca..a7baaed141f 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -140,7 +140,7 @@ bool BKE_appdir_font_folder_default(char *dir); * Find Python executable. */ bool BKE_appdir_program_python_search(char *fullpath, - const size_t fullpath_len, + size_t fullpath_len, int version_major, int version_minor); diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index db8f3759bf8..6020da08f51 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -73,7 +73,7 @@ bool BKE_id_attribute_rename(struct ID *id, const char *new_name, struct ReportList *reports); -int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask); +int BKE_id_attributes_length(struct ID *id, CustomDataMask mask); struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id); void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer); diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index 3ffdcee05eb..f69ba79e23f 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -26,8 +26,9 @@ #include "BKE_attribute.h" #include "BLI_color.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_function_ref.hh" -#include "BLI_math_vec_types.hh" /** * This file defines classes that help to provide access to attribute data on a #GeometryComponent. diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh index a7bdca06790..802c744972c 100644 --- a/source/blender/blenkernel/BKE_attribute_math.hh +++ b/source/blender/blenkernel/BKE_attribute_math.hh @@ -18,7 +18,8 @@ #include "BLI_array.hh" #include "BLI_color.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "DNA_customdata_types.h" @@ -159,12 +160,12 @@ template<> inline float mix2(const float factor, const float &a, const float &b) template<> inline float2 mix2(const float factor, const float2 &a, const float2 &b) { - return math::interpolate(a, b, factor); + return float2::interpolate(a, b, factor); } template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b) { - return math::interpolate(a, b, factor); + return float3::interpolate(a, b, factor); } template<> diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 42c8a5dae5d..146e6394fd6 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -128,7 +128,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -148,7 +148,7 @@ BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -165,7 +165,7 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -188,7 +188,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -212,7 +212,7 @@ BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -229,7 +229,7 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -251,7 +251,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, float epsilon, int tree_type, int axis, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); @@ -263,7 +263,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data, */ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, const struct Mesh *mesh, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, int tree_type); /** @@ -272,7 +272,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, BVHTree *BKE_bvhtree_from_editmesh_get(BVHTreeFromEditMesh *data, struct BMEditMesh *em, int tree_type, - const BVHCacheType bvh_cache_type, + BVHCacheType bvh_cache_type, struct BVHCache **bvh_cache_p, ThreadMutex *mesh_eval_mutex); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index b5b6296a0fa..17a44274712 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -323,7 +323,7 @@ void CustomData_bmesh_copy_data_exclude_by_type(const struct CustomData *source, struct CustomData *dest, void *src_block, void **dest_block, - const CustomDataMask mask_exclude); + CustomDataMask mask_exclude); /** * Copies data of a single layer of a given type. @@ -496,7 +496,7 @@ void CustomData_bmesh_free_block_data(struct CustomData *data, void *block); */ void CustomData_bmesh_free_block_data_exclude_by_type(struct CustomData *data, void *block, - const CustomDataMask mask_exclude); + CustomDataMask mask_exclude); /** * Copy custom data to/from layers as in mesh/derived-mesh, to edit-mesh diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index f92f33b2776..acb89637f20 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -23,11 +23,11 @@ #include #include +#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_function_ref.hh" #include "BLI_hash.hh" #include "BLI_map.hh" -#include "BLI_math_vec_types.hh" #include "BLI_set.hh" #include "BLI_user_counter.hh" #include "BLI_vector_set.hh" diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 7b87189a13f..80c6b155be0 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -367,7 +367,7 @@ void BKE_image_packfiles(struct ReportList *reports, struct Image *ima, const ch void BKE_image_packfiles_from_mem(struct ReportList *reports, struct Image *ima, char *data, - const size_t data_len); + size_t data_len); /** * Prints memory statistics for images. diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh index 738b768d906..238b6f4dcae 100644 --- a/source/blender/blenkernel/BKE_mesh_sample.hh +++ b/source/blender/blenkernel/BKE_mesh_sample.hh @@ -22,7 +22,7 @@ #include "FN_generic_virtual_array.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BKE_attribute.h" diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 5f8222e33d4..a76fe2f83e0 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1374,18 +1374,12 @@ void ntreeCompositTagRender(struct Scene *scene); * - Each render layer node calls the update function of the * render engine that's used for its scene. * - The render engine calls RE_engine_register_pass for each pass. - * - #RE_engine_register_pass calls #ntreeCompositRegisterPass, - * which calls #node_cmp_rlayers_register_pass for every render layer node. + * - #RE_engine_register_pass calls #node_cmp_rlayers_register_pass. * * TODO: This is *not* part of `blenkernel`, it's defined under "source/blender/nodes/". * This declaration should be moved out of BKE. */ void ntreeCompositUpdateRLayers(struct bNodeTree *ntree); -void ntreeCompositRegisterPass(struct bNodeTree *ntree, - struct Scene *scene, - struct ViewLayer *view_layer, - const char *name, - eNodeSocketDatatype type); void ntreeCompositClearTags(struct bNodeTree *ntree); struct bNodeSocket *ntreeCompositOutputFileAddSocket(struct bNodeTree *ntree, diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 8610bc09a92..a40359e8650 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -317,11 +317,8 @@ void BKE_scene_multiview_view_prefix_get(struct Scene *scene, const char *name, char *r_prefix, const char **r_ext); -void BKE_scene_multiview_videos_dimensions_get(const struct RenderData *rd, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); +void BKE_scene_multiview_videos_dimensions_get( + const struct RenderData *rd, size_t width, size_t height, size_t *r_width, size_t *r_height); int BKE_scene_multiview_num_videos_get(const struct RenderData *rd); /* depsgraph */ diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh index a87f76da8da..2c14880978f 100644 --- a/source/blender/blenkernel/BKE_spline.hh +++ b/source/blender/blenkernel/BKE_spline.hh @@ -24,8 +24,8 @@ #include "FN_generic_virtual_array.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" -#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BKE_attribute_access.hh" diff --git a/source/blender/blenkernel/BKE_vfont.h b/source/blender/blenkernel/BKE_vfont.h index d0a44ce4e47..3397f2ef82a 100644 --- a/source/blender/blenkernel/BKE_vfont.h +++ b/source/blender/blenkernel/BKE_vfont.h @@ -104,7 +104,7 @@ void BKE_vfont_select_clamp(struct Object *ob); void BKE_vfont_clipboard_free(void); void BKE_vfont_clipboard_set(const char32_t *text_buf, const struct CharInfo *info_buf, - const size_t len); + size_t len); void BKE_vfont_clipboard_get(char32_t **r_text_buf, struct CharInfo **r_info_buf, size_t *r_len_utf8, diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h index b40facc3572..2b551a76d73 100644 --- a/source/blender/blenkernel/BKE_volume.h +++ b/source/blender/blenkernel/BKE_volume.h @@ -163,8 +163,8 @@ bool BKE_volume_save(const struct Volume *volume, * file or copy shared grids to make them writeable. */ #ifdef __cplusplus +# include "BLI_float3.hh" # include "BLI_float4x4.hh" -# include "BLI_math_vec_types.hh" # include "BLI_string_ref.hh" bool BKE_volume_min_max(const Volume *volume, blender::float3 &r_min, blender::float3 &r_max); diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 73785e2ee2b..4bfd71ba932 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -38,9 +38,9 @@ #include "BLI_array.h" #include "BLI_bitmap.h" #include "BLI_blenlib.h" +#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_task.h" #include "BLI_task.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index cc43a3e26a8..1a4265d936b 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -30,7 +30,7 @@ #include "DNA_pointcloud_types.h" #include "BLI_color.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" #include "BLI_span.hh" #include "BLT_translation.h" diff --git a/source/blender/blenkernel/intern/data_transfer_intern.h b/source/blender/blenkernel/intern/data_transfer_intern.h index e5218415df9..b5b3db31fbf 100644 --- a/source/blender/blenkernel/intern/data_transfer_intern.h +++ b/source/blender/blenkernel/intern/data_transfer_intern.h @@ -44,9 +44,9 @@ void data_transfer_layersmapping_add_item(struct ListBase *r_map, void *data_dst, int data_src_n, int data_dst_n, - const size_t elem_size, - const size_t data_size, - const size_t data_offset, + size_t elem_size, + size_t data_size, + size_t data_offset, uint64_t data_flag, cd_datatransfer_interp interp, void *interp_data); diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 88a58220b23..2b4238d26bb 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -217,8 +217,9 @@ VArray mesh_normals_varray(const MeshComponent &mesh_component, * calculating unnecessary values and to allow normalizing the result much more simply. */ for (const int i : mask) { const MEdge &edge = edges[i]; - edge_normals[i] = math::normalize( - math::interpolate(vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f)); + edge_normals[i] = float3::interpolate( + vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f) + .normalized(); } return VArray::ForContainer(std::move(edge_normals)); diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc index 116d77f1a2a..f8681647a77 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.cc +++ b/source/blender/blenkernel/intern/gpencil_geom.cc @@ -33,10 +33,10 @@ #include "BLI_array_utils.h" #include "BLI_blenlib.h" +#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_heap.h" -#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_polyfill_2d.h" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/hair.cc b/source/blender/blenkernel/intern/hair.cc index b7ba159f631..c5b154c9a4b 100644 --- a/source/blender/blenkernel/intern/hair.cc +++ b/source/blender/blenkernel/intern/hair.cc @@ -28,9 +28,9 @@ #include "DNA_material_types.h" #include "DNA_object_types.h" +#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math_base.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 4899c3671aa..23b1054f814 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -2446,7 +2446,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and draw the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.file, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.file, sizeof(stamp_data.file)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2469,7 +2469,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.date, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.date, sizeof(stamp_data.date)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2492,7 +2492,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.rendertime, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.rendertime, sizeof(stamp_data.rendertime)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2515,7 +2515,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.memory, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.memory, sizeof(stamp_data.memory)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2538,7 +2538,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.hostname, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.hostname, sizeof(stamp_data.hostname)); /* the extra pixel for background. */ y -= BUFF_MARGIN_Y * 2; @@ -2562,7 +2562,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs + (h - h_fixed), 0.0); - BLF_draw_buffer(mono, stamp_data.note, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.note, sizeof(stamp_data.note)); } BLF_disable(mono, BLF_WORD_WRAP); @@ -2586,7 +2586,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.marker, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.marker, sizeof(stamp_data.marker)); /* space width. */ x += w + pad; @@ -2609,7 +2609,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.time, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.time, sizeof(stamp_data.time)); /* space width. */ x += w + pad; @@ -2631,7 +2631,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.frame, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.frame, sizeof(stamp_data.frame)); /* space width. */ x += w + pad; @@ -2651,7 +2651,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.camera, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.camera, sizeof(stamp_data.camera)); /* space width. */ x += w + pad; @@ -2671,7 +2671,7 @@ void BKE_image_stamp_buf(Scene *scene, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.cameralens, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.cameralens, sizeof(stamp_data.cameralens)); } if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) { @@ -2693,7 +2693,7 @@ void BKE_image_stamp_buf(Scene *scene, /* and pad the text. */ BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.scene, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.scene, sizeof(stamp_data.scene)); } if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) { @@ -2715,7 +2715,7 @@ void BKE_image_stamp_buf(Scene *scene, y + h + BUFF_MARGIN_Y); BLF_position(mono, x, y + y_ofs, 0.0); - BLF_draw_buffer(mono, stamp_data.strip, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(mono, stamp_data.strip, sizeof(stamp_data.strip)); } /* cleanup the buffer. */ diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 8ceaced1972..12c63ab0523 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -36,13 +36,13 @@ #include "BLI_bitmap.h" #include "BLI_edgehash.h" #include "BLI_endian_switch.h" +#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_index_range.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_memarena.h" #include "BLI_string.h" #include "BLI_task.hh" @@ -1597,16 +1597,16 @@ bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3]) [&](IndexRange range, const Result &init) { Result result = init; for (const int i : range) { - math::min_max(float3(me->mvert[i].co), result.min, result.max); + float3::min_max(me->mvert[i].co, result.min, result.max); } return result; }, [](const Result &a, const Result &b) { - return Result{math::min(a.min, b.min), math::max(a.max, b.max)}; + return Result{float3::min(a.min, b.min), float3::max(a.max, b.max)}; }); - copy_v3_v3(r_min, math::min(minmax.min, float3(r_min))); - copy_v3_v3(r_max, math::max(minmax.max, float3(r_max))); + copy_v3_v3(r_min, float3::min(minmax.min, r_min)); + copy_v3_v3(r_max, float3::max(minmax.max, r_max)); return true; } diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc index a4a5fe2be2e..771d79a0445 100644 --- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc +++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc @@ -32,9 +32,9 @@ #include "BLI_alloca.h" #include "BLI_array.hh" +#include "BLI_float2.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_mesh_boolean.hh" #include "BLI_mesh_intersect.hh" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc index 50464da86e9..3447185089d 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc @@ -31,8 +31,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_index_range.hh" -#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_mesh_types.h" diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc index 20fdda8bdc7..e682486390c 100644 --- a/source/blender/blenkernel/intern/object_dupli.cc +++ b/source/blender/blenkernel/intern/object_dupli.cc @@ -31,9 +31,9 @@ #include "BLI_string_utf8.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_vector.hh" @@ -1026,8 +1026,6 @@ static void get_dupliface_transform_from_coords(Span coords, const float scale_fac, float r_mat[4][4]) { - using namespace blender::math; - /* Location. */ float3 location(0); for (const float3 &coord : coords) { @@ -1038,7 +1036,9 @@ static void get_dupliface_transform_from_coords(Span coords, /* Rotation. */ float quat[4]; - float3 f_no = normalize(cross_poly(coords)); + float3 f_no; + cross_poly_v3(f_no, (const float(*)[3])coords.data(), (uint)coords.size()); + f_no.normalize(); tri_to_quat_ex(quat, coords[0], coords[1], coords[2], f_no); /* Scale. */ diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc index b5f016e4d76..a041e04bf71 100644 --- a/source/blender/blenkernel/intern/pointcloud.cc +++ b/source/blender/blenkernel/intern/pointcloud.cc @@ -25,9 +25,9 @@ #include "DNA_object_types.h" #include "DNA_pointcloud_types.h" +#include "BLI_float3.hh" #include "BLI_index_range.hh" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" @@ -275,8 +275,6 @@ struct MinMaxResult { static MinMaxResult min_max_no_radii(Span positions) { - using namespace blender::math; - return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -284,19 +282,17 @@ static MinMaxResult min_max_no_radii(Span positions) [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - min_max(positions[i], result.min, result.max); + float3::min_max(positions[i], result.min, result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; + return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; }); } static MinMaxResult min_max_with_radii(Span positions, Span radii) { - using namespace blender::math; - return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -304,20 +300,18 @@ static MinMaxResult min_max_with_radii(Span positions, Span radii [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - result.min = min(positions[i] - radii[i], result.min); - result.max = max(positions[i] + radii[i], result.max); + result.min = float3::min(positions[i] - radii[i], result.min); + result.max = float3::max(positions[i] + radii[i], result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; + return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; }); } bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r_max[3]) { - using namespace blender::math; - if (!pointcloud->totpoint) { return false; } @@ -328,8 +322,8 @@ bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r {pointcloud->radius, pointcloud->totpoint}) : min_max_no_radii(positions); - copy_v3_v3(r_min, min(min_max.min, float3(r_min))); - copy_v3_v3(r_max, max(min_max.max, float3(r_max))); + copy_v3_v3(r_min, float3::min(min_max.min, r_min)); + copy_v3_v3(r_max, float3::max(min_max.max, r_max)); return true; } @@ -346,7 +340,7 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob) ob->runtime.bb = static_cast(MEM_callocN(sizeof(BoundBox), "pointcloud boundbox")); } - float3 min, max; + blender::float3 min, max; INIT_MINMAX(min, max); if (ob->runtime.geometry_set_eval != nullptr) { ob->runtime.geometry_set_eval->compute_boundbox_without_instances(&min, &max); diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index ec4b0e8d51d..b0f9de5963a 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -28,9 +28,9 @@ #include "DNA_simulation_types.h" #include "BLI_compiler_compat.h" +#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 3262d768b6c..857022345f3 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -166,15 +166,13 @@ static void accumulate_lengths(Span positions, const bool is_cyclic, MutableSpan lengths) { - using namespace blender::math; - float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { - length += distance(positions[i], positions[i + 1]); + length += float3::distance(positions[i], positions[i + 1]); lengths[i] = length; } if (is_cyclic) { - lengths.last() = length + distance(positions.last(), positions.first()); + lengths.last() = length + float3::distance(positions.last(), positions.first()); } } @@ -202,13 +200,11 @@ Span Spline::evaluated_lengths() const static float3 direction_bisect(const float3 &prev, const float3 &middle, const float3 &next) { - using namespace blender::math; - - const float3 dir_prev = normalize(middle - prev); - const float3 dir_next = normalize(next - middle); + const float3 dir_prev = (middle - prev).normalized(); + const float3 dir_next = (next - middle).normalized(); - const float3 result = normalize(dir_prev + dir_next); - if (UNLIKELY(is_zero(result))) { + const float3 result = (dir_prev + dir_next).normalized(); + if (UNLIKELY(result.is_zero())) { return float3(0.0f, 0.0f, 1.0f); } return result; @@ -218,8 +214,6 @@ static void calculate_tangents(Span positions, const bool is_cyclic, MutableSpan tangents) { - using namespace blender::math; - if (positions.size() == 1) { tangents.first() = float3(0.0f, 0.0f, 1.0f); return; @@ -238,8 +232,8 @@ static void calculate_tangents(Span positions, tangents.last() = direction_bisect(second_to_last, last, first); } else { - tangents.first() = normalize(positions[1] - positions[0]); - tangents.last() = normalize(positions.last() - positions[positions.size() - 2]); + tangents.first() = (positions[1] - positions[0]).normalized(); + tangents.last() = (positions.last() - positions[positions.size() - 2]).normalized(); } } @@ -270,22 +264,18 @@ static float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, const float angle) { - using namespace blender::math; - BLI_ASSERT_UNIT_V3(direction); BLI_ASSERT_UNIT_V3(axis); - const float3 axis_scaled = axis * dot(direction, axis); + const float3 axis_scaled = axis * float3::dot(direction, axis); const float3 diff = direction - axis_scaled; - const float3 cross = blender::math::cross(axis, diff); + const float3 cross = float3::cross(axis, diff); return axis_scaled + diff * std::cos(angle) + cross * std::sin(angle); } static void calculate_normals_z_up(Span tangents, MutableSpan r_normals) { - using namespace blender::math; - BLI_assert(r_normals.size() == tangents.size()); /* Same as in `vec_to_quat`. */ @@ -296,7 +286,7 @@ static void calculate_normals_z_up(Span tangents, MutableSpan r_ r_normals[i] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[i] = normalize(float3(tangent.y, -tangent.x, 0.0f)); + r_normals[i] = float3(tangent.y, -tangent.x, 0.0f).normalized(); } } } @@ -308,14 +298,12 @@ static float3 calculate_next_normal(const float3 &last_normal, const float3 &last_tangent, const float3 ¤t_tangent) { - using namespace blender::math; - - if (is_zero(last_tangent) || is_zero(current_tangent)) { + if (last_tangent.is_zero() || current_tangent.is_zero()) { return last_normal; } const float angle = angle_normalized_v3v3(last_tangent, current_tangent); if (angle != 0.0) { - const float3 axis = normalize(cross(last_tangent, current_tangent)); + const float3 axis = float3::cross(last_tangent, current_tangent).normalized(); return rotate_direction_around_axis(last_normal, axis, angle); } return last_normal; @@ -325,7 +313,6 @@ static void calculate_normals_minimum(Span tangents, const bool cyclic, MutableSpan r_normals) { - using namespace blender::math; BLI_assert(r_normals.size() == tangents.size()); if (r_normals.is_empty()) { @@ -340,7 +327,7 @@ static void calculate_normals_minimum(Span tangents, r_normals[0] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[0] = normalize(float3(first_tangent.y, -first_tangent.x, 0.0f)); + r_normals[0] = float3(first_tangent.y, -first_tangent.x, 0.0f).normalized(); } /* Forward normal with minimum twist along the entire spline. */ diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc index 980437014b1..b24c8960857 100644 --- a/source/blender/blenkernel/intern/spline_bezier.cc +++ b/source/blender/blenkernel/intern/spline_bezier.cc @@ -199,13 +199,11 @@ void BezierSpline::ensure_auto_handles() const } for (const int i : IndexRange(this->size())) { - using namespace blender; - if (ELEM(HandleType::Auto, handle_types_left_[i], handle_types_right_[i])) { const float3 prev_diff = positions_[i] - previous_position(positions_, is_cyclic_, i); const float3 next_diff = next_position(positions_, is_cyclic_, i) - positions_[i]; - float prev_len = math::length(prev_diff); - float next_len = math::length(next_diff); + float prev_len = prev_diff.length(); + float next_len = next_diff.length(); if (prev_len == 0.0f) { prev_len = 1.0f; } @@ -215,7 +213,7 @@ void BezierSpline::ensure_auto_handles() const const float3 dir = next_diff / next_len + prev_diff / prev_len; /* This magic number is unfortunate, but comes from elsewhere in Blender. */ - const float len = math::length(dir) * 2.5614f; + const float len = dir.length() * 2.5614f; if (len != 0.0f) { if (handle_types_left_[i] == HandleType::Auto) { const float prev_len_clamped = std::min(prev_len, next_len * 5.0f); @@ -230,12 +228,12 @@ void BezierSpline::ensure_auto_handles() const if (handle_types_left_[i] == HandleType::Vector) { const float3 prev = previous_position(positions_, is_cyclic_, i); - handle_positions_left_[i] = math::interpolate(positions_[i], prev, 1.0f / 3.0f); + handle_positions_left_[i] = float3::interpolate(positions_[i], prev, 1.0f / 3.0f); } if (handle_types_right_[i] == HandleType::Vector) { const float3 next = next_position(positions_, is_cyclic_, i); - handle_positions_right_[i] = math::interpolate(positions_[i], next, 1.0f / 3.0f); + handle_positions_right_[i] = float3::interpolate(positions_[i], next, 1.0f / 3.0f); } } @@ -277,8 +275,6 @@ static void set_handle_position(const float3 &position, float3 &handle, float3 &handle_other) { - using namespace blender::math; - /* Don't bother when the handle positions are calculated automatically anyway. */ if (ELEM(type, BezierSpline::HandleType::Auto, BezierSpline::HandleType::Vector)) { return; @@ -287,9 +283,9 @@ static void set_handle_position(const float3 &position, handle = new_value; if (type_other == BezierSpline::HandleType::Align) { /* Keep track of the old length of the opposite handle. */ - const float length = distance(handle_other, position); + const float length = float3::distance(handle_other, position); /* Set the other handle to directly opposite from the current handle. */ - const float3 dir = normalize(handle - position); + const float3 dir = (handle - position).normalized(); handle_other = position - dir * length; } } @@ -357,7 +353,6 @@ int BezierSpline::evaluated_points_size() const void BezierSpline::correct_end_tangents() const { - using namespace blender::math; if (is_cyclic_) { return; } @@ -365,10 +360,10 @@ void BezierSpline::correct_end_tangents() const MutableSpan tangents(evaluated_tangents_cache_); if (handle_positions_right_.first() != positions_.first()) { - tangents.first() = normalize(handle_positions_right_.first() - positions_.first()); + tangents.first() = (handle_positions_right_.first() - positions_.first()).normalized(); } if (handle_positions_left_.last() != positions_.last()) { - tangents.last() = normalize(positions_.last() - handle_positions_left_.last()); + tangents.last() = (positions_.last() - handle_positions_left_.last()).normalized(); } } @@ -376,22 +371,20 @@ BezierSpline::InsertResult BezierSpline::calculate_segment_insertion(const int i const int next_index, const float parameter) { - using namespace blender::math; - BLI_assert(parameter <= 1.0f && parameter >= 0.0f); BLI_assert(next_index == 0 || next_index == index + 1); const float3 &point_prev = positions_[index]; const float3 &handle_prev = handle_positions_right_[index]; const float3 &handle_next = handle_positions_left_[next_index]; const float3 &point_next = positions_[next_index]; - const float3 center_point = interpolate(handle_prev, handle_next, parameter); + const float3 center_point = float3::interpolate(handle_prev, handle_next, parameter); BezierSpline::InsertResult result; - result.handle_prev = interpolate(point_prev, handle_prev, parameter); - result.handle_next = interpolate(handle_next, point_next, parameter); - result.left_handle = interpolate(result.handle_prev, center_point, parameter); - result.right_handle = interpolate(center_point, result.handle_next, parameter); - result.position = interpolate(result.left_handle, result.right_handle, parameter); + result.handle_prev = float3::interpolate(point_prev, handle_prev, parameter); + result.handle_next = float3::interpolate(handle_next, point_next, parameter); + result.left_handle = float3::interpolate(result.handle_prev, center_point, parameter); + result.right_handle = float3::interpolate(center_point, result.handle_next, parameter); + result.position = float3::interpolate(result.left_handle, result.right_handle, parameter); return result; } diff --git a/source/blender/blenkernel/intern/tracking_test.cc b/source/blender/blenkernel/intern/tracking_test.cc index d85d71b7c86..a3845dcad8f 100644 --- a/source/blender/blenkernel/intern/tracking_test.cc +++ b/source/blender/blenkernel/intern/tracking_test.cc @@ -5,7 +5,7 @@ #include "DNA_tracking_types.h" #include "BKE_tracking.h" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" namespace blender { diff --git a/source/blender/blenkernel/intern/type_conversions.cc b/source/blender/blenkernel/intern/type_conversions.cc index cb05337ef2a..b23220286e6 100644 --- a/source/blender/blenkernel/intern/type_conversions.cc +++ b/source/blender/blenkernel/intern/type_conversions.cc @@ -19,7 +19,8 @@ #include "FN_multi_function_builder.hh" #include "BLI_color.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" namespace blender::bke { diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index c17706dc216..4b71c98339b 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -28,12 +28,12 @@ #include "BLI_compiler_compat.h" #include "BLI_fileops.h" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_ghash.h" #include "BLI_index_range.hh" #include "BLI_map.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc index c0a205b5673..6dc497bb616 100644 --- a/source/blender/blenkernel/intern/volume_render.cc +++ b/source/blender/blenkernel/intern/volume_render.cc @@ -21,8 +21,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_math_matrix.h" -#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_vector.hh" diff --git a/source/blender/blenkernel/intern/volume_to_mesh.cc b/source/blender/blenkernel/intern/volume_to_mesh.cc index 733549c0022..6e465b2fdf0 100644 --- a/source/blender/blenkernel/intern/volume_to_mesh.cc +++ b/source/blender/blenkernel/intern/volume_to_mesh.cc @@ -16,7 +16,7 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_array_store.h b/source/blender/blenlib/BLI_array_store.h index 0be361d4ab9..68928f53e55 100644 --- a/source/blender/blenlib/BLI_array_store.h +++ b/source/blender/blenlib/BLI_array_store.h @@ -84,7 +84,7 @@ size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs); */ BArrayState *BLI_array_store_state_add(BArrayStore *bs, const void *data, - const size_t data_len, + size_t data_len, const BArrayState *state_reference); /** * Remove a state and free any unused #BChunk data. diff --git a/source/blender/blenlib/BLI_array_utils.h b/source/blender/blenlib/BLI_array_utils.h index 50fc2ce909b..202ae9a9786 100644 --- a/source/blender/blenlib/BLI_array_utils.h +++ b/source/blender/blenlib/BLI_array_utils.h @@ -52,7 +52,7 @@ void _bli_array_wrap(void *arr, uint arr_len, size_t arr_stride, int dir); * Access via #BLI_array_wrap */ void _bli_array_permute( - void *arr, uint arr_len, const size_t arr_stride, const uint *order, void *arr_temp); + void *arr, uint arr_len, size_t arr_stride, const uint *order, void *arr_temp); #define BLI_array_permute(arr, arr_len, order) \ _bli_array_permute(arr, arr_len, sizeof(*(arr)), order, NULL) #define BLI_array_permute_ex(arr, arr_len, order, arr_temp) \ @@ -152,7 +152,7 @@ bool _bli_array_is_zeroed(const void *arr, uint arr_len, size_t arr_stride); */ bool _bli_array_iter_spiral_square(const void *arr_v, const int arr_shape[2], - const size_t elem_size, + size_t elem_size, const int center[2], bool (*test_fn)(const void *arr_item, void *user_data), void *user_data); diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h index 7f577443cf7..e79d44fd934 100644 --- a/source/blender/blenlib/BLI_buffer.h +++ b/source/blender/blenlib/BLI_buffer.h @@ -74,7 +74,7 @@ enum { /** * \note Never decreases the amount of memory allocated. */ -void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); +void BLI_buffer_resize(BLI_Buffer *buffer, size_t new_count); /** * Ensure size, throwing away old data, respecting #BLI_BUFFER_USE_CALLOC. @@ -83,7 +83,7 @@ void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); * - Ignored (malloc'd). * - Cleared (when #BLI_BUFFER_USE_CALLOC is set). */ -void BLI_buffer_reinit(BLI_Buffer *buffer, const size_t new_count); +void BLI_buffer_reinit(BLI_Buffer *buffer, size_t new_count); /** * Append an array of elements. diff --git a/source/blender/blenlib/BLI_delaunay_2d.h b/source/blender/blenlib/BLI_delaunay_2d.h index 1ee0be64cee..db0df95499f 100644 --- a/source/blender/blenlib/BLI_delaunay_2d.h +++ b/source/blender/blenlib/BLI_delaunay_2d.h @@ -215,9 +215,9 @@ void BLI_delaunay_2d_cdt_free(CDT_result *result); /* C++ Interface. */ # include "BLI_array.hh" +# include "BLI_double2.hh" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" +# include "BLI_mpq2.hh" # include "BLI_vector.hh" namespace blender::meshintersect { diff --git a/source/blender/blenlib/BLI_double2.hh b/source/blender/blenlib/BLI_double2.hh new file mode 100644 index 00000000000..0abff01ab2f --- /dev/null +++ b/source/blender/blenlib/BLI_double2.hh @@ -0,0 +1,143 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include "BLI_double3.hh" + +namespace blender { + +struct double2 { + double x, y; + + double2() = default; + + double2(const double *ptr) : x{ptr[0]}, y{ptr[1]} + { + } + + double2(double x, double y) : x(x), y(y) + { + } + + double2(const double3 &other) : x(other.x), y(other.y) + { + } + + operator double *() + { + return &x; + } + + operator const double *() const + { + return &x; + } + + double length() const + { + return len_v2_db(*this); + } + + friend double2 operator+(const double2 &a, const double2 &b) + { + return {a.x + b.x, a.y + b.y}; + } + + friend double2 operator-(const double2 &a, const double2 &b) + { + return {a.x - b.x, a.y - b.y}; + } + + friend double2 operator*(const double2 &a, double b) + { + return {a.x * b, a.y * b}; + } + + friend double2 operator/(const double2 &a, double b) + { + BLI_assert(b != 0.0); + return {a.x / b, a.y / b}; + } + + friend double2 operator*(double a, const double2 &b) + { + return b * a; + } + + friend bool operator==(const double2 &a, const double2 &b) + { + return a.x == b.x && a.y == b.y; + } + + friend bool operator!=(const double2 &a, const double2 &b) + { + return a.x != b.x || a.y != b.y; + } + + friend std::ostream &operator<<(std::ostream &stream, const double2 &v) + { + stream << "(" << v.x << ", " << v.y << ")"; + return stream; + } + + static double dot(const double2 &a, const double2 &b) + { + return a.x * b.x + a.y * b.y; + } + + static double2 interpolate(const double2 &a, const double2 &b, double t) + { + return a * (1 - t) + b * t; + } + + static double2 abs(const double2 &a) + { + return double2(fabs(a.x), fabs(a.y)); + } + + static double distance(const double2 &a, const double2 &b) + { + return (a - b).length(); + } + + static double distance_squared(const double2 &a, const double2 &b) + { + double2 diff = a - b; + return double2::dot(diff, diff); + } + + struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + double lambda; + }; + + static isect_result isect_seg_seg(const double2 &v1, + const double2 &v2, + const double2 &v3, + const double2 &v4); +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_double3.hh b/source/blender/blenlib/BLI_double3.hh new file mode 100644 index 00000000000..ab258c9121b --- /dev/null +++ b/source/blender/blenlib/BLI_double3.hh @@ -0,0 +1,246 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include + +#include "BLI_math_vector.h" +#include "BLI_span.hh" + +namespace blender { + +struct double3 { + double x, y, z; + + double3() = default; + + double3(const double *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} + { + } + + double3(const double (*ptr)[3]) : double3((const double *)ptr) + { + } + + explicit double3(double value) : x(value), y(value), z(value) + { + } + + explicit double3(int value) : x(value), y(value), z(value) + { + } + + double3(double x, double y, double z) : x{x}, y{y}, z{z} + { + } + + operator const double *() const + { + return &x; + } + + operator double *() + { + return &x; + } + + double normalize_and_get_length() + { + return normalize_v3_db(*this); + } + + double3 normalized() const + { + double3 result; + normalize_v3_v3_db(result, *this); + return result; + } + + double length() const + { + return len_v3_db(*this); + } + + double length_squared() const + { + return len_squared_v3_db(*this); + } + + void reflect(const double3 &normal) + { + *this = this->reflected(normal); + } + + double3 reflected(const double3 &normal) const + { + double3 result; + reflect_v3_v3v3_db(result, *this, normal); + return result; + } + + static double3 safe_divide(const double3 &a, const double3 &b) + { + double3 result; + result.x = (b.x == 0.0) ? 0.0 : a.x / b.x; + result.y = (b.y == 0.0) ? 0.0 : a.y / b.y; + result.z = (b.z == 0.0) ? 0.0 : a.z / b.z; + return result; + } + + void invert() + { + x = -x; + y = -y; + z = -z; + } + + friend double3 operator+(const double3 &a, const double3 &b) + { + return {a.x + b.x, a.y + b.y, a.z + b.z}; + } + + void operator+=(const double3 &b) + { + this->x += b.x; + this->y += b.y; + this->z += b.z; + } + + friend double3 operator-(const double3 &a, const double3 &b) + { + return {a.x - b.x, a.y - b.y, a.z - b.z}; + } + + friend double3 operator-(const double3 &a) + { + return {-a.x, -a.y, -a.z}; + } + + void operator-=(const double3 &b) + { + this->x -= b.x; + this->y -= b.y; + this->z -= b.z; + } + + void operator*=(const double &scalar) + { + this->x *= scalar; + this->y *= scalar; + this->z *= scalar; + } + + void operator*=(const double3 &other) + { + this->x *= other.x; + this->y *= other.y; + this->z *= other.z; + } + + friend double3 operator*(const double3 &a, const double3 &b) + { + return {a.x * b.x, a.y * b.y, a.z * b.z}; + } + + friend double3 operator*(const double3 &a, const double &b) + { + return {a.x * b, a.y * b, a.z * b}; + } + + friend double3 operator*(const double &a, const double3 &b) + { + return b * a; + } + + friend double3 operator/(const double3 &a, const double &b) + { + BLI_assert(b != 0.0); + return {a.x / b, a.y / b, a.z / b}; + } + + friend bool operator==(const double3 &a, const double3 &b) + { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + + friend bool operator!=(const double3 &a, const double3 &b) + { + return a.x != b.x || a.y != b.y || a.z != b.z; + } + + friend std::ostream &operator<<(std::ostream &stream, const double3 &v) + { + stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; + return stream; + } + + static double dot(const double3 &a, const double3 &b) + { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static double3 cross_high_precision(const double3 &a, const double3 &b) + { + double3 result; + cross_v3_v3v3_db(result, a, b); + return result; + } + + static double3 project(const double3 &a, const double3 &b) + { + double3 result; + project_v3_v3v3_db(result, a, b); + return result; + } + + static double distance(const double3 &a, const double3 &b) + { + return (a - b).length(); + } + + static double distance_squared(const double3 &a, const double3 &b) + { + double3 diff = a - b; + return double3::dot(diff, diff); + } + + static double3 interpolate(const double3 &a, const double3 &b, double t) + { + return a * (1 - t) + b * t; + } + + static double3 abs(const double3 &a) + { + return double3(fabs(a.x), fabs(a.y), fabs(a.z)); + } + + static int dominant_axis(const double3 &a) + { + double x = (a.x >= 0) ? a.x : -a.x; + double y = (a.y >= 0) ? a.y : -a.y; + double z = (a.z >= 0) ? a.z : -a.z; + return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); + } + + static double3 cross_poly(Span poly); +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index 0022823b3de..28cb5f6d84b 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -155,8 +155,7 @@ double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL( * * \note can return NULL when the size is not big enough */ -char *BLI_current_working_dir(char *dir, const size_t maxncpy) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); +char *BLI_current_working_dir(char *dir, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); eFileAttributes BLI_file_attributes(const char *path); /** \} */ diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh new file mode 100644 index 00000000000..bb4229db86e --- /dev/null +++ b/source/blender/blenlib/BLI_float2.hh @@ -0,0 +1,218 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +#include "BLI_float3.hh" + +namespace blender { + +struct float2 { + float x, y; + + float2() = default; + + float2(const float *ptr) : x{ptr[0]}, y{ptr[1]} + { + } + + explicit float2(float value) : x(value), y(value) + { + } + + explicit float2(int value) : x(value), y(value) + { + } + + float2(float x, float y) : x(x), y(y) + { + } + + float2(const float3 &other) : x(other.x), y(other.y) + { + } + + operator float *() + { + return &x; + } + + operator const float *() const + { + return &x; + } + + float length() const + { + return len_v2(*this); + } + + float length_squared() const + { + return len_squared_v2(*this); + } + + bool is_zero() const + { + return this->x == 0.0f && this->y == 0.0f; + } + + float2 &operator+=(const float2 &other) + { + x += other.x; + y += other.y; + return *this; + } + + float2 &operator-=(const float2 &other) + { + x -= other.x; + y -= other.y; + return *this; + } + + float2 &operator*=(float factor) + { + x *= factor; + y *= factor; + return *this; + } + + float2 &operator/=(float divisor) + { + x /= divisor; + y /= divisor; + return *this; + } + + uint64_t hash() const + { + uint64_t x1 = *reinterpret_cast(&x); + uint64_t x2 = *reinterpret_cast(&y); + return (x1 * 812519) ^ (x2 * 707951); + } + + friend float2 operator+(const float2 &a, const float2 &b) + { + return {a.x + b.x, a.y + b.y}; + } + + friend float2 operator-(const float2 &a, const float2 &b) + { + return {a.x - b.x, a.y - b.y}; + } + + friend float2 operator-(const float2 &a, const float &b) + { + return {a.x - b, a.y - b}; + } + + friend float2 operator*(const float2 &a, float b) + { + return {a.x * b, a.y * b}; + } + + friend float2 operator/(const float2 &a, float b) + { + BLI_assert(b != 0.0f); + return {a.x / b, a.y / b}; + } + + friend float2 operator*(float a, const float2 &b) + { + return b * a; + } + + friend std::ostream &operator<<(std::ostream &stream, const float2 &v) + { + stream << "(" << v.x << ", " << v.y << ")"; + return stream; + } + + static float2 safe_divide(const float2 &a, const float b) + { + return (b != 0.0f) ? a / b : float2(0.0f); + } + + static float2 floor(const float2 &a) + { + return float2(floorf(a.x), floorf(a.y)); + } + + /** + * Returns a normalized vector. The original vector is not changed. + */ + float2 normalized() const + { + float2 result; + normalize_v2_v2(result, *this); + return result; + } + + static float dot(const float2 &a, const float2 &b) + { + return a.x * b.x + a.y * b.y; + } + + static float2 interpolate(const float2 &a, const float2 &b, float t) + { + return a * (1 - t) + b * t; + } + + static float2 abs(const float2 &a) + { + return float2(fabsf(a.x), fabsf(a.y)); + } + + static float distance(const float2 &a, const float2 &b) + { + return (a - b).length(); + } + + static float distance_squared(const float2 &a, const float2 &b) + { + float2 diff = a - b; + return float2::dot(diff, diff); + } + + struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + float lambda; + float mu; + }; + + static isect_result isect_seg_seg(const float2 &v1, + const float2 &v2, + const float2 &v3, + const float2 &v4); + + friend bool operator==(const float2 &a, const float2 &b) + { + return a.x == b.x && a.y == b.y; + } + + friend bool operator!=(const float2 &a, const float2 &b) + { + return !(a == b); + } +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh new file mode 100644 index 00000000000..765f524fb31 --- /dev/null +++ b/source/blender/blenlib/BLI_float3.hh @@ -0,0 +1,320 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +#include + +#include "BLI_math_vector.h" + +namespace blender { + +struct float3 { + float x, y, z; + + float3() = default; + + float3(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} + { + } + + float3(const float (*ptr)[3]) : float3(static_cast(ptr[0])) + { + } + + explicit float3(float value) : x(value), y(value), z(value) + { + } + + explicit float3(int value) : x(value), y(value), z(value) + { + } + + float3(float x, float y, float z) : x{x}, y{y}, z{z} + { + } + + operator const float *() const + { + return &x; + } + + operator float *() + { + return &x; + } + + friend float3 operator+(const float3 &a, const float3 &b) + { + return {a.x + b.x, a.y + b.y, a.z + b.z}; + } + + friend float3 operator+(const float3 &a, const float &b) + { + return {a.x + b, a.y + b, a.z + b}; + } + + float3 &operator+=(const float3 &b) + { + this->x += b.x; + this->y += b.y; + this->z += b.z; + return *this; + } + + friend float3 operator-(const float3 &a, const float3 &b) + { + return {a.x - b.x, a.y - b.y, a.z - b.z}; + } + + friend float3 operator-(const float3 &a) + { + return {-a.x, -a.y, -a.z}; + } + + friend float3 operator-(const float3 &a, const float &b) + { + return {a.x - b, a.y - b, a.z - b}; + } + + float3 &operator-=(const float3 &b) + { + this->x -= b.x; + this->y -= b.y; + this->z -= b.z; + return *this; + } + + float3 &operator*=(float scalar) + { + this->x *= scalar; + this->y *= scalar; + this->z *= scalar; + return *this; + } + + float3 &operator*=(const float3 &other) + { + this->x *= other.x; + this->y *= other.y; + this->z *= other.z; + return *this; + } + + friend float3 operator*(const float3 &a, const float3 &b) + { + return {a.x * b.x, a.y * b.y, a.z * b.z}; + } + + friend float3 operator*(const float3 &a, float b) + { + return {a.x * b, a.y * b, a.z * b}; + } + + friend float3 operator*(float a, const float3 &b) + { + return b * a; + } + + friend float3 operator/(const float3 &a, float b) + { + BLI_assert(b != 0.0f); + return {a.x / b, a.y / b, a.z / b}; + } + + friend std::ostream &operator<<(std::ostream &stream, const float3 &v) + { + stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; + return stream; + } + + friend bool operator==(const float3 &a, const float3 &b) + { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + + friend bool operator!=(const float3 &a, const float3 &b) + { + return !(a == b); + } + + float normalize_and_get_length() + { + return normalize_v3(*this); + } + + /** + * Normalizes the vector in place. + */ + void normalize() + { + normalize_v3(*this); + } + + /** + * Returns a normalized vector. The original vector is not changed. + */ + float3 normalized() const + { + float3 result; + normalize_v3_v3(result, *this); + return result; + } + + float length() const + { + return len_v3(*this); + } + + float length_squared() const + { + return len_squared_v3(*this); + } + + bool is_zero() const + { + return this->x == 0.0f && this->y == 0.0f && this->z == 0.0f; + } + + void reflect(const float3 &normal) + { + *this = this->reflected(normal); + } + + float3 reflected(const float3 &normal) const + { + float3 result; + reflect_v3_v3v3(result, *this, normal); + return result; + } + + static float3 refract(const float3 &incident, const float3 &normal, const float eta) + { + float3 result; + float k = 1.0f - eta * eta * (1.0f - dot(normal, incident) * dot(normal, incident)); + if (k < 0.0f) { + result = float3(0.0f); + } + else { + result = eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal; + } + return result; + } + + static float3 faceforward(const float3 &vector, const float3 &incident, const float3 &reference) + { + return dot(reference, incident) < 0.0f ? vector : -vector; + } + + static float3 safe_divide(const float3 &a, const float3 &b) + { + float3 result; + result.x = (b.x == 0.0f) ? 0.0f : a.x / b.x; + result.y = (b.y == 0.0f) ? 0.0f : a.y / b.y; + result.z = (b.z == 0.0f) ? 0.0f : a.z / b.z; + return result; + } + + static float3 min(const float3 &a, const float3 &b) + { + return {a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z}; + } + + static float3 max(const float3 &a, const float3 &b) + { + return {a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z}; + } + + static void min_max(const float3 &vector, float3 &min, float3 &max) + { + min = float3::min(vector, min); + max = float3::max(vector, max); + } + + static float3 safe_divide(const float3 &a, const float b) + { + return (b != 0.0f) ? a / b : float3(0.0f); + } + + static float3 floor(const float3 &a) + { + return float3(floorf(a.x), floorf(a.y), floorf(a.z)); + } + + void invert() + { + x = -x; + y = -y; + z = -z; + } + + uint64_t hash() const + { + uint64_t x1 = *reinterpret_cast(&x); + uint64_t x2 = *reinterpret_cast(&y); + uint64_t x3 = *reinterpret_cast(&z); + return (x1 * 435109) ^ (x2 * 380867) ^ (x3 * 1059217); + } + + static float dot(const float3 &a, const float3 &b) + { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static float3 cross_high_precision(const float3 &a, const float3 &b) + { + float3 result; + cross_v3_v3v3_hi_prec(result, a, b); + return result; + } + + static float3 cross(const float3 &a, const float3 &b) + { + float3 result; + cross_v3_v3v3(result, a, b); + return result; + } + + static float3 project(const float3 &a, const float3 &b) + { + float3 result; + project_v3_v3v3(result, a, b); + return result; + } + + static float distance(const float3 &a, const float3 &b) + { + return (a - b).length(); + } + + static float distance_squared(const float3 &a, const float3 &b) + { + float3 diff = a - b; + return float3::dot(diff, diff); + } + + static float3 interpolate(const float3 &a, const float3 &b, float t) + { + return a * (1 - t) + b * t; + } + + static float3 abs(const float3 &a) + { + return float3(fabsf(a.x), fabsf(a.y), fabsf(a.z)); + } +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_float4.hh b/source/blender/blenlib/BLI_float4.hh new file mode 100644 index 00000000000..5b487f6d029 --- /dev/null +++ b/source/blender/blenlib/BLI_float4.hh @@ -0,0 +1,138 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +namespace blender { + +struct float4 { + float x, y, z, w; + + float4() = default; + + float4(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]}, w{ptr[3]} + { + } + + explicit float4(float value) : x(value), y(value), z(value), w(value) + { + } + + explicit float4(int value) : x(value), y(value), z(value), w(value) + { + } + + float4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) + { + } + + operator float *() + { + return &x; + } + + friend float4 operator+(const float4 &a, const float &b) + { + return {a.x + b, a.y + b, a.z + b, a.w + b}; + } + + operator const float *() const + { + return &x; + } + + float4 &operator+=(const float4 &other) + { + x += other.x; + y += other.y; + z += other.z; + w += other.w; + return *this; + } + + friend float4 operator-(const float4 &a, const float4 &b) + { + return {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; + } + + friend float4 operator-(const float4 &a, const float &b) + { + return {a.x - b, a.y - b, a.z - b, a.w - b}; + } + + friend float4 operator+(const float4 &a, const float4 &b) + { + return {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; + } + + friend float4 operator/(const float4 &a, float f) + { + BLI_assert(f != 0.0f); + return a * (1.0f / f); + } + + float4 &operator*=(float factor) + { + x *= factor; + y *= factor; + z *= factor; + w *= factor; + return *this; + } + + friend float4 operator*(const float4 &a, float b) + { + return {a.x * b, a.y * b, a.z * b, a.w * b}; + } + + friend float4 operator*(float a, const float4 &b) + { + return b * a; + } + + float length() const + { + return len_v4(*this); + } + + static float distance(const float4 &a, const float4 &b) + { + return (a - b).length(); + } + + static float4 safe_divide(const float4 &a, const float b) + { + return (b != 0.0f) ? a / b : float4(0.0f); + } + + static float4 interpolate(const float4 &a, const float4 &b, float t) + { + return a * (1 - t) + b * t; + } + + static float4 floor(const float4 &a) + { + return float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w)); + } + + static float4 normalize(const float4 &a) + { + const float t = len_v4(a); + return (t != 0.0f) ? a / t : float4(0.0f); + } +}; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_float4x4.hh b/source/blender/blenlib/BLI_float4x4.hh index 81c969d02d0..b7f839f4ddf 100644 --- a/source/blender/blenlib/BLI_float4x4.hh +++ b/source/blender/blenlib/BLI_float4x4.hh @@ -16,9 +16,8 @@ #pragma once +#include "BLI_float3.hh" #include "BLI_math_matrix.h" -#include "BLI_math_vec_types.hh" -#include "BLI_math_vector.h" namespace blender { @@ -64,7 +63,7 @@ struct float4x4 { * Without the negation, the result would be a so called improper rotation. That means it * contains a reflection. Such an improper rotation matrix could not be converted to another * representation of a rotation such as euler angles. */ - const float3 cross = -math::cross(forward, up); + const float3 cross = -float3::cross(forward, up); float4x4 matrix; matrix.values[0][0] = forward.x; diff --git a/source/blender/blenlib/BLI_gsqueue.h b/source/blender/blenlib/BLI_gsqueue.h index 8b32c09b56b..a35c743c80b 100644 --- a/source/blender/blenlib/BLI_gsqueue.h +++ b/source/blender/blenlib/BLI_gsqueue.h @@ -31,7 +31,7 @@ extern "C" { typedef struct _GSQueue GSQueue; -GSQueue *BLI_gsqueue_new(const size_t elem_size); +GSQueue *BLI_gsqueue_new(size_t elem_size); /** * Returns true if the queue is empty, false otherwise. */ diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 64852b95ae4..f73d1f22502 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -85,7 +85,7 @@ void *BLI_findptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, - const size_t bytes_size, + size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** * Find the first item in the list that matches the given string, or the given index as fallback. @@ -96,7 +96,7 @@ void *BLI_listbase_bytes_find(const ListBase *listbase, */ void *BLI_listbase_string_or_index_find(const struct ListBase *listbase, const char *string, - const size_t string_offset, + size_t string_offset, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /* Find backwards. */ @@ -133,7 +133,7 @@ void *BLI_rfindptr(const struct ListBase *listbase, */ void *BLI_listbase_bytes_rfind(const ListBase *listbase, const void *bytes, - const size_t bytes_size, + size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** diff --git a/source/blender/blenlib/BLI_math_boolean.hh b/source/blender/blenlib/BLI_math_boolean.hh index 8cf93c82dec..20fd00b2aa4 100644 --- a/source/blender/blenlib/BLI_math_boolean.hh +++ b/source/blender/blenlib/BLI_math_boolean.hh @@ -21,11 +21,13 @@ * \brief Math vector functions needed specifically for mesh intersect and boolean. */ -#include "BLI_math_vec_types.hh" +#include "BLI_double2.hh" +#include "BLI_double3.hh" #ifdef WITH_GMP # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" +# include "BLI_mpq2.hh" +# include "BLI_mpq3.hh" #endif namespace blender { diff --git a/source/blender/blenlib/BLI_math_vec_mpq_types.hh b/source/blender/blenlib/BLI_math_vec_mpq_types.hh deleted file mode 100644 index 36eb0cac83c..00000000000 --- a/source/blender/blenlib/BLI_math_vec_mpq_types.hh +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#ifdef WITH_GMP - -# include "BLI_math_mpq.hh" -# include "BLI_math_vec_types.hh" - -namespace blender { - -using mpq2 = vec_base; -using mpq3 = vec_base; - -namespace math { - -uint64_t hash_mpq_class(const mpq_class &value); - -template<> inline uint64_t vector_hash(const mpq2 &vec) -{ - return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33); -} - -template<> inline uint64_t vector_hash(const mpq3 &vec) -{ - return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33) ^ (hash_mpq_class(vec.z) * 33 * 37); -} - -/** - * Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ -template<> inline mpq_class length(const mpq2 &a) -{ - return mpq_class(sqrt(length_squared(a).get_d())); -} - -/** - * Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ -template<> inline mpq_class length(const mpq3 &a) -{ - return mpq_class(sqrt(length_squared(a).get_d())); -} - -/** - * The buffer avoids allocating a temporary variable. - */ -inline mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) -{ - buffer = a; - buffer -= b; - return dot(buffer, buffer); -} - -/** - * The buffer avoids allocating a temporary variable. - */ -inline mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) -{ - buffer = a; - buffer *= b; - buffer.x += buffer.y; - buffer.x += buffer.z; - return buffer.x; -} - -} // namespace math - -} // namespace blender - -#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh deleted file mode 100644 index 52aacd294e4..00000000000 --- a/source/blender/blenlib/BLI_math_vec_types.hh +++ /dev/null @@ -1,566 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright 2022, Blender Foundation. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include -#include -#include -#include - -#include "BLI_math_vector.hh" -#include "BLI_utildefines.h" - -namespace blender { - -/* clang-format off */ -template -using as_uint_type = std::conditional_t>>>; -/* clang-format on */ - -template struct vec_struct_base { - std::array values; -}; - -template struct vec_struct_base { - T x, y; -}; - -template struct vec_struct_base { - T x, y, z; -}; - -template struct vec_struct_base { - T x, y, z, w; -}; - -template struct vec_base : public vec_struct_base { - - static constexpr int type_length = Size; - - using base_type = T; - using uint_type = vec_base, Size>; - - vec_base() = default; - - explicit vec_base(uint value) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(value); - } - } - - explicit vec_base(int value) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(value); - } - } - - explicit vec_base(float value) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(value); - } - } - - explicit vec_base(double value) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(value); - } - } - -/* Workaround issue with template BLI_ENABLE_IF((Size == 2)) not working. */ -#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test)) - - template vec_base(T _x, T _y) - { - (*this)[0] = _x; - (*this)[1] = _y; - } - - template vec_base(T _x, T _y, T _z) - { - (*this)[0] = _x; - (*this)[1] = _y; - (*this)[2] = _z; - } - - template vec_base(T _x, T _y, T _z, T _w) - { - (*this)[0] = _x; - (*this)[1] = _y; - (*this)[2] = _z; - (*this)[3] = _w; - } - - /** Mixed scalar-vector constructors. */ - - template - constexpr vec_base(const vec_base &xy, T z) - : vec_base(static_cast(xy.x), static_cast(xy.y), z) - { - } - - template - constexpr vec_base(T x, const vec_base &yz) - : vec_base(x, static_cast(yz.x), static_cast(yz.y)) - { - } - - template - vec_base(vec_base xyz, T w) - : vec_base( - static_cast(xyz.x), static_cast(xyz.y), static_cast(xyz.z), static_cast(w)) - { - } - - template - vec_base(T x, vec_base yzw) - : vec_base( - static_cast(x), static_cast(yzw.x), static_cast(yzw.y), static_cast(yzw.z)) - { - } - - template - vec_base(vec_base xy, vec_base zw) - : vec_base( - static_cast(xy.x), static_cast(xy.y), static_cast(zw.x), static_cast(zw.y)) - { - } - - template - vec_base(vec_base xy, T z, T w) - : vec_base(static_cast(xy.x), static_cast(xy.y), static_cast(z), static_cast(w)) - { - } - - template - vec_base(T x, vec_base yz, T w) - : vec_base(static_cast(x), static_cast(yz.x), static_cast(yz.y), static_cast(w)) - { - } - - template - vec_base(T x, T y, vec_base zw) - : vec_base(static_cast(x), static_cast(y), static_cast(zw.x), static_cast(zw.y)) - { - } - - /** Masking. */ - - template Size)> - explicit vec_base(const vec_base &other) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(other[i]); - } - } - -#undef BLI_ENABLE_IF_VEC - - /** Conversion from pointers (from C-style vectors). */ - - vec_base(const T *ptr) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = ptr[i]; - } - } - - vec_base(const T (*ptr)[Size]) : vec_base(static_cast(ptr[0])) - { - } - - /** Conversion from other vector types. */ - - template explicit vec_base(const vec_base &vec) - { - for (int i = 0; i < Size; i++) { - (*this)[i] = static_cast(vec[i]); - } - } - - /** C-style pointer dereference. */ - - operator const T *() const - { - return reinterpret_cast(this); - } - - operator T *() - { - return reinterpret_cast(this); - } - - /** Array access. */ - - const T &operator[](int index) const - { - BLI_assert(index >= 0); - BLI_assert(index < Size); - return reinterpret_cast(this)[index]; - } - - T &operator[](int index) - { - BLI_assert(index >= 0); - BLI_assert(index < Size); - return reinterpret_cast(this)[index]; - } - - /** Internal Operators Macro. */ - -#define BLI_INT_OP(_T) template))> - -#define BLI_VEC_OP_IMPL(_result, _i, _op) \ - vec_base _result; \ - for (int _i = 0; _i < Size; _i++) { \ - _op; \ - } \ - return _result; - -#define BLI_VEC_OP_IMPL_SELF(_i, _op) \ - for (int _i = 0; _i < Size; _i++) { \ - _op; \ - } \ - return *this; - - /** Arithmetic operators. */ - - friend vec_base operator+(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b[i]); - } - - friend vec_base operator+(const vec_base &a, const T &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b); - } - - friend vec_base operator+(const T &a, const vec_base &b) - { - return b + a; - } - - vec_base &operator+=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b[i]); - } - - vec_base &operator+=(const T &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b); - } - - friend vec_base operator-(const vec_base &a) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = -a[i]); - } - - friend vec_base operator-(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b[i]); - } - - friend vec_base operator-(const vec_base &a, const T &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b); - } - - friend vec_base operator-(const T &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a - b[i]); - } - - vec_base &operator-=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b[i]); - } - - vec_base &operator-=(const T &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b); - } - - friend vec_base operator*(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b[i]); - } - - friend vec_base operator*(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b); - } - - friend vec_base operator*(T a, const vec_base &b) - { - return b * a; - } - - vec_base &operator*=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b); - } - - vec_base &operator*=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b[i]); - } - - friend vec_base operator/(const vec_base &a, const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b[i]); - } - - friend vec_base operator/(const vec_base &a, T b) - { - BLI_assert(b != T(0)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b); - } - - friend vec_base operator/(T a, const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a / b[i]); - } - - vec_base &operator/=(T b) - { - BLI_assert(b != T(0)); - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b); - } - - vec_base &operator/=(const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b[i]); - } - - /** Binary operators. */ - - BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b[i]); - } - - BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b); - } - - BLI_INT_OP(T) friend vec_base operator&(T a, const vec_base &b) - { - return b & a; - } - - BLI_INT_OP(T) vec_base &operator&=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b); - } - - BLI_INT_OP(T) vec_base &operator&=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b[i]); - } - - BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b[i]); - } - - BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b); - } - - BLI_INT_OP(T) friend vec_base operator|(T a, const vec_base &b) - { - return b | a; - } - - BLI_INT_OP(T) vec_base &operator|=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b); - } - - BLI_INT_OP(T) vec_base &operator|=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b[i]); - } - - BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b[i]); - } - - BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b); - } - - BLI_INT_OP(T) friend vec_base operator^(T a, const vec_base &b) - { - return b ^ a; - } - - BLI_INT_OP(T) vec_base &operator^=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b); - } - - BLI_INT_OP(T) vec_base &operator^=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b[i]); - } - - BLI_INT_OP(T) friend vec_base operator~(const vec_base &a) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = ~a[i]); - } - - /** Bit-shift operators. */ - - BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b[i]); - } - - BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b); - } - - BLI_INT_OP(T) vec_base &operator<<=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b); - } - - BLI_INT_OP(T) vec_base &operator<<=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b[i]); - } - - BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, const vec_base &b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b[i]); - } - - BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, T b) - { - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b); - } - - BLI_INT_OP(T) vec_base &operator>>=(T b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b); - } - - BLI_INT_OP(T) vec_base &operator>>=(const vec_base &b) - { - BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b[i]); - } - - /** Modulo operators. */ - - BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b[i]); - } - - BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, T b) - { - BLI_assert(b != 0); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b); - } - - BLI_INT_OP(T) friend vec_base operator%(T a, const vec_base &b) - { - BLI_assert(!math::is_any_zero(b)); - BLI_VEC_OP_IMPL(ret, i, ret[i] = a % b[i]); - } - -#undef BLI_INT_OP -#undef BLI_VEC_OP_IMPL -#undef BLI_VEC_OP_IMPL_SELF - - /** Compare. */ - - friend bool operator==(const vec_base &a, const vec_base &b) - { - for (int i = 0; i < Size; i++) { - if (a[i] != b[i]) { - return false; - } - } - return true; - } - - friend bool operator!=(const vec_base &a, const vec_base &b) - { - return !(a == b); - } - - /** Misc. */ - - uint64_t hash() const - { - return math::vector_hash(*this); - } - - friend std::ostream &operator<<(std::ostream &stream, const vec_base &v) - { - stream << "("; - for (int i = 0; i < Size; i++) { - stream << v[i]; - if (i != Size - 1) { - stream << ", "; - } - } - stream << ")"; - return stream; - } -}; - -using int2 = vec_base; -using int3 = vec_base; -using int4 = vec_base; - -using uint2 = vec_base; -using uint3 = vec_base; -using uint4 = vec_base; - -using float2 = vec_base; -using float3 = vec_base; -using float4 = vec_base; - -using double2 = vec_base; -using double3 = vec_base; -using double4 = vec_base; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_math_vector.hh b/source/blender/blenlib/BLI_math_vector.hh deleted file mode 100644 index e7d765df842..00000000000 --- a/source/blender/blenlib/BLI_math_vector.hh +++ /dev/null @@ -1,399 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright 2022, Blender Foundation. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include -#include - -#include "BLI_math_base_safe.h" -#include "BLI_math_vector.h" -#include "BLI_span.hh" -#include "BLI_utildefines.h" - -#ifdef WITH_GMP -# include "BLI_math_mpq.hh" -#endif - -namespace blender::math { - -#ifndef NDEBUG -# define BLI_ASSERT_UNIT(v) \ - { \ - const float _test_unit = length_squared(v); \ - BLI_assert(!(std::abs(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \ - !(std::abs(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \ - } \ - (void)0 -#else -# define BLI_ASSERT_UNIT(v) (void)(v) -#endif - -#define bT typename T::base_type - -#ifdef WITH_GMP -# define BLI_ENABLE_IF_FLT_VEC(T) \ - BLI_ENABLE_IF((std::is_floating_point_v || \ - std::is_same_v)) -#else -# define BLI_ENABLE_IF_FLT_VEC(T) BLI_ENABLE_IF((std::is_floating_point_v)) -#endif - -#define BLI_ENABLE_IF_INT_VEC(T) BLI_ENABLE_IF((std::is_integral_v)) - -template inline bool is_zero(const T &a) -{ - for (int i = 0; i < T::type_length; i++) { - if (a[i] != bT(0)) { - return false; - } - } - return true; -} - -template inline bool is_any_zero(const T &a) -{ - for (int i = 0; i < T::type_length; i++) { - if (a[i] == bT(0)) { - return true; - } - } - return false; -} - -template inline T abs(const T &a) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = a[i] >= 0 ? a[i] : -a[i]; - } - return result; -} - -template inline T min(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = a[i] < b[i] ? a[i] : b[i]; - } - return result; -} - -template inline T max(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = a[i] > b[i] ? a[i] : b[i]; - } - return result; -} - -template inline T clamp(const T &a, const T &min_v, const T &max_v) -{ - T result = a; - for (int i = 0; i < T::type_length; i++) { - CLAMP(result[i], min_v[i], max_v[i]); - } - return result; -} - -template inline T clamp(const T &a, const bT &min_v, const bT &max_v) -{ - T result = a; - for (int i = 0; i < T::type_length; i++) { - CLAMP(result[i], min_v, max_v); - } - return result; -} - -template inline T mod(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - BLI_assert(b[i] != 0); - result[i] = std::fmod(a[i], b[i]); - } - return result; -} - -template inline T mod(const T &a, bT b) -{ - BLI_assert(b != 0); - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = std::fmod(a[i], b); - } - return result; -} - -template inline T safe_mod(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = (b[i] != 0) ? std::fmod(a[i], b[i]) : 0; - } - return result; -} - -template inline T safe_mod(const T &a, bT b) -{ - if (b == 0) { - return T(0.0f); - } - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = std::fmod(a[i], b); - } - return result; -} - -template inline void min_max(const T &vector, T &min_vec, T &max_vec) -{ - min_vec = min(vector, min_vec); - max_vec = max(vector, max_vec); -} - -template inline T safe_divide(const T &a, const T &b) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = (b[i] == 0) ? 0 : a[i] / b[i]; - } - return result; -} - -template inline T safe_divide(const T &a, const bT b) -{ - return (b != 0) ? a / b : T(0.0f); -} - -template inline T floor(const T &a) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = std::floor(a[i]); - } - return result; -} - -template inline T ceil(const T &a) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = std::ceil(a[i]); - } - return result; -} - -template inline T fract(const T &a) -{ - T result; - for (int i = 0; i < T::type_length; i++) { - result[i] = a[i] - std::floor(a[i]); - } - return result; -} - -template inline bT dot(const T &a, const T &b) -{ - bT result = a[0] * b[0]; - for (int i = 1; i < T::type_length; i++) { - result += a[i] * b[i]; - } - return result; -} - -template inline bT length_manhattan(const T &a) -{ - bT result = std::abs(a[0]); - for (int i = 1; i < T::type_length; i++) { - result += std::abs(a[i]); - } - return result; -} - -template inline bT length_squared(const T &a) -{ - return dot(a, a); -} - -template inline bT length(const T &a) -{ - return std::sqrt(length_squared(a)); -} - -template inline bT distance_manhattan(const T &a, const T &b) -{ - return length_manhattan(a - b); -} - -template inline bT distance_squared(const T &a, const T &b) -{ - return length_squared(a - b); -} - -template inline bT distance(const T &a, const T &b) -{ - return length(a - b); -} - -template uint64_t vector_hash(const T &vec) -{ - BLI_STATIC_ASSERT(T::type_length <= 4, "Longer types need to implement vector_hash themself."); - const typename T::uint_type &uvec = *reinterpret_cast(&vec); - uint64_t result; - result = uvec[0] * uint64_t(435109); - if constexpr (T::type_length > 1) { - result ^= uvec[1] * uint64_t(380867); - } - if constexpr (T::type_length > 2) { - result ^= uvec[2] * uint64_t(1059217); - } - if constexpr (T::type_length > 3) { - result ^= uvec[3] * uint64_t(2002613); - } - return result; -} - -template inline T reflect(const T &incident, const T &normal) -{ - BLI_ASSERT_UNIT(normal); - return incident - 2.0 * dot(normal, incident) * normal; -} - -template -inline T refract(const T &incident, const T &normal, const bT eta) -{ - float dot_ni = dot(normal, incident); - float k = 1.0f - eta * eta * (1.0f - dot_ni * dot_ni); - if (k < 0.0f) { - return T(0.0f); - } - return eta * incident - (eta * dot_ni + sqrt(k)) * normal; -} - -template inline T project(const T &p, const T &v_proj) -{ - if (UNLIKELY(is_zero(v_proj))) { - return T(0.0f); - } - return v_proj * (dot(p, v_proj) / dot(v_proj, v_proj)); -} - -template -inline T normalize_and_get_length(const T &v, bT &out_length) -{ - out_length = length_squared(v); - /* A larger value causes normalize errors in a scaled down models with camera extreme close. */ - constexpr bT threshold = std::is_same_v ? 1.0e-70 : 1.0e-35f; - if (out_length > threshold) { - out_length = sqrt(out_length); - return v / out_length; - } - /* Either the vector is small or one of it's values contained `nan`. */ - out_length = 0.0; - return T(0.0); -} - -template inline T normalize(const T &v) -{ - bT len; - return normalize_and_get_length(v, len); -} - -template -inline T cross(const T &a, const T &b) -{ - return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; -} - -template)), - BLI_ENABLE_IF((T::type_length == 3))> -inline T cross_high_precision(const T &a, const T &b) -{ - return {(float)((double)a.y * b.z - (double)a.z * b.y), - (float)((double)a.z * b.x - (double)a.x * b.z), - (float)((double)a.x * b.y - (double)a.y * b.x)}; -} - -template -inline T cross_poly(Span poly) -{ - /* Newell's Method. */ - int nv = static_cast(poly.size()); - if (nv < 3) { - return T(0, 0, 0); - } - const T *v_prev = &poly[nv - 1]; - const T *v_curr = &poly[0]; - T n(0, 0, 0); - for (int i = 0; i < nv;) { - n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); - n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); - n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); - v_prev = v_curr; - ++i; - if (i < nv) { - v_curr = &poly[i]; - } - } - return n; -} - -template inline T interpolate(const T &a, const T &b, bT t) -{ - return a * (1 - t) + b * t; -} - -template -inline T faceforward(const T &vector, const T &incident, const T &reference) -{ - return (dot(reference, incident) < 0) ? vector : -vector; -} - -template inline int dominant_axis(const T &a) -{ - T b = abs(a); - return ((b.x > b.y) ? ((b.x > b.z) ? 0 : 2) : ((b.y > b.z) ? 1 : 2)); -} - -/** Intersections. */ - -template struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - bT lambda; -}; - -template -isect_result isect_seg_seg(const T &v1, const T &v2, const T &v3, const T &v4); - -#undef BLI_ENABLE_IF_FLT_VEC -#undef BLI_ENABLE_IF_INT_VEC -#undef bT - -} // namespace blender::math diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h index 4ac4712bc8c..bcfe2efc5e5 100644 --- a/source/blender/blenlib/BLI_memarena.h +++ b/source/blender/blenlib/BLI_memarena.h @@ -38,13 +38,13 @@ extern "C" { struct MemArena; typedef struct MemArena MemArena; -struct MemArena *BLI_memarena_new(const size_t bufsize, +struct MemArena *BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC; void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_malloc(struct MemArena *ma) ATTR_NONNULL(1); void BLI_memarena_use_calloc(struct MemArena *ma) ATTR_NONNULL(1); -void BLI_memarena_use_align(struct MemArena *ma, const size_t align) ATTR_NONNULL(1); +void BLI_memarena_use_align(struct MemArena *ma, size_t align) ATTR_NONNULL(1); void *BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2); void *BLI_memarena_calloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT diff --git a/source/blender/blenlib/BLI_memory_utils.h b/source/blender/blenlib/BLI_memory_utils.h index 79e25e26040..09d8f646905 100644 --- a/source/blender/blenlib/BLI_memory_utils.h +++ b/source/blender/blenlib/BLI_memory_utils.h @@ -29,7 +29,7 @@ extern "C" { /* it may be defined already */ #ifndef __BLI_UTILDEFINES_H__ -bool BLI_memory_is_zero(const void *arr, const size_t size); +bool BLI_memory_is_zero(const void *arr, size_t size); #endif #ifdef __cplusplus diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh index 9a5be79b61e..37691017c12 100644 --- a/source/blender/blenlib/BLI_memory_utils.hh +++ b/source/blender/blenlib/BLI_memory_utils.hh @@ -557,4 +557,13 @@ Container &move_assign_container(Container &dst, Container &&src) noexcept( return dst; } +/** + * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for + * SFINAE in common cases. + * + * \note Often one has to invoke this macro with double parenthesis. That's because the condition + * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. + */ +#define BLI_ENABLE_IF(condition) typename std::enable_if_t * = nullptr + } // namespace blender diff --git a/source/blender/blenlib/BLI_mesh_intersect.hh b/source/blender/blenlib/BLI_mesh_intersect.hh index 0ebee6f16a8..71a8abb822f 100644 --- a/source/blender/blenlib/BLI_mesh_intersect.hh +++ b/source/blender/blenlib/BLI_mesh_intersect.hh @@ -28,11 +28,12 @@ # include # include "BLI_array.hh" +# include "BLI_double3.hh" +# include "BLI_float3.hh" # include "BLI_index_range.hh" # include "BLI_map.hh" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" +# include "BLI_mpq3.hh" # include "BLI_span.hh" # include "BLI_utility_mixins.hh" # include "BLI_vector.hh" diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh new file mode 100644 index 00000000000..18bc8821d9c --- /dev/null +++ b/source/blender/blenlib/BLI_mpq2.hh @@ -0,0 +1,184 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#ifdef WITH_GMP + +# include "BLI_math_mpq.hh" +# include "BLI_mpq3.hh" + +namespace blender { + +struct mpq2 { + mpq_class x, y; + + mpq2() = default; + + mpq2(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]} + { + } + + mpq2(mpq_class x, mpq_class y) : x(x), y(y) + { + } + + mpq2(const mpq2 &other) : x(other.x), y(other.y) + { + } + + mpq2(mpq2 &&other) noexcept : x(std::move(other.x)), y(std::move(other.y)) + { + } + + ~mpq2() = default; + + mpq2 &operator=(const mpq2 &other) + { + if (this != &other) { + x = other.x; + y = other.y; + } + return *this; + } + + mpq2 &operator=(mpq2 &&other) noexcept + { + x = std::move(other.x); + y = std::move(other.y); + return *this; + } + + mpq2(const mpq3 &other) : x(other.x), y(other.y) + { + } + + operator mpq_class *() + { + return &x; + } + + operator const mpq_class *() const + { + return &x; + } + + /** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ + mpq_class length() const + { + mpq_class lsquared = dot(*this, *this); + return mpq_class(sqrt(lsquared.get_d())); + } + + friend mpq2 operator+(const mpq2 &a, const mpq2 &b) + { + return {a.x + b.x, a.y + b.y}; + } + + friend mpq2 operator-(const mpq2 &a, const mpq2 &b) + { + return {a.x - b.x, a.y - b.y}; + } + + friend mpq2 operator*(const mpq2 &a, mpq_class b) + { + return {a.x * b, a.y * b}; + } + + friend mpq2 operator/(const mpq2 &a, mpq_class b) + { + BLI_assert(b != 0); + return {a.x / b, a.y / b}; + } + + friend mpq2 operator*(mpq_class a, const mpq2 &b) + { + return b * a; + } + + friend bool operator==(const mpq2 &a, const mpq2 &b) + { + return a.x == b.x && a.y == b.y; + } + + friend bool operator!=(const mpq2 &a, const mpq2 &b) + { + return a.x != b.x || a.y != b.y; + } + + friend std::ostream &operator<<(std::ostream &stream, const mpq2 &v) + { + stream << "(" << v.x << ", " << v.y << ")"; + return stream; + } + + static mpq_class dot(const mpq2 &a, const mpq2 &b) + { + return a.x * b.x + a.y * b.y; + } + + static mpq2 interpolate(const mpq2 &a, const mpq2 &b, mpq_class t) + { + return a * (1 - t) + b * t; + } + + static mpq2 abs(const mpq2 &a) + { + mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; + mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; + return mpq2(abs_x, abs_y); + } + + static mpq_class distance(const mpq2 &a, const mpq2 &b) + { + return (a - b).length(); + } + + static mpq_class distance_squared(const mpq2 &a, const mpq2 &b) + { + mpq2 diff = a - b; + return dot(diff, diff); + } + + struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + mpq_class lambda; + }; + + static isect_result isect_seg_seg(const mpq2 &v1, + const mpq2 &v2, + const mpq2 &v3, + const mpq2 &v4); + + /** There is a sensible use for hashing on exact arithmetic types. */ + uint64_t hash() const; +}; + +} // namespace blender + +#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_mpq3.hh b/source/blender/blenlib/BLI_mpq3.hh new file mode 100644 index 00000000000..b9eda2ad7e1 --- /dev/null +++ b/source/blender/blenlib/BLI_mpq3.hh @@ -0,0 +1,297 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#ifdef WITH_GMP + +# include + +# include "BLI_math.h" +# include "BLI_math_mpq.hh" +# include "BLI_span.hh" + +namespace blender { + +struct mpq3 { + mpq_class x, y, z; + + mpq3() = default; + + mpq3(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} + { + } + + mpq3(const mpq_class (*ptr)[3]) : mpq3((const mpq_class *)ptr) + { + } + + explicit mpq3(mpq_class value) : x(value), y(value), z(value) + { + } + + explicit mpq3(int value) : x(value), y(value), z(value) + { + } + + mpq3(mpq_class x, mpq_class y, mpq_class z) : x{x}, y{y}, z{z} + { + } + + operator const mpq_class *() const + { + return &x; + } + + operator mpq_class *() + { + return &x; + } + + /* Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ + mpq_class normalize_and_get_length() + { + double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; + double len = normalize_v3_db(dv); + this->x = mpq_class(dv[0]); + this->y = mpq_class(dv[1]); + this->z = mpq_class(dv[2]); + return len; + } + + mpq3 normalized() const + { + double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; + double dr[3]; + normalize_v3_v3_db(dr, dv); + return mpq3(mpq_class(dr[0]), mpq_class(dr[1]), mpq_class(dr[2])); + } + + /* Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of double. + */ + mpq_class length() const + { + mpq_class lsquared = this->length_squared(); + double dsquared = lsquared.get_d(); + double d = sqrt(dsquared); + return mpq_class(d); + } + + mpq_class length_squared() const + { + return x * x + y * y + z * z; + } + + void reflect(const mpq3 &normal) + { + *this = this->reflected(normal); + } + + mpq3 reflected(const mpq3 &normal) const + { + mpq3 result; + const mpq_class dot2 = 2 * dot(*this, normal); + result.x = this->x - (dot2 * normal.x); + result.y = this->y - (dot2 * normal.y); + result.z = this->z - (dot2 * normal.z); + return result; + } + + static mpq3 safe_divide(const mpq3 &a, const mpq3 &b) + { + mpq3 result; + result.x = (b.x == 0) ? mpq_class(0) : a.x / b.x; + result.y = (b.y == 0) ? mpq_class(0) : a.y / b.y; + result.z = (b.z == 0) ? mpq_class(0) : a.z / b.z; + return result; + } + + void invert() + { + x = -x; + y = -y; + z = -z; + } + + friend mpq3 operator+(const mpq3 &a, const mpq3 &b) + { + return mpq3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + void operator+=(const mpq3 &b) + { + this->x += b.x; + this->y += b.y; + this->z += b.z; + } + + friend mpq3 operator-(const mpq3 &a, const mpq3 &b) + { + return mpq3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + friend mpq3 operator-(const mpq3 &a) + { + return mpq3(-a.x, -a.y, -a.z); + } + + void operator-=(const mpq3 &b) + { + this->x -= b.x; + this->y -= b.y; + this->z -= b.z; + } + + void operator*=(mpq_class scalar) + { + this->x *= scalar; + this->y *= scalar; + this->z *= scalar; + } + + void operator*=(const mpq3 &other) + { + this->x *= other.x; + this->y *= other.y; + this->z *= other.z; + } + + friend mpq3 operator*(const mpq3 &a, const mpq3 &b) + { + return {a.x * b.x, a.y * b.y, a.z * b.z}; + } + + friend mpq3 operator*(const mpq3 &a, const mpq_class &b) + { + return mpq3(a.x * b, a.y * b, a.z * b); + } + + friend mpq3 operator*(const mpq_class &a, const mpq3 &b) + { + return mpq3(a * b.x, a * b.y, a * b.z); + } + + friend mpq3 operator/(const mpq3 &a, const mpq_class &b) + { + BLI_assert(b != 0); + return mpq3(a.x / b, a.y / b, a.z / b); + } + + friend bool operator==(const mpq3 &a, const mpq3 &b) + { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + + friend bool operator!=(const mpq3 &a, const mpq3 &b) + { + return a.x != b.x || a.y != b.y || a.z != b.z; + } + + friend std::ostream &operator<<(std::ostream &stream, const mpq3 &v) + { + stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; + return stream; + } + + static mpq_class dot(const mpq3 &a, const mpq3 &b) + { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) + { + buffer = a; + buffer *= b; + buffer.x += buffer.y; + buffer.x += buffer.z; + return buffer.x; + } + + static mpq3 cross(const mpq3 &a, const mpq3 &b) + { + return mpq3(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]); + } + + static mpq3 cross_high_precision(const mpq3 &a, const mpq3 &b) + { + return cross(a, b); + } + + static mpq3 project(const mpq3 &a, const mpq3 &b) + { + const mpq_class mul = mpq3::dot(a, b) / mpq3::dot(b, b); + return mpq3(mul * b[0], mul * b[1], mul * b[2]); + } + + static mpq_class distance(const mpq3 &a, const mpq3 &b) + { + mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); + return diff.length(); + } + + static mpq_class distance_squared(const mpq3 &a, const mpq3 &b) + { + mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); + return mpq3::dot(diff, diff); + } + + static mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) + { + buffer = a; + buffer -= b; + return mpq3::dot(buffer, buffer); + } + + static mpq3 interpolate(const mpq3 &a, const mpq3 &b, mpq_class t) + { + mpq_class s = 1 - t; + return mpq3(a.x * s + b.x * t, a.y * s + b.y * t, a.z * s + b.z * t); + } + + static mpq3 abs(const mpq3 &a) + { + mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; + mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; + mpq_class abs_z = (a.z >= 0) ? a.z : -a.z; + return mpq3(abs_x, abs_y, abs_z); + } + + static int dominant_axis(const mpq3 &a) + { + mpq_class x = (a.x >= 0) ? a.x : -a.x; + mpq_class y = (a.y >= 0) ? a.y : -a.y; + mpq_class z = (a.z >= 0) ? a.z : -a.z; + return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); + } + + static mpq3 cross_poly(Span poly); + + /** There is a sensible use for hashing on exact arithmetic types. */ + uint64_t hash() const; +}; + +uint64_t hash_mpq_class(const mpq_class &value); + +} // namespace blender + +#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_noise.hh b/source/blender/blenlib/BLI_noise.hh index 297c65c250a..4f68ef17ca2 100644 --- a/source/blender/blenlib/BLI_noise.hh +++ b/source/blender/blenlib/BLI_noise.hh @@ -16,7 +16,9 @@ #pragma once -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" +#include "BLI_float4.hh" namespace blender::noise { diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 16f479cb3b8..658cc0c3825 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -75,16 +75,15 @@ bool BLI_make_existing_file(const char *name); * - Doesn't use CWD, or deal with relative paths. * - Only fill's in \a dir and \a file when they are non NULL. */ -void BLI_split_dirfile( - const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen); +void BLI_split_dirfile(const char *string, char *dir, char *file, size_t dirlen, size_t filelen); /** * Copies the parent directory part of string into `dir`, max length `dirlen`. */ -void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen); +void BLI_split_dir_part(const char *string, char *dir, size_t dirlen); /** * Copies the leaf filename part of string into `file`, max length `filelen`. */ -void BLI_split_file_part(const char *string, char *file, const size_t filelen); +void BLI_split_file_part(const char *string, char *file, size_t filelen); /** * Returns a pointer to the last extension (e.g. the position of the last period). * Returns NULL if there is no extension. @@ -94,7 +93,7 @@ const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(); /** * Append a filename to a dir, ensuring slash separates. */ -void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__restrict file) +void BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict file) ATTR_NONNULL(); /** * Simple appending of filename to dir, does not check for valid path! @@ -104,7 +103,7 @@ void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__re * that de-duplicates separators and can handle an arbitrary number of paths. */ void BLI_join_dirfile(char *__restrict dst, - const size_t maxlen, + size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL(); /** @@ -114,7 +113,7 @@ void BLI_join_dirfile(char *__restrict dst, * \note If you want a trailing slash, add `SEP_STR` as the last path argument, * duplicate slashes will be cleaned up. */ -size_t BLI_path_join(char *__restrict dst, const size_t dst_len, const char *path_first, ...) +size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first, ...) ATTR_NONNULL(1, 3) ATTR_SENTINEL(0); /** * Like Python's `os.path.basename()` @@ -164,12 +163,12 @@ void BLI_path_slash_rstrip(char *string) ATTR_NONNULL(); void BLI_path_slash_native(char *path) ATTR_NONNULL(); #ifdef _WIN32 -bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen); +bool BLI_path_program_extensions_add_win32(char *name, size_t maxlen); #endif /** * Search for a binary (executable) */ -bool BLI_path_program_search(char *fullname, const size_t maxlen, const char *name); +bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name); /** * \return true when `str` end with `ext` (case insensitive). @@ -353,7 +352,7 @@ bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(); * This is _not_ something Blender's internal paths support, instead they use the "//" prefix. * In most cases #BLI_path_abs should be used instead. */ -bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) ATTR_NONNULL(); +bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL(); /** * Replaces `file` with a relative version (prefixed by "//") such that #BLI_path_abs, given * the same `relfile`, will convert it back to its original value. diff --git a/source/blender/blenlib/BLI_rand.hh b/source/blender/blenlib/BLI_rand.hh index 667d6df8996..cc9e9b374d7 100644 --- a/source/blender/blenlib/BLI_rand.hh +++ b/source/blender/blenlib/BLI_rand.hh @@ -20,8 +20,9 @@ #pragma once +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h index 653f5f61c9e..eb4e69a42d4 100644 --- a/source/blender/blenlib/BLI_stack.h +++ b/source/blender/blenlib/BLI_stack.h @@ -28,13 +28,13 @@ extern "C" { typedef struct BLI_Stack BLI_Stack; -BLI_Stack *BLI_stack_new_ex(const size_t elem_size, +BLI_Stack *BLI_stack_new_ex(size_t elem_size, const char *description, - const size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** * Create a new homogeneous stack with elements of 'elem_size' bytes. */ -BLI_Stack *BLI_stack_new(const size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT +BLI_Stack *BLI_stack_new(size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index a82e97914db..8177545911c 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -42,8 +42,7 @@ extern "C" { * \param len: The number of bytes to duplicate * \retval Returns the duplicated string */ -char *BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); +char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /** * Duplicates the cstring \a str into a newly mallocN'd @@ -74,8 +73,7 @@ char *BLI_strdupcat(const char *__restrict str1, * the size of dst) * \retval Returns dst */ -char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) - ATTR_NONNULL(); +char *BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(); /** * Like BLI_strncpy but ensures dst is always padded by given char, @@ -107,7 +105,7 @@ char *BLI_strncpy_ensure_pad(char *__restrict dst, */ size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, - const size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); @@ -186,7 +184,7 @@ void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL(); * \note Larger tables should use a hash table. */ bool BLI_str_replace_table_exact(char *string, - const size_t string_len, + size_t string_len, const char *replace_table[][2], int replace_table_len); @@ -235,7 +233,7 @@ char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT * * \note This is used for creating animation paths in blend files. */ -size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) +size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(); /** * This roughly matches C and Python's string escaping with double quotes - `"`. @@ -251,9 +249,9 @@ size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const si */ size_t BLI_str_unescape_ex(char *__restrict dst, const char *__restrict src, - const size_t src_maxncpy, + size_t src_maxncpy, /* Additional arguments. */ - const size_t dst_maxncpy, + size_t dst_maxncpy, bool *r_is_complete) ATTR_NONNULL(); /** * See #BLI_str_unescape_ex doc-string. @@ -265,7 +263,7 @@ size_t BLI_str_unescape_ex(char *__restrict dst, * * \note This is used for parsing animation paths in blend files (runs often). */ -size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy) +size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_maxncpy) ATTR_NONNULL(); /** @@ -359,10 +357,10 @@ int BLI_strcmp_ignore_pad(const char *str1, const char *str2, char pad) ATTR_WAR /** * Determine the length of a fixed-size string. */ -size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL(); -void BLI_str_toupper_ascii(char *str, const size_t len) ATTR_NONNULL(); +void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(); +void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(); /** * Strip white-space from end of the string. */ @@ -479,7 +477,7 @@ bool BLI_string_all_words_matched(const char *name, * \return The number of words found in \a str */ int BLI_string_find_split_words(const char *str, - const size_t len, + size_t len, char delim, int r_words[][2], int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 82622d442fb..108a2f5fc7d 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -110,14 +110,12 @@ size_t BLI_str_utf8_from_unicode_len(unsigned int c) ATTR_WARN_UNUSED_RESULT; * * \return number of bytes written. */ -size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, const size_t outbuf_len) - ATTR_NONNULL(2); +size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, size_t outbuf_len) ATTR_NONNULL(2); size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, - const size_t maxncpy) ATTR_NONNULL(1, 2); -size_t BLI_str_utf32_as_utf8(char *__restrict dst, - const char32_t *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); +size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, size_t maxncpy) + ATTR_NONNULL(1, 2); /** * \return The UTF-32 len in UTF-8. */ @@ -162,21 +160,20 @@ size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RES size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; -size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes) +size_t BLI_strnlen_utf8_ex(const char *strc, size_t maxlen, size_t *r_len_bytes) ATTR_NONNULL(1, 3); /** * \param strc: the string to measure the length. * \param maxlen: the string length (in bytes) * \return the unicode length (not in bytes!) */ -size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) - ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +size_t BLI_strnlen_utf8(const char *strc, size_t maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, - const size_t maxncpy) ATTR_NONNULL(1, 2); + size_t maxncpy) ATTR_NONNULL(1, 2); /** * Count columns that character/string occupies (based on `wcwidth.co`). diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index fd3918ff217..818bfe8182b 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -57,11 +57,11 @@ bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(); * Based on `BLI_split_dirfile()` / `os.path.splitext()`, * `"a.b.c"` -> (`"a.b"`, `".c"`). */ -void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len); +void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, size_t str_len); /** * `"a.b.c"` -> (`"a."`, `"b.c"`). */ -void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len); +void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size_t str_len); /** * Join strings, return newly allocated string. @@ -127,7 +127,7 @@ char *BLI_string_join_array_by_sep_char_with_tableN(char sep, size_t BLI_string_flip_side_name(char *r_name, const char *from_name, bool strip_number, - const size_t name_len); + size_t name_len); /** * Ensures name is unique (according to criteria specified by caller in unique_check callback), diff --git a/source/blender/blenlib/BLI_timecode.h b/source/blender/blenlib/BLI_timecode.h index f0349e289ac..1cd18dc86ab 100644 --- a/source/blender/blenlib/BLI_timecode.h +++ b/source/blender/blenlib/BLI_timecode.h @@ -42,7 +42,7 @@ extern "C" { * \return length of \a str */ size_t BLI_timecode_string_from_time(char *str, - const size_t maxncpy, + size_t maxncpy, int brevity_level, float time_seconds, double fps, @@ -56,7 +56,7 @@ size_t BLI_timecode_string_from_time(char *str, * \param time_seconds: time total time in seconds * \return length of \a str */ -size_t BLI_timecode_string_from_time_simple(char *str, const size_t maxncpy, double time_seconds) +size_t BLI_timecode_string_from_time_simple(char *str, size_t maxncpy, double time_seconds) ATTR_NONNULL(); /** @@ -72,7 +72,7 @@ size_t BLI_timecode_string_from_time_simple(char *str, const size_t maxncpy, dou * \note in some cases this is used to print non-seconds values. */ size_t BLI_timecode_string_from_time_seconds(char *str, - const size_t maxncpy, + size_t maxncpy, int brevity_level, float time_seconds) ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 9fe092fe525..35d4158de59 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -638,7 +638,7 @@ extern "C" { /** * Check if memory is zeroed, as with `memset(arr, 0, arr_size)`. */ -extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); +extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); #endif #define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member) \ @@ -840,15 +840,6 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); /** No-op for expressions we don't want to instantiate, but must remain valid. */ #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) -/** - * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for - * SFINAE in common cases. - * - * \note Often one has to invoke this macro with double parenthesis. That's because the condition - * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. - */ -#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr - /** \} */ #ifdef __cplusplus diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 90c6760019a..3958fd8e2d2 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -192,6 +192,8 @@ set(SRC BLI_dlrbTree.h BLI_dot_export.hh BLI_dot_export_attribute_enums.hh + BLI_double2.hh + BLI_double3.hh BLI_dynlib.h BLI_dynstr.h BLI_easing.h @@ -205,6 +207,9 @@ set(SRC BLI_fileops.hh BLI_fileops_types.h BLI_filereader.h + BLI_float2.hh + BLI_float3.hh + BLI_float4.hh BLI_float4x4.hh BLI_fnmatch.h BLI_function_ref.hh @@ -253,8 +258,6 @@ set(SRC BLI_math_statistics.h BLI_math_time.h BLI_math_vector.h - BLI_math_vec_types.hh - BLI_math_vec_mpq_types.hh BLI_memarena.h BLI_memblock.h BLI_memiter.h @@ -264,6 +267,8 @@ set(SRC BLI_mesh_boolean.hh BLI_mesh_intersect.hh BLI_mmap.h + BLI_mpq2.hh + BLI_mpq3.hh BLI_multi_value_map.hh BLI_noise.h BLI_noise.hh @@ -439,7 +444,6 @@ if(WITH_GTESTS) tests/BLI_math_rotation_test.cc tests/BLI_math_solvers_test.cc tests/BLI_math_time_test.cc - tests/BLI_math_vec_types_test.cc tests/BLI_math_vector_test.cc tests/BLI_memiter_test.cc tests/BLI_memory_utils_test.cc diff --git a/source/blender/blenlib/intern/BLI_mempool_private.h b/source/blender/blenlib/intern/BLI_mempool_private.h index 90569d87c41..03b0b11297b 100644 --- a/source/blender/blenlib/intern/BLI_mempool_private.h +++ b/source/blender/blenlib/intern/BLI_mempool_private.h @@ -54,8 +54,9 @@ typedef struct ParallelMempoolTaskData { * * See #BLI_task_parallel_mempool implementation for detailed usage example. */ -ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter) - ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, + size_t num_iter) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(); void mempool_iter_threadsafe_destroy(ParallelMempoolTaskData *iter_arr) ATTR_NONNULL(); /** diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc index 842e6cb6135..53e881a9fc7 100644 --- a/source/blender/blenlib/intern/delaunay_2d.cc +++ b/source/blender/blenlib/intern/delaunay_2d.cc @@ -25,10 +25,11 @@ #include #include "BLI_array.hh" +#include "BLI_double2.hh" #include "BLI_linklist.h" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_mpq_types.hh" +#include "BLI_mpq2.hh" #include "BLI_set.hh" #include "BLI_task.hh" #include "BLI_vector.hh" @@ -37,8 +38,6 @@ namespace blender::meshintersect { -using namespace blender::math; - /* Throughout this file, template argument T will be an * arithmetic-like type, like float, double, or mpq_class. */ @@ -789,11 +788,11 @@ bool in_line(const FatCo &a, } vec2 exact_ab = b.exact - a.exact; vec2 exact_ac = c.exact - a.exact; - if (dot(exact_ab, exact_ac) < 0) { + if (vec2::dot(exact_ab, exact_ac) < 0) { return false; } vec2 exact_bc = c.exact - b.exact; - return dot(exact_bc, exact_ac) >= 0; + return vec2::dot(exact_bc, exact_ac) >= 0; } #endif @@ -802,11 +801,11 @@ bool in_line(const FatCo &a, const FatCo &b, const FatCo { vec2 ab = b.approx - a.approx; vec2 ac = c.approx - a.approx; - if (dot(ab, ac) < 0) { + if (vec2::dot(ab, ac) < 0) { return false; } vec2 bc = c.approx - b.approx; - return dot(bc, ac) >= 0; + return vec2::dot(bc, ac) >= 0; } template<> CDTVert::CDTVert(const vec2 &pt) @@ -1082,7 +1081,7 @@ template CDTEdge *CDTArrangement::split_edge(SymEdge *se, T SymEdge *sesymprev = prev(sesym); SymEdge *sesymprevsym = sym(sesymprev); SymEdge *senext = se->next; - CDTVert *v = this->add_vert(interpolate(*a, *b, lambda)); + CDTVert *v = this->add_vert(vec2::interpolate(*a, *b, lambda)); CDTEdge *e = this->add_edge(v, se->next->vert, se->face, sesym->face); sesym->vert = v; SymEdge *newse = &e->symedges[0]; @@ -1705,16 +1704,16 @@ void fill_crossdata_for_intersect(const FatCo &curco, BLI_assert(se_vcva->vert == vc && se_vcva->next->vert == va); BLI_assert(se_vcvb->vert == vc && se_vcvb->next->vert == vb); UNUSED_VARS_NDEBUG(vc); - auto isect = isect_seg_seg>(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); + auto isect = vec2::isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); T &lambda = isect.lambda; switch (isect.kind) { - case isect_result>::LINE_LINE_CROSS: { + case vec2::isect_result::LINE_LINE_CROSS: { #ifdef WITH_GMP if (!std::is_same::value) { #else if (true) { #endif - double len_ab = distance(va->co.approx, vb->co.approx); + double len_ab = vec2::distance(va->co.approx, vb->co.approx); if (lambda * len_ab <= epsilon) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1736,7 +1735,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case isect_result>::LINE_LINE_EXACT: { + case vec2::isect_result::LINE_LINE_EXACT: { if (lambda == 0) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1751,7 +1750,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case isect_result>::LINE_LINE_NONE: { + case vec2::isect_result::LINE_LINE_NONE: { #ifdef WITH_GMP if (std::is_same::value) { BLI_assert(false); @@ -1767,9 +1766,9 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case isect_result>::LINE_LINE_COLINEAR: { - if (distance_squared(va->co.approx, v2->co.approx) <= - distance_squared(vb->co.approx, v2->co.approx)) { + case vec2::isect_result::LINE_LINE_COLINEAR: { + if (vec2::distance_squared(va->co.approx, v2->co.approx) <= + vec2::distance_squared(vb->co.approx, v2->co.approx)) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } else { @@ -1846,7 +1845,7 @@ void get_next_crossing_from_edge(CrossData *cd, { CDTVert *va = cd->in->vert; CDTVert *vb = cd->in->next->vert; - vec2 curco = interpolate(va->co.exact, vb->co.exact, cd->lambda); + vec2 curco = vec2::interpolate(va->co.exact, vb->co.exact, cd->lambda); FatCo fat_curco(curco); SymEdge *se_ac = sym(cd->in)->next; CDTVert *vc = se_ac->next->vert; @@ -2387,7 +2386,7 @@ template void remove_non_constraint_edges_leave_valid_bmesh(CDT_stat dissolvable_edges[i].e = e; const vec2 &co1 = e->symedges[0].vert->co.approx; const vec2 &co2 = e->symedges[1].vert->co.approx; - dissolvable_edges[i].len_squared = distance_squared(co1, co2); + dissolvable_edges[i].len_squared = vec2::distance_squared(co1, co2); i++; } } @@ -2570,18 +2569,18 @@ template void detect_holes(CDT_state *cdt_state) if (e->symedges[0].face->visit_index == e->symedges[1].face->visit_index) { continue; /* Don't count hits on edges between faces in same region. */ } - auto isect = isect_seg_seg>(ray_end.exact, + auto isect = vec2::isect_seg_seg(ray_end.exact, mid.exact, e->symedges[0].vert->co.exact, e->symedges[1].vert->co.exact); switch (isect.kind) { - case isect_result>::LINE_LINE_CROSS: { + case vec2::isect_result::LINE_LINE_CROSS: { hits++; break; } - case isect_result>::LINE_LINE_EXACT: - case isect_result>::LINE_LINE_NONE: - case isect_result>::LINE_LINE_COLINEAR: + case vec2::isect_result::LINE_LINE_EXACT: + case vec2::isect_result::LINE_LINE_NONE: + case vec2::isect_result::LINE_LINE_COLINEAR: break; } } diff --git a/source/blender/blenlib/intern/math_boolean.cc b/source/blender/blenlib/intern/math_boolean.cc index 0bae3c23f79..c16755868aa 100644 --- a/source/blender/blenlib/intern/math_boolean.cc +++ b/source/blender/blenlib/intern/math_boolean.cc @@ -18,10 +18,15 @@ * \ingroup bli */ +#include "BLI_double2.hh" +#include "BLI_double3.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_hash.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_mpq2.hh" +#include "BLI_mpq3.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc index 6fab6c9a383..223c0e273f0 100644 --- a/source/blender/blenlib/intern/math_vec.cc +++ b/source/blender/blenlib/intern/math_vec.cc @@ -18,83 +18,89 @@ * \ingroup bli */ +#include "BLI_double2.hh" +#include "BLI_double3.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_hash.hh" -#include "BLI_math_vec_mpq_types.hh" -#include "BLI_math_vector.hh" +#include "BLI_math_mpq.hh" +#include "BLI_mpq2.hh" +#include "BLI_mpq3.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" -namespace blender::math { +namespace blender { -template<> -isect_result isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4) +float2::isect_result float2::isect_seg_seg(const float2 &v1, + const float2 &v2, + const float2 &v3, + const float2 &v4) { - isect_result ans; + float2::isect_result ans; float div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0f) { ans.lambda = 0.0f; - ans.kind = isect_result::LINE_LINE_COLINEAR; + ans.mu = 0.0f; + ans.kind = float2::isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; - float mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; - if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) { - if (ans.lambda == 0.0f || ans.lambda == 1.0f || mu == 0.0f || mu == 1.0f) { - ans.kind = isect_result::LINE_LINE_EXACT; + ans.mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; + if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && ans.mu >= 0.0f && ans.mu <= 1.0f) { + if (ans.lambda == 0.0f || ans.lambda == 1.0f || ans.mu == 0.0f || ans.mu == 1.0f) { + ans.kind = float2::isect_result::LINE_LINE_EXACT; } else { - ans.kind = isect_result::LINE_LINE_CROSS; + ans.kind = float2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result::LINE_LINE_NONE; + ans.kind = float2::isect_result::LINE_LINE_NONE; } } return ans; } -template<> -isect_result isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4) +double2::isect_result double2::isect_seg_seg(const double2 &v1, + const double2 &v2, + const double2 &v3, + const double2 &v4) { - isect_result ans; + double2::isect_result ans; double div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = isect_result::LINE_LINE_COLINEAR; + ans.kind = double2::isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; double mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; if (ans.lambda >= 0.0 && ans.lambda <= 1.0 && mu >= 0.0 && mu <= 1.0) { if (ans.lambda == 0.0 || ans.lambda == 1.0 || mu == 0.0 || mu == 1.0) { - ans.kind = isect_result::LINE_LINE_EXACT; + ans.kind = double2::isect_result::LINE_LINE_EXACT; } else { - ans.kind = isect_result::LINE_LINE_CROSS; + ans.kind = double2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result::LINE_LINE_NONE; + ans.kind = double2::isect_result::LINE_LINE_NONE; } } return ans; } #ifdef WITH_GMP -template<> -isect_result isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4) +mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, + const mpq2 &v2, + const mpq2 &v3, + const mpq2 &v4) { - isect_result ans; + mpq2::isect_result ans; mpq_class div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = isect_result::LINE_LINE_COLINEAR; + ans.kind = mpq2::isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; @@ -103,21 +109,66 @@ isect_result isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, if (ans.lambda >= 0 && ans.lambda <= 1 && ((div > 0 && mudiv >= 0 && mudiv <= div) || (div < 0 && mudiv <= 0 && mudiv >= div))) { if (ans.lambda == 0 || ans.lambda == 1 || mudiv == 0 || mudiv == div) { - ans.kind = isect_result::LINE_LINE_EXACT; + ans.kind = mpq2::isect_result::LINE_LINE_EXACT; } else { - ans.kind = isect_result::LINE_LINE_CROSS; + ans.kind = mpq2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result::LINE_LINE_NONE; + ans.kind = mpq2::isect_result::LINE_LINE_NONE; } } return ans; } #endif +double3 double3::cross_poly(Span poly) +{ + /* Newell's Method. */ + int nv = static_cast(poly.size()); + if (nv < 3) { + return double3(0, 0, 0); + } + const double3 *v_prev = &poly[nv - 1]; + const double3 *v_curr = &poly[0]; + double3 n(0, 0, 0); + for (int i = 0; i < nv;) { + n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); + n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); + n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); + v_prev = v_curr; + ++i; + if (i < nv) { + v_curr = &poly[i]; + } + } + return n; +} + #ifdef WITH_GMP +mpq3 mpq3::cross_poly(Span poly) +{ + /* Newell's Method. */ + int nv = static_cast(poly.size()); + if (nv < 3) { + return mpq3(0); + } + const mpq3 *v_prev = &poly[nv - 1]; + const mpq3 *v_curr = &poly[0]; + mpq3 n(0); + for (int i = 0; i < nv;) { + n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); + n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); + n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); + v_prev = v_curr; + ++i; + if (i < nv) { + v_curr = &poly[i]; + } + } + return n; +} uint64_t hash_mpq_class(const mpq_class &value) { @@ -125,6 +176,20 @@ uint64_t hash_mpq_class(const mpq_class &value) return get_default_hash(static_cast(value.get_d())); } +uint64_t mpq2::hash() const +{ + uint64_t hashx = hash_mpq_class(this->x); + uint64_t hashy = hash_mpq_class(this->y); + return hashx ^ (hashy * 33); +} + +uint64_t mpq3::hash() const +{ + uint64_t hashx = hash_mpq_class(this->x); + uint64_t hashy = hash_mpq_class(this->y); + uint64_t hashz = hash_mpq_class(this->z); + return hashx ^ (hashy * 33) ^ (hashz * 33 * 37); +} #endif -} // namespace blender::math +} // namespace blender diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index a3eae1896d3..ce4db0c6b9d 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -28,6 +28,8 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" +# include "BLI_double3.hh" +# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" @@ -35,9 +37,8 @@ # include "BLI_math_boolean.hh" # include "BLI_math_geom.h" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" # include "BLI_mesh_intersect.hh" +# include "BLI_mpq3.hh" # include "BLI_set.hh" # include "BLI_span.hh" # include "BLI_stack.hh" @@ -1632,13 +1633,13 @@ static Edge find_good_sorting_edge(const Vert *testp, ordinate[axis_next] = -abscissa[axis]; ordinate[axis_next_next] = 0; /* By construction, dot(abscissa, ordinate) == 0, so they are perpendicular. */ - mpq3 normal = math::cross(abscissa, ordinate); + mpq3 normal = mpq3::cross(abscissa, ordinate); if (dbg_level > 0) { std::cout << "abscissa = " << abscissa << "\n"; std::cout << "ordinate = " << ordinate << "\n"; std::cout << "normal = " << normal << "\n"; } - mpq_class nlen2 = math::length_squared(normal); + mpq_class nlen2 = normal.length_squared(); mpq_class max_abs_slope = -1; Edge esort; const Vector &edges = tmtopo.vert_edges(closestp); @@ -1647,12 +1648,12 @@ static Edge find_good_sorting_edge(const Vert *testp, const mpq3 &co_other = v_other->co_exact; mpq3 evec = co_other - co_closest; /* Get projection of evec onto plane of abscissa and ordinate. */ - mpq3 proj_evec = evec - (math::dot(evec, normal) / nlen2) * normal; + mpq3 proj_evec = evec - (mpq3::dot(evec, normal) / nlen2) * normal; /* The projection calculations along the abscissa and ordinate should * be scaled by 1/abscissa and 1/ordinate respectively, * but we can skip: it won't affect which `evec` has the maximum slope. */ - mpq_class evec_a = math::dot(proj_evec, abscissa); - mpq_class evec_o = math::dot(proj_evec, ordinate); + mpq_class evec_a = mpq3::dot(proj_evec, abscissa); + mpq_class evec_o = mpq3::dot(proj_evec, ordinate); if (dbg_level > 0) { std::cout << "e = " << e << "\n"; std::cout << "v_other = " << v_other << "\n"; @@ -1790,8 +1791,8 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, ap = p; ap -= a; - mpq_class d1 = math::dot_with_buffer(ab, ap, m); - mpq_class d2 = math::dot_with_buffer(ac, ap, m); + mpq_class d1 = mpq3::dot_with_buffer(ab, ap, m); + mpq_class d2 = mpq3::dot_with_buffer(ac, ap, m); if (d1 <= 0 && d2 <= 0) { /* Barycentric coordinates (1,0,0). */ *r_edge = -1; @@ -1799,13 +1800,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = a\n"; } - return math::distance_squared_with_buffer(p, a, m); + return mpq3::distance_squared_with_buffer(p, a, m); } /* Check if p in vertex region outside b. */ bp = p; bp -= b; - mpq_class d3 = math::dot_with_buffer(ab, bp, m); - mpq_class d4 = math::dot_with_buffer(ac, bp, m); + mpq_class d3 = mpq3::dot_with_buffer(ab, bp, m); + mpq_class d4 = mpq3::dot_with_buffer(ac, bp, m); if (d3 >= 0 && d4 <= d3) { /* Barycentric coordinates (0,1,0). */ *r_edge = -1; @@ -1813,7 +1814,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = b\n"; } - return math::distance_squared_with_buffer(p, b, m); + return mpq3::distance_squared_with_buffer(p, b, m); } /* Check if p in region of ab. */ mpq_class vc = d1 * d4 - d3 * d2; @@ -1828,13 +1829,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ab at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* Check if p in vertex region outside c. */ cp = p; cp -= c; - mpq_class d5 = math::dot_with_buffer(ab, cp, m); - mpq_class d6 = math::dot_with_buffer(ac, cp, m); + mpq_class d5 = mpq3::dot_with_buffer(ab, cp, m); + mpq_class d6 = mpq3::dot_with_buffer(ac, cp, m); if (d6 >= 0 && d5 <= d6) { /* Barycentric coordinates (0,0,1). */ *r_edge = -1; @@ -1842,7 +1843,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = c\n"; } - return math::distance_squared_with_buffer(p, c, m); + return mpq3::distance_squared_with_buffer(p, c, m); } /* Check if p in edge region of ac. */ mpq_class vb = d5 * d2 - d1 * d6; @@ -1857,7 +1858,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ac at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* Check if p in edge region of bc. */ mpq_class va = d3 * d6 - d5 * d4; @@ -1873,7 +1874,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on bc at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* p inside face region. Compute barycentric coordinates (u,v,w). */ mpq_class denom = 1 / (va + vb + vc); @@ -1889,7 +1890,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = inside at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } static float closest_on_tri_to_point_float_dist_squared(const float3 &p, @@ -2609,7 +2610,7 @@ static void test_tri_inside_shapes(const IMesh &tm, double3 test_point = calc_point_inside_tri_db(tri_test); /* Offset the test point a tiny bit in the tri_test normal direction. */ tri_test.populate_plane(false); - double3 norm = math::normalize(tri_test.plane->norm); + double3 norm = tri_test.plane->norm.normalized(); const double offset_amount = 1e-5; double3 offset_test_point = test_point + offset_amount * norm; if (dbg_level > 0) { @@ -3001,7 +3002,7 @@ static void init_face_merge_state(FaceMergeState *fms, std::cout << "process tri = " << &tri << "\n"; } BLI_assert(tri.plane_populated()); - if (math::dot(norm, tri.plane->norm) <= 0.0) { + if (double3::dot(norm, tri.plane->norm) <= 0.0) { if (dbg_level > 0) { std::cout << "triangle has wrong orientation, skipping\n"; } @@ -3026,7 +3027,7 @@ static void init_face_merge_state(FaceMergeState *fms, } if (me_index == -1) { double3 vec = new_me.v2->co - new_me.v1->co; - new_me.len_squared = math::length_squared(vec); + new_me.len_squared = vec.length_squared(); new_me.orig = tri.edge_orig[i]; new_me.is_intersect = tri.is_intersect[i]; new_me.dissolvable = (new_me.orig == NO_INDEX && !new_me.is_intersect); @@ -3266,7 +3267,7 @@ static Vector merge_tris_for_face(Vector tris, bool done = false; double3 first_tri_normal = tm.face(tris[0])->plane->norm; double3 second_tri_normal = tm.face(tris[1])->plane->norm; - if (tris.size() == 2 && math::dot(first_tri_normal, second_tri_normal) > 0.0) { + if (tris.size() == 2 && double3::dot(first_tri_normal, second_tri_normal) > 0.0) { /* Is this a case where quad with one diagonal remained unchanged? * Worth special handling because this case will be very common. */ Face &tri1 = *tm.face(tris[0]); @@ -3331,7 +3332,7 @@ static bool approx_in_line(const double3 &a, const double3 &b, const double3 &c) { double3 vec1 = b - a; double3 vec2 = c - b; - double cos_ang = math::dot(math::normalize(vec1), math::normalize(vec2)); + double cos_ang = double3::dot(vec1.normalized(), vec2.normalized()); return fabs(cos_ang - 1.0) < 1e-4; } diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc index 982759ffcff..1f150137ba3 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -30,13 +30,15 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" +# include "BLI_double3.hh" +# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" # include "BLI_math_boolean.hh" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" +# include "BLI_mpq2.hh" +# include "BLI_mpq3.hh" # include "BLI_polyfill_2d.h" # include "BLI_set.hh" # include "BLI_span.hh" @@ -196,14 +198,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co_exact; } - normal_exact = math::cross_poly(co.as_span()); + normal_exact = mpq3::cross_poly(co); } else { mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact; mpq3 tr12 = vert[1]->co_exact - vert[2]->co_exact; - normal_exact = math::cross(tr02, tr12); + normal_exact = mpq3::cross(tr02, tr12); } - mpq_class d_exact = -math::dot(normal_exact, vert[0]->co_exact); + mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact); plane = new Plane(normal_exact, d_exact); } else { @@ -213,14 +215,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co; } - normal = math::cross_poly(co.as_span()); + normal = double3::cross_poly(co); } else { double3 tr02 = vert[0]->co - vert[2]->co; double3 tr12 = vert[1]->co - vert[2]->co; - normal = math::cross(tr02, tr12); + normal = double3::cross_high_precision(tr02, tr12); } - double d = -math::dot(normal, vert[0]->co); + double d = -double3::dot(normal, vert[0]->co); plane = new Plane(normal, d); } } @@ -1096,15 +1098,15 @@ static mpq2 project_3d_to_2d(const mpq3 &p3d, int proj_axis) */ static double supremum_dot_cross(const double3 &a, const double3 &b) { - double3 abs_a = math::abs(a); - double3 abs_b = math::abs(b); + double3 abs_a = double3::abs(a); + double3 abs_b = double3::abs(b); double3 c; /* This is dot(cross(a, b), cross(a,b)) but using absolute values for a and b * and always using + when operation is + or -. */ c[0] = abs_a[1] * abs_b[2] + abs_a[2] * abs_b[1]; c[1] = abs_a[2] * abs_b[0] + abs_a[0] * abs_b[2]; c[2] = abs_a[0] * abs_b[1] + abs_a[1] * abs_b[0]; - return math::dot(c, c); + return double3::dot(c, c); } /* The index of dot when inputs are plane_coords with index 1 is much higher. @@ -1141,11 +1143,11 @@ static int filter_plane_side(const double3 &p, const double3 &abs_plane_p, const double3 &abs_plane_no) { - double d = math::dot(p - plane_p, plane_no); + double d = double3::dot(p - plane_p, plane_no); if (d == 0.0) { return 0; } - double supremum = math::dot(abs_p + abs_plane_p, abs_plane_no); + double supremum = double3::dot(abs_p + abs_plane_p, abs_plane_no); double err_bound = supremum * index_plane_side * DBL_EPSILON; if (fabs(d) > err_bound) { return d > 0 ? 1 : -1; @@ -1176,9 +1178,9 @@ static inline mpq3 tti_interp( ab -= b; ac = a; ac -= c; - mpq_class den = math::dot_with_buffer(ab, n, dotbuf); + mpq_class den = mpq3::dot_with_buffer(ab, n, dotbuf); BLI_assert(den != 0); - mpq_class alpha = math::dot_with_buffer(ac, n, dotbuf) / den; + mpq_class alpha = mpq3::dot_with_buffer(ac, n, dotbuf) / den; return a - alpha * ab; } @@ -1207,7 +1209,7 @@ static inline int tti_above(const mpq3 &a, n.y = ba.z * ca.x - ba.x * ca.z; n.z = ba.x * ca.y - ba.y * ca.x; - return sgn(math::dot_with_buffer(ad, n, dotbuf)); + return sgn(mpq3::dot_with_buffer(ad, n, dotbuf)); } /** @@ -1426,11 +1428,11 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) const double3 &d_r2 = vr2->co; const double3 &d_n2 = tri2.plane->norm; - const double3 &abs_d_p1 = math::abs(d_p1); - const double3 &abs_d_q1 = math::abs(d_q1); - const double3 &abs_d_r1 = math::abs(d_r1); - const double3 &abs_d_r2 = math::abs(d_r2); - const double3 &abs_d_n2 = math::abs(d_n2); + const double3 &abs_d_p1 = double3::abs(d_p1); + const double3 &abs_d_q1 = double3::abs(d_q1); + const double3 &abs_d_r1 = double3::abs(d_r1); + const double3 &abs_d_r2 = double3::abs(d_r2); + const double3 &abs_d_n2 = double3::abs(d_n2); int sp1 = filter_plane_side(d_p1, d_r2, d_n2, abs_d_p1, abs_d_r2, abs_d_n2); int sq1 = filter_plane_side(d_q1, d_r2, d_n2, abs_d_q1, abs_d_r2, abs_d_n2); @@ -1446,9 +1448,9 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) } const double3 &d_n1 = tri1.plane->norm; - const double3 &abs_d_p2 = math::abs(d_p2); - const double3 &abs_d_q2 = math::abs(d_q2); - const double3 &abs_d_n1 = math::abs(d_n1); + const double3 &abs_d_p2 = double3::abs(d_p2); + const double3 &abs_d_q2 = double3::abs(d_q2); + const double3 &abs_d_n1 = double3::abs(d_n1); int sp2 = filter_plane_side(d_p2, d_r1, d_n1, abs_d_p2, abs_d_r1, abs_d_n1); int sq2 = filter_plane_side(d_q2, d_r1, d_n1, abs_d_q2, abs_d_r1, abs_d_n1); @@ -1475,17 +1477,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp1 == 0) { buf[0] = p1; buf[0] -= r2; - sp1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); + sp1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (sq1 == 0) { buf[0] = q1; buf[0] -= r2; - sq1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); + sq1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (sr1 == 0) { buf[0] = r1; buf[0] -= r2; - sr1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); + sr1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (dbg_level > 1) { @@ -1507,17 +1509,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp2 == 0) { buf[0] = p2; buf[0] -= r1; - sp2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); + sp2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (sq2 == 0) { buf[0] = q2; buf[0] -= r1; - sq2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); + sq2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (sr2 == 0) { buf[0] = r2; buf[0] -= r1; - sr2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); + sr2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (dbg_level > 1) { @@ -1719,7 +1721,7 @@ static CDT_data prepare_cdt_input(const IMesh &tm, int t, const Vectorplane_populated()); ans.t_plane = tm.face(t)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); prepare_need_tri(ans, tm, t); for (const ITT_value &itt : itts) { switch (itt.kind) { @@ -1755,7 +1757,7 @@ static CDT_data prepare_cdt_input_for_cluster(const IMesh &tm, BLI_assert(tm.face(t0)->plane_populated()); ans.t_plane = tm.face(t0)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); for (const int t : cl) { prepare_need_tri(ans, tm, t); } @@ -2002,9 +2004,9 @@ static bool is_quad_flip_first_third(const double3 &v1, const double3 &normal) { double3 dir_v3v1 = v3 - v1; - double3 tangent = math::cross(dir_v3v1, normal); - double dot = math::dot(v1, tangent); - return (math::dot(v4, tangent) >= dot) || (math::dot(v2, tangent) <= dot); + double3 tangent = double3::cross_high_precision(dir_v3v1, normal); + double dot = double3::dot(v1, tangent); + return (double3::dot(v4, tangent) >= dot) || (double3::dot(v2, tangent) <= dot); } /** @@ -2122,7 +2124,7 @@ static Array exact_triangulate_poly(Face *f, IMeshArena *arena) f->populate_plane(false); } const double3 &poly_normal = f->plane->norm; - int axis = math::dominant_axis(poly_normal); + int axis = double3::dominant_axis(poly_normal); /* If project down y axis as opposed to x or z, the orientation * of the polygon will be reversed. * Yet another reversal happens if the poly normal in the dominant @@ -2201,15 +2203,15 @@ static bool face_is_degenerate(const Face *f) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double3 dab = math::cross(da, db); - double dab_length_squared = math::length_squared(dab); + double3 dab = double3::cross_high_precision(da, db); + double dab_length_squared = dab.length_squared(); double err_bound = supremum_dot_cross(dab, dab) * index_dot_cross * DBL_EPSILON; if (dab_length_squared > err_bound) { return false; } mpq3 a = v2->co_exact - v0->co_exact; mpq3 b = v2->co_exact - v1->co_exact; - mpq3 ab = math::cross(a, b); + mpq3 ab = mpq3::cross(a, b); if (ab.x == 0 && ab.y == 0 && ab.z == 0) { return true; } @@ -2229,8 +2231,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double da_length_squared = math::length_squared(da); - double db_length_squared = math::length_squared(db); + double da_length_squared = da.length_squared(); + double db_length_squared = db.length_squared(); if (da_length_squared == 0.0 || db_length_squared == 0.0) { return true; } @@ -2238,8 +2240,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) * The triangle is almost degenerate if sin t is almost 0. * sin^2 t = |da x db|^2 / (|da|^2 |db|^2) */ - double3 dab = math::cross(da, db); - double dab_length_squared = math::length_squared(dab); + double3 dab = double3::cross_high_precision(da, db); + double dab_length_squared = dab.length_squared(); double sin_squared_t = dab_length_squared / (da_length_squared * db_length_squared); if (sin_squared_t < 1e-8) { return true; diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc index 3460c1284fc..a6ad18801fd 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -50,7 +50,9 @@ #include #include -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" +#include "BLI_float4.hh" #include "BLI_math_base_safe.h" #include "BLI_noise.hh" #include "BLI_utildefines.h" @@ -1467,7 +1469,7 @@ void voronoi_smooth_f1(const float w, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_w != nullptr) { smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor; @@ -1590,7 +1592,7 @@ static float voronoi_distance(const float2 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float2::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1613,7 +1615,7 @@ void voronoi_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1652,7 +1654,7 @@ void voronoi_smooth_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1674,10 +1676,11 @@ void voronoi_smooth_f1(const float2 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; + smoothPosition = float2::interpolate(smoothPosition, pointPosition, h) - + correctionFactor; } } } @@ -1701,7 +1704,7 @@ void voronoi_f2(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1745,7 +1748,7 @@ void voronoi_f2(const float2 coord, void voronoi_distance_to_edge(const float2 coord, const float randomness, float *r_distance) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float2 vectorToClosest = float2(0.0f, 0.0f); @@ -1774,7 +1777,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float const float2 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v2v2(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v2v2((vectorToClosest + vectorToPoint) / 2.0f, - math::normalize(perpendicularToEdge)); + perpendicularToEdge.normalized()); minDistance = std::min(minDistance, distanceToEdge); } } @@ -1784,7 +1787,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *r_radius) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float2 closestPoint = float2(0.0f, 0.0f); @@ -1795,7 +1798,7 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j); const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(pointPosition, localPosition); + const float distanceToPoint = float2::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -1814,14 +1817,14 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j) + closestPointOffset; const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float2::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float2::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 3D Voronoi **** */ @@ -1833,7 +1836,7 @@ static float voronoi_distance(const float3 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float3::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1857,7 +1860,7 @@ void voronoi_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1899,7 +1902,7 @@ void voronoi_smooth_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1922,10 +1925,10 @@ void voronoi_smooth_f1(const float3 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = float3::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -1951,7 +1954,7 @@ void voronoi_f2(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1997,7 +2000,7 @@ void voronoi_f2(const float3 coord, void voronoi_distance_to_edge(const float3 coord, const float randomness, float *r_distance) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float3 vectorToClosest = float3(0.0f, 0.0f, 0.0f); @@ -2029,7 +2032,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float const float3 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v3v3(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v3v3((vectorToClosest + vectorToPoint) / 2.0f, - math::normalize(perpendicularToEdge)); + perpendicularToEdge.normalized()); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2040,7 +2043,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *r_radius) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float3 closestPoint = float3(0.0f, 0.0f, 0.0f); @@ -2052,7 +2055,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k); const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(pointPosition, localPosition); + const float distanceToPoint = float3::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2073,7 +2076,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k) + closestPointOffset; const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float3::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2081,7 +2084,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float3::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 4D Voronoi **** */ @@ -2093,7 +2096,7 @@ static float voronoi_distance(const float4 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float4::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z) + fabsf(a.w - b.w); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -2118,7 +2121,7 @@ void voronoi_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -2163,7 +2166,7 @@ void voronoi_smooth_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -2188,10 +2191,10 @@ void voronoi_smooth_f1(const float4 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = float4::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -2218,7 +2221,7 @@ void voronoi_f2(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2267,7 +2270,7 @@ void voronoi_f2(const float4 coord, void voronoi_distance_to_edge(const float4 coord, const float randomness, float *r_distance) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float4 vectorToClosest = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2304,7 +2307,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float const float4 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v4v4(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v4v4((vectorToClosest + vectorToPoint) / 2.0f, - math::normalize(perpendicularToEdge)); + float4::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2316,7 +2319,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *r_radius) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float4 closestPoint = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2330,7 +2333,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(pointPosition, localPosition); + const float distanceToPoint = float4::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2354,7 +2357,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float4::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2363,7 +2366,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float4::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /** \} */ diff --git a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc index eac3faa6d15..70e3a99e57a 100644 --- a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc +++ b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc @@ -21,9 +21,10 @@ extern "C" { #define DO_RANDOM_TESTS 0 #include "BLI_array.hh" +#include "BLI_double2.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_mpq_types.hh" +#include "BLI_mpq2.hh" #include "BLI_vector.hh" #include "BLI_delaunay_2d.h" diff --git a/source/blender/blenlib/tests/BLI_math_vec_types_test.cc b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc deleted file mode 100644 index 8aa1f90fde2..00000000000 --- a/source/blender/blenlib/tests/BLI_math_vec_types_test.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* Apache License, Version 2.0 */ - -#include "testing/testing.h" - -#include "BLI_math_vec_types.hh" - -namespace blender::tests { - -using namespace blender::math; - -TEST(math_vec_types, ScalarConstructorUnsigned) -{ - float2 u(5u); - EXPECT_EQ(u[0], 5.0f); - EXPECT_EQ(u[1], 5.0f); -} - -TEST(math_vec_types, ScalarConstructorInt) -{ - float2 i(-5); - EXPECT_EQ(i[0], -5.0f); - EXPECT_EQ(i[1], -5.0f); -} - -TEST(math_vec_types, ScalarConstructorFloat) -{ - float2 f(5.2f); - EXPECT_FLOAT_EQ(f[0], 5.2f); - EXPECT_FLOAT_EQ(f[1], 5.2f); -} - -TEST(math_vec_types, ScalarConstructorDouble) -{ - float2 d(5.2); - EXPECT_FLOAT_EQ(d[0], 5.2f); - EXPECT_FLOAT_EQ(d[1], 5.2f); -} - -TEST(math_vec_types, MultiScalarConstructorVec2) -{ - int2 i(5.5f, -1.8); - EXPECT_EQ(i[0], 5); - EXPECT_EQ(i[1], -1); -} - -TEST(math_vec_types, MultiScalarConstructorVec3) -{ - int3 i(5.5f, -1.8, 6u); - EXPECT_EQ(i[0], 5); - EXPECT_EQ(i[1], -1); - EXPECT_EQ(i[2], 6); -} - -TEST(math_vec_types, MultiScalarConstructorVec4) -{ - int4 i(5.5f, -1.8, 6u, 0.888f); - EXPECT_EQ(i[0], 5); - EXPECT_EQ(i[1], -1); - EXPECT_EQ(i[2], 6); - EXPECT_EQ(i[3], 0); -} - -TEST(math_vec_types, MixedScalarVectorConstructorVec3) -{ - float3 fl_v2(float2(5.5f), 1.8f); - EXPECT_FLOAT_EQ(fl_v2[0], 5.5f); - EXPECT_FLOAT_EQ(fl_v2[1], 5.5f); - EXPECT_FLOAT_EQ(fl_v2[2], 1.8f); - - float3 v2_fl(1.8f, float2(5.5f)); - EXPECT_FLOAT_EQ(v2_fl[0], 1.8f); - EXPECT_FLOAT_EQ(v2_fl[1], 5.5f); - EXPECT_FLOAT_EQ(v2_fl[2], 5.5f); -} - -TEST(math_vec_types, MixedScalarVectorConstructorVec4) -{ - int4 v2_fl_fl(float2(1), 2, 3); - EXPECT_EQ(v2_fl_fl[0], 1); - EXPECT_EQ(v2_fl_fl[1], 1); - EXPECT_EQ(v2_fl_fl[2], 2); - EXPECT_EQ(v2_fl_fl[3], 3); - - float4 fl_v2_fl(1, int2(2), 3); - EXPECT_EQ(fl_v2_fl[0], 1); - EXPECT_EQ(fl_v2_fl[1], 2); - EXPECT_EQ(fl_v2_fl[2], 2); - EXPECT_EQ(fl_v2_fl[3], 3); - - double4 fl_fl_v2(1, 2, double2(3)); - EXPECT_EQ(fl_fl_v2[0], 1); - EXPECT_EQ(fl_fl_v2[1], 2); - EXPECT_EQ(fl_fl_v2[2], 3); - EXPECT_EQ(fl_fl_v2[3], 3); - - int4 v2_v2(float2(1), uint2(2)); - EXPECT_EQ(v2_v2[0], 1); - EXPECT_EQ(v2_v2[1], 1); - EXPECT_EQ(v2_v2[2], 2); - EXPECT_EQ(v2_v2[3], 2); - - float4 v3_fl(uint3(1), 2); - EXPECT_EQ(v3_fl[0], 1); - EXPECT_EQ(v3_fl[1], 1); - EXPECT_EQ(v3_fl[2], 1); - EXPECT_EQ(v3_fl[3], 2); - - uint4 fl_v3(1, float3(2)); - EXPECT_EQ(fl_v3[0], 1); - EXPECT_EQ(fl_v3[1], 2); - EXPECT_EQ(fl_v3[2], 2); - EXPECT_EQ(fl_v3[3], 2); -} - -TEST(math_vec_types, ComponentMasking) -{ - int4 i(0, 1, 2, 3); - float2 f2 = float2(i); - EXPECT_EQ(f2[0], 0.0f); - EXPECT_EQ(f2[1], 1.0f); -} - -TEST(math_vec_types, PointerConversion) -{ - float array[3] = {1.0f, 2.0f, 3.0f}; - float3 farray(array); - EXPECT_EQ(farray[0], 1.0f); - EXPECT_EQ(farray[1], 2.0f); - EXPECT_EQ(farray[2], 3.0f); -} - -TEST(math_vec_types, PointerArrayConversion) -{ - float array[1][3] = {{1.0f, 2.0f, 3.0f}}; - float(*ptr)[3] = array; - float3 fptr(ptr); - EXPECT_EQ(fptr[0], 1.0f); - EXPECT_EQ(fptr[1], 2.0f); - EXPECT_EQ(fptr[2], 3.0f); -} - -TEST(math_vec_types, VectorTypeConversion) -{ - double2 d(int2(float2(5.75f, -1.57f))); - EXPECT_EQ(d[0], 5.0); - EXPECT_EQ(d[1], -1.0); -} - -} // namespace blender::tests diff --git a/source/blender/blenlib/tests/BLI_memory_utils_test.cc b/source/blender/blenlib/tests/BLI_memory_utils_test.cc index 74e54151a06..207f310d902 100644 --- a/source/blender/blenlib/tests/BLI_memory_utils_test.cc +++ b/source/blender/blenlib/tests/BLI_memory_utils_test.cc @@ -1,6 +1,6 @@ /* Apache License, Version 2.0 */ -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_memory_utils.hh" #include "BLI_strict_flags.h" #include "testing/testing.h" diff --git a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc index 2b8fb3dbea4..d759f0c3be4 100644 --- a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc @@ -11,8 +11,8 @@ #include "BLI_array.hh" #include "BLI_map.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_boolean.hh" +#include "BLI_mpq3.hh" #include "BLI_vector.hh" #ifdef WITH_GMP diff --git a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc index d2d76593129..68111fb8eb1 100644 --- a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc @@ -10,8 +10,8 @@ #include "BLI_array.hh" #include "BLI_math_mpq.hh" -#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_intersect.hh" +#include "BLI_mpq3.hh" #include "BLI_task.h" #include "BLI_vector.hh" diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 7865c79323d..85ea27b0f4e 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -1186,6 +1186,7 @@ static BMO_FlagSet bmo_enum_triangulate_quad_method[] = { {MOD_TRIANGULATE_QUAD_FIXED, "FIXED"}, {MOD_TRIANGULATE_QUAD_ALTERNATE, "ALTERNATE"}, {MOD_TRIANGULATE_QUAD_SHORTEDGE, "SHORT_EDGE"}, + {MOD_TRIANGULATE_QUAD_LONGEDGE, "LONG_EDGE"}, {0, NULL}, }; diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index e9eaf865e3c..e7280303c26 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -1007,6 +1007,7 @@ void BM_face_triangulate(BMesh *bm, break; } case MOD_TRIANGULATE_QUAD_SHORTEDGE: + case MOD_TRIANGULATE_QUAD_LONGEDGE: case MOD_TRIANGULATE_QUAD_BEAUTY: default: { BMLoop *l_v3, *l_v4; @@ -1023,6 +1024,12 @@ void BM_face_triangulate(BMesh *bm, d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); split_24 = ((d2 - d1) > 0.0f); } + else if (quad_method == MOD_TRIANGULATE_QUAD_LONGEDGE) { + float d1, d2; + d1 = len_squared_v3v3(l_v4->v->co, l_v2->v->co); + d2 = len_squared_v3v3(l_v1->v->co, l_v3->v->co); + split_24 = ((d2 - d1) < 0.0f); + } else { /* first check if the quad is concave on either diagonal */ const int flip_flag = is_quad_flip_v3( diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 96dc17c2d1a..905d1443002 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -647,6 +647,15 @@ endif() blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +if(WITH_UNITY_BUILD) + set_target_properties(bf_compositor PROPERTIES UNITY_BUILD ON) + set_target_properties(bf_compositor PROPERTIES UNITY_BUILD_BATCH_SIZE 10) +endif() + +if(COMMAND target_precompile_headers) + target_precompile_headers(bf_compositor PRIVATE COM_precomp.h) +endif() + if(CXX_WARN_NO_SUGGEST_OVERRIDE) target_compile_options(bf_compositor PRIVATE "-Wsuggest-override") endif() diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index 794bf1b23bc..1c3a28670df 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -18,7 +18,7 @@ #pragma once -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" #include "DNA_vec_types.h" diff --git a/source/blender/compositor/COM_precomp.h b/source/blender/compositor/COM_precomp.h new file mode 100644 index 00000000000..4d2681ea0cd --- /dev/null +++ b/source/blender/compositor/COM_precomp.h @@ -0,0 +1,33 @@ +/* Pre-compiled headers, see: D13797. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "COM_ConstantOperation.h" +#include "COM_ConvertOperation.h" +#include "COM_Debug.h" +#include "COM_Enums.h" +#include "COM_ExecutionGroup.h" +#include "COM_ExecutionSystem.h" +#include "COM_MultiThreadedOperation.h" +#include "COM_Node.h" +#include "COM_NodeOperation.h" +#include "COM_OpenCLDevice.h" +#include "COM_SetAlphaMultiplyOperation.h" +#include "COM_SetColorOperation.h" +#include "COM_SetSamplerOperation.h" +#include "COM_SetValueOperation.h" +#include "COM_SetVectorOperation.h" +#include "COM_defines.h" diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 0e871f47b87..e601ebac4e1 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -136,7 +136,7 @@ void add_exr_channels(void *exrhandle, const char *layer_name, const DataType datatype, const char *view_name, - const size_t width, + size_t width, bool use_half_float, float *buf); void free_exr_channels(void *exrhandle, diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 1c09417e9ab..fcdc3fe58e8 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1475,6 +1475,17 @@ void DepsgraphRelationBuilder::build_animation_images(ID *id) id, NodeType::IMAGE_ANIMATION, OperationCode::IMAGE_ANIMATION); TimeSourceKey time_src_key; add_relation(time_src_key, image_animation_key, "TimeSrc -> Image Animation"); + + /* The image users of these ids may change during evaluation. Make sure that the image + * animation update happens after evaluation. */ + if (GS(id->name) == ID_MA) { + OperationKey material_update_key(id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE); + add_relation(material_update_key, image_animation_key, "Material Update -> Image Animation"); + } + else if (GS(id->name) == ID_WO) { + OperationKey world_update_key(id, NodeType::SHADING, OperationCode::WORLD_UPDATE); + add_relation(world_update_key, image_animation_key, "World Update -> Image Animation"); + } } } diff --git a/source/blender/depsgraph/intern/node/deg_node_factory.h b/source/blender/depsgraph/intern/node/deg_node_factory.h index 125f340a0fa..b3153a7ddfb 100644 --- a/source/blender/depsgraph/intern/node/deg_node_factory.h +++ b/source/blender/depsgraph/intern/node/deg_node_factory.h @@ -55,7 +55,7 @@ template struct DepsNodeFactoryImpl : public DepsNodeFacto void register_node_typeinfo(DepsNodeFactory *factory); /* Get typeinfo for specified type */ -DepsNodeFactory *type_get_factory(const NodeType type); +DepsNodeFactory *type_get_factory(NodeType type); } // namespace deg } // namespace blender diff --git a/source/blender/draw/intern/draw_cache_impl_curve.cc b/source/blender/draw/intern/draw_cache_impl_curve.cc index 33cf0e9a3cd..1108d40125b 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.cc +++ b/source/blender/draw/intern/draw_cache_impl_curve.cc @@ -26,8 +26,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc index b846da3f016..ea702e5efdd 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc @@ -25,7 +25,9 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" +#include "BLI_float4.hh" #include "BLI_string.h" #include "BKE_attribute.h" diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 73a94f066e3..79dda480a0a 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -54,6 +54,7 @@ #include "BKE_deform.h" #include "BKE_global.h" #include "BKE_gpencil.h" +#include "BKE_gpencil_curve.h" #include "BKE_gpencil_geom.h" #include "BKE_layer.h" #include "BKE_main.h" @@ -834,7 +835,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p, /* color strength */ if (brush_settings->flag & GP_BRUSH_USE_STRENGTH_PRESSURE) { pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); } /* Set vertex colors for buffer. */ @@ -918,6 +919,19 @@ static short gpencil_stroke_addpoint(tGPsdata *p, return GP_STROKEADD_INVALID; } +static void gpencil_stroke_unselect(bGPdata *gpd, bGPDstroke *gps) +{ + gps->flag &= ~GP_STROKE_SELECT; + BKE_gpencil_stroke_select_index_reset(gps); + for (int i = 0; i < gps->totpoints; i++) { + gps->points[i].flag &= ~GP_SPOINT_SELECT; + } + /* Update the selection from the stroke to the curve. */ + if (gps->editcurve) { + BKE_gpencil_editcurve_stroke_sync_selection(gpd, gps, gps->editcurve); + } +} + /* make a new stroke from the buffer data */ static void gpencil_stroke_newfrombuffer(tGPsdata *p) { @@ -928,6 +942,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) tGPspoint *ptc; MDeformVert *dvert = NULL; Brush *brush = p->brush; + BrushGpencilSettings *brush_settings = brush->gpencil_settings; ToolSettings *ts = p->scene->toolsettings; Depsgraph *depsgraph = p->depsgraph; Object *obact = (Object *)p->ownerPtr.data; @@ -1016,7 +1031,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; /* Apply the vertex color to point. */ @@ -1050,7 +1065,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); pt->time = ptc->time; /* Apply the vertex color to point. */ ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); @@ -1175,7 +1190,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* copy pressure and time */ pt->pressure = ptc->pressure; pt->strength = ptc->strength; - CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); + CLAMP(pt->strength, MIN2(GPENCIL_STRENGTH_MIN, brush_settings->draw_strength), 1.0f); copy_v4_v4(pt->vert_color, ptc->vert_color); pt->time = ptc->time; pt->uv_fac = ptc->uv_fac; @@ -1300,7 +1315,12 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) ctrl2, GPENCIL_MINIMUM_JOIN_DIST, &pt_index); + if (gps_target != NULL) { + /* Unselect all points of source and destination strokes. This is required to avoid + * a change in the resolution of the original strokes during the join. */ + gpencil_stroke_unselect(gpd, gps); + gpencil_stroke_unselect(gpd, gps_target); gps = ED_gpencil_stroke_join_and_trim(p->gpd, p->gpf, gps, gps_target, pt_index); } else { diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h index 8a669a2afc2..6bcddfa631a 100644 --- a/source/blender/editors/include/ED_util.h +++ b/source/blender/editors/include/ED_util.h @@ -102,7 +102,7 @@ void ED_slider_destroy(struct bContext *C, struct tSlider *slider); */ void ED_slider_status_string_get(const struct tSlider *slider, char *status_string, - const size_t size_of_status_string); + size_t size_of_status_string); float ED_slider_factor_get(struct tSlider *slider); void ED_slider_factor_set(struct tSlider *slider, float factor); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index f01b8318e98..9ce07cd2e07 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -495,7 +495,7 @@ float UI_text_clip_middle_ex(const struct uiFontStyle *fstyle, char *str, float okwidth, float minwidth, - const size_t max_len, + size_t max_len, char rpart_sep); /** @@ -2957,15 +2957,17 @@ void UI_fontstyle_set(const struct uiFontStyle *fs); void UI_fontstyle_draw_ex(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, + size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, - size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info); + void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str, + size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params); /** diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 027f03d05c7..923f741e3ae 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -688,11 +688,11 @@ extern void ui_hsvcube_pos_from_vals( */ extern void ui_but_string_get_ex(uiBut *but, char *str, - const size_t maxlen, + size_t maxlen, int float_precision, bool use_exp_float, bool *r_use_exp_float) ATTR_NONNULL(1, 2); -extern void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) ATTR_NONNULL(); +extern void ui_but_string_get(uiBut *but, char *str, size_t maxlen) ATTR_NONNULL(); /** * A version of #ui_but_string_get_ex for dynamic buffer sizes * (where #ui_but_string_get_max_length returns 0). diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index bc1d3387ad7..135cef5fe53 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1146,6 +1146,7 @@ static void panel_draw_aligned_widgets(const uiStyle *style, UI_fontstyle_draw(fontstyle, &title_rect, panel->drawname, + sizeof(panel->drawname), title_color, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index e146443faaa..fe58a6a05ae 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -74,6 +74,8 @@ #define UI_TIP_PADDING (int)(UI_TIP_PAD_FAC * UI_UNIT_Y) #define UI_TIP_MAXWIDTH 600 +#define UI_TIP_STR_MAX 1024 + typedef struct uiTooltipFormat { enum { UI_TIP_STYLE_NORMAL = 0, @@ -214,7 +216,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw header and active data (is done here to be able to change color) */ rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_MAIN]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); /* offset to the end of the last line */ if (field->text_suffix) { @@ -224,7 +226,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.ymax -= yofs; rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_ACTIVE]); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text_suffix, drawcol, &fs_params); + UI_fontstyle_draw( + &data->fstyle, &bbox, field->text_suffix, UI_TIP_STR_MAX, drawcol, &fs_params); /* undo offset */ bbox.xmin -= xofs; @@ -243,7 +246,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* XXX, needed because we don't have mono in 'U.uifonts' */ BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); - UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); } else { BLI_assert(field->format.style == UI_TIP_STYLE_NORMAL); @@ -255,7 +258,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region /* draw remaining data */ rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); UI_fontstyle_set(&data->fstyle); - UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); } bbox.ymax -= data->lineh * field->geom.lines; @@ -1215,12 +1218,12 @@ static ARegion *ui_tooltip_create_with_data(bContext *C, BLI_assert(ELEM(field->format.style, UI_TIP_STYLE_NORMAL, UI_TIP_STYLE_HEADER)); font_id = data->fstyle.uifont_id; } - w = BLF_width_ex(font_id, field->text, BLF_DRAW_STR_DUMMY_MAX, &info); + w = BLF_width_ex(font_id, field->text, UI_TIP_STR_MAX, &info); /* check for suffix (enum label) */ if (field->text_suffix && field->text_suffix[0]) { x_pos = info.width; - w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, BLF_DRAW_STR_DUMMY_MAX)); + w = max_ii(w, x_pos + BLF_width(font_id, field->text_suffix, UI_TIP_STR_MAX)); } fontw = max_ii(fontw, w); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index c28769a4951..44942d508ca 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -140,9 +140,9 @@ static uiFont *uifont_to_blfont(int id) void UI_fontstyle_draw_ex(const uiFontStyle *fs, const rcti *rect, const char *str, + const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params, - size_t len, int *r_xofs, int *r_yofs, struct ResultBLF *r_info) @@ -183,10 +183,10 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, } if (fs_params->align == UI_STYLE_TEXT_CENTER) { - xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); + xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len))); } else if (fs_params->align == UI_STYLE_TEXT_RIGHT) { - xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len); + xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len); } yofs = MAX2(0, yofs); @@ -196,7 +196,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_color4ubv(fs->uifont_id, col); - BLF_draw_ex(fs->uifont_id, str, len, r_info); + BLF_draw_ex(fs->uifont_id, str, str_len, r_info); BLF_disable(fs->uifont_id, font_flag); @@ -211,12 +211,11 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs, void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, + const size_t str_len, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params) { - int xofs, yofs; - - UI_fontstyle_draw_ex(fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, NULL); + UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, NULL, NULL, NULL); } void UI_fontstyle_draw_rotated(const uiFontStyle *fs, diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ad8c0842657..b44496731f7 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2130,11 +2130,11 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, + drawlen, wcol->text, &(struct uiFontStyleDraw_Params){ .align = align, }, - drawlen, &font_xofs, &font_yofs, NULL); @@ -2194,6 +2194,7 @@ static void widget_draw_text(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, drawstr_right, + UI_MAX_DRAW_STR, col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5417,11 +5418,11 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw_ex(fstyle, rect, drawstr, + sizeof(drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, }, - BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, &info); @@ -5468,6 +5469,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, rect, hint_drawstr, + sizeof(hint_drawstr), wt->wcol.text, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_RIGHT, @@ -5523,6 +5525,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle, UI_fontstyle_draw(fstyle, &trect, drawstr, + sizeof(drawstr), text_col, &(struct uiFontStyleDraw_Params){ .align = text_align, diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index b9943d13b19..06e21f91d04 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -3527,6 +3527,8 @@ static int object_add_named_exec(bContext *C, wmOperator *op) } basen->object->visibility_flag &= ~OB_HIDE_VIEWPORT; + /* Do immediately, as #copy_object_set_idnew() below operates on visible objects. */ + BKE_base_eval_flags(basen); /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or * BKE_view_layer_base_deselect_all(). */ diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 16e83395401..4f94927533b 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -722,7 +722,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r SpaceProperties *sbuts = CTX_wm_space_properties(C); ShaderPreview *sp = static_cast(WM_jobs_customdata(wm, area)); rcti newrect; - int ok; + bool ok; int newx = BLI_rcti_size_x(rect); int newy = BLI_rcti_size_y(rect); diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 44e9735866d..dd1b4e10e60 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -240,6 +240,7 @@ static void file_draw_string(int sx, UI_fontstyle_draw(&fs, &rect, fname, + sizeof(fname), col, &(struct uiFontStyleDraw_Params){ .align = align, @@ -289,12 +290,12 @@ static void file_draw_string_multiline(int sx, UI_fontstyle_draw_ex(&style->widget, &rect, string, + len, text_col, &(struct uiFontStyleDraw_Params){ .align = UI_STYLE_TEXT_LEFT, .word_wrap = true, }, - len, NULL, NULL, &result); diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 2d3c42b16d1..e9a385c525b 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2452,7 +2452,7 @@ static void frame_node_draw_label(const bNodeTree &ntree, const bool has_label = node.label[0] != '\0'; if (has_label) { BLF_position(fontid, x, y, 0); - BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, label, sizeof(label)); } /* draw text body */ diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 02d68189997..4834ca3174a 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -28,9 +28,9 @@ #include "DNA_anim_types.h" #include "DNA_node_types.h" +#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_vector.hh" diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index 740d1fbb6f9..0f542734f66 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -23,7 +23,7 @@ #pragma once -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" #include "BLI_vector.hh" #include "BKE_node.h" @@ -43,6 +43,9 @@ struct bNodeLink; struct bNodeSocket; struct wmGizmoGroupType; struct wmKeyConfig; +namespace blender { +struct float2; +} struct wmWindow; /** Temporary data used in node link drag modal operator. */ diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index 803cf38c53a..334ca1f76ee 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -111,13 +111,11 @@ static bNode *node_under_mouse_select(bNodeTree &ntree, int mx, int my) static bNode *node_under_mouse_tweak(bNodeTree &ntree, const float2 &mouse) { - using namespace blender::math; - LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) { if (node->type == NODE_REROUTE) { bNodeSocket *socket = (bNodeSocket *)node->inputs.first; const float2 location{socket->locx, socket->locy}; - if (distance(mouse, location) < 24.0f) { + if (float2::distance(mouse, location) < 24.0f) { return node; } } diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index e814530d1e2..6dffc0bc2a4 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -2262,28 +2262,15 @@ void sequencer_draw_preview(const bContext *C, seq_prefetch_wm_notify(C, scene); } -/* Draw backdrop in sequencer timeline. */ -static void draw_seq_backdrop(View2D *v2d) +static void draw_seq_timeline_channels(View2D *v2d) { - int i; - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - /* View backdrop. */ - immUniformThemeColor(TH_BACK); - immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax); - - /* Darker overlay over the view backdrop. */ - immUniformThemeColorShade(TH_BACK, -10); - immRectf(pos, v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0); - - /* Alternating horizontal stripes. */ - i = max_ii(1, ((int)v2d->cur.ymin) - 1); - GPU_blend(GPU_BLEND_ALPHA); immUniformThemeColor(TH_ROW_ALTERNATE); + /* Alternating horizontal stripes. */ + int i = max_ii(1, ((int)v2d->cur.ymin) - 1); while (i < v2d->cur.ymax) { if (i & 1) { immRectf(pos, v2d->cur.xmin, i, v2d->cur.xmax, i + 1); @@ -2295,6 +2282,14 @@ static void draw_seq_backdrop(View2D *v2d) immUnbindProgram(); } +static void draw_seq_timeline_channel_numbers(ARegion *region) +{ + View2D *v2d = ®ion->v2d; + rcti rect; + BLI_rcti_init(&rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); + UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); +} + static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *region) { Scene *scene = CTX_data_scene(C); @@ -2718,7 +2713,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region) } UI_view2d_view_ortho(v2d); - draw_seq_backdrop(v2d); + draw_seq_timeline_channels(v2d); if ((sseq->flag & SEQ_SHOW_OVERLAY) && (sseq->timeline_overlay.flag & SEQ_TIMELINE_SHOW_GRID)) { U.v2d_min_gridsize *= 3; UI_view2d_draw_lines_x__discrete_frames_or_seconds( @@ -2776,13 +2771,7 @@ void draw_timeline_seq(const bContext *C, ARegion *region) UI_view2d_view_restore(C); ED_time_scrub_draw(region, scene, !(sseq->flag & SEQ_DRAWFRAMES), true); - /* Draw channel numbers. */ - { - rcti rect; - BLI_rcti_init( - &rect, 0, 15 * UI_DPI_FAC, 15 * UI_DPI_FAC, region->winy - UI_TIME_SCRUB_MARGIN_Y); - UI_view2d_draw_scale_y__block(region, v2d, &rect, TH_SCROLL_TEXT); - } + draw_seq_timeline_channel_numbers(region); } void draw_timeline_seq_display(const bContext *C, ARegion *region) diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc index ede8756a9da..ee623083db7 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc @@ -19,8 +19,9 @@ #include "MEM_guardedalloc.h" #include "BLI_color.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_hash.hh" -#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index f4b5ff819ed..7cc2d8d0b48 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -17,7 +17,8 @@ #include #include -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BKE_geometry_set.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc index 556c0b0d5ca..36c7f1057df 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc @@ -123,7 +123,9 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float2 cell) { return math::distance_squared(cell, value) > threshold_sq; }, + [&](const float2 cell) { + return float2::distance_squared(cell, value) > threshold_sq; + }, prev_mask, new_indices); break; @@ -153,7 +155,9 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float3 cell) { return math::distance_squared(cell, value) > threshold_sq; }, + [&](const float3 cell) { + return float3::distance_squared(cell, value) > threshold_sq; + }, prev_mask, new_indices); break; diff --git a/source/blender/editors/util/ed_draw.c b/source/blender/editors/util/ed_draw.c index ccbde07f5b1..3e85862a847 100644 --- a/source/blender/editors/util/ed_draw.c +++ b/source/blender/editors/util/ed_draw.c @@ -599,9 +599,9 @@ static void metadata_custom_draw_fields(const char *field, const char *value, vo } MetadataCustomDrawContext *ctx = (MetadataCustomDrawContext *)ctx_v; char temp_str[MAX_METADATA_STR]; - BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: %s", field, value); + SNPRINTF(temp_str, "%s: %s", field, value); BLF_position(ctx->fontid, ctx->xmin, ctx->ymin + ctx->current_y, 0.0f); - BLF_draw(ctx->fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(ctx->fontid, temp_str, sizeof(temp_str)); ctx->current_y += ctx->vertical_offset; } @@ -625,18 +625,18 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const /* first line */ if (i == 0) { bool do_newline = false; - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[0]); if (metadata_is_valid(ibuf, temp_str, 0, len)) { BLF_position(fontid, xmin, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); do_newline = true; } - len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]); + len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[1]); if (metadata_is_valid(ibuf, temp_str, 1, len)) { - int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); BLF_position(fontid, xmax - line_width, ymax - vertical_offset, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); do_newline = true; } @@ -645,32 +645,32 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const } } /* Strip */ else if (ELEM(i, 1, 2)) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); ofs_y += vertical_offset; } } /* Note (wrapped) */ else if (i == 3) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { struct ResultBLF info; BLF_enable(fontid, BLF_WORD_WRAP); BLF_wordwrap(fontid, ibuf->x - (margin * 2)); BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw_ex(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX, &info); + BLF_draw_ex(fontid, temp_str, sizeof(temp_str), &info); BLF_wordwrap(fontid, 0); BLF_disable(fontid, BLF_WORD_WRAP); ofs_y += vertical_offset * info.lines; } } else { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { - int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + int line_width = BLF_width(fontid, temp_str, sizeof(temp_str)); BLF_position(fontid, xmax - line_width, ymax - vertical_offset - ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); ofs_y += vertical_offset; } } @@ -687,12 +687,12 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const int ofs_x = 0; ofs_y = ctx.current_y; for (int i = 5; i < 10; i++) { - int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); + int len = SNPRINTF_RLEN(temp_str, "%s: ", meta_data_list[i]); if (metadata_is_valid(ibuf, temp_str, i, len)) { BLF_position(fontid, xmin + ofs_x, ymin + ofs_y, 0.0f); - BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw(fontid, temp_str, sizeof(temp_str)); - ofs_x += BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX) + UI_UNIT_X; + ofs_x += BLF_width(fontid, temp_str, sizeof(temp_str)) + UI_UNIT_X; } } } diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt index b7eaf018dba..47da6bc55f6 100644 --- a/source/blender/freestyle/CMakeLists.txt +++ b/source/blender/freestyle/CMakeLists.txt @@ -594,4 +594,7 @@ if(WIN32) endif() blender_add_lib(bf_freestyle "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") -blender_precompile_headers(bf_freestyle FRS_precomp.cpp FRS_precomp.h) + +if(COMMAND target_precompile_headers) + target_precompile_headers(bf_freestyle PRIVATE FRS_precomp.h) +endif() diff --git a/source/blender/freestyle/FRS_precomp.cpp b/source/blender/freestyle/FRS_precomp.cpp deleted file mode 100644 index 7e50a47f45b..00000000000 --- a/source/blender/freestyle/FRS_precomp.cpp +++ /dev/null @@ -1,2 +0,0 @@ -/* Pre-compiled headers, see: D2606. */ -#include "FRS_precomp.h" diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc index 0bbfbc8cb10..058fb76af2b 100644 --- a/source/blender/functions/intern/cpp_types.cc +++ b/source/blender/functions/intern/cpp_types.cc @@ -18,8 +18,9 @@ #include "FN_field_cpp_type.hh" #include "BLI_color.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" -#include "BLI_math_vec_types.hh" namespace blender::fn { diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index c7481c6ea67..65d7631445d 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -544,7 +544,7 @@ bool IMB_prepare_write_ImBuf(bool isfloat, struct ImBuf *ibuf); */ bool IMB_ispic(const char *filepath); bool IMB_ispic_type_matches(const char *filepath, int filetype); -int IMB_ispic_type_from_memory(const unsigned char *buf, const size_t buf_size); +int IMB_ispic_type_from_memory(const unsigned char *buf, size_t buf_size); int IMB_ispic_type(const char *filepath); /** @@ -972,28 +972,20 @@ void IMB_update_gpu_texture_sub(struct GPUTexture *tex, /** * \attention defined in stereoimbuf.c */ -void IMB_stereo3d_write_dimensions(char mode, - bool is_squeezed, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); -void IMB_stereo3d_read_dimensions(char mode, - bool is_squeezed, - const size_t width, - const size_t height, - size_t *r_width, - size_t *r_height); +void IMB_stereo3d_write_dimensions( + char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); +void IMB_stereo3d_read_dimensions( + char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height); int *IMB_stereo3d_from_rect(struct ImageFormatData *im_format, - const size_t x, - const size_t y, - const size_t channels, + size_t x, + size_t y, + size_t channels, int *rect_left, int *rect_right); float *IMB_stereo3d_from_rectf(struct ImageFormatData *im_format, - const size_t x, - const size_t y, - const size_t channels, + size_t x, + size_t y, + size_t channels, float *rectf_left, float *rectf_right); /** diff --git a/source/blender/imbuf/IMB_metadata.h b/source/blender/imbuf/IMB_metadata.h index 652ce913ee5..50982d08c3e 100644 --- a/source/blender/imbuf/IMB_metadata.h +++ b/source/blender/imbuf/IMB_metadata.h @@ -58,10 +58,7 @@ void IMB_metadata_free(struct IDProperty *metadata); * \param len: length of value buffer allocated by user. * \return 1 (true) if metadata is present and value for the key found, 0 (false) otherwise. */ -bool IMB_metadata_get_field(struct IDProperty *metadata, - const char *key, - char *value, - const size_t len); +bool IMB_metadata_get_field(struct IDProperty *metadata, const char *key, char *value, size_t len); /** * Set user data in the metadata. diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h index 104458ffa7a..bf6aef3ecd3 100644 --- a/source/blender/imbuf/intern/IMB_filetype.h +++ b/source/blender/imbuf/intern/IMB_filetype.h @@ -41,7 +41,7 @@ typedef struct ImFileType { * \note that this may only read in a small part of the files header, * see: #IMB_ispic_type for details. */ - bool (*is_a)(const unsigned char *buf, const size_t size); + bool (*is_a)(const unsigned char *buf, size_t size); /** Load an image from memory. */ struct ImBuf *(*load)(const unsigned char *mem, @@ -93,7 +93,7 @@ void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty); /** \name Format: PNG (#IMB_FTYPE_PNG) * \{ */ -bool imb_is_a_png(const unsigned char *mem, const size_t size); +bool imb_is_a_png(const unsigned char *mem, size_t size); struct ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, @@ -106,7 +106,7 @@ bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: TARGA (#IMB_FTYPE_TGA) * \{ */ -bool imb_is_a_targa(const unsigned char *buf, const size_t size); +bool imb_is_a_targa(const unsigned char *buf, size_t size); struct ImBuf *imb_loadtarga(const unsigned char *mem, size_t size, int flags, @@ -119,7 +119,7 @@ bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: IRIS (#IMB_FTYPE_IMAGIC) * \{ */ -bool imb_is_a_iris(const unsigned char *mem, const size_t size); +bool imb_is_a_iris(const unsigned char *mem, size_t size); /** * Read in a B/W RGB or RGBA iris image file and return an image buffer. */ @@ -135,7 +135,7 @@ bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JP2 (#IMB_FTYPE_JP2) * \{ */ -bool imb_is_a_jp2(const unsigned char *buf, const size_t size); +bool imb_is_a_jp2(const unsigned char *buf, size_t size); struct ImBuf *imb_load_jp2(const unsigned char *mem, size_t size, int flags, @@ -151,7 +151,7 @@ bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JPEG (#IMB_FTYPE_JPG) * \{ */ -bool imb_is_a_jpeg(const unsigned char *mem, const size_t size); +bool imb_is_a_jpeg(const unsigned char *mem, size_t size); bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags); struct ImBuf *imb_load_jpeg(const unsigned char *buffer, size_t size, @@ -164,7 +164,7 @@ struct ImBuf *imb_load_jpeg(const unsigned char *buffer, /** \name Format: BMP (#IMB_FTYPE_BMP) * \{ */ -bool imb_is_a_bmp(const unsigned char *buf, const size_t size); +bool imb_is_a_bmp(const unsigned char *buf, size_t size); struct ImBuf *imb_bmp_decode(const unsigned char *mem, size_t size, int flags, @@ -178,7 +178,7 @@ bool imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: CINEON (#IMB_FTYPE_CINEON) * \{ */ -bool imb_is_a_cineon(const unsigned char *buf, const size_t size); +bool imb_is_a_cineon(const unsigned char *buf, size_t size); bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_cineon(const unsigned char *mem, size_t size, @@ -191,7 +191,7 @@ struct ImBuf *imb_load_cineon(const unsigned char *mem, /** \name Format: DPX (#IMB_FTYPE_DPX) * \{ */ -bool imb_is_a_dpx(const unsigned char *buf, const size_t size); +bool imb_is_a_dpx(const unsigned char *buf, size_t size); bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_dpx(const unsigned char *mem, size_t size, @@ -204,7 +204,7 @@ struct ImBuf *imb_load_dpx(const unsigned char *mem, /** \name Format: HDR (#IMB_FTYPE_RADHDR) * \{ */ -bool imb_is_a_hdr(const unsigned char *buf, const size_t size); +bool imb_is_a_hdr(const unsigned char *buf, size_t size); struct ImBuf *imb_loadhdr(const unsigned char *mem, size_t size, int flags, @@ -218,7 +218,7 @@ bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags); * \{ */ void imb_inittiff(void); -bool imb_is_a_tiff(const unsigned char *buf, const size_t size); +bool imb_is_a_tiff(const unsigned char *buf, size_t size); /** * Loads a TIFF file. * \param mem: Memory containing the TIFF file. diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 1d81653c7cd..6a05b681c88 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -879,7 +879,7 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); # else - /* Scale with swscale then flip image over Y axis. */ + /* Scale with swscale. */ int *dstStride = anim->pFrameRGB->linesize; uint8_t **dst = anim->pFrameRGB->data; const int dstStride2[4] = {dstStride[0], 0, 0, 0}; @@ -896,11 +896,12 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); - bottom = (unsigned char *)ibuf->rect; - top = bottom + ibuf->x * (ibuf->y - 1) * 4; + /* Flip destination image buffer over Y axis. */ + bottom = (unsigned char *)dst[0]; + top = bottom + anim->x * (anim->y - 1) * 4; - h = (ibuf->y + 1) / 2; - w = ibuf->x; + h = (anim->y + 1) / 2; + w = anim->x; for (y = 0; y < h; y++) { unsigned char tmp[4]; diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index 931c4f267f9..2d540f13a52 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -26,7 +26,7 @@ extern "C" { #endif -bool imb_is_a_dds(const unsigned char *mem, const size_t size); +bool imb_is_a_dds(const unsigned char *mem, size_t size); bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_dds(const unsigned char *mem, size_t size, diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index 659050cdb00..1201bd1b5e0 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -31,7 +31,7 @@ extern "C" { struct ImBuf; -bool imb_is_a_photoshop(const unsigned char *mem, const size_t size); +bool imb_is_a_photoshop(const unsigned char *mem, size_t size); int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h index 14336620926..4321c95db30 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.h +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -36,7 +36,7 @@ void imb_exitopenexr(void); * Test presence of OpenEXR file. * \param mem: pointer to loaded OpenEXR bit-stream. */ -bool imb_is_a_openexr(const unsigned char *mem, const size_t size); +bool imb_is_a_openexr(const unsigned char *mem, size_t size); bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 7f4e4dd31df..925ef0a8502 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -77,7 +77,7 @@ static const unsigned char *oldreadcolrs(RGBE *scan, scan[0][BLU] = *mem++; scan[0][EXP] = *mem++; if (scan[0][RED] == 1 && scan[0][GRN] == 1 && scan[0][BLU] == 1) { - for (i = scan[0][EXP] << rshift; i > 0; i--) { + for (i = scan[0][EXP] << rshift; i > 0 && len > 0; i--) { COPY_RGBE(scan[-1], scan[0]); scan++; len--; @@ -227,7 +227,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, int found = 0; int width = 0, height = 0; const unsigned char *ptr, *mem_eof = mem + size; - char oriY[80], oriX[80]; + char oriY[3], oriX[3]; if (!imb_is_a_hdr(mem, size)) { return NULL; @@ -244,22 +244,33 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, } } - if ((found && (x < (size + 2))) == 0) { + if ((found && (x < (size - 1))) == 0) { /* Data not found! */ return NULL; } - if (sscanf((const char *)&mem[x + 1], - "%79s %d %79s %d", - (char *)&oriY, - &height, - (char *)&oriX, - &width) != 4) { + x++; + + /* sscanf requires a null-terminated buffer argument */ + char buf[32] = {0}; + memcpy(buf, &mem[x], MIN2(sizeof(buf) - 1, size - x)); + + if (sscanf(buf, "%2s %d %2s %d", (char *)&oriY, &height, (char *)&oriX, &width) != 4) { + return NULL; + } + + if (width < 1 || height < 1) { return NULL; } + /* Checking that width x height does not extend past mem_eof is not easily possible + * since the format uses RLE compression. Can cause excessive memory allocation to occur. */ + /* find end of this line, data right behind it */ - ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n'); + ptr = (const unsigned char *)strchr((const char *)&mem[x], '\n'); + if (ptr == NULL || ptr >= mem_eof) { + return NULL; + } ptr++; if (flags & IB_test) { diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc index 4a359c49d26..86fa580bf1f 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.cc +++ b/source/blender/io/alembic/intern/abc_reader_object.cc @@ -120,29 +120,10 @@ static Imath::M44d blend_matrices(const Imath::M44d &m0, const Imath::M44d &m1, * the matrices manually. */ - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - mat0[i][j] = static_cast(m0[i][j]); - } - } - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - mat1[i][j] = static_cast(m1[i][j]); - } - } - + convert_matrix_datatype(m0, mat0); + convert_matrix_datatype(m1, mat1); interp_m4_m4m4(ret, mat0, mat1, weight); - - Imath::M44d m; - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - m[i][j] = ret[i][j]; - } - } - - return m; + return convert_matrix_datatype(ret); } Imath::M44d get_matrix(const IXformSchema &schema, const float time) diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc index 7868bade8c1..f031648d2ed 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc @@ -23,8 +23,9 @@ * \ingroup bgpencil */ +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" -#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_span.hh" @@ -282,7 +283,7 @@ float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, bGPDstroke *gps) const float2 screen_ex = gpencil_3D_point_to_2D(&pt->x); const float2 v1 = screen_co - screen_ex; - float radius = math::length(v1); + float radius = v1.length(); BKE_gpencil_free_stroke(gps_perimeter); return MAX2(radius, 1.0f); diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.hh b/source/blender/io/gpencil/intern/gpencil_io_base.hh index ae54d5056dc..09557cd7a4d 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.hh +++ b/source/blender/io/gpencil/intern/gpencil_io_base.hh @@ -22,8 +22,9 @@ * \ingroup bgpencil */ +#include "BLI_float2.hh" +#include "BLI_float3.hh" #include "BLI_float4x4.hh" -#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "DNA_space_types.h" /* for FILE_MAX */ diff --git a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc index 455ebb7c3cb..941d1137f4d 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc @@ -21,8 +21,8 @@ * \ingroup bgpencil */ +#include "BLI_float3.hh" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_gpencil_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh index e6d2853d040..9a4dfe3efe3 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh @@ -22,7 +22,7 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_utility_mixins.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index 5b710939e00..b99d41e0c72 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -21,8 +21,8 @@ #include "BKE_image.h" #include "BKE_node.h" +#include "BLI_float3.hh" #include "BLI_map.hh" -#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "DNA_material_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh index a84dcb80a48..2f62d189bd1 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh @@ -20,8 +20,8 @@ #pragma once +#include "BLI_float3.hh" #include "BLI_map.hh" -#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc index ec690115115..91aabd8fa76 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc @@ -18,9 +18,9 @@ * \ingroup obj */ +#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" -#include "BLI_math_vec_types.hh" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index 0feca806f35..f9151bb97f8 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -236,7 +236,7 @@ TEST(obj_exporter_writer, mtllib) static bool strings_equal_after_first_lines(const std::string &a, const std::string &b) { /* If `dbg_level > 0` then a failing test will print context around the first mismatch. */ - const bool dbg_level = 0; + const int dbg_level = 0; const size_t a_len = a.size(); const size_t b_len = b.size(); const size_t a_next = a.find_first_of('\n'); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index fc041e257b0..1d0796bda8b 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1852,6 +1852,7 @@ enum { MOD_TRIANGULATE_QUAD_FIXED = 1, MOD_TRIANGULATE_QUAD_ALTERNATE = 2, MOD_TRIANGULATE_QUAD_SHORTEDGE = 3, + MOD_TRIANGULATE_QUAD_LONGEDGE = 4, }; typedef struct LaplacianSmoothModifierData { diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 29d61bcf2ff..114e350b582 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -2118,6 +2118,7 @@ typedef enum GeometryNodeTriangulateQuads { GEO_NODE_TRIANGULATE_QUAD_FIXED = 1, GEO_NODE_TRIANGULATE_QUAD_ALTERNATE = 2, GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE = 3, + GEO_NODE_TRIANGULATE_QUAD_LONGEDGE = 4, } GeometryNodeTriangulateQuads; typedef enum GeometryNodePointInstanceType { diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 77c0db81b37..b32d98e3cb1 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -1743,7 +1743,7 @@ bool RNA_struct_override_matches(struct Main *bmain, struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, const char *root_path, - const size_t root_path_len, + size_t root_path_len, struct IDOverrideLibrary *override, eRNAOverrideMatch flags, eRNAOverrideMatchResult *r_report_flags); diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 20e6e931b4b..95ad184c6b9 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -544,7 +544,7 @@ int rna_property_override_diff_default(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - const size_t rna_path_len, + size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index f0e32a19d04..723ae384fdf 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -214,7 +214,7 @@ typedef int (*RNAPropOverrideDiff)(struct Main *bmain, int mode, struct IDOverrideLibrary *override, const char *rna_path, - const size_t rna_path_len, + size_t rna_path_len, int flags, bool *r_override_changed); diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index d46ae13b482..0f0734c8448 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -331,7 +331,12 @@ const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[] = { "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads based on the distance between the vertices"}, + "Split the quads along their shortest diagonal"}, + {MOD_TRIANGULATE_QUAD_LONGEDGE, + "LONGEST_DIAGONAL", + 0, + "Longest Diagonal", + "Split the quads along their longest diagonal"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index e7307e6e058..ecbeadf1fa4 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -9488,7 +9488,12 @@ static void def_geo_triangulate(StructRNA *srna) "SHORTEST_DIAGONAL", 0, "Shortest Diagonal", - "Split the quads based on the distance between the vertices"}, + "Split the quads along their shortest diagonal"}, + {GEO_NODE_TRIANGULATE_QUAD_LONGEDGE, + "LONGEST_DIAGONAL", + 0, + "Longest Diagonal", + "Split the quads along their longest diagonal"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc index 910b52dea67..778b5746471 100644 --- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc +++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc @@ -197,8 +197,8 @@ static float compute_voxel_size(const ModifierEvalContext *ctx, /* Compute the voxel size based on the desired number of voxels and the approximated bounding box * of the volume. */ const BoundBox *bb = BKE_object_boundbox_get(mvmd->object); - const float diagonal = math::distance(transform * float3(bb->vec[6]), - transform * float3(bb->vec[0])); + const float diagonal = float3::distance(transform * float3(bb->vec[6]), + transform * float3(bb->vec[0])); const float approximate_volume_side_length = diagonal + mvmd->exterior_band_width * 2.0f; const float voxel_size = approximate_volume_side_length / mvmd->voxel_amount / volume_simplify; return voxel_size; diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 49528845197..cee5d0be65d 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -28,8 +28,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" +#include "BLI_float3.hh" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_multi_value_map.hh" #include "BLI_set.hh" #include "BLI_string.h" diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh index 6ea89beee2e..a0a2e6f81f8 100644 --- a/source/blender/nodes/NOD_math_functions.hh +++ b/source/blender/nodes/NOD_math_functions.hh @@ -18,9 +18,9 @@ #include "DNA_node_types.h" +#include "BLI_float3.hh" #include "BLI_math_base_safe.h" #include "BLI_math_rotation.h" -#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" namespace blender::nodes { @@ -240,8 +240,6 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -261,21 +259,40 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation case NODE_VECTOR_MATH_MULTIPLY: return dispatch([](float3 a, float3 b) { return a * b; }); case NODE_VECTOR_MATH_DIVIDE: - return dispatch([](float3 a, float3 b) { return safe_divide(a, b); }); + return dispatch([](float3 a, float3 b) { + return float3(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z)); + }); case NODE_VECTOR_MATH_CROSS_PRODUCT: - return dispatch([](float3 a, float3 b) { return cross_high_precision(a, b); }); + return dispatch([](float3 a, float3 b) { return float3::cross_high_precision(a, b); }); case NODE_VECTOR_MATH_PROJECT: - return dispatch([](float3 a, float3 b) { return project(a, b); }); + return dispatch([](float3 a, float3 b) { + float length_squared = b.length_squared(); + return (length_squared != 0.0) ? (float3::dot(a, b) / length_squared) * b : float3(0.0f); + }); case NODE_VECTOR_MATH_REFLECT: - return dispatch([](float3 a, float3 b) { return reflect(a, normalize(b)); }); + return dispatch([](float3 a, float3 b) { + b.normalize(); + return a.reflected(b); + }); case NODE_VECTOR_MATH_SNAP: - return dispatch([](float3 a, float3 b) { return floor(safe_divide(a, b)) * b; }); + return dispatch([](float3 a, float3 b) { + return float3(floor(safe_divide(a.x, b.x)), + floor(safe_divide(a.y, b.y)), + floor(safe_divide(a.z, b.z))) * + b; + }); case NODE_VECTOR_MATH_MODULO: - return dispatch([](float3 a, float3 b) { return mod(a, b); }); + return dispatch([](float3 a, float3 b) { + return float3(safe_modf(a.x, b.x), safe_modf(a.y, b.y), safe_modf(a.z, b.z)); + }); case NODE_VECTOR_MATH_MINIMUM: - return dispatch([](float3 a, float3 b) { return min(a, b); }); + return dispatch([](float3 a, float3 b) { + return float3(min_ff(a.x, b.x), min_ff(a.y, b.y), min_ff(a.z, b.z)); + }); case NODE_VECTOR_MATH_MAXIMUM: - return dispatch([](float3 a, float3 b) { return max(a, b); }); + return dispatch([](float3 a, float3 b) { + return float3(max_ff(a.x, b.x), max_ff(a.y, b.y), max_ff(a.z, b.z)); + }); default: return false; } @@ -289,8 +306,6 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -304,9 +319,9 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation switch (operation) { case NODE_VECTOR_MATH_DOT_PRODUCT: - return dispatch([](float3 a, float3 b) { return dot(a, b); }); + return dispatch([](float3 a, float3 b) { return float3::dot(a, b); }); case NODE_VECTOR_MATH_DISTANCE: - return dispatch([](float3 a, float3 b) { return distance(a, b); }); + return dispatch([](float3 a, float3 b) { return float3::distance(a, b); }); default: return false; } @@ -320,8 +335,6 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -341,7 +354,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOpera return float3(wrapf(a.x, b.x, c.x), wrapf(a.y, b.y, c.y), wrapf(a.z, b.z, c.z)); }); case NODE_VECTOR_MATH_FACEFORWARD: - return dispatch([](float3 a, float3 b, float3 c) { return faceforward(a, b, c); }); + return dispatch([](float3 a, float3 b, float3 c) { return float3::faceforward(a, b, c); }); default: return false; } @@ -355,8 +368,6 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -370,7 +381,8 @@ inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperat switch (operation) { case NODE_VECTOR_MATH_REFRACT: - return dispatch([](float3 a, float3 b, float c) { return refract(a, normalize(b), c); }); + return dispatch( + [](float3 a, float3 b, float c) { return float3::refract(a, b.normalized(), c); }); default: return false; } @@ -384,8 +396,6 @@ template inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -399,7 +409,7 @@ inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation oper switch (operation) { case NODE_VECTOR_MATH_LENGTH: - return dispatch([](float3 in) { return length(in); }); + return dispatch([](float3 in) { return in.length(); }); default: return false; } @@ -440,8 +450,6 @@ template inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { - using namespace blender::math; - const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -455,15 +463,20 @@ inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation ope switch (operation) { case NODE_VECTOR_MATH_NORMALIZE: - return dispatch([](float3 in) { return normalize(in); }); /* Should be safe. */ + return dispatch([](float3 in) { + float3 out = in; + out.normalize(); + return out; + }); /* Should be safe. */ case NODE_VECTOR_MATH_FLOOR: - return dispatch([](float3 in) { return floor(in); }); + return dispatch([](float3 in) { return float3(floor(in.x), floor(in.y), floor(in.z)); }); case NODE_VECTOR_MATH_CEIL: - return dispatch([](float3 in) { return ceil(in); }); + return dispatch([](float3 in) { return float3(ceil(in.x), ceil(in.y), ceil(in.z)); }); case NODE_VECTOR_MATH_FRACTION: - return dispatch([](float3 in) { return fract(in); }); + return dispatch( + [](float3 in) { return in - float3(floor(in.x), floor(in.y), floor(in.z)); }); case NODE_VECTOR_MATH_ABSOLUTE: - return dispatch([](float3 in) { return abs(in); }); + return dispatch([](float3 in) { return float3::abs(in); }); case NODE_VECTOR_MATH_SINE: return dispatch([](float3 in) { return float3(sinf(in.x), sinf(in.y), sinf(in.z)); }); case NODE_VECTOR_MATH_COSINE: diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh index a1972c66ca2..c0580a2c919 100644 --- a/source/blender/nodes/NOD_socket_declarations.hh +++ b/source/blender/nodes/NOD_socket_declarations.hh @@ -21,7 +21,7 @@ #include "RNA_types.h" #include "BLI_color.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" namespace blender::nodes::decl { diff --git a/source/blender/nodes/composite/node_composite_tree.cc b/source/blender/nodes/composite/node_composite_tree.cc index 08dbd4ad6f0..c54382cc1ad 100644 --- a/source/blender/nodes/composite/node_composite_tree.cc +++ b/source/blender/nodes/composite/node_composite_tree.cc @@ -249,23 +249,6 @@ void ntreeCompositUpdateRLayers(bNodeTree *ntree) } } -void ntreeCompositRegisterPass(bNodeTree *ntree, - Scene *scene, - ViewLayer *view_layer, - const char *name, - eNodeSocketDatatype type) -{ - if (ntree == nullptr) { - return; - } - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node->type == CMP_NODE_R_LAYERS) { - node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type); - } - } -} - void ntreeCompositTagRender(Scene *scene) { /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes, diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index 6f4f9d7e597..f2b9fbc2215 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -269,7 +269,12 @@ void node_cmp_rlayers_register_pass(bNodeTree *ntree, } } -static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), +struct CreateOutputUserData { + bNodeTree &ntree; + bNode &node; +}; + +static void cmp_node_rlayer_create_outputs_cb(void *userdata, Scene *scene, ViewLayer *view_layer, const char *name, @@ -277,18 +282,8 @@ static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), const char *UNUSED(chanid), eNodeSocketDatatype type) { - /* Register the pass in all scenes that have a render layer node for this layer. - * Since multiple scenes can be used in the compositor, the code must loop over all scenes - * and check whether their nodetree has a node that needs to be updated. */ - /* NOTE: using G_MAIN seems valid here, - * unless we want to register that for every other temp Main we could generate??? */ - ntreeCompositRegisterPass(scene->nodetree, scene, view_layer, name, type); - - for (Scene *sce = (Scene *)G_MAIN->scenes.first; sce; sce = (Scene *)sce->id.next) { - if (sce->nodetree && sce != scene) { - ntreeCompositRegisterPass(sce->nodetree, scene, view_layer, name, type); - } - } + CreateOutputUserData &data = *(CreateOutputUserData *)userdata; + node_cmp_rlayers_register_pass(&data.ntree, &data.node, scene, view_layer, name, type); } static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, @@ -308,14 +303,17 @@ static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, data->prev_index = -1; node->storage = data; + CreateOutputUserData userdata = {*ntree, *node}; + RenderEngine *engine = RE_engine_create(engine_type); RE_engine_update_render_passes( - engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, nullptr); + engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, &userdata); RE_engine_free(engine); if ((scene->r.mode & R_EDGE_FRS) && (view_layer->freestyle_config.flags & FREESTYLE_AS_RENDER_PASS)) { - ntreeCompositRegisterPass(ntree, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); + node_cmp_rlayers_register_pass( + ntree, node, scene, view_layer, RE_PASSNAME_FREESTYLE, SOCK_RGBA); } MEM_freeN(data); diff --git a/source/blender/nodes/function/node_function_util.hh b/source/blender/nodes/function/node_function_util.hh index 69c617b4f01..acde9c4b55b 100644 --- a/source/blender/nodes/function/node_function_util.hh +++ b/source/blender/nodes/function/node_function_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc index bcc035e6ede..f4ce8d2f35a 100644 --- a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc +++ b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc @@ -69,14 +69,14 @@ static void align_rotations_auto_pivot(IndexMask mask, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = math::normalize(vector); - float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); + const float3 new_axis = vector.normalized(); + float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc index 7c09bace756..3bb46511eeb 100644 --- a/source/blender/nodes/function/nodes/node_fn_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_compare.cc @@ -265,7 +265,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Than - Dot Product", - [](float3 a, float3 b, float comp) { return math::dot(a, b) < comp; }}; + [](float3 a, float3 b, float comp) { return float3::dot(a, b) < comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -283,7 +283,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Than - Length", - [](float3 a, float3 b) { return math::length(a) < math::length(b); }}; + [](float3 a, float3 b) { return a.length() < b.length(); }}; return &fn; } } @@ -299,7 +299,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Equal - Dot Product", - [](float3 a, float3 b, float comp) { return math::dot(a, b) <= comp; }}; + [](float3 a, float3 b, float comp) { return float3::dot(a, b) <= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -317,7 +317,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Equal - Length", - [](float3 a, float3 b) { return math::length(a) <= math::length(b); }}; + [](float3 a, float3 b) { return a.length() <= b.length(); }}; return &fn; } } @@ -333,7 +333,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Than - Dot Product", - [](float3 a, float3 b, float comp) { return math::dot(a, b) > comp; }}; + [](float3 a, float3 b, float comp) { return float3::dot(a, b) > comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -351,7 +351,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Than - Length", - [](float3 a, float3 b) { return math::length(a) > math::length(b); }}; + [](float3 a, float3 b) { return a.length() > b.length(); }}; return &fn; } } @@ -367,7 +367,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Equal - Dot Product", - [](float3 a, float3 b, float comp) { return math::dot(a, b) >= comp; }}; + [](float3 a, float3 b, float comp) { return float3::dot(a, b) >= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -385,7 +385,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Equal - Length", - [](float3 a, float3 b) { return math::length(a) >= math::length(b); }}; + [](float3 a, float3 b) { return a.length() >= b.length(); }}; return &fn; } } @@ -402,7 +402,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(math::dot(a, b) - comp) <= epsilon; + return abs(float3::dot(a, b) - comp) <= epsilon; }}; return &fn; } @@ -424,7 +424,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(math::length(a) - math::length(b)) <= epsilon; + return abs(a.length() - b.length()) <= epsilon; }}; return &fn; } @@ -442,7 +442,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Not Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(math::dot(a, b) - comp) >= epsilon; + return abs(float3::dot(a, b) - comp) >= epsilon; }}; return &fn; } @@ -464,7 +464,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Not Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(math::length(a) - math::length(b)) > epsilon; + return abs(a.length() - b.length()) > epsilon; }}; return &fn; } diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh index e063be62987..1c2a8f521c0 100644 --- a/source/blender/nodes/geometry/node_geometry_util.hh +++ b/source/blender/nodes/geometry/node_geometry_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_math_vec_types.hh" +#include "BLI_float3.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" @@ -83,7 +83,7 @@ Mesh *create_cylinder_or_cone_mesh(float radius_top, int circle_segments, int side_segments, int fill_segments, - const GeometryNodeMeshCircleFillType fill_type, + GeometryNodeMeshCircleFillType fill_type, ConeAttributeOutputs &attribute_outputs); Mesh *create_cuboid_mesh(float3 size, int verts_x, int verts_y, int verts_z); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc index 1d064586238..36ad4605a4b 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc @@ -90,14 +90,14 @@ static void align_rotations_auto_pivot(const VArray &vectors, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = math::normalize(vector); - float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); + const float3 new_axis = vector.normalized(); + float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc index 20f500b1bd8..74dac73f255 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc @@ -81,7 +81,7 @@ static void calculate_mesh_proximity(const VArray &positions, for (int i : range) { /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[i]); + nearest.dist_sq = float3::distance_squared(nearest.co, positions[i]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[i], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc index a85a7c56cb9..b0210f2eb94 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc @@ -229,7 +229,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = math::distance_squared(position, float3(mvert.co)); + const float distance_sq = float3::distance_squared(position, mvert.co); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc index 1e6b7f92a77..8555d7cc8a3 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc @@ -241,13 +241,13 @@ static void copy_uniform_sample_point_attributes(Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent = math::normalize(tangent); + tangent.normalize(); } spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals = math::normalize(normals); + normals.normalize(); } } }); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc index c712e82ca18..29eff373d15 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_point_distribute.cc @@ -321,7 +321,7 @@ BLI_NOINLINE static void interpolate_existing_attributes( continue; } - for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { + for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { const int offset = instance_start_offsets[i_instance]; Span bary_coords = bary_coords_array[i_instance]; Span looptri_indices = looptri_indices_array[i_instance]; @@ -516,7 +516,7 @@ static void distribute_points_poisson_disk(Span set_group const VArray density_factors = component.attribute_get_for_read( density_attribute_name, ATTR_DOMAIN_CORNER, use_one_default ? 1.0f : 0.0f); - for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) { + for ([[maybe_unused]] const int i_set_instance : set_group.transforms.index_range()) { Vector &positions = positions_all[i_instance]; Vector &bary_coords = bary_coords_all[i_instance]; Vector &looptri_indices = looptri_indices_all[i_instance]; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc index f54ffc53a6e..7b1bbed8ae4 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc @@ -161,7 +161,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = math::distance(min, max); + const float diagonal = float3::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc index cfae88e0625..dd03092a594 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc @@ -107,7 +107,7 @@ static void raycast_to_mesh(const Mesh &mesh, for (const int i : ray_origins.index_range()) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = math::normalize(ray_directions[i]); + const float3 ray_direction = ray_directions[i].normalized(); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc index 929d9046f98..7e09721273a 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc @@ -16,7 +16,7 @@ #include "BLI_array.hh" #include "BLI_delaunay_2d.h" -#include "BLI_math_vec_types.hh" +#include "BLI_double2.hh" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc index 68b609f8045..1a44fce86a6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc @@ -122,9 +122,9 @@ static Array calculate_directions(const Span positions) Array directions(size); for (const int i : IndexRange(size - 1)) { - directions[i] = math::normalize(positions[i + 1] - positions[i]); + directions[i] = (positions[i + 1] - positions[i]).normalized(); } - directions[size - 1] = math::normalize(positions[0] - positions[size - 1]); + directions[size - 1] = (positions[0] - positions[size - 1]).normalized(); return directions; } @@ -135,9 +135,9 @@ static Array calculate_axes(const Span directions) const int size = directions.size(); Array axes(size); - axes[0] = math::normalize(math::cross(-directions[size - 1], directions[0])); + axes[0] = float3::cross(-directions[size - 1], directions[0]).normalized(); for (const int i : IndexRange(1, size - 1)) { - axes[i] = math::normalize(math::cross(-directions[i - 1], directions[i])); + axes[i] = float3::cross(-directions[i - 1], directions[i]).normalized(); } return axes; @@ -248,8 +248,8 @@ static void limit_radii(FilletData &fd, const bool cyclic) if (cyclic) { /* Calculate lengths between adjacent control points. */ - const float len_prev = math::distance(positions[0], positions[size - 1]); - const float len_next = math::distance(positions[0], positions[1]); + const float len_prev = float3::distance(positions[0], positions[size - 1]); + const float len_next = float3::distance(positions[0], positions[1]); /* Calculate tangent lengths of fillets in control points. */ const float tan_len = radii[0] * tan(angles[0] / 2.0f); @@ -271,16 +271,16 @@ static void limit_radii(FilletData &fd, const bool cyclic) } /* Initialize max_radii to largest possible radii. */ - float prev_dist = math::distance(positions[1], positions[0]); + float prev_dist = float3::distance(positions[1], positions[0]); for (const int i : IndexRange(1, size - 2)) { - const float temp_dist = math::distance(positions[i], positions[i + 1]); + const float temp_dist = float3::distance(positions[i], positions[i + 1]); max_radii[i] = std::min(prev_dist, temp_dist) / tan(angles[i] / 2.0f); prev_dist = temp_dist; } /* Max radii calculations for each index. */ for (const int i : IndexRange(start, fillet_count - 1)) { - const float len_next = math::distance(positions[i], positions[i + 1]); + const float len_next = float3::distance(positions[i], positions[i + 1]); const float tan_len = radii[i] * tan(angles[i] / 2.0f); const float tan_len_next = radii[i + 1] * tan(angles[i + 1] / 2.0f); @@ -415,8 +415,7 @@ static void update_bezier_positions(const FilletData &fd, const float3 center = get_center(dst_spline.positions()[i_dst] - positions[i_src], fd, i_src); /* Calculate the vector of the radius formed by the first vertex. */ float3 radius_vec = dst_spline.positions()[i_dst] - center; - float radius; - radius_vec = math::normalize_and_get_length(radius_vec, radius); + const float radius = radius_vec.normalize_and_get_length(); dst_spline.handle_types_right().slice(1, count - 2).fill(BezierSpline::HandleType::Align); dst_spline.handle_types_left().slice(1, count - 2).fill(BezierSpline::HandleType::Align); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc index 7b5d1a1dc80..a7fb493c7d7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc @@ -101,8 +101,8 @@ static void node_update(bNodeTree *ntree, bNode *node) static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3) { - const float3 a = math::normalize(p2 - p1); - const float3 b = math::normalize(p3 - p1); + const float3 a = (p2 - p1).normalized(); + const float3 b = (p3 - p1).normalized(); return (ELEM(a, b, b * -1.0f)); } @@ -122,18 +122,18 @@ static std::unique_ptr create_point_circle_curve( float3 center; /* Midpoints of `P1->P2` and `P2->P3`. */ - const float3 q1 = math::interpolate(p1, p2, 0.5f); - const float3 q2 = math::interpolate(p2, p3, 0.5f); + const float3 q1 = float3::interpolate(p1, p2, 0.5f); + const float3 q2 = float3::interpolate(p2, p3, 0.5f); /* Normal Vectors of `P1->P2` and `P2->P3` */ - const float3 v1 = math::normalize(p2 - p1); - const float3 v2 = math::normalize(p3 - p2); + const float3 v1 = (p2 - p1).normalized(); + const float3 v2 = (p3 - p2).normalized(); /* Normal of plane of main 2 segments P1->P2 and `P2->P3`. */ - const float3 v3 = math::normalize(math::cross(v1, v2)); + const float3 v3 = float3::cross(v1, v2).normalized(); /* Normal of plane of first perpendicular bisector and `P1->P2`. */ - const float3 v4 = math::normalize(math::cross(v3, v1)); + const float3 v4 = float3::cross(v3, v1).normalized(); /* Determine Center-point from the intersection of 3 planes. */ float plane_1[4], plane_2[4], plane_3[4]; @@ -148,7 +148,7 @@ static std::unique_ptr create_point_circle_curve( } /* Get the radius from the center-point to p1. */ - const float r = math::distance(p1, center); + const float r = float3::distance(p1, center); const float theta_step = ((2 * M_PI) / (float)resolution); for (const int i : IndexRange(resolution)) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc index d35fa0a2fdc..ff9218b1ac2 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc @@ -100,7 +100,7 @@ static std::unique_ptr create_direction_line_curve(const float3 start spline->resize(2); MutableSpan positions = spline->positions(); positions[0] = start; - positions[1] = math::normalize(direction) * length + start; + positions[1] = direction.normalized() * length + start; spline->radii().fill(1.0f); spline->tilts().fill(0.0f); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc index 885d92a111b..084d27e9d24 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc @@ -58,9 +58,9 @@ static std::unique_ptr create_quadratic_bezier_curve(const float3 p1, const float step = 1.0f / resolution; for (const int i : IndexRange(resolution + 1)) { const float factor = step * i; - const float3 q1 = math::interpolate(p1, p2, factor); - const float3 q2 = math::interpolate(p2, p3, factor); - positions[i] = math::interpolate(q1, q2, factor); + const float3 q1 = float3::interpolate(p1, p2, factor); + const float3 q2 = float3::interpolate(p2, p3, factor); + positions[i] = float3::interpolate(q1, q2, factor); } curve->add_spline(std::move(spline)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc index 56fbc50f033..038f7625825 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc @@ -185,7 +185,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_tangents = splines[spline_indices[i]]->evaluated_tangents(); - sampled_tangents[i] = math::normalize(sample_with_lookup(lookup, evaluated_tangents)); + sampled_tangents[i] = sample_with_lookup(lookup, evaluated_tangents).normalized(); } } @@ -193,7 +193,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_normals = splines[spline_indices[i]]->evaluated_normals(); - sampled_normals[i] = math::normalize(sample_with_lookup(lookup, evaluated_normals)); + sampled_normals[i] = sample_with_lookup(lookup, evaluated_normals).normalized(); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc index 257a5b8df00..40dde645756 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc @@ -96,7 +96,7 @@ static void calculate_nurbs_lengths(const NURBSpline &spline, MutableSpan float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { lengths[i] = length; - length += math::distance(positions[i], positions[i + 1]); + length += float3::distance(positions[i], positions[i + 1]); } lengths.last() = length; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc index 19efd4b7508..a8553b636a4 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc @@ -285,7 +285,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent = math::normalize(tangent); + tangent.normalize(); } } @@ -293,7 +293,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals = math::normalize(normals); + normals.normalize(); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc index 624a8b6b0f6..28a8fb80294 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc @@ -21,7 +21,7 @@ #include "BKE_image.h" -#include "BLI_math_vec_types.hh" +#include "BLI_float4.hh" #include "BLI_threads.h" #include "BLI_timeit.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc index e90a9eb393b..5b67258a947 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc @@ -155,7 +155,7 @@ static void calculate_polys(const CuboidConfig &config, /* Calculate polys for Bottom faces. */ int vert_1_start = 0; - for (const int UNUSED(y) : IndexRange(config.edges_y)) { + for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { const int vert_1 = vert_1_start + x; const int vert_2 = vert_1_start + config.verts_x + x; @@ -173,7 +173,7 @@ static void calculate_polys(const CuboidConfig &config, vert_1_start = 0; int vert_2_start = config.verts_x * config.verts_y; - for (const int UNUSED(z) : IndexRange(config.edges_z)) { + for ([[maybe_unused]] const int z : IndexRange(config.edges_z)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, @@ -196,7 +196,7 @@ static void calculate_polys(const CuboidConfig &config, (config.verts_x - 2) * (config.verts_y - 2)); vert_2_start = vert_1_start + config.verts_x; - for (const int UNUSED(y) : IndexRange(config.edges_y)) { + for ([[maybe_unused]] const int y : IndexRange(config.edges_y)) { for (const int x : IndexRange(config.edges_x)) { define_quad(polys, loops, diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc index 8a2b054ece0..5116e78fdda 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc @@ -155,8 +155,8 @@ static void node_geo_exec(GeoNodeExecParams params) if (count_mode == GEO_NODE_MESH_LINE_COUNT_RESOLUTION) { /* Don't allow asymptotic count increase for low resolution values. */ const float resolution = std::max(params.extract_input("Resolution"), 0.0001f); - const int count = math::length(total_delta) / resolution + 1; - const float3 delta = math::normalize(total_delta) * resolution; + const int count = total_delta.length() / resolution + 1; + const float3 delta = total_delta.normalized() * resolution; mesh = create_line_mesh(start, delta, count); } else if (count_mode == GEO_NODE_MESH_LINE_COUNT_TOTAL) { @@ -204,7 +204,7 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count) MutableSpan edges{mesh->medge, mesh->totedge}; short normal[3]; - normal_float_to_short_v3(normal, math::normalize(delta)); + normal_float_to_short_v3(normal, delta.normalized()); for (const int i : verts.index_range()) { copy_v3_v3(verts[i].co, start + delta * i); diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc index 373e6bfdd18..41178d5c4e6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc @@ -178,7 +178,7 @@ static void calculate_sphere_faces(MutableSpan loops, int ring_vert_index_start = 1; int ring_edge_index_start = segments; - for (const int UNUSED(ring) : IndexRange(1, rings - 2)) { + for ([[maybe_unused]] const int ring : IndexRange(1, rings - 2)) { const int next_ring_vert_index_start = ring_vert_index_start + segments; const int next_ring_edge_index_start = ring_edge_index_start + segments * 2; const int ring_vertical_edge_index_start = ring_edge_index_start + segments; diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc index c165bcf8e35..dda4543d5e1 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc @@ -166,7 +166,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = math::distance(min, max); + const float diagonal = float3::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc index 772638ef240..e0117c4726d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc @@ -85,7 +85,7 @@ static bool calculate_mesh_proximity(const VArray &positions, for (int i : range) { const int index = mask[i]; /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[index]); + nearest.dist_sq = float3::distance_squared(nearest.co, positions[index]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[index], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc index c38503f688c..2c35ca0afc9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc @@ -163,7 +163,7 @@ static void raycast_to_mesh(IndexMask mask, for (const int i : mask) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = math::normalize(ray_directions[i]); + const float3 ray_direction = ray_directions[i].normalized(); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc index feab0a6743f..82d09bbc208 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc @@ -106,7 +106,7 @@ static void set_position_in_component(const GeometryNodeCurveHandleMode mode, } } else { - for (int UNUSED(i) : spline->positions().index_range()) { + for ([[maybe_unused]] int i : spline->positions().index_range()) { if (current_mask < selection.size() && selection[current_mask] == current_point) { current_mask++; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc index 6867051ecfe..331460296a6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc @@ -296,7 +296,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = math::distance_squared(position, float3(mvert.co)); + const float distance_sq = float3::distance_squared(position, mvert.co); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc index 6187a2eacf9..7f866ea6f4a 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc @@ -37,7 +37,7 @@ namespace blender::nodes { static bool use_translate(const float3 rotation, const float3 scale) { - if (compare_ff(math::length_squared(rotation), 0.0f, 1e-9f) != 1) { + if (compare_ff(rotation.length_squared(), 0.0f, 1e-9f) != 1) { return false; } if (compare_ff(scale.x, 1.0f, 1e-9f) != 1 || compare_ff(scale.y, 1.0f, 1e-9f) != 1 || @@ -49,7 +49,7 @@ static bool use_translate(const float3 rotation, const float3 scale) static void translate_mesh(Mesh &mesh, const float3 translation) { - if (!math::is_zero(translation)) { + if (!translation.is_zero()) { BKE_mesh_translate(&mesh, translation, false); } } diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc index ed72580ccf1..6a6b6e3d3cc 100644 --- a/source/blender/nodes/intern/node_socket.cc +++ b/source/blender/nodes/intern/node_socket.cc @@ -26,8 +26,8 @@ #include "DNA_node_types.h" #include "BLI_color.hh" +#include "BLI_float3.hh" #include "BLI_listbase.h" -#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/node_shader_util.hh b/source/blender/nodes/shader/node_shader_util.hh index 5a5b4f613f3..9d4d57d01dd 100644 --- a/source/blender/nodes/shader/node_shader_util.hh +++ b/source/blender/nodes/shader/node_shader_util.hh @@ -29,9 +29,9 @@ #include "BLI_blenlib.h" #include "BLI_color.hh" +#include "BLI_float3.hh" #include "BLI_math.h" #include "BLI_math_base_safe.h" -#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_threads.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc index bc7ca661a77..3276a1bfd72 100644 --- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc +++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc @@ -272,7 +272,7 @@ class MapRangeVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -315,8 +315,8 @@ class MapRangeSteppedVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(6, "Vector"); for (int64_t i : mask) { - float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); - factor = math::safe_divide(math::floor(factor * (steps[i] + 1.0f)), steps[i]); + float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + factor = float3::safe_divide(float3::floor(factor * (steps[i] + 1.0f)), steps[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -355,7 +355,7 @@ class MapRangeSmoothstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = (float3(3.0f) - 2.0f * factor) * (factor * factor); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; @@ -390,7 +390,7 @@ class MapRangeSmootherstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc index 81a69ef18da..61b1613c11a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc @@ -19,7 +19,8 @@ #include "node_shader_util.hh" -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float4.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc index 53be5bc09d9..85e0f262ca7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc @@ -130,7 +130,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - const float r = std::max(0.999999f - math::length(vector[i]), 0.0f); + const float r = std::max(0.999999f - vector[i].length(), 0.0f); fac[i] = r * r; } break; @@ -140,7 +140,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - fac[i] = std::max(0.999999f - math::length(vector[i]), 0.0f); + fac[i] = std::max(0.999999f - vector[i].length(), 0.0f); } break; } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc index 1c703313edf..0e549859a39 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc @@ -176,14 +176,14 @@ class NoiseFunction : public fn::MultiFunction { const VArray &vector = params.readonly_single_input(0, "Vector"); if (compute_factor) { for (int64_t i : mask) { - const float2 position = float2(vector[i] * scale[i]); + const float2 position = vector[i] * scale[i]; r_factor[i] = noise::perlin_fractal_distorted( position, detail[i], roughness[i], distortion[i]); } } if (compute_color) { for (int64_t i : mask) { - const float2 position = float2(vector[i] * scale[i]); + const float2 position = vector[i] * scale[i]; const float3 c = noise::perlin_float3_fractal_distorted( position, detail[i], roughness[i], distortion[i]); r_color[i] = ColorGeometry4f(c[0], c[1], c[2], 1.0f); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc index 209f96449cd..2b5c1ddfe21 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc @@ -313,7 +313,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -345,7 +345,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -380,7 +380,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -416,7 +416,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -446,7 +446,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -479,7 +479,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -519,7 +519,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -560,7 +560,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -604,7 +604,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -837,7 +837,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -868,7 +868,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -902,7 +902,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = math::safe_divide(pos, scale[i]); + pos = float2::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -937,7 +937,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -966,7 +966,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } break; @@ -999,7 +999,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = math::safe_divide(r_position[i], scale[i]); + r_position[i] = float3::safe_divide(r_position[i], scale[i]); } } } @@ -1040,7 +1040,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1080,7 +1080,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1123,7 +1123,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = math::safe_divide(pos, scale[i]); + pos = float4::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 604792389fa..f08665d75e7 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -57,20 +57,20 @@ void PyC_Err_PrintWithFunc(PyObject *py_func); void PyC_FileAndNum(const char **r_filename, int *r_lineno); void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno); /* checks python is running */ int PyC_AsArray_FAST(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value_fast, - const Py_ssize_t length, + Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value, - const Py_ssize_t length, + Py_ssize_t length, const PyTypeObject *type, const char *error_prefix); int PyC_AsArray_Multi_FAST(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value_fast, const int *dims, int dims_len, @@ -78,7 +78,7 @@ int PyC_AsArray_Multi_FAST(void *array, const char *error_prefix); int PyC_AsArray_Multi(void *array, - const size_t array_item_size, + size_t array_item_size, PyObject *value, const int *dims, int dims_len, diff --git a/source/blender/render/RE_bake.h b/source/blender/render/RE_bake.h index 43d3b5b323c..b7ce3da71ff 100644 --- a/source/blender/render/RE_bake.h +++ b/source/blender/render/RE_bake.h @@ -96,7 +96,7 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, BakePixel pixel_array_to[], BakeHighPolyData highpoly[], int tot_highpoly, - const size_t num_pixels, + size_t num_pixels, bool is_custom_cage, float cage_extrusion, float max_ray_distance, @@ -106,16 +106,16 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low, void RE_bake_pixels_populate(struct Mesh *me, struct BakePixel *pixel_array, - const size_t num_pixels, + size_t num_pixels, const struct BakeTargets *targets, const char *uv_layer); -void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask); +void RE_bake_mask_fill(const BakePixel pixel_array[], size_t num_pixels, char *mask); void RE_bake_margin(struct ImBuf *ibuf, char *mask, int margin); void RE_bake_normal_world_to_object(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], struct Object *ob, @@ -125,14 +125,14 @@ void RE_bake_normal_world_to_object(const BakePixel pixel_array[], * to a tangent space normal map for a given low poly mesh. */ void RE_bake_normal_world_to_tangent(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], struct Mesh *me, const eBakeNormalSwizzle normal_swizzle[3], float mat[4][4]); void RE_bake_normal_world_to_world(const BakePixel pixel_array[], - const size_t num_pixels, + size_t num_pixels, int depth, float result[], const eBakeNormalSwizzle normal_swizzle[3]); diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index 8776bc63cf0..a35e83a8632 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -3344,12 +3344,12 @@ static ImBuf *do_text_effect(const SeqRenderData *context, fonty = line_height; BLF_position(font, x + max_ii(fontx / 55, 1), y - max_ii(fonty / 30, 1), 0.0f); BLF_buffer_col(font, data->shadow_color); - BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(font, data->text, sizeof(data->text)); } BLF_position(font, x, y, 0.0f); BLF_buffer_col(font, data->color); - BLF_draw_buffer(font, data->text, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_buffer(font, data->text, sizeof(data->text)); BLF_buffer(font, NULL, NULL, 0, 0, 0, NULL); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 9a8a6a3a3ac..2e305c0bf3c 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -607,7 +607,7 @@ int WM_operator_confirm_message_ex(struct bContext *C, const char *title, int icon, const char *message, - const wmOperatorCallContext opcontext); + wmOperatorCallContext opcontext); int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message); /* Operator API. */ diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 99bab3ae23d..344f4959a93 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -193,7 +193,6 @@ bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWind static void wm_window_match_init(bContext *C, ListBase *wmlist) { *wmlist = G_MAIN->wm; - BLI_listbase_clear(&G_MAIN->wm); wmWindow *active_win = CTX_wm_window(C); @@ -220,6 +219,8 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist) } } + BLI_listbase_clear(&G_MAIN->wm); + /* reset active window */ CTX_wm_window_set(C, active_win); -- cgit v1.2.3 From d43b5791e0c1f6581a539c2663ec8200e107740a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 12 Jan 2022 12:57:07 +0100 Subject: BLI: Refactor vector types & functions to use templates This patch implements the vector types (i.e:`float2`) by making heavy usage of templating. All vector functions are now outside of the vector classes (inside the `blender::math` namespace) and are not vector size dependent for the most part. In the ongoing effort to make shaders less GL centric, we are aiming to share more code between GLSL and C++ to avoid code duplication. ####Motivations: - We are aiming to share UBO and SSBO structures between GLSL and C++. This means we will use many of the existing vector types and others we currently don't have (uintX, intX). All these variations were asking for many more code duplication. - Deduplicate existing code which is duplicated for each vector size. - We also want to share small functions. Which means that vector functions should be static and not in the class namespace. - Reduce friction to use these types in new projects due to their incompleteness. - The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a bit of a let down. Most clases are incomplete, out of sync with each others with different codestyles, and some functions that should be static are not (i.e: `float3::reflect()`). ####Upsides: - Still support `.x, .y, .z, .w` for readability. - Compact, readable and easilly extendable. - All of the vector functions are available for all the vectors types and can be restricted to certain types. Also template specialization let us define exception for special class (like mpq). - With optimization ON, the compiler unroll the loops and performance is the same. ####Downsides: - Might impact debugability. Though I would arge that the bugs are rarelly caused by the vector class itself (since the operations are quite trivial) but by the type conversions. - Might impact compile time. I did not saw a significant impact since the usage is not really widespread. - Functions needs to be rewritten to support arbitrary vector length. For instance, one can't call `len_squared_v3v3` in `math::length_squared()` and call it a day. - Type cast does not work with the template version of the `math::` vector functions. Meaning you need to manually cast `float *` and `(float *)[3]` to `float3` for the function calls. i.e: `math::distance_squared(float3(nearest.co), positions[i]);` - Some parts might loose in readability: `float3::dot(v1.normalized(), v2.normalized())` becoming `math::dot(math::normalize(v1), math::normalize(v2))` But I propose, when appropriate, to use `using namespace blender::math;` on function local or file scope to increase readability. `dot(normalize(v1), normalize(v2))` ####Consideration: - Include back `.length()` method. It is quite handy and is more C++ oriented. - I considered the GLM library as a candidate for replacement. It felt like too much for what we need and would be difficult to extend / modify to our needs. - I used Macros to reduce code in operators declaration and potential copy paste bugs. This could reduce debugability and could be reverted. - This touches `delaunay_2d.cc` and the intersection code. I would like to know @howardt opinion on the matter. - The `noexcept` on the copy constructor of `mpq(2|3)` is being removed. But according to @JacquesLucke it is not a real problem for now. I would like to give a huge thanks to @JacquesLucke who helped during this and pushed me to reduce the duplication further. Reviewed By: brecht, sergey, JacquesLucke Differential Revision: https://developer.blender.org/D13791 --- source/blender/blenkernel/BKE_attribute_access.hh | 3 +- source/blender/blenkernel/BKE_attribute_math.hh | 7 +- source/blender/blenkernel/BKE_geometry_set.hh | 2 +- source/blender/blenkernel/BKE_mesh_sample.hh | 2 +- source/blender/blenkernel/BKE_spline.hh | 2 +- source/blender/blenkernel/BKE_volume.h | 2 +- source/blender/blenkernel/intern/DerivedMesh.cc | 2 +- .../blender/blenkernel/intern/attribute_access.cc | 2 +- .../blenkernel/intern/geometry_component_mesh.cc | 5 +- source/blender/blenkernel/intern/gpencil_geom.cc | 2 +- source/blender/blenkernel/intern/hair.cc | 2 +- source/blender/blenkernel/intern/mesh.cc | 10 +- .../blenkernel/intern/mesh_boolean_convert.cc | 2 +- .../blender/blenkernel/intern/mesh_remesh_voxel.cc | 2 +- source/blender/blenkernel/intern/object_dupli.cc | 8 +- source/blender/blenkernel/intern/pointcloud.cc | 24 +- source/blender/blenkernel/intern/simulation.cc | 2 +- source/blender/blenkernel/intern/spline_base.cc | 41 +- source/blender/blenkernel/intern/spline_bezier.cc | 37 +- source/blender/blenkernel/intern/tracking_test.cc | 2 +- .../blender/blenkernel/intern/type_conversions.cc | 3 +- source/blender/blenkernel/intern/volume.cc | 2 +- source/blender/blenkernel/intern/volume_render.cc | 2 +- source/blender/blenkernel/intern/volume_to_mesh.cc | 2 +- source/blender/blenlib/BLI_delaunay_2d.h | 4 +- source/blender/blenlib/BLI_double2.hh | 143 ------ source/blender/blenlib/BLI_double3.hh | 246 --------- source/blender/blenlib/BLI_float2.hh | 218 -------- source/blender/blenlib/BLI_float3.hh | 320 ------------ source/blender/blenlib/BLI_float4.hh | 138 ----- source/blender/blenlib/BLI_float4x4.hh | 5 +- source/blender/blenlib/BLI_math_boolean.hh | 6 +- source/blender/blenlib/BLI_math_vec_mpq_types.hh | 91 ++++ source/blender/blenlib/BLI_math_vec_types.hh | 566 +++++++++++++++++++++ source/blender/blenlib/BLI_math_vector.hh | 399 +++++++++++++++ source/blender/blenlib/BLI_memory_utils.hh | 9 - source/blender/blenlib/BLI_mesh_intersect.hh | 5 +- source/blender/blenlib/BLI_mpq2.hh | 184 ------- source/blender/blenlib/BLI_mpq3.hh | 297 ----------- source/blender/blenlib/BLI_noise.hh | 4 +- source/blender/blenlib/BLI_rand.hh | 3 +- source/blender/blenlib/BLI_utildefines.h | 9 + source/blender/blenlib/CMakeLists.txt | 10 +- source/blender/blenlib/intern/delaunay_2d.cc | 45 +- source/blender/blenlib/intern/math_boolean.cc | 7 +- source/blender/blenlib/intern/math_vec.cc | 133 ++--- source/blender/blenlib/intern/mesh_boolean.cc | 51 +- source/blender/blenlib/intern/mesh_intersect.cc | 88 ++-- source/blender/blenlib/intern/noise.cc | 79 ++- .../blender/blenlib/tests/BLI_delaunay_2d_test.cc | 3 +- .../blenlib/tests/BLI_math_vec_types_test.cc | 149 ++++++ .../blender/blenlib/tests/BLI_memory_utils_test.cc | 2 +- .../blender/blenlib/tests/BLI_mesh_boolean_test.cc | 2 +- .../blenlib/tests/BLI_mesh_intersect_test.cc | 2 +- source/blender/compositor/COM_defines.h | 2 +- .../blender/draw/intern/draw_cache_impl_curve.cc | 2 +- .../mesh_extractors/extract_mesh_vbo_attributes.cc | 4 +- source/blender/editors/space_node/node_group.cc | 2 +- source/blender/editors/space_node/node_intern.hh | 5 +- source/blender/editors/space_node/node_select.cc | 4 +- .../space_spreadsheet/spreadsheet_column.cc | 3 +- .../space_spreadsheet/spreadsheet_layout.cc | 3 +- .../space_spreadsheet/spreadsheet_row_filter.cc | 8 +- source/blender/functions/intern/cpp_types.cc | 3 +- .../blender/io/gpencil/intern/gpencil_io_base.cc | 5 +- .../blender/io/gpencil/intern/gpencil_io_base.hh | 3 +- .../io/gpencil/intern/gpencil_io_import_svg.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mesh.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.cc | 2 +- .../io/wavefront_obj/exporter/obj_export_mtl.hh | 2 +- .../io/wavefront_obj/exporter/obj_export_nurbs.cc | 2 +- .../blender/modifiers/intern/MOD_mesh_to_volume.cc | 4 +- source/blender/modifiers/intern/MOD_nodes.cc | 2 +- source/blender/nodes/NOD_math_functions.hh | 75 ++- source/blender/nodes/NOD_socket_declarations.hh | 2 +- .../blender/nodes/function/node_function_util.hh | 2 +- .../nodes/node_fn_align_euler_to_vector.cc | 8 +- .../nodes/function/nodes/node_fn_compare.cc | 24 +- .../blender/nodes/geometry/node_geometry_util.hh | 2 +- .../node_geo_legacy_align_rotation_to_vector.cc | 8 +- .../legacy/node_geo_legacy_attribute_proximity.cc | 2 +- .../legacy/node_geo_legacy_attribute_transfer.cc | 2 +- .../legacy/node_geo_legacy_curve_to_points.cc | 4 +- .../legacy/node_geo_legacy_points_to_volume.cc | 2 +- .../nodes/legacy/node_geo_legacy_raycast.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fill.cc | 2 +- .../nodes/geometry/nodes/node_geo_curve_fillet.cc | 21 +- .../nodes/node_geo_curve_primitive_circle.cc | 18 +- .../nodes/node_geo_curve_primitive_line.cc | 2 +- .../node_geo_curve_primitive_quadratic_bezier.cc | 6 +- .../nodes/geometry/nodes/node_geo_curve_sample.cc | 4 +- .../nodes/node_geo_curve_spline_parameter.cc | 2 +- .../geometry/nodes/node_geo_curve_to_points.cc | 4 +- .../nodes/geometry/nodes/node_geo_image_texture.cc | 2 +- .../geometry/nodes/node_geo_mesh_primitive_line.cc | 6 +- .../geometry/nodes/node_geo_points_to_volume.cc | 2 +- .../nodes/geometry/nodes/node_geo_proximity.cc | 2 +- .../nodes/geometry/nodes/node_geo_raycast.cc | 2 +- .../geometry/nodes/node_geo_transfer_attribute.cc | 2 +- .../nodes/geometry/nodes/node_geo_transform.cc | 4 +- source/blender/nodes/intern/node_socket.cc | 2 +- source/blender/nodes/shader/node_shader_util.hh | 2 +- .../nodes/shader/nodes/node_shader_map_range.cc | 10 +- .../nodes/shader/nodes/node_shader_tex_brick.cc | 3 +- .../nodes/shader/nodes/node_shader_tex_gradient.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_noise.cc | 4 +- .../nodes/shader/nodes/node_shader_tex_voronoi.cc | 36 +- 107 files changed, 1645 insertions(+), 2074 deletions(-) delete mode 100644 source/blender/blenlib/BLI_double2.hh delete mode 100644 source/blender/blenlib/BLI_double3.hh delete mode 100644 source/blender/blenlib/BLI_float2.hh delete mode 100644 source/blender/blenlib/BLI_float3.hh delete mode 100644 source/blender/blenlib/BLI_float4.hh create mode 100644 source/blender/blenlib/BLI_math_vec_mpq_types.hh create mode 100644 source/blender/blenlib/BLI_math_vec_types.hh create mode 100644 source/blender/blenlib/BLI_math_vector.hh delete mode 100644 source/blender/blenlib/BLI_mpq2.hh delete mode 100644 source/blender/blenlib/BLI_mpq3.hh create mode 100644 source/blender/blenlib/tests/BLI_math_vec_types_test.cc (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index f69ba79e23f..3ffdcee05eb 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -26,9 +26,8 @@ #include "BKE_attribute.h" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_function_ref.hh" +#include "BLI_math_vec_types.hh" /** * This file defines classes that help to provide access to attribute data on a #GeometryComponent. diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh index 802c744972c..a7bdca06790 100644 --- a/source/blender/blenkernel/BKE_attribute_math.hh +++ b/source/blender/blenkernel/BKE_attribute_math.hh @@ -18,8 +18,7 @@ #include "BLI_array.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "DNA_customdata_types.h" @@ -160,12 +159,12 @@ template<> inline float mix2(const float factor, const float &a, const float &b) template<> inline float2 mix2(const float factor, const float2 &a, const float2 &b) { - return float2::interpolate(a, b, factor); + return math::interpolate(a, b, factor); } template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b) { - return float3::interpolate(a, b, factor); + return math::interpolate(a, b, factor); } template<> diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index acb89637f20..f92f33b2776 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -23,11 +23,11 @@ #include #include -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_function_ref.hh" #include "BLI_hash.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_set.hh" #include "BLI_user_counter.hh" #include "BLI_vector_set.hh" diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh index 238b6f4dcae..738b768d906 100644 --- a/source/blender/blenkernel/BKE_mesh_sample.hh +++ b/source/blender/blenkernel/BKE_mesh_sample.hh @@ -22,7 +22,7 @@ #include "FN_generic_virtual_array.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BKE_attribute.h" diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh index 2c14880978f..a87f76da8da 100644 --- a/source/blender/blenkernel/BKE_spline.hh +++ b/source/blender/blenkernel/BKE_spline.hh @@ -24,8 +24,8 @@ #include "FN_generic_virtual_array.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BKE_attribute_access.hh" diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h index 2b551a76d73..b40facc3572 100644 --- a/source/blender/blenkernel/BKE_volume.h +++ b/source/blender/blenkernel/BKE_volume.h @@ -163,8 +163,8 @@ bool BKE_volume_save(const struct Volume *volume, * file or copy shared grids to make them writeable. */ #ifdef __cplusplus -# include "BLI_float3.hh" # include "BLI_float4x4.hh" +# include "BLI_math_vec_types.hh" # include "BLI_string_ref.hh" bool BKE_volume_min_max(const Volume *volume, blender::float3 &r_min, blender::float3 &r_max); diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 4bfd71ba932..73785e2ee2b 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -38,9 +38,9 @@ #include "BLI_array.h" #include "BLI_bitmap.h" #include "BLI_blenlib.h" -#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_task.h" #include "BLI_task.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 1a4265d936b..cc43a3e26a8 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -30,7 +30,7 @@ #include "DNA_pointcloud_types.h" #include "BLI_color.hh" -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLT_translation.h" diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 2b4238d26bb..88a58220b23 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -217,9 +217,8 @@ VArray mesh_normals_varray(const MeshComponent &mesh_component, * calculating unnecessary values and to allow normalizing the result much more simply. */ for (const int i : mask) { const MEdge &edge = edges[i]; - edge_normals[i] = float3::interpolate( - vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f) - .normalized(); + edge_normals[i] = math::normalize( + math::interpolate(vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f)); } return VArray::ForContainer(std::move(edge_normals)); diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc index f8681647a77..116d77f1a2a 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.cc +++ b/source/blender/blenkernel/intern/gpencil_geom.cc @@ -33,10 +33,10 @@ #include "BLI_array_utils.h" #include "BLI_blenlib.h" -#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_heap.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_polyfill_2d.h" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/hair.cc b/source/blender/blenkernel/intern/hair.cc index c5b154c9a4b..b7ba159f631 100644 --- a/source/blender/blenkernel/intern/hair.cc +++ b/source/blender/blenkernel/intern/hair.cc @@ -28,9 +28,9 @@ #include "DNA_material_types.h" #include "DNA_object_types.h" -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math_base.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 12c63ab0523..8ceaced1972 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -36,13 +36,13 @@ #include "BLI_bitmap.h" #include "BLI_edgehash.h" #include "BLI_endian_switch.h" -#include "BLI_float3.hh" #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_index_range.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_memarena.h" #include "BLI_string.h" #include "BLI_task.hh" @@ -1597,16 +1597,16 @@ bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3]) [&](IndexRange range, const Result &init) { Result result = init; for (const int i : range) { - float3::min_max(me->mvert[i].co, result.min, result.max); + math::min_max(float3(me->mvert[i].co), result.min, result.max); } return result; }, [](const Result &a, const Result &b) { - return Result{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return Result{math::min(a.min, b.min), math::max(a.max, b.max)}; }); - copy_v3_v3(r_min, float3::min(minmax.min, r_min)); - copy_v3_v3(r_max, float3::max(minmax.max, r_max)); + copy_v3_v3(r_min, math::min(minmax.min, float3(r_min))); + copy_v3_v3(r_max, math::max(minmax.max, float3(r_max))); return true; } diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc index 771d79a0445..a4a5fe2be2e 100644 --- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc +++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc @@ -32,9 +32,9 @@ #include "BLI_alloca.h" #include "BLI_array.hh" -#include "BLI_float2.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_mesh_boolean.hh" #include "BLI_mesh_intersect.hh" #include "BLI_span.hh" diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc index 3447185089d..50464da86e9 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc @@ -31,8 +31,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_index_range.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_mesh_types.h" diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc index e682486390c..20fdda8bdc7 100644 --- a/source/blender/blenkernel/intern/object_dupli.cc +++ b/source/blender/blenkernel/intern/object_dupli.cc @@ -31,9 +31,9 @@ #include "BLI_string_utf8.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_vector.hh" @@ -1026,6 +1026,8 @@ static void get_dupliface_transform_from_coords(Span coords, const float scale_fac, float r_mat[4][4]) { + using namespace blender::math; + /* Location. */ float3 location(0); for (const float3 &coord : coords) { @@ -1036,9 +1038,7 @@ static void get_dupliface_transform_from_coords(Span coords, /* Rotation. */ float quat[4]; - float3 f_no; - cross_poly_v3(f_no, (const float(*)[3])coords.data(), (uint)coords.size()); - f_no.normalize(); + float3 f_no = normalize(cross_poly(coords)); tri_to_quat_ex(quat, coords[0], coords[1], coords[2], f_no); /* Scale. */ diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc index a041e04bf71..b5f016e4d76 100644 --- a/source/blender/blenkernel/intern/pointcloud.cc +++ b/source/blender/blenkernel/intern/pointcloud.cc @@ -25,9 +25,9 @@ #include "DNA_object_types.h" #include "DNA_pointcloud_types.h" -#include "BLI_float3.hh" #include "BLI_index_range.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" @@ -275,6 +275,8 @@ struct MinMaxResult { static MinMaxResult min_max_no_radii(Span positions) { + using namespace blender::math; + return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -282,17 +284,19 @@ static MinMaxResult min_max_no_radii(Span positions) [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - float3::min_max(positions[i], result.min, result.max); + min_max(positions[i], result.min, result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; }); } static MinMaxResult min_max_with_radii(Span positions, Span radii) { + using namespace blender::math; + return blender::threading::parallel_reduce( positions.index_range(), 1024, @@ -300,18 +304,20 @@ static MinMaxResult min_max_with_radii(Span positions, Span radii [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { - result.min = float3::min(positions[i] - radii[i], result.min); - result.max = float3::max(positions[i] + radii[i], result.max); + result.min = min(positions[i] - radii[i], result.min); + result.max = max(positions[i] + radii[i], result.max); } return result; }, [](const MinMaxResult &a, const MinMaxResult &b) { - return MinMaxResult{float3::min(a.min, b.min), float3::max(a.max, b.max)}; + return MinMaxResult{min(a.min, b.min), max(a.max, b.max)}; }); } bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r_max[3]) { + using namespace blender::math; + if (!pointcloud->totpoint) { return false; } @@ -322,8 +328,8 @@ bool BKE_pointcloud_minmax(const PointCloud *pointcloud, float r_min[3], float r {pointcloud->radius, pointcloud->totpoint}) : min_max_no_radii(positions); - copy_v3_v3(r_min, float3::min(min_max.min, r_min)); - copy_v3_v3(r_max, float3::max(min_max.max, r_max)); + copy_v3_v3(r_min, min(min_max.min, float3(r_min))); + copy_v3_v3(r_max, max(min_max.max, float3(r_max))); return true; } @@ -340,7 +346,7 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob) ob->runtime.bb = static_cast(MEM_callocN(sizeof(BoundBox), "pointcloud boundbox")); } - blender::float3 min, max; + float3 min, max; INIT_MINMAX(min, max); if (ob->runtime.geometry_set_eval != nullptr) { ob->runtime.geometry_set_eval->compute_boundbox_without_instances(&min, &max); diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index b0f9de5963a..ec4b0e8d51d 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -28,9 +28,9 @@ #include "DNA_simulation_types.h" #include "BLI_compiler_compat.h" -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_span.hh" #include "BLI_string.h" diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 857022345f3..3262d768b6c 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -166,13 +166,15 @@ static void accumulate_lengths(Span positions, const bool is_cyclic, MutableSpan lengths) { + using namespace blender::math; + float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { - length += float3::distance(positions[i], positions[i + 1]); + length += distance(positions[i], positions[i + 1]); lengths[i] = length; } if (is_cyclic) { - lengths.last() = length + float3::distance(positions.last(), positions.first()); + lengths.last() = length + distance(positions.last(), positions.first()); } } @@ -200,11 +202,13 @@ Span Spline::evaluated_lengths() const static float3 direction_bisect(const float3 &prev, const float3 &middle, const float3 &next) { - const float3 dir_prev = (middle - prev).normalized(); - const float3 dir_next = (next - middle).normalized(); + using namespace blender::math; + + const float3 dir_prev = normalize(middle - prev); + const float3 dir_next = normalize(next - middle); - const float3 result = (dir_prev + dir_next).normalized(); - if (UNLIKELY(result.is_zero())) { + const float3 result = normalize(dir_prev + dir_next); + if (UNLIKELY(is_zero(result))) { return float3(0.0f, 0.0f, 1.0f); } return result; @@ -214,6 +218,8 @@ static void calculate_tangents(Span positions, const bool is_cyclic, MutableSpan tangents) { + using namespace blender::math; + if (positions.size() == 1) { tangents.first() = float3(0.0f, 0.0f, 1.0f); return; @@ -232,8 +238,8 @@ static void calculate_tangents(Span positions, tangents.last() = direction_bisect(second_to_last, last, first); } else { - tangents.first() = (positions[1] - positions[0]).normalized(); - tangents.last() = (positions.last() - positions[positions.size() - 2]).normalized(); + tangents.first() = normalize(positions[1] - positions[0]); + tangents.last() = normalize(positions.last() - positions[positions.size() - 2]); } } @@ -264,18 +270,22 @@ static float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, const float angle) { + using namespace blender::math; + BLI_ASSERT_UNIT_V3(direction); BLI_ASSERT_UNIT_V3(axis); - const float3 axis_scaled = axis * float3::dot(direction, axis); + const float3 axis_scaled = axis * dot(direction, axis); const float3 diff = direction - axis_scaled; - const float3 cross = float3::cross(axis, diff); + const float3 cross = blender::math::cross(axis, diff); return axis_scaled + diff * std::cos(angle) + cross * std::sin(angle); } static void calculate_normals_z_up(Span tangents, MutableSpan r_normals) { + using namespace blender::math; + BLI_assert(r_normals.size() == tangents.size()); /* Same as in `vec_to_quat`. */ @@ -286,7 +296,7 @@ static void calculate_normals_z_up(Span tangents, MutableSpan r_ r_normals[i] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[i] = float3(tangent.y, -tangent.x, 0.0f).normalized(); + r_normals[i] = normalize(float3(tangent.y, -tangent.x, 0.0f)); } } } @@ -298,12 +308,14 @@ static float3 calculate_next_normal(const float3 &last_normal, const float3 &last_tangent, const float3 ¤t_tangent) { - if (last_tangent.is_zero() || current_tangent.is_zero()) { + using namespace blender::math; + + if (is_zero(last_tangent) || is_zero(current_tangent)) { return last_normal; } const float angle = angle_normalized_v3v3(last_tangent, current_tangent); if (angle != 0.0) { - const float3 axis = float3::cross(last_tangent, current_tangent).normalized(); + const float3 axis = normalize(cross(last_tangent, current_tangent)); return rotate_direction_around_axis(last_normal, axis, angle); } return last_normal; @@ -313,6 +325,7 @@ static void calculate_normals_minimum(Span tangents, const bool cyclic, MutableSpan r_normals) { + using namespace blender::math; BLI_assert(r_normals.size() == tangents.size()); if (r_normals.is_empty()) { @@ -327,7 +340,7 @@ static void calculate_normals_minimum(Span tangents, r_normals[0] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[0] = float3(first_tangent.y, -first_tangent.x, 0.0f).normalized(); + r_normals[0] = normalize(float3(first_tangent.y, -first_tangent.x, 0.0f)); } /* Forward normal with minimum twist along the entire spline. */ diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc index b24c8960857..980437014b1 100644 --- a/source/blender/blenkernel/intern/spline_bezier.cc +++ b/source/blender/blenkernel/intern/spline_bezier.cc @@ -199,11 +199,13 @@ void BezierSpline::ensure_auto_handles() const } for (const int i : IndexRange(this->size())) { + using namespace blender; + if (ELEM(HandleType::Auto, handle_types_left_[i], handle_types_right_[i])) { const float3 prev_diff = positions_[i] - previous_position(positions_, is_cyclic_, i); const float3 next_diff = next_position(positions_, is_cyclic_, i) - positions_[i]; - float prev_len = prev_diff.length(); - float next_len = next_diff.length(); + float prev_len = math::length(prev_diff); + float next_len = math::length(next_diff); if (prev_len == 0.0f) { prev_len = 1.0f; } @@ -213,7 +215,7 @@ void BezierSpline::ensure_auto_handles() const const float3 dir = next_diff / next_len + prev_diff / prev_len; /* This magic number is unfortunate, but comes from elsewhere in Blender. */ - const float len = dir.length() * 2.5614f; + const float len = math::length(dir) * 2.5614f; if (len != 0.0f) { if (handle_types_left_[i] == HandleType::Auto) { const float prev_len_clamped = std::min(prev_len, next_len * 5.0f); @@ -228,12 +230,12 @@ void BezierSpline::ensure_auto_handles() const if (handle_types_left_[i] == HandleType::Vector) { const float3 prev = previous_position(positions_, is_cyclic_, i); - handle_positions_left_[i] = float3::interpolate(positions_[i], prev, 1.0f / 3.0f); + handle_positions_left_[i] = math::interpolate(positions_[i], prev, 1.0f / 3.0f); } if (handle_types_right_[i] == HandleType::Vector) { const float3 next = next_position(positions_, is_cyclic_, i); - handle_positions_right_[i] = float3::interpolate(positions_[i], next, 1.0f / 3.0f); + handle_positions_right_[i] = math::interpolate(positions_[i], next, 1.0f / 3.0f); } } @@ -275,6 +277,8 @@ static void set_handle_position(const float3 &position, float3 &handle, float3 &handle_other) { + using namespace blender::math; + /* Don't bother when the handle positions are calculated automatically anyway. */ if (ELEM(type, BezierSpline::HandleType::Auto, BezierSpline::HandleType::Vector)) { return; @@ -283,9 +287,9 @@ static void set_handle_position(const float3 &position, handle = new_value; if (type_other == BezierSpline::HandleType::Align) { /* Keep track of the old length of the opposite handle. */ - const float length = float3::distance(handle_other, position); + const float length = distance(handle_other, position); /* Set the other handle to directly opposite from the current handle. */ - const float3 dir = (handle - position).normalized(); + const float3 dir = normalize(handle - position); handle_other = position - dir * length; } } @@ -353,6 +357,7 @@ int BezierSpline::evaluated_points_size() const void BezierSpline::correct_end_tangents() const { + using namespace blender::math; if (is_cyclic_) { return; } @@ -360,10 +365,10 @@ void BezierSpline::correct_end_tangents() const MutableSpan tangents(evaluated_tangents_cache_); if (handle_positions_right_.first() != positions_.first()) { - tangents.first() = (handle_positions_right_.first() - positions_.first()).normalized(); + tangents.first() = normalize(handle_positions_right_.first() - positions_.first()); } if (handle_positions_left_.last() != positions_.last()) { - tangents.last() = (positions_.last() - handle_positions_left_.last()).normalized(); + tangents.last() = normalize(positions_.last() - handle_positions_left_.last()); } } @@ -371,20 +376,22 @@ BezierSpline::InsertResult BezierSpline::calculate_segment_insertion(const int i const int next_index, const float parameter) { + using namespace blender::math; + BLI_assert(parameter <= 1.0f && parameter >= 0.0f); BLI_assert(next_index == 0 || next_index == index + 1); const float3 &point_prev = positions_[index]; const float3 &handle_prev = handle_positions_right_[index]; const float3 &handle_next = handle_positions_left_[next_index]; const float3 &point_next = positions_[next_index]; - const float3 center_point = float3::interpolate(handle_prev, handle_next, parameter); + const float3 center_point = interpolate(handle_prev, handle_next, parameter); BezierSpline::InsertResult result; - result.handle_prev = float3::interpolate(point_prev, handle_prev, parameter); - result.handle_next = float3::interpolate(handle_next, point_next, parameter); - result.left_handle = float3::interpolate(result.handle_prev, center_point, parameter); - result.right_handle = float3::interpolate(center_point, result.handle_next, parameter); - result.position = float3::interpolate(result.left_handle, result.right_handle, parameter); + result.handle_prev = interpolate(point_prev, handle_prev, parameter); + result.handle_next = interpolate(handle_next, point_next, parameter); + result.left_handle = interpolate(result.handle_prev, center_point, parameter); + result.right_handle = interpolate(center_point, result.handle_next, parameter); + result.position = interpolate(result.left_handle, result.right_handle, parameter); return result; } diff --git a/source/blender/blenkernel/intern/tracking_test.cc b/source/blender/blenkernel/intern/tracking_test.cc index a3845dcad8f..d85d71b7c86 100644 --- a/source/blender/blenkernel/intern/tracking_test.cc +++ b/source/blender/blenkernel/intern/tracking_test.cc @@ -5,7 +5,7 @@ #include "DNA_tracking_types.h" #include "BKE_tracking.h" -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" namespace blender { diff --git a/source/blender/blenkernel/intern/type_conversions.cc b/source/blender/blenkernel/intern/type_conversions.cc index b23220286e6..cb05337ef2a 100644 --- a/source/blender/blenkernel/intern/type_conversions.cc +++ b/source/blender/blenkernel/intern/type_conversions.cc @@ -19,8 +19,7 @@ #include "FN_multi_function_builder.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" namespace blender::bke { diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index 4b71c98339b..c17706dc216 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -28,12 +28,12 @@ #include "BLI_compiler_compat.h" #include "BLI_fileops.h" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" #include "BLI_ghash.h" #include "BLI_index_range.hh" #include "BLI_map.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc index 6dc497bb616..c0a205b5673 100644 --- a/source/blender/blenkernel/intern/volume_render.cc +++ b/source/blender/blenkernel/intern/volume_render.cc @@ -21,8 +21,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_math_matrix.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_vector.hh" diff --git a/source/blender/blenkernel/intern/volume_to_mesh.cc b/source/blender/blenkernel/intern/volume_to_mesh.cc index 6e465b2fdf0..733549c0022 100644 --- a/source/blender/blenkernel/intern/volume_to_mesh.cc +++ b/source/blender/blenkernel/intern/volume_to_mesh.cc @@ -16,7 +16,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_delaunay_2d.h b/source/blender/blenlib/BLI_delaunay_2d.h index db0df95499f..1ee0be64cee 100644 --- a/source/blender/blenlib/BLI_delaunay_2d.h +++ b/source/blender/blenlib/BLI_delaunay_2d.h @@ -215,9 +215,9 @@ void BLI_delaunay_2d_cdt_free(CDT_result *result); /* C++ Interface. */ # include "BLI_array.hh" -# include "BLI_double2.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_vector.hh" namespace blender::meshintersect { diff --git a/source/blender/blenlib/BLI_double2.hh b/source/blender/blenlib/BLI_double2.hh deleted file mode 100644 index 0abff01ab2f..00000000000 --- a/source/blender/blenlib/BLI_double2.hh +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include "BLI_double3.hh" - -namespace blender { - -struct double2 { - double x, y; - - double2() = default; - - double2(const double *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - double2(double x, double y) : x(x), y(y) - { - } - - double2(const double3 &other) : x(other.x), y(other.y) - { - } - - operator double *() - { - return &x; - } - - operator const double *() const - { - return &x; - } - - double length() const - { - return len_v2_db(*this); - } - - friend double2 operator+(const double2 &a, const double2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend double2 operator-(const double2 &a, const double2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend double2 operator*(const double2 &a, double b) - { - return {a.x * b, a.y * b}; - } - - friend double2 operator/(const double2 &a, double b) - { - BLI_assert(b != 0.0); - return {a.x / b, a.y / b}; - } - - friend double2 operator*(double a, const double2 &b) - { - return b * a; - } - - friend bool operator==(const double2 &a, const double2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const double2 &a, const double2 &b) - { - return a.x != b.x || a.y != b.y; - } - - friend std::ostream &operator<<(std::ostream &stream, const double2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static double dot(const double2 &a, const double2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static double2 interpolate(const double2 &a, const double2 &b, double t) - { - return a * (1 - t) + b * t; - } - - static double2 abs(const double2 &a) - { - return double2(fabs(a.x), fabs(a.y)); - } - - static double distance(const double2 &a, const double2 &b) - { - return (a - b).length(); - } - - static double distance_squared(const double2 &a, const double2 &b) - { - double2 diff = a - b; - return double2::dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - double lambda; - }; - - static isect_result isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4); -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_double3.hh b/source/blender/blenlib/BLI_double3.hh deleted file mode 100644 index ab258c9121b..00000000000 --- a/source/blender/blenlib/BLI_double3.hh +++ /dev/null @@ -1,246 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include - -#include "BLI_math_vector.h" -#include "BLI_span.hh" - -namespace blender { - -struct double3 { - double x, y, z; - - double3() = default; - - double3(const double *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - double3(const double (*ptr)[3]) : double3((const double *)ptr) - { - } - - explicit double3(double value) : x(value), y(value), z(value) - { - } - - explicit double3(int value) : x(value), y(value), z(value) - { - } - - double3(double x, double y, double z) : x{x}, y{y}, z{z} - { - } - - operator const double *() const - { - return &x; - } - - operator double *() - { - return &x; - } - - double normalize_and_get_length() - { - return normalize_v3_db(*this); - } - - double3 normalized() const - { - double3 result; - normalize_v3_v3_db(result, *this); - return result; - } - - double length() const - { - return len_v3_db(*this); - } - - double length_squared() const - { - return len_squared_v3_db(*this); - } - - void reflect(const double3 &normal) - { - *this = this->reflected(normal); - } - - double3 reflected(const double3 &normal) const - { - double3 result; - reflect_v3_v3v3_db(result, *this, normal); - return result; - } - - static double3 safe_divide(const double3 &a, const double3 &b) - { - double3 result; - result.x = (b.x == 0.0) ? 0.0 : a.x / b.x; - result.y = (b.y == 0.0) ? 0.0 : a.y / b.y; - result.z = (b.z == 0.0) ? 0.0 : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - friend double3 operator+(const double3 &a, const double3 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z}; - } - - void operator+=(const double3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - } - - friend double3 operator-(const double3 &a, const double3 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z}; - } - - friend double3 operator-(const double3 &a) - { - return {-a.x, -a.y, -a.z}; - } - - void operator-=(const double3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - } - - void operator*=(const double &scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - } - - void operator*=(const double3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - } - - friend double3 operator*(const double3 &a, const double3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend double3 operator*(const double3 &a, const double &b) - { - return {a.x * b, a.y * b, a.z * b}; - } - - friend double3 operator*(const double &a, const double3 &b) - { - return b * a; - } - - friend double3 operator/(const double3 &a, const double &b) - { - BLI_assert(b != 0.0); - return {a.x / b, a.y / b, a.z / b}; - } - - friend bool operator==(const double3 &a, const double3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const double3 &a, const double3 &b) - { - return a.x != b.x || a.y != b.y || a.z != b.z; - } - - friend std::ostream &operator<<(std::ostream &stream, const double3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - static double dot(const double3 &a, const double3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static double3 cross_high_precision(const double3 &a, const double3 &b) - { - double3 result; - cross_v3_v3v3_db(result, a, b); - return result; - } - - static double3 project(const double3 &a, const double3 &b) - { - double3 result; - project_v3_v3v3_db(result, a, b); - return result; - } - - static double distance(const double3 &a, const double3 &b) - { - return (a - b).length(); - } - - static double distance_squared(const double3 &a, const double3 &b) - { - double3 diff = a - b; - return double3::dot(diff, diff); - } - - static double3 interpolate(const double3 &a, const double3 &b, double t) - { - return a * (1 - t) + b * t; - } - - static double3 abs(const double3 &a) - { - return double3(fabs(a.x), fabs(a.y), fabs(a.z)); - } - - static int dominant_axis(const double3 &a) - { - double x = (a.x >= 0) ? a.x : -a.x; - double y = (a.y >= 0) ? a.y : -a.y; - double z = (a.z >= 0) ? a.z : -a.z; - return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); - } - - static double3 cross_poly(Span poly); -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh deleted file mode 100644 index bb4229db86e..00000000000 --- a/source/blender/blenlib/BLI_float2.hh +++ /dev/null @@ -1,218 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include "BLI_float3.hh" - -namespace blender { - -struct float2 { - float x, y; - - float2() = default; - - float2(const float *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - explicit float2(float value) : x(value), y(value) - { - } - - explicit float2(int value) : x(value), y(value) - { - } - - float2(float x, float y) : x(x), y(y) - { - } - - float2(const float3 &other) : x(other.x), y(other.y) - { - } - - operator float *() - { - return &x; - } - - operator const float *() const - { - return &x; - } - - float length() const - { - return len_v2(*this); - } - - float length_squared() const - { - return len_squared_v2(*this); - } - - bool is_zero() const - { - return this->x == 0.0f && this->y == 0.0f; - } - - float2 &operator+=(const float2 &other) - { - x += other.x; - y += other.y; - return *this; - } - - float2 &operator-=(const float2 &other) - { - x -= other.x; - y -= other.y; - return *this; - } - - float2 &operator*=(float factor) - { - x *= factor; - y *= factor; - return *this; - } - - float2 &operator/=(float divisor) - { - x /= divisor; - y /= divisor; - return *this; - } - - uint64_t hash() const - { - uint64_t x1 = *reinterpret_cast(&x); - uint64_t x2 = *reinterpret_cast(&y); - return (x1 * 812519) ^ (x2 * 707951); - } - - friend float2 operator+(const float2 &a, const float2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend float2 operator-(const float2 &a, const float2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend float2 operator-(const float2 &a, const float &b) - { - return {a.x - b, a.y - b}; - } - - friend float2 operator*(const float2 &a, float b) - { - return {a.x * b, a.y * b}; - } - - friend float2 operator/(const float2 &a, float b) - { - BLI_assert(b != 0.0f); - return {a.x / b, a.y / b}; - } - - friend float2 operator*(float a, const float2 &b) - { - return b * a; - } - - friend std::ostream &operator<<(std::ostream &stream, const float2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static float2 safe_divide(const float2 &a, const float b) - { - return (b != 0.0f) ? a / b : float2(0.0f); - } - - static float2 floor(const float2 &a) - { - return float2(floorf(a.x), floorf(a.y)); - } - - /** - * Returns a normalized vector. The original vector is not changed. - */ - float2 normalized() const - { - float2 result; - normalize_v2_v2(result, *this); - return result; - } - - static float dot(const float2 &a, const float2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static float2 interpolate(const float2 &a, const float2 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float2 abs(const float2 &a) - { - return float2(fabsf(a.x), fabsf(a.y)); - } - - static float distance(const float2 &a, const float2 &b) - { - return (a - b).length(); - } - - static float distance_squared(const float2 &a, const float2 &b) - { - float2 diff = a - b; - return float2::dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - float lambda; - float mu; - }; - - static isect_result isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4); - - friend bool operator==(const float2 &a, const float2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const float2 &a, const float2 &b) - { - return !(a == b); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh deleted file mode 100644 index 765f524fb31..00000000000 --- a/source/blender/blenlib/BLI_float3.hh +++ /dev/null @@ -1,320 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -#include - -#include "BLI_math_vector.h" - -namespace blender { - -struct float3 { - float x, y, z; - - float3() = default; - - float3(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - float3(const float (*ptr)[3]) : float3(static_cast(ptr[0])) - { - } - - explicit float3(float value) : x(value), y(value), z(value) - { - } - - explicit float3(int value) : x(value), y(value), z(value) - { - } - - float3(float x, float y, float z) : x{x}, y{y}, z{z} - { - } - - operator const float *() const - { - return &x; - } - - operator float *() - { - return &x; - } - - friend float3 operator+(const float3 &a, const float3 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z}; - } - - friend float3 operator+(const float3 &a, const float &b) - { - return {a.x + b, a.y + b, a.z + b}; - } - - float3 &operator+=(const float3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - return *this; - } - - friend float3 operator-(const float3 &a, const float3 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z}; - } - - friend float3 operator-(const float3 &a) - { - return {-a.x, -a.y, -a.z}; - } - - friend float3 operator-(const float3 &a, const float &b) - { - return {a.x - b, a.y - b, a.z - b}; - } - - float3 &operator-=(const float3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - return *this; - } - - float3 &operator*=(float scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - return *this; - } - - float3 &operator*=(const float3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - return *this; - } - - friend float3 operator*(const float3 &a, const float3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend float3 operator*(const float3 &a, float b) - { - return {a.x * b, a.y * b, a.z * b}; - } - - friend float3 operator*(float a, const float3 &b) - { - return b * a; - } - - friend float3 operator/(const float3 &a, float b) - { - BLI_assert(b != 0.0f); - return {a.x / b, a.y / b, a.z / b}; - } - - friend std::ostream &operator<<(std::ostream &stream, const float3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - friend bool operator==(const float3 &a, const float3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const float3 &a, const float3 &b) - { - return !(a == b); - } - - float normalize_and_get_length() - { - return normalize_v3(*this); - } - - /** - * Normalizes the vector in place. - */ - void normalize() - { - normalize_v3(*this); - } - - /** - * Returns a normalized vector. The original vector is not changed. - */ - float3 normalized() const - { - float3 result; - normalize_v3_v3(result, *this); - return result; - } - - float length() const - { - return len_v3(*this); - } - - float length_squared() const - { - return len_squared_v3(*this); - } - - bool is_zero() const - { - return this->x == 0.0f && this->y == 0.0f && this->z == 0.0f; - } - - void reflect(const float3 &normal) - { - *this = this->reflected(normal); - } - - float3 reflected(const float3 &normal) const - { - float3 result; - reflect_v3_v3v3(result, *this, normal); - return result; - } - - static float3 refract(const float3 &incident, const float3 &normal, const float eta) - { - float3 result; - float k = 1.0f - eta * eta * (1.0f - dot(normal, incident) * dot(normal, incident)); - if (k < 0.0f) { - result = float3(0.0f); - } - else { - result = eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal; - } - return result; - } - - static float3 faceforward(const float3 &vector, const float3 &incident, const float3 &reference) - { - return dot(reference, incident) < 0.0f ? vector : -vector; - } - - static float3 safe_divide(const float3 &a, const float3 &b) - { - float3 result; - result.x = (b.x == 0.0f) ? 0.0f : a.x / b.x; - result.y = (b.y == 0.0f) ? 0.0f : a.y / b.y; - result.z = (b.z == 0.0f) ? 0.0f : a.z / b.z; - return result; - } - - static float3 min(const float3 &a, const float3 &b) - { - return {a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z}; - } - - static float3 max(const float3 &a, const float3 &b) - { - return {a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z}; - } - - static void min_max(const float3 &vector, float3 &min, float3 &max) - { - min = float3::min(vector, min); - max = float3::max(vector, max); - } - - static float3 safe_divide(const float3 &a, const float b) - { - return (b != 0.0f) ? a / b : float3(0.0f); - } - - static float3 floor(const float3 &a) - { - return float3(floorf(a.x), floorf(a.y), floorf(a.z)); - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - uint64_t hash() const - { - uint64_t x1 = *reinterpret_cast(&x); - uint64_t x2 = *reinterpret_cast(&y); - uint64_t x3 = *reinterpret_cast(&z); - return (x1 * 435109) ^ (x2 * 380867) ^ (x3 * 1059217); - } - - static float dot(const float3 &a, const float3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static float3 cross_high_precision(const float3 &a, const float3 &b) - { - float3 result; - cross_v3_v3v3_hi_prec(result, a, b); - return result; - } - - static float3 cross(const float3 &a, const float3 &b) - { - float3 result; - cross_v3_v3v3(result, a, b); - return result; - } - - static float3 project(const float3 &a, const float3 &b) - { - float3 result; - project_v3_v3v3(result, a, b); - return result; - } - - static float distance(const float3 &a, const float3 &b) - { - return (a - b).length(); - } - - static float distance_squared(const float3 &a, const float3 &b) - { - float3 diff = a - b; - return float3::dot(diff, diff); - } - - static float3 interpolate(const float3 &a, const float3 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float3 abs(const float3 &a) - { - return float3(fabsf(a.x), fabsf(a.y), fabsf(a.z)); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float4.hh b/source/blender/blenlib/BLI_float4.hh deleted file mode 100644 index 5b487f6d029..00000000000 --- a/source/blender/blenlib/BLI_float4.hh +++ /dev/null @@ -1,138 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -namespace blender { - -struct float4 { - float x, y, z, w; - - float4() = default; - - float4(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]}, w{ptr[3]} - { - } - - explicit float4(float value) : x(value), y(value), z(value), w(value) - { - } - - explicit float4(int value) : x(value), y(value), z(value), w(value) - { - } - - float4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) - { - } - - operator float *() - { - return &x; - } - - friend float4 operator+(const float4 &a, const float &b) - { - return {a.x + b, a.y + b, a.z + b, a.w + b}; - } - - operator const float *() const - { - return &x; - } - - float4 &operator+=(const float4 &other) - { - x += other.x; - y += other.y; - z += other.z; - w += other.w; - return *this; - } - - friend float4 operator-(const float4 &a, const float4 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w}; - } - - friend float4 operator-(const float4 &a, const float &b) - { - return {a.x - b, a.y - b, a.z - b, a.w - b}; - } - - friend float4 operator+(const float4 &a, const float4 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; - } - - friend float4 operator/(const float4 &a, float f) - { - BLI_assert(f != 0.0f); - return a * (1.0f / f); - } - - float4 &operator*=(float factor) - { - x *= factor; - y *= factor; - z *= factor; - w *= factor; - return *this; - } - - friend float4 operator*(const float4 &a, float b) - { - return {a.x * b, a.y * b, a.z * b, a.w * b}; - } - - friend float4 operator*(float a, const float4 &b) - { - return b * a; - } - - float length() const - { - return len_v4(*this); - } - - static float distance(const float4 &a, const float4 &b) - { - return (a - b).length(); - } - - static float4 safe_divide(const float4 &a, const float b) - { - return (b != 0.0f) ? a / b : float4(0.0f); - } - - static float4 interpolate(const float4 &a, const float4 &b, float t) - { - return a * (1 - t) + b * t; - } - - static float4 floor(const float4 &a) - { - return float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w)); - } - - static float4 normalize(const float4 &a) - { - const float t = len_v4(a); - return (t != 0.0f) ? a / t : float4(0.0f); - } -}; - -} // namespace blender diff --git a/source/blender/blenlib/BLI_float4x4.hh b/source/blender/blenlib/BLI_float4x4.hh index b7f839f4ddf..81c969d02d0 100644 --- a/source/blender/blenlib/BLI_float4x4.hh +++ b/source/blender/blenlib/BLI_float4x4.hh @@ -16,8 +16,9 @@ #pragma once -#include "BLI_float3.hh" #include "BLI_math_matrix.h" +#include "BLI_math_vec_types.hh" +#include "BLI_math_vector.h" namespace blender { @@ -63,7 +64,7 @@ struct float4x4 { * Without the negation, the result would be a so called improper rotation. That means it * contains a reflection. Such an improper rotation matrix could not be converted to another * representation of a rotation such as euler angles. */ - const float3 cross = -float3::cross(forward, up); + const float3 cross = -math::cross(forward, up); float4x4 matrix; matrix.values[0][0] = forward.x; diff --git a/source/blender/blenlib/BLI_math_boolean.hh b/source/blender/blenlib/BLI_math_boolean.hh index 20fd00b2aa4..8cf93c82dec 100644 --- a/source/blender/blenlib/BLI_math_boolean.hh +++ b/source/blender/blenlib/BLI_math_boolean.hh @@ -21,13 +21,11 @@ * \brief Math vector functions needed specifically for mesh intersect and boolean. */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" +#include "BLI_math_vec_types.hh" #ifdef WITH_GMP # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" #endif namespace blender { diff --git a/source/blender/blenlib/BLI_math_vec_mpq_types.hh b/source/blender/blenlib/BLI_math_vec_mpq_types.hh new file mode 100644 index 00000000000..36eb0cac83c --- /dev/null +++ b/source/blender/blenlib/BLI_math_vec_mpq_types.hh @@ -0,0 +1,91 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#ifdef WITH_GMP + +# include "BLI_math_mpq.hh" +# include "BLI_math_vec_types.hh" + +namespace blender { + +using mpq2 = vec_base; +using mpq3 = vec_base; + +namespace math { + +uint64_t hash_mpq_class(const mpq_class &value); + +template<> inline uint64_t vector_hash(const mpq2 &vec) +{ + return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33); +} + +template<> inline uint64_t vector_hash(const mpq3 &vec) +{ + return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33) ^ (hash_mpq_class(vec.z) * 33 * 37); +} + +/** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ +template<> inline mpq_class length(const mpq2 &a) +{ + return mpq_class(sqrt(length_squared(a).get_d())); +} + +/** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ +template<> inline mpq_class length(const mpq3 &a) +{ + return mpq_class(sqrt(length_squared(a).get_d())); +} + +/** + * The buffer avoids allocating a temporary variable. + */ +inline mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) +{ + buffer = a; + buffer -= b; + return dot(buffer, buffer); +} + +/** + * The buffer avoids allocating a temporary variable. + */ +inline mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) +{ + buffer = a; + buffer *= b; + buffer.x += buffer.y; + buffer.x += buffer.z; + return buffer.x; +} + +} // namespace math + +} // namespace blender + +#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh new file mode 100644 index 00000000000..52aacd294e4 --- /dev/null +++ b/source/blender/blenlib/BLI_math_vec_types.hh @@ -0,0 +1,566 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include +#include +#include +#include + +#include "BLI_math_vector.hh" +#include "BLI_utildefines.h" + +namespace blender { + +/* clang-format off */ +template +using as_uint_type = std::conditional_t>>>; +/* clang-format on */ + +template struct vec_struct_base { + std::array values; +}; + +template struct vec_struct_base { + T x, y; +}; + +template struct vec_struct_base { + T x, y, z; +}; + +template struct vec_struct_base { + T x, y, z, w; +}; + +template struct vec_base : public vec_struct_base { + + static constexpr int type_length = Size; + + using base_type = T; + using uint_type = vec_base, Size>; + + vec_base() = default; + + explicit vec_base(uint value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(int value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(float value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + + explicit vec_base(double value) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(value); + } + } + +/* Workaround issue with template BLI_ENABLE_IF((Size == 2)) not working. */ +#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test)) + + template vec_base(T _x, T _y) + { + (*this)[0] = _x; + (*this)[1] = _y; + } + + template vec_base(T _x, T _y, T _z) + { + (*this)[0] = _x; + (*this)[1] = _y; + (*this)[2] = _z; + } + + template vec_base(T _x, T _y, T _z, T _w) + { + (*this)[0] = _x; + (*this)[1] = _y; + (*this)[2] = _z; + (*this)[3] = _w; + } + + /** Mixed scalar-vector constructors. */ + + template + constexpr vec_base(const vec_base &xy, T z) + : vec_base(static_cast(xy.x), static_cast(xy.y), z) + { + } + + template + constexpr vec_base(T x, const vec_base &yz) + : vec_base(x, static_cast(yz.x), static_cast(yz.y)) + { + } + + template + vec_base(vec_base xyz, T w) + : vec_base( + static_cast(xyz.x), static_cast(xyz.y), static_cast(xyz.z), static_cast(w)) + { + } + + template + vec_base(T x, vec_base yzw) + : vec_base( + static_cast(x), static_cast(yzw.x), static_cast(yzw.y), static_cast(yzw.z)) + { + } + + template + vec_base(vec_base xy, vec_base zw) + : vec_base( + static_cast(xy.x), static_cast(xy.y), static_cast(zw.x), static_cast(zw.y)) + { + } + + template + vec_base(vec_base xy, T z, T w) + : vec_base(static_cast(xy.x), static_cast(xy.y), static_cast(z), static_cast(w)) + { + } + + template + vec_base(T x, vec_base yz, T w) + : vec_base(static_cast(x), static_cast(yz.x), static_cast(yz.y), static_cast(w)) + { + } + + template + vec_base(T x, T y, vec_base zw) + : vec_base(static_cast(x), static_cast(y), static_cast(zw.x), static_cast(zw.y)) + { + } + + /** Masking. */ + + template Size)> + explicit vec_base(const vec_base &other) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(other[i]); + } + } + +#undef BLI_ENABLE_IF_VEC + + /** Conversion from pointers (from C-style vectors). */ + + vec_base(const T *ptr) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = ptr[i]; + } + } + + vec_base(const T (*ptr)[Size]) : vec_base(static_cast(ptr[0])) + { + } + + /** Conversion from other vector types. */ + + template explicit vec_base(const vec_base &vec) + { + for (int i = 0; i < Size; i++) { + (*this)[i] = static_cast(vec[i]); + } + } + + /** C-style pointer dereference. */ + + operator const T *() const + { + return reinterpret_cast(this); + } + + operator T *() + { + return reinterpret_cast(this); + } + + /** Array access. */ + + const T &operator[](int index) const + { + BLI_assert(index >= 0); + BLI_assert(index < Size); + return reinterpret_cast(this)[index]; + } + + T &operator[](int index) + { + BLI_assert(index >= 0); + BLI_assert(index < Size); + return reinterpret_cast(this)[index]; + } + + /** Internal Operators Macro. */ + +#define BLI_INT_OP(_T) template))> + +#define BLI_VEC_OP_IMPL(_result, _i, _op) \ + vec_base _result; \ + for (int _i = 0; _i < Size; _i++) { \ + _op; \ + } \ + return _result; + +#define BLI_VEC_OP_IMPL_SELF(_i, _op) \ + for (int _i = 0; _i < Size; _i++) { \ + _op; \ + } \ + return *this; + + /** Arithmetic operators. */ + + friend vec_base operator+(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b[i]); + } + + friend vec_base operator+(const vec_base &a, const T &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] + b); + } + + friend vec_base operator+(const T &a, const vec_base &b) + { + return b + a; + } + + vec_base &operator+=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b[i]); + } + + vec_base &operator+=(const T &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] += b); + } + + friend vec_base operator-(const vec_base &a) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = -a[i]); + } + + friend vec_base operator-(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b[i]); + } + + friend vec_base operator-(const vec_base &a, const T &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] - b); + } + + friend vec_base operator-(const T &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a - b[i]); + } + + vec_base &operator-=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b[i]); + } + + vec_base &operator-=(const T &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] -= b); + } + + friend vec_base operator*(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b[i]); + } + + friend vec_base operator*(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] * b); + } + + friend vec_base operator*(T a, const vec_base &b) + { + return b * a; + } + + vec_base &operator*=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b); + } + + vec_base &operator*=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] *= b[i]); + } + + friend vec_base operator/(const vec_base &a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b[i]); + } + + friend vec_base operator/(const vec_base &a, T b) + { + BLI_assert(b != T(0)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b); + } + + friend vec_base operator/(T a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a / b[i]); + } + + vec_base &operator/=(T b) + { + BLI_assert(b != T(0)); + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b); + } + + vec_base &operator/=(const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b[i]); + } + + /** Binary operators. */ + + BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b[i]); + } + + BLI_INT_OP(T) friend vec_base operator&(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] & b); + } + + BLI_INT_OP(T) friend vec_base operator&(T a, const vec_base &b) + { + return b & a; + } + + BLI_INT_OP(T) vec_base &operator&=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b); + } + + BLI_INT_OP(T) vec_base &operator&=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] &= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b[i]); + } + + BLI_INT_OP(T) friend vec_base operator|(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] | b); + } + + BLI_INT_OP(T) friend vec_base operator|(T a, const vec_base &b) + { + return b | a; + } + + BLI_INT_OP(T) vec_base &operator|=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b); + } + + BLI_INT_OP(T) vec_base &operator|=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] |= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b[i]); + } + + BLI_INT_OP(T) friend vec_base operator^(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] ^ b); + } + + BLI_INT_OP(T) friend vec_base operator^(T a, const vec_base &b) + { + return b ^ a; + } + + BLI_INT_OP(T) vec_base &operator^=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b); + } + + BLI_INT_OP(T) vec_base &operator^=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] ^= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator~(const vec_base &a) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = ~a[i]); + } + + /** Bit-shift operators. */ + + BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b[i]); + } + + BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b); + } + + BLI_INT_OP(T) vec_base &operator<<=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b); + } + + BLI_INT_OP(T) vec_base &operator<<=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b[i]); + } + + BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b); + } + + BLI_INT_OP(T) vec_base &operator>>=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b); + } + + BLI_INT_OP(T) vec_base &operator>>=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b[i]); + } + + /** Modulo operators. */ + + BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b[i]); + } + + BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, T b) + { + BLI_assert(b != 0); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] % b); + } + + BLI_INT_OP(T) friend vec_base operator%(T a, const vec_base &b) + { + BLI_assert(!math::is_any_zero(b)); + BLI_VEC_OP_IMPL(ret, i, ret[i] = a % b[i]); + } + +#undef BLI_INT_OP +#undef BLI_VEC_OP_IMPL +#undef BLI_VEC_OP_IMPL_SELF + + /** Compare. */ + + friend bool operator==(const vec_base &a, const vec_base &b) + { + for (int i = 0; i < Size; i++) { + if (a[i] != b[i]) { + return false; + } + } + return true; + } + + friend bool operator!=(const vec_base &a, const vec_base &b) + { + return !(a == b); + } + + /** Misc. */ + + uint64_t hash() const + { + return math::vector_hash(*this); + } + + friend std::ostream &operator<<(std::ostream &stream, const vec_base &v) + { + stream << "("; + for (int i = 0; i < Size; i++) { + stream << v[i]; + if (i != Size - 1) { + stream << ", "; + } + } + stream << ")"; + return stream; + } +}; + +using int2 = vec_base; +using int3 = vec_base; +using int4 = vec_base; + +using uint2 = vec_base; +using uint3 = vec_base; +using uint4 = vec_base; + +using float2 = vec_base; +using float3 = vec_base; +using float4 = vec_base; + +using double2 = vec_base; +using double3 = vec_base; +using double4 = vec_base; + +} // namespace blender diff --git a/source/blender/blenlib/BLI_math_vector.hh b/source/blender/blenlib/BLI_math_vector.hh new file mode 100644 index 00000000000..e7d765df842 --- /dev/null +++ b/source/blender/blenlib/BLI_math_vector.hh @@ -0,0 +1,399 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#pragma once + +/** \file + * \ingroup bli + */ + +#include +#include + +#include "BLI_math_base_safe.h" +#include "BLI_math_vector.h" +#include "BLI_span.hh" +#include "BLI_utildefines.h" + +#ifdef WITH_GMP +# include "BLI_math_mpq.hh" +#endif + +namespace blender::math { + +#ifndef NDEBUG +# define BLI_ASSERT_UNIT(v) \ + { \ + const float _test_unit = length_squared(v); \ + BLI_assert(!(std::abs(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \ + !(std::abs(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \ + } \ + (void)0 +#else +# define BLI_ASSERT_UNIT(v) (void)(v) +#endif + +#define bT typename T::base_type + +#ifdef WITH_GMP +# define BLI_ENABLE_IF_FLT_VEC(T) \ + BLI_ENABLE_IF((std::is_floating_point_v || \ + std::is_same_v)) +#else +# define BLI_ENABLE_IF_FLT_VEC(T) BLI_ENABLE_IF((std::is_floating_point_v)) +#endif + +#define BLI_ENABLE_IF_INT_VEC(T) BLI_ENABLE_IF((std::is_integral_v)) + +template inline bool is_zero(const T &a) +{ + for (int i = 0; i < T::type_length; i++) { + if (a[i] != bT(0)) { + return false; + } + } + return true; +} + +template inline bool is_any_zero(const T &a) +{ + for (int i = 0; i < T::type_length; i++) { + if (a[i] == bT(0)) { + return true; + } + } + return false; +} + +template inline T abs(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] >= 0 ? a[i] : -a[i]; + } + return result; +} + +template inline T min(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] < b[i] ? a[i] : b[i]; + } + return result; +} + +template inline T max(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] > b[i] ? a[i] : b[i]; + } + return result; +} + +template inline T clamp(const T &a, const T &min_v, const T &max_v) +{ + T result = a; + for (int i = 0; i < T::type_length; i++) { + CLAMP(result[i], min_v[i], max_v[i]); + } + return result; +} + +template inline T clamp(const T &a, const bT &min_v, const bT &max_v) +{ + T result = a; + for (int i = 0; i < T::type_length; i++) { + CLAMP(result[i], min_v, max_v); + } + return result; +} + +template inline T mod(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + BLI_assert(b[i] != 0); + result[i] = std::fmod(a[i], b[i]); + } + return result; +} + +template inline T mod(const T &a, bT b) +{ + BLI_assert(b != 0); + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::fmod(a[i], b); + } + return result; +} + +template inline T safe_mod(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = (b[i] != 0) ? std::fmod(a[i], b[i]) : 0; + } + return result; +} + +template inline T safe_mod(const T &a, bT b) +{ + if (b == 0) { + return T(0.0f); + } + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::fmod(a[i], b); + } + return result; +} + +template inline void min_max(const T &vector, T &min_vec, T &max_vec) +{ + min_vec = min(vector, min_vec); + max_vec = max(vector, max_vec); +} + +template inline T safe_divide(const T &a, const T &b) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = (b[i] == 0) ? 0 : a[i] / b[i]; + } + return result; +} + +template inline T safe_divide(const T &a, const bT b) +{ + return (b != 0) ? a / b : T(0.0f); +} + +template inline T floor(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::floor(a[i]); + } + return result; +} + +template inline T ceil(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = std::ceil(a[i]); + } + return result; +} + +template inline T fract(const T &a) +{ + T result; + for (int i = 0; i < T::type_length; i++) { + result[i] = a[i] - std::floor(a[i]); + } + return result; +} + +template inline bT dot(const T &a, const T &b) +{ + bT result = a[0] * b[0]; + for (int i = 1; i < T::type_length; i++) { + result += a[i] * b[i]; + } + return result; +} + +template inline bT length_manhattan(const T &a) +{ + bT result = std::abs(a[0]); + for (int i = 1; i < T::type_length; i++) { + result += std::abs(a[i]); + } + return result; +} + +template inline bT length_squared(const T &a) +{ + return dot(a, a); +} + +template inline bT length(const T &a) +{ + return std::sqrt(length_squared(a)); +} + +template inline bT distance_manhattan(const T &a, const T &b) +{ + return length_manhattan(a - b); +} + +template inline bT distance_squared(const T &a, const T &b) +{ + return length_squared(a - b); +} + +template inline bT distance(const T &a, const T &b) +{ + return length(a - b); +} + +template uint64_t vector_hash(const T &vec) +{ + BLI_STATIC_ASSERT(T::type_length <= 4, "Longer types need to implement vector_hash themself."); + const typename T::uint_type &uvec = *reinterpret_cast(&vec); + uint64_t result; + result = uvec[0] * uint64_t(435109); + if constexpr (T::type_length > 1) { + result ^= uvec[1] * uint64_t(380867); + } + if constexpr (T::type_length > 2) { + result ^= uvec[2] * uint64_t(1059217); + } + if constexpr (T::type_length > 3) { + result ^= uvec[3] * uint64_t(2002613); + } + return result; +} + +template inline T reflect(const T &incident, const T &normal) +{ + BLI_ASSERT_UNIT(normal); + return incident - 2.0 * dot(normal, incident) * normal; +} + +template +inline T refract(const T &incident, const T &normal, const bT eta) +{ + float dot_ni = dot(normal, incident); + float k = 1.0f - eta * eta * (1.0f - dot_ni * dot_ni); + if (k < 0.0f) { + return T(0.0f); + } + return eta * incident - (eta * dot_ni + sqrt(k)) * normal; +} + +template inline T project(const T &p, const T &v_proj) +{ + if (UNLIKELY(is_zero(v_proj))) { + return T(0.0f); + } + return v_proj * (dot(p, v_proj) / dot(v_proj, v_proj)); +} + +template +inline T normalize_and_get_length(const T &v, bT &out_length) +{ + out_length = length_squared(v); + /* A larger value causes normalize errors in a scaled down models with camera extreme close. */ + constexpr bT threshold = std::is_same_v ? 1.0e-70 : 1.0e-35f; + if (out_length > threshold) { + out_length = sqrt(out_length); + return v / out_length; + } + /* Either the vector is small or one of it's values contained `nan`. */ + out_length = 0.0; + return T(0.0); +} + +template inline T normalize(const T &v) +{ + bT len; + return normalize_and_get_length(v, len); +} + +template +inline T cross(const T &a, const T &b) +{ + return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; +} + +template)), + BLI_ENABLE_IF((T::type_length == 3))> +inline T cross_high_precision(const T &a, const T &b) +{ + return {(float)((double)a.y * b.z - (double)a.z * b.y), + (float)((double)a.z * b.x - (double)a.x * b.z), + (float)((double)a.x * b.y - (double)a.y * b.x)}; +} + +template +inline T cross_poly(Span poly) +{ + /* Newell's Method. */ + int nv = static_cast(poly.size()); + if (nv < 3) { + return T(0, 0, 0); + } + const T *v_prev = &poly[nv - 1]; + const T *v_curr = &poly[0]; + T n(0, 0, 0); + for (int i = 0; i < nv;) { + n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); + n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); + n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); + v_prev = v_curr; + ++i; + if (i < nv) { + v_curr = &poly[i]; + } + } + return n; +} + +template inline T interpolate(const T &a, const T &b, bT t) +{ + return a * (1 - t) + b * t; +} + +template +inline T faceforward(const T &vector, const T &incident, const T &reference) +{ + return (dot(reference, incident) < 0) ? vector : -vector; +} + +template inline int dominant_axis(const T &a) +{ + T b = abs(a); + return ((b.x > b.y) ? ((b.x > b.z) ? 0 : 2) : ((b.y > b.z) ? 1 : 2)); +} + +/** Intersections. */ + +template struct isect_result { + enum { + LINE_LINE_COLINEAR = -1, + LINE_LINE_NONE = 0, + LINE_LINE_EXACT = 1, + LINE_LINE_CROSS = 2, + } kind; + bT lambda; +}; + +template +isect_result isect_seg_seg(const T &v1, const T &v2, const T &v3, const T &v4); + +#undef BLI_ENABLE_IF_FLT_VEC +#undef BLI_ENABLE_IF_INT_VEC +#undef bT + +} // namespace blender::math diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh index 37691017c12..9a5be79b61e 100644 --- a/source/blender/blenlib/BLI_memory_utils.hh +++ b/source/blender/blenlib/BLI_memory_utils.hh @@ -557,13 +557,4 @@ Container &move_assign_container(Container &dst, Container &&src) noexcept( return dst; } -/** - * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for - * SFINAE in common cases. - * - * \note Often one has to invoke this macro with double parenthesis. That's because the condition - * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. - */ -#define BLI_ENABLE_IF(condition) typename std::enable_if_t * = nullptr - } // namespace blender diff --git a/source/blender/blenlib/BLI_mesh_intersect.hh b/source/blender/blenlib/BLI_mesh_intersect.hh index 71a8abb822f..0ebee6f16a8 100644 --- a/source/blender/blenlib/BLI_mesh_intersect.hh +++ b/source/blender/blenlib/BLI_mesh_intersect.hh @@ -28,12 +28,11 @@ # include # include "BLI_array.hh" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_index_range.hh" # include "BLI_map.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_span.hh" # include "BLI_utility_mixins.hh" # include "BLI_vector.hh" diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh deleted file mode 100644 index 18bc8821d9c..00000000000 --- a/source/blender/blenlib/BLI_mpq2.hh +++ /dev/null @@ -1,184 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#ifdef WITH_GMP - -# include "BLI_math_mpq.hh" -# include "BLI_mpq3.hh" - -namespace blender { - -struct mpq2 { - mpq_class x, y; - - mpq2() = default; - - mpq2(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]} - { - } - - mpq2(mpq_class x, mpq_class y) : x(x), y(y) - { - } - - mpq2(const mpq2 &other) : x(other.x), y(other.y) - { - } - - mpq2(mpq2 &&other) noexcept : x(std::move(other.x)), y(std::move(other.y)) - { - } - - ~mpq2() = default; - - mpq2 &operator=(const mpq2 &other) - { - if (this != &other) { - x = other.x; - y = other.y; - } - return *this; - } - - mpq2 &operator=(mpq2 &&other) noexcept - { - x = std::move(other.x); - y = std::move(other.y); - return *this; - } - - mpq2(const mpq3 &other) : x(other.x), y(other.y) - { - } - - operator mpq_class *() - { - return &x; - } - - operator const mpq_class *() const - { - return &x; - } - - /** - * Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ - mpq_class length() const - { - mpq_class lsquared = dot(*this, *this); - return mpq_class(sqrt(lsquared.get_d())); - } - - friend mpq2 operator+(const mpq2 &a, const mpq2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend mpq2 operator-(const mpq2 &a, const mpq2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend mpq2 operator*(const mpq2 &a, mpq_class b) - { - return {a.x * b, a.y * b}; - } - - friend mpq2 operator/(const mpq2 &a, mpq_class b) - { - BLI_assert(b != 0); - return {a.x / b, a.y / b}; - } - - friend mpq2 operator*(mpq_class a, const mpq2 &b) - { - return b * a; - } - - friend bool operator==(const mpq2 &a, const mpq2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const mpq2 &a, const mpq2 &b) - { - return a.x != b.x || a.y != b.y; - } - - friend std::ostream &operator<<(std::ostream &stream, const mpq2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static mpq_class dot(const mpq2 &a, const mpq2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static mpq2 interpolate(const mpq2 &a, const mpq2 &b, mpq_class t) - { - return a * (1 - t) + b * t; - } - - static mpq2 abs(const mpq2 &a) - { - mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; - mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; - return mpq2(abs_x, abs_y); - } - - static mpq_class distance(const mpq2 &a, const mpq2 &b) - { - return (a - b).length(); - } - - static mpq_class distance_squared(const mpq2 &a, const mpq2 &b) - { - mpq2 diff = a - b; - return dot(diff, diff); - } - - struct isect_result { - enum { - LINE_LINE_COLINEAR = -1, - LINE_LINE_NONE = 0, - LINE_LINE_EXACT = 1, - LINE_LINE_CROSS = 2, - } kind; - mpq_class lambda; - }; - - static isect_result isect_seg_seg(const mpq2 &v1, - const mpq2 &v2, - const mpq2 &v3, - const mpq2 &v4); - - /** There is a sensible use for hashing on exact arithmetic types. */ - uint64_t hash() const; -}; - -} // namespace blender - -#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_mpq3.hh b/source/blender/blenlib/BLI_mpq3.hh deleted file mode 100644 index b9eda2ad7e1..00000000000 --- a/source/blender/blenlib/BLI_mpq3.hh +++ /dev/null @@ -1,297 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#ifdef WITH_GMP - -# include - -# include "BLI_math.h" -# include "BLI_math_mpq.hh" -# include "BLI_span.hh" - -namespace blender { - -struct mpq3 { - mpq_class x, y, z; - - mpq3() = default; - - mpq3(const mpq_class *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} - { - } - - mpq3(const mpq_class (*ptr)[3]) : mpq3((const mpq_class *)ptr) - { - } - - explicit mpq3(mpq_class value) : x(value), y(value), z(value) - { - } - - explicit mpq3(int value) : x(value), y(value), z(value) - { - } - - mpq3(mpq_class x, mpq_class y, mpq_class z) : x{x}, y{y}, z{z} - { - } - - operator const mpq_class *() const - { - return &x; - } - - operator mpq_class *() - { - return &x; - } - - /* Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ - mpq_class normalize_and_get_length() - { - double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; - double len = normalize_v3_db(dv); - this->x = mpq_class(dv[0]); - this->y = mpq_class(dv[1]); - this->z = mpq_class(dv[2]); - return len; - } - - mpq3 normalized() const - { - double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; - double dr[3]; - normalize_v3_v3_db(dr, dv); - return mpq3(mpq_class(dr[0]), mpq_class(dr[1]), mpq_class(dr[2])); - } - - /* Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of double. - */ - mpq_class length() const - { - mpq_class lsquared = this->length_squared(); - double dsquared = lsquared.get_d(); - double d = sqrt(dsquared); - return mpq_class(d); - } - - mpq_class length_squared() const - { - return x * x + y * y + z * z; - } - - void reflect(const mpq3 &normal) - { - *this = this->reflected(normal); - } - - mpq3 reflected(const mpq3 &normal) const - { - mpq3 result; - const mpq_class dot2 = 2 * dot(*this, normal); - result.x = this->x - (dot2 * normal.x); - result.y = this->y - (dot2 * normal.y); - result.z = this->z - (dot2 * normal.z); - return result; - } - - static mpq3 safe_divide(const mpq3 &a, const mpq3 &b) - { - mpq3 result; - result.x = (b.x == 0) ? mpq_class(0) : a.x / b.x; - result.y = (b.y == 0) ? mpq_class(0) : a.y / b.y; - result.z = (b.z == 0) ? mpq_class(0) : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - friend mpq3 operator+(const mpq3 &a, const mpq3 &b) - { - return mpq3(a.x + b.x, a.y + b.y, a.z + b.z); - } - - void operator+=(const mpq3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - } - - friend mpq3 operator-(const mpq3 &a, const mpq3 &b) - { - return mpq3(a.x - b.x, a.y - b.y, a.z - b.z); - } - - friend mpq3 operator-(const mpq3 &a) - { - return mpq3(-a.x, -a.y, -a.z); - } - - void operator-=(const mpq3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - } - - void operator*=(mpq_class scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - } - - void operator*=(const mpq3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - } - - friend mpq3 operator*(const mpq3 &a, const mpq3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend mpq3 operator*(const mpq3 &a, const mpq_class &b) - { - return mpq3(a.x * b, a.y * b, a.z * b); - } - - friend mpq3 operator*(const mpq_class &a, const mpq3 &b) - { - return mpq3(a * b.x, a * b.y, a * b.z); - } - - friend mpq3 operator/(const mpq3 &a, const mpq_class &b) - { - BLI_assert(b != 0); - return mpq3(a.x / b, a.y / b, a.z / b); - } - - friend bool operator==(const mpq3 &a, const mpq3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const mpq3 &a, const mpq3 &b) - { - return a.x != b.x || a.y != b.y || a.z != b.z; - } - - friend std::ostream &operator<<(std::ostream &stream, const mpq3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - static mpq_class dot(const mpq3 &a, const mpq3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) - { - buffer = a; - buffer *= b; - buffer.x += buffer.y; - buffer.x += buffer.z; - return buffer.x; - } - - static mpq3 cross(const mpq3 &a, const mpq3 &b) - { - return mpq3(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]); - } - - static mpq3 cross_high_precision(const mpq3 &a, const mpq3 &b) - { - return cross(a, b); - } - - static mpq3 project(const mpq3 &a, const mpq3 &b) - { - const mpq_class mul = mpq3::dot(a, b) / mpq3::dot(b, b); - return mpq3(mul * b[0], mul * b[1], mul * b[2]); - } - - static mpq_class distance(const mpq3 &a, const mpq3 &b) - { - mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); - return diff.length(); - } - - static mpq_class distance_squared(const mpq3 &a, const mpq3 &b) - { - mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); - return mpq3::dot(diff, diff); - } - - static mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) - { - buffer = a; - buffer -= b; - return mpq3::dot(buffer, buffer); - } - - static mpq3 interpolate(const mpq3 &a, const mpq3 &b, mpq_class t) - { - mpq_class s = 1 - t; - return mpq3(a.x * s + b.x * t, a.y * s + b.y * t, a.z * s + b.z * t); - } - - static mpq3 abs(const mpq3 &a) - { - mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; - mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; - mpq_class abs_z = (a.z >= 0) ? a.z : -a.z; - return mpq3(abs_x, abs_y, abs_z); - } - - static int dominant_axis(const mpq3 &a) - { - mpq_class x = (a.x >= 0) ? a.x : -a.x; - mpq_class y = (a.y >= 0) ? a.y : -a.y; - mpq_class z = (a.z >= 0) ? a.z : -a.z; - return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); - } - - static mpq3 cross_poly(Span poly); - - /** There is a sensible use for hashing on exact arithmetic types. */ - uint64_t hash() const; -}; - -uint64_t hash_mpq_class(const mpq_class &value); - -} // namespace blender - -#endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_noise.hh b/source/blender/blenlib/BLI_noise.hh index 4f68ef17ca2..297c65c250a 100644 --- a/source/blender/blenlib/BLI_noise.hh +++ b/source/blender/blenlib/BLI_noise.hh @@ -16,9 +16,7 @@ #pragma once -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" namespace blender::noise { diff --git a/source/blender/blenlib/BLI_rand.hh b/source/blender/blenlib/BLI_rand.hh index cc9e9b374d7..667d6df8996 100644 --- a/source/blender/blenlib/BLI_rand.hh +++ b/source/blender/blenlib/BLI_rand.hh @@ -20,9 +20,8 @@ #pragma once -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 35d4158de59..c4b31810669 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -840,6 +840,15 @@ extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); /** No-op for expressions we don't want to instantiate, but must remain valid. */ #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) +/** + * Utility macro that wraps `std::enable_if` to make it a bit easier to use and less verbose for + * SFINAE in common cases. + * + * \note Often one has to invoke this macro with double parenthesis. That's because the condition + * often contains a comma and angle brackets are not recognized as parenthesis by the preprocessor. + */ +#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr + /** \} */ #ifdef __cplusplus diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 3958fd8e2d2..90c6760019a 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -192,8 +192,6 @@ set(SRC BLI_dlrbTree.h BLI_dot_export.hh BLI_dot_export_attribute_enums.hh - BLI_double2.hh - BLI_double3.hh BLI_dynlib.h BLI_dynstr.h BLI_easing.h @@ -207,9 +205,6 @@ set(SRC BLI_fileops.hh BLI_fileops_types.h BLI_filereader.h - BLI_float2.hh - BLI_float3.hh - BLI_float4.hh BLI_float4x4.hh BLI_fnmatch.h BLI_function_ref.hh @@ -258,6 +253,8 @@ set(SRC BLI_math_statistics.h BLI_math_time.h BLI_math_vector.h + BLI_math_vec_types.hh + BLI_math_vec_mpq_types.hh BLI_memarena.h BLI_memblock.h BLI_memiter.h @@ -267,8 +264,6 @@ set(SRC BLI_mesh_boolean.hh BLI_mesh_intersect.hh BLI_mmap.h - BLI_mpq2.hh - BLI_mpq3.hh BLI_multi_value_map.hh BLI_noise.h BLI_noise.hh @@ -444,6 +439,7 @@ if(WITH_GTESTS) tests/BLI_math_rotation_test.cc tests/BLI_math_solvers_test.cc tests/BLI_math_time_test.cc + tests/BLI_math_vec_types_test.cc tests/BLI_math_vector_test.cc tests/BLI_memiter_test.cc tests/BLI_memory_utils_test.cc diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc index 53e881a9fc7..842e6cb6135 100644 --- a/source/blender/blenlib/intern/delaunay_2d.cc +++ b/source/blender/blenlib/intern/delaunay_2d.cc @@ -25,11 +25,10 @@ #include #include "BLI_array.hh" -#include "BLI_double2.hh" #include "BLI_linklist.h" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_set.hh" #include "BLI_task.hh" #include "BLI_vector.hh" @@ -38,6 +37,8 @@ namespace blender::meshintersect { +using namespace blender::math; + /* Throughout this file, template argument T will be an * arithmetic-like type, like float, double, or mpq_class. */ @@ -788,11 +789,11 @@ bool in_line(const FatCo &a, } vec2 exact_ab = b.exact - a.exact; vec2 exact_ac = c.exact - a.exact; - if (vec2::dot(exact_ab, exact_ac) < 0) { + if (dot(exact_ab, exact_ac) < 0) { return false; } vec2 exact_bc = c.exact - b.exact; - return vec2::dot(exact_bc, exact_ac) >= 0; + return dot(exact_bc, exact_ac) >= 0; } #endif @@ -801,11 +802,11 @@ bool in_line(const FatCo &a, const FatCo &b, const FatCo { vec2 ab = b.approx - a.approx; vec2 ac = c.approx - a.approx; - if (vec2::dot(ab, ac) < 0) { + if (dot(ab, ac) < 0) { return false; } vec2 bc = c.approx - b.approx; - return vec2::dot(bc, ac) >= 0; + return dot(bc, ac) >= 0; } template<> CDTVert::CDTVert(const vec2 &pt) @@ -1081,7 +1082,7 @@ template CDTEdge *CDTArrangement::split_edge(SymEdge *se, T SymEdge *sesymprev = prev(sesym); SymEdge *sesymprevsym = sym(sesymprev); SymEdge *senext = se->next; - CDTVert *v = this->add_vert(vec2::interpolate(*a, *b, lambda)); + CDTVert *v = this->add_vert(interpolate(*a, *b, lambda)); CDTEdge *e = this->add_edge(v, se->next->vert, se->face, sesym->face); sesym->vert = v; SymEdge *newse = &e->symedges[0]; @@ -1704,16 +1705,16 @@ void fill_crossdata_for_intersect(const FatCo &curco, BLI_assert(se_vcva->vert == vc && se_vcva->next->vert == va); BLI_assert(se_vcvb->vert == vc && se_vcvb->next->vert == vb); UNUSED_VARS_NDEBUG(vc); - auto isect = vec2::isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); + auto isect = isect_seg_seg>(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); T &lambda = isect.lambda; switch (isect.kind) { - case vec2::isect_result::LINE_LINE_CROSS: { + case isect_result>::LINE_LINE_CROSS: { #ifdef WITH_GMP if (!std::is_same::value) { #else if (true) { #endif - double len_ab = vec2::distance(va->co.approx, vb->co.approx); + double len_ab = distance(va->co.approx, vb->co.approx); if (lambda * len_ab <= epsilon) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1735,7 +1736,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_EXACT: { + case isect_result>::LINE_LINE_EXACT: { if (lambda == 0) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1750,7 +1751,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_NONE: { + case isect_result>::LINE_LINE_NONE: { #ifdef WITH_GMP if (std::is_same::value) { BLI_assert(false); @@ -1766,9 +1767,9 @@ void fill_crossdata_for_intersect(const FatCo &curco, } break; } - case vec2::isect_result::LINE_LINE_COLINEAR: { - if (vec2::distance_squared(va->co.approx, v2->co.approx) <= - vec2::distance_squared(vb->co.approx, v2->co.approx)) { + case isect_result>::LINE_LINE_COLINEAR: { + if (distance_squared(va->co.approx, v2->co.approx) <= + distance_squared(vb->co.approx, v2->co.approx)) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } else { @@ -1845,7 +1846,7 @@ void get_next_crossing_from_edge(CrossData *cd, { CDTVert *va = cd->in->vert; CDTVert *vb = cd->in->next->vert; - vec2 curco = vec2::interpolate(va->co.exact, vb->co.exact, cd->lambda); + vec2 curco = interpolate(va->co.exact, vb->co.exact, cd->lambda); FatCo fat_curco(curco); SymEdge *se_ac = sym(cd->in)->next; CDTVert *vc = se_ac->next->vert; @@ -2386,7 +2387,7 @@ template void remove_non_constraint_edges_leave_valid_bmesh(CDT_stat dissolvable_edges[i].e = e; const vec2 &co1 = e->symedges[0].vert->co.approx; const vec2 &co2 = e->symedges[1].vert->co.approx; - dissolvable_edges[i].len_squared = vec2::distance_squared(co1, co2); + dissolvable_edges[i].len_squared = distance_squared(co1, co2); i++; } } @@ -2569,18 +2570,18 @@ template void detect_holes(CDT_state *cdt_state) if (e->symedges[0].face->visit_index == e->symedges[1].face->visit_index) { continue; /* Don't count hits on edges between faces in same region. */ } - auto isect = vec2::isect_seg_seg(ray_end.exact, + auto isect = isect_seg_seg>(ray_end.exact, mid.exact, e->symedges[0].vert->co.exact, e->symedges[1].vert->co.exact); switch (isect.kind) { - case vec2::isect_result::LINE_LINE_CROSS: { + case isect_result>::LINE_LINE_CROSS: { hits++; break; } - case vec2::isect_result::LINE_LINE_EXACT: - case vec2::isect_result::LINE_LINE_NONE: - case vec2::isect_result::LINE_LINE_COLINEAR: + case isect_result>::LINE_LINE_EXACT: + case isect_result>::LINE_LINE_NONE: + case isect_result>::LINE_LINE_COLINEAR: break; } } diff --git a/source/blender/blenlib/intern/math_boolean.cc b/source/blender/blenlib/intern/math_boolean.cc index c16755868aa..0bae3c23f79 100644 --- a/source/blender/blenlib/intern/math_boolean.cc +++ b/source/blender/blenlib/intern/math_boolean.cc @@ -18,15 +18,10 @@ * \ingroup bli */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" -#include "BLI_mpq3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc index 223c0e273f0..6fab6c9a383 100644 --- a/source/blender/blenlib/intern/math_vec.cc +++ b/source/blender/blenlib/intern/math_vec.cc @@ -18,89 +18,83 @@ * \ingroup bli */ -#include "BLI_double2.hh" -#include "BLI_double3.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" -#include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" -#include "BLI_mpq3.hh" +#include "BLI_math_vec_mpq_types.hh" +#include "BLI_math_vector.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" -namespace blender { +namespace blender::math { -float2::isect_result float2::isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4) +template<> +isect_result isect_seg_seg(const float2 &v1, + const float2 &v2, + const float2 &v3, + const float2 &v4) { - float2::isect_result ans; + isect_result ans; float div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0f) { ans.lambda = 0.0f; - ans.mu = 0.0f; - ans.kind = float2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; - ans.mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; - if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && ans.mu >= 0.0f && ans.mu <= 1.0f) { - if (ans.lambda == 0.0f || ans.lambda == 1.0f || ans.mu == 0.0f || ans.mu == 1.0f) { - ans.kind = float2::isect_result::LINE_LINE_EXACT; + float mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; + if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) { + if (ans.lambda == 0.0f || ans.lambda == 1.0f || mu == 0.0f || mu == 1.0f) { + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = float2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = float2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } -double2::isect_result double2::isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4) +template<> +isect_result isect_seg_seg(const double2 &v1, + const double2 &v2, + const double2 &v3, + const double2 &v4) { - double2::isect_result ans; + isect_result ans; double div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = double2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; double mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; if (ans.lambda >= 0.0 && ans.lambda <= 1.0 && mu >= 0.0 && mu <= 1.0) { if (ans.lambda == 0.0 || ans.lambda == 1.0 || mu == 0.0 || mu == 1.0) { - ans.kind = double2::isect_result::LINE_LINE_EXACT; + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = double2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = double2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } #ifdef WITH_GMP -mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, - const mpq2 &v2, - const mpq2 &v3, - const mpq2 &v4) +template<> +isect_result isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4) { - mpq2::isect_result ans; + isect_result ans; mpq_class div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); if (div == 0.0) { ans.lambda = 0.0; - ans.kind = mpq2::isect_result::LINE_LINE_COLINEAR; + ans.kind = isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; @@ -109,66 +103,21 @@ mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, if (ans.lambda >= 0 && ans.lambda <= 1 && ((div > 0 && mudiv >= 0 && mudiv <= div) || (div < 0 && mudiv <= 0 && mudiv >= div))) { if (ans.lambda == 0 || ans.lambda == 1 || mudiv == 0 || mudiv == div) { - ans.kind = mpq2::isect_result::LINE_LINE_EXACT; + ans.kind = isect_result::LINE_LINE_EXACT; } else { - ans.kind = mpq2::isect_result::LINE_LINE_CROSS; + ans.kind = isect_result::LINE_LINE_CROSS; } } else { - ans.kind = mpq2::isect_result::LINE_LINE_NONE; + ans.kind = isect_result::LINE_LINE_NONE; } } return ans; } #endif -double3 double3::cross_poly(Span poly) -{ - /* Newell's Method. */ - int nv = static_cast(poly.size()); - if (nv < 3) { - return double3(0, 0, 0); - } - const double3 *v_prev = &poly[nv - 1]; - const double3 *v_curr = &poly[0]; - double3 n(0, 0, 0); - for (int i = 0; i < nv;) { - n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); - n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); - n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); - v_prev = v_curr; - ++i; - if (i < nv) { - v_curr = &poly[i]; - } - } - return n; -} - #ifdef WITH_GMP -mpq3 mpq3::cross_poly(Span poly) -{ - /* Newell's Method. */ - int nv = static_cast(poly.size()); - if (nv < 3) { - return mpq3(0); - } - const mpq3 *v_prev = &poly[nv - 1]; - const mpq3 *v_curr = &poly[0]; - mpq3 n(0); - for (int i = 0; i < nv;) { - n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]); - n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]); - n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]); - v_prev = v_curr; - ++i; - if (i < nv) { - v_curr = &poly[i]; - } - } - return n; -} uint64_t hash_mpq_class(const mpq_class &value) { @@ -176,20 +125,6 @@ uint64_t hash_mpq_class(const mpq_class &value) return get_default_hash(static_cast(value.get_d())); } -uint64_t mpq2::hash() const -{ - uint64_t hashx = hash_mpq_class(this->x); - uint64_t hashy = hash_mpq_class(this->y); - return hashx ^ (hashy * 33); -} - -uint64_t mpq3::hash() const -{ - uint64_t hashx = hash_mpq_class(this->x); - uint64_t hashy = hash_mpq_class(this->y); - uint64_t hashz = hash_mpq_class(this->z); - return hashx ^ (hashy * 33) ^ (hashz * 33 * 37); -} #endif -} // namespace blender +} // namespace blender::math diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index ce4db0c6b9d..a3eae1896d3 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -28,8 +28,6 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" @@ -37,8 +35,9 @@ # include "BLI_math_boolean.hh" # include "BLI_math_geom.h" # include "BLI_math_mpq.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_mesh_intersect.hh" -# include "BLI_mpq3.hh" # include "BLI_set.hh" # include "BLI_span.hh" # include "BLI_stack.hh" @@ -1633,13 +1632,13 @@ static Edge find_good_sorting_edge(const Vert *testp, ordinate[axis_next] = -abscissa[axis]; ordinate[axis_next_next] = 0; /* By construction, dot(abscissa, ordinate) == 0, so they are perpendicular. */ - mpq3 normal = mpq3::cross(abscissa, ordinate); + mpq3 normal = math::cross(abscissa, ordinate); if (dbg_level > 0) { std::cout << "abscissa = " << abscissa << "\n"; std::cout << "ordinate = " << ordinate << "\n"; std::cout << "normal = " << normal << "\n"; } - mpq_class nlen2 = normal.length_squared(); + mpq_class nlen2 = math::length_squared(normal); mpq_class max_abs_slope = -1; Edge esort; const Vector &edges = tmtopo.vert_edges(closestp); @@ -1648,12 +1647,12 @@ static Edge find_good_sorting_edge(const Vert *testp, const mpq3 &co_other = v_other->co_exact; mpq3 evec = co_other - co_closest; /* Get projection of evec onto plane of abscissa and ordinate. */ - mpq3 proj_evec = evec - (mpq3::dot(evec, normal) / nlen2) * normal; + mpq3 proj_evec = evec - (math::dot(evec, normal) / nlen2) * normal; /* The projection calculations along the abscissa and ordinate should * be scaled by 1/abscissa and 1/ordinate respectively, * but we can skip: it won't affect which `evec` has the maximum slope. */ - mpq_class evec_a = mpq3::dot(proj_evec, abscissa); - mpq_class evec_o = mpq3::dot(proj_evec, ordinate); + mpq_class evec_a = math::dot(proj_evec, abscissa); + mpq_class evec_o = math::dot(proj_evec, ordinate); if (dbg_level > 0) { std::cout << "e = " << e << "\n"; std::cout << "v_other = " << v_other << "\n"; @@ -1791,8 +1790,8 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, ap = p; ap -= a; - mpq_class d1 = mpq3::dot_with_buffer(ab, ap, m); - mpq_class d2 = mpq3::dot_with_buffer(ac, ap, m); + mpq_class d1 = math::dot_with_buffer(ab, ap, m); + mpq_class d2 = math::dot_with_buffer(ac, ap, m); if (d1 <= 0 && d2 <= 0) { /* Barycentric coordinates (1,0,0). */ *r_edge = -1; @@ -1800,13 +1799,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = a\n"; } - return mpq3::distance_squared_with_buffer(p, a, m); + return math::distance_squared_with_buffer(p, a, m); } /* Check if p in vertex region outside b. */ bp = p; bp -= b; - mpq_class d3 = mpq3::dot_with_buffer(ab, bp, m); - mpq_class d4 = mpq3::dot_with_buffer(ac, bp, m); + mpq_class d3 = math::dot_with_buffer(ab, bp, m); + mpq_class d4 = math::dot_with_buffer(ac, bp, m); if (d3 >= 0 && d4 <= d3) { /* Barycentric coordinates (0,1,0). */ *r_edge = -1; @@ -1814,7 +1813,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = b\n"; } - return mpq3::distance_squared_with_buffer(p, b, m); + return math::distance_squared_with_buffer(p, b, m); } /* Check if p in region of ab. */ mpq_class vc = d1 * d4 - d3 * d2; @@ -1829,13 +1828,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ab at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* Check if p in vertex region outside c. */ cp = p; cp -= c; - mpq_class d5 = mpq3::dot_with_buffer(ab, cp, m); - mpq_class d6 = mpq3::dot_with_buffer(ac, cp, m); + mpq_class d5 = math::dot_with_buffer(ab, cp, m); + mpq_class d6 = math::dot_with_buffer(ac, cp, m); if (d6 >= 0 && d5 <= d6) { /* Barycentric coordinates (0,0,1). */ *r_edge = -1; @@ -1843,7 +1842,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = c\n"; } - return mpq3::distance_squared_with_buffer(p, c, m); + return math::distance_squared_with_buffer(p, c, m); } /* Check if p in edge region of ac. */ mpq_class vb = d5 * d2 - d1 * d6; @@ -1858,7 +1857,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ac at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* Check if p in edge region of bc. */ mpq_class va = d3 * d6 - d5 * d4; @@ -1874,7 +1873,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on bc at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } /* p inside face region. Compute barycentric coordinates (u,v,w). */ mpq_class denom = 1 / (va + vb + vc); @@ -1890,7 +1889,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = inside at " << r << "\n"; } - return mpq3::distance_squared_with_buffer(p, r, m); + return math::distance_squared_with_buffer(p, r, m); } static float closest_on_tri_to_point_float_dist_squared(const float3 &p, @@ -2610,7 +2609,7 @@ static void test_tri_inside_shapes(const IMesh &tm, double3 test_point = calc_point_inside_tri_db(tri_test); /* Offset the test point a tiny bit in the tri_test normal direction. */ tri_test.populate_plane(false); - double3 norm = tri_test.plane->norm.normalized(); + double3 norm = math::normalize(tri_test.plane->norm); const double offset_amount = 1e-5; double3 offset_test_point = test_point + offset_amount * norm; if (dbg_level > 0) { @@ -3002,7 +3001,7 @@ static void init_face_merge_state(FaceMergeState *fms, std::cout << "process tri = " << &tri << "\n"; } BLI_assert(tri.plane_populated()); - if (double3::dot(norm, tri.plane->norm) <= 0.0) { + if (math::dot(norm, tri.plane->norm) <= 0.0) { if (dbg_level > 0) { std::cout << "triangle has wrong orientation, skipping\n"; } @@ -3027,7 +3026,7 @@ static void init_face_merge_state(FaceMergeState *fms, } if (me_index == -1) { double3 vec = new_me.v2->co - new_me.v1->co; - new_me.len_squared = vec.length_squared(); + new_me.len_squared = math::length_squared(vec); new_me.orig = tri.edge_orig[i]; new_me.is_intersect = tri.is_intersect[i]; new_me.dissolvable = (new_me.orig == NO_INDEX && !new_me.is_intersect); @@ -3267,7 +3266,7 @@ static Vector merge_tris_for_face(Vector tris, bool done = false; double3 first_tri_normal = tm.face(tris[0])->plane->norm; double3 second_tri_normal = tm.face(tris[1])->plane->norm; - if (tris.size() == 2 && double3::dot(first_tri_normal, second_tri_normal) > 0.0) { + if (tris.size() == 2 && math::dot(first_tri_normal, second_tri_normal) > 0.0) { /* Is this a case where quad with one diagonal remained unchanged? * Worth special handling because this case will be very common. */ Face &tri1 = *tm.face(tris[0]); @@ -3332,7 +3331,7 @@ static bool approx_in_line(const double3 &a, const double3 &b, const double3 &c) { double3 vec1 = b - a; double3 vec2 = c - b; - double cos_ang = double3::dot(vec1.normalized(), vec2.normalized()); + double cos_ang = math::dot(math::normalize(vec1), math::normalize(vec2)); return fabs(cos_ang - 1.0) < 1e-4; } diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc index 1f150137ba3..982759ffcff 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -30,15 +30,13 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" -# include "BLI_double3.hh" -# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" # include "BLI_math_boolean.hh" # include "BLI_math_mpq.hh" -# include "BLI_mpq2.hh" -# include "BLI_mpq3.hh" +# include "BLI_math_vec_mpq_types.hh" +# include "BLI_math_vec_types.hh" # include "BLI_polyfill_2d.h" # include "BLI_set.hh" # include "BLI_span.hh" @@ -198,14 +196,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co_exact; } - normal_exact = mpq3::cross_poly(co); + normal_exact = math::cross_poly(co.as_span()); } else { mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact; mpq3 tr12 = vert[1]->co_exact - vert[2]->co_exact; - normal_exact = mpq3::cross(tr02, tr12); + normal_exact = math::cross(tr02, tr12); } - mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact); + mpq_class d_exact = -math::dot(normal_exact, vert[0]->co_exact); plane = new Plane(normal_exact, d_exact); } else { @@ -215,14 +213,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co; } - normal = double3::cross_poly(co); + normal = math::cross_poly(co.as_span()); } else { double3 tr02 = vert[0]->co - vert[2]->co; double3 tr12 = vert[1]->co - vert[2]->co; - normal = double3::cross_high_precision(tr02, tr12); + normal = math::cross(tr02, tr12); } - double d = -double3::dot(normal, vert[0]->co); + double d = -math::dot(normal, vert[0]->co); plane = new Plane(normal, d); } } @@ -1098,15 +1096,15 @@ static mpq2 project_3d_to_2d(const mpq3 &p3d, int proj_axis) */ static double supremum_dot_cross(const double3 &a, const double3 &b) { - double3 abs_a = double3::abs(a); - double3 abs_b = double3::abs(b); + double3 abs_a = math::abs(a); + double3 abs_b = math::abs(b); double3 c; /* This is dot(cross(a, b), cross(a,b)) but using absolute values for a and b * and always using + when operation is + or -. */ c[0] = abs_a[1] * abs_b[2] + abs_a[2] * abs_b[1]; c[1] = abs_a[2] * abs_b[0] + abs_a[0] * abs_b[2]; c[2] = abs_a[0] * abs_b[1] + abs_a[1] * abs_b[0]; - return double3::dot(c, c); + return math::dot(c, c); } /* The index of dot when inputs are plane_coords with index 1 is much higher. @@ -1143,11 +1141,11 @@ static int filter_plane_side(const double3 &p, const double3 &abs_plane_p, const double3 &abs_plane_no) { - double d = double3::dot(p - plane_p, plane_no); + double d = math::dot(p - plane_p, plane_no); if (d == 0.0) { return 0; } - double supremum = double3::dot(abs_p + abs_plane_p, abs_plane_no); + double supremum = math::dot(abs_p + abs_plane_p, abs_plane_no); double err_bound = supremum * index_plane_side * DBL_EPSILON; if (fabs(d) > err_bound) { return d > 0 ? 1 : -1; @@ -1178,9 +1176,9 @@ static inline mpq3 tti_interp( ab -= b; ac = a; ac -= c; - mpq_class den = mpq3::dot_with_buffer(ab, n, dotbuf); + mpq_class den = math::dot_with_buffer(ab, n, dotbuf); BLI_assert(den != 0); - mpq_class alpha = mpq3::dot_with_buffer(ac, n, dotbuf) / den; + mpq_class alpha = math::dot_with_buffer(ac, n, dotbuf) / den; return a - alpha * ab; } @@ -1209,7 +1207,7 @@ static inline int tti_above(const mpq3 &a, n.y = ba.z * ca.x - ba.x * ca.z; n.z = ba.x * ca.y - ba.y * ca.x; - return sgn(mpq3::dot_with_buffer(ad, n, dotbuf)); + return sgn(math::dot_with_buffer(ad, n, dotbuf)); } /** @@ -1428,11 +1426,11 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) const double3 &d_r2 = vr2->co; const double3 &d_n2 = tri2.plane->norm; - const double3 &abs_d_p1 = double3::abs(d_p1); - const double3 &abs_d_q1 = double3::abs(d_q1); - const double3 &abs_d_r1 = double3::abs(d_r1); - const double3 &abs_d_r2 = double3::abs(d_r2); - const double3 &abs_d_n2 = double3::abs(d_n2); + const double3 &abs_d_p1 = math::abs(d_p1); + const double3 &abs_d_q1 = math::abs(d_q1); + const double3 &abs_d_r1 = math::abs(d_r1); + const double3 &abs_d_r2 = math::abs(d_r2); + const double3 &abs_d_n2 = math::abs(d_n2); int sp1 = filter_plane_side(d_p1, d_r2, d_n2, abs_d_p1, abs_d_r2, abs_d_n2); int sq1 = filter_plane_side(d_q1, d_r2, d_n2, abs_d_q1, abs_d_r2, abs_d_n2); @@ -1448,9 +1446,9 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) } const double3 &d_n1 = tri1.plane->norm; - const double3 &abs_d_p2 = double3::abs(d_p2); - const double3 &abs_d_q2 = double3::abs(d_q2); - const double3 &abs_d_n1 = double3::abs(d_n1); + const double3 &abs_d_p2 = math::abs(d_p2); + const double3 &abs_d_q2 = math::abs(d_q2); + const double3 &abs_d_n1 = math::abs(d_n1); int sp2 = filter_plane_side(d_p2, d_r1, d_n1, abs_d_p2, abs_d_r1, abs_d_n1); int sq2 = filter_plane_side(d_q2, d_r1, d_n1, abs_d_q2, abs_d_r1, abs_d_n1); @@ -1477,17 +1475,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp1 == 0) { buf[0] = p1; buf[0] -= r2; - sp1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sp1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (sq1 == 0) { buf[0] = q1; buf[0] -= r2; - sq1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sq1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (sr1 == 0) { buf[0] = r1; buf[0] -= r2; - sr1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); + sr1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); } if (dbg_level > 1) { @@ -1509,17 +1507,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) if (sp2 == 0) { buf[0] = p2; buf[0] -= r1; - sp2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sp2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (sq2 == 0) { buf[0] = q2; buf[0] -= r1; - sq2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sq2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (sr2 == 0) { buf[0] = r2; buf[0] -= r1; - sr2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); + sr2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); } if (dbg_level > 1) { @@ -1721,7 +1719,7 @@ static CDT_data prepare_cdt_input(const IMesh &tm, int t, const Vectorplane_populated()); ans.t_plane = tm.face(t)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); prepare_need_tri(ans, tm, t); for (const ITT_value &itt : itts) { switch (itt.kind) { @@ -1757,7 +1755,7 @@ static CDT_data prepare_cdt_input_for_cluster(const IMesh &tm, BLI_assert(tm.face(t0)->plane_populated()); ans.t_plane = tm.face(t0)->plane; BLI_assert(ans.t_plane->exact_populated()); - ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact); for (const int t : cl) { prepare_need_tri(ans, tm, t); } @@ -2004,9 +2002,9 @@ static bool is_quad_flip_first_third(const double3 &v1, const double3 &normal) { double3 dir_v3v1 = v3 - v1; - double3 tangent = double3::cross_high_precision(dir_v3v1, normal); - double dot = double3::dot(v1, tangent); - return (double3::dot(v4, tangent) >= dot) || (double3::dot(v2, tangent) <= dot); + double3 tangent = math::cross(dir_v3v1, normal); + double dot = math::dot(v1, tangent); + return (math::dot(v4, tangent) >= dot) || (math::dot(v2, tangent) <= dot); } /** @@ -2124,7 +2122,7 @@ static Array exact_triangulate_poly(Face *f, IMeshArena *arena) f->populate_plane(false); } const double3 &poly_normal = f->plane->norm; - int axis = double3::dominant_axis(poly_normal); + int axis = math::dominant_axis(poly_normal); /* If project down y axis as opposed to x or z, the orientation * of the polygon will be reversed. * Yet another reversal happens if the poly normal in the dominant @@ -2203,15 +2201,15 @@ static bool face_is_degenerate(const Face *f) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double3 dab = double3::cross_high_precision(da, db); - double dab_length_squared = dab.length_squared(); + double3 dab = math::cross(da, db); + double dab_length_squared = math::length_squared(dab); double err_bound = supremum_dot_cross(dab, dab) * index_dot_cross * DBL_EPSILON; if (dab_length_squared > err_bound) { return false; } mpq3 a = v2->co_exact - v0->co_exact; mpq3 b = v2->co_exact - v1->co_exact; - mpq3 ab = mpq3::cross(a, b); + mpq3 ab = math::cross(a, b); if (ab.x == 0 && ab.y == 0 && ab.z == 0) { return true; } @@ -2231,8 +2229,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double da_length_squared = da.length_squared(); - double db_length_squared = db.length_squared(); + double da_length_squared = math::length_squared(da); + double db_length_squared = math::length_squared(db); if (da_length_squared == 0.0 || db_length_squared == 0.0) { return true; } @@ -2240,8 +2238,8 @@ static bool any_degenerate_tris_fast(const Array triangulation) * The triangle is almost degenerate if sin t is almost 0. * sin^2 t = |da x db|^2 / (|da|^2 |db|^2) */ - double3 dab = double3::cross_high_precision(da, db); - double dab_length_squared = dab.length_squared(); + double3 dab = math::cross(da, db); + double dab_length_squared = math::length_squared(dab); double sin_squared_t = dab_length_squared / (da_length_squared * db_length_squared); if (sin_squared_t < 1e-8) { return true; diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc index a6ad18801fd..3460c1284fc 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -50,9 +50,7 @@ #include #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_math_base_safe.h" #include "BLI_noise.hh" #include "BLI_utildefines.h" @@ -1469,7 +1467,7 @@ void voronoi_smooth_f1(const float w, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_w != nullptr) { smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor; @@ -1592,7 +1590,7 @@ static float voronoi_distance(const float2 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float2::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1615,7 +1613,7 @@ void voronoi_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1654,7 +1652,7 @@ void voronoi_smooth_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1676,11 +1674,10 @@ void voronoi_smooth_f1(const float2 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float2::interpolate(smoothPosition, pointPosition, h) - - correctionFactor; + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } } @@ -1704,7 +1701,7 @@ void voronoi_f2(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1748,7 +1745,7 @@ void voronoi_f2(const float2 coord, void voronoi_distance_to_edge(const float2 coord, const float randomness, float *r_distance) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float2 vectorToClosest = float2(0.0f, 0.0f); @@ -1777,7 +1774,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float const float2 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v2v2(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v2v2((vectorToClosest + vectorToPoint) / 2.0f, - perpendicularToEdge.normalized()); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -1787,7 +1784,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *r_radius) { - const float2 cellPosition = float2::floor(coord); + const float2 cellPosition = math::floor(coord); const float2 localPosition = coord - cellPosition; float2 closestPoint = float2(0.0f, 0.0f); @@ -1798,7 +1795,7 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j); const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float2::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -1817,14 +1814,14 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float * const float2 cellOffset = float2(i, j) + closestPointOffset; const float2 pointPosition = cellOffset + hash_float_to_float2(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float2::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; } } } - *r_radius = float2::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 3D Voronoi **** */ @@ -1836,7 +1833,7 @@ static float voronoi_distance(const float3 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float3::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1860,7 +1857,7 @@ void voronoi_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1902,7 +1899,7 @@ void voronoi_smooth_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1925,10 +1922,10 @@ void voronoi_smooth_f1(const float3 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float3::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -1954,7 +1951,7 @@ void voronoi_f2(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2000,7 +1997,7 @@ void voronoi_f2(const float3 coord, void voronoi_distance_to_edge(const float3 coord, const float randomness, float *r_distance) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float3 vectorToClosest = float3(0.0f, 0.0f, 0.0f); @@ -2032,7 +2029,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float const float3 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v3v3(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v3v3((vectorToClosest + vectorToPoint) / 2.0f, - perpendicularToEdge.normalized()); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2043,7 +2040,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *r_radius) { - const float3 cellPosition = float3::floor(coord); + const float3 cellPosition = math::floor(coord); const float3 localPosition = coord - cellPosition; float3 closestPoint = float3(0.0f, 0.0f, 0.0f); @@ -2055,7 +2052,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k); const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float3::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2076,7 +2073,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * const float3 cellOffset = float3(i, j, k) + closestPointOffset; const float3 pointPosition = cellOffset + hash_float_to_float3(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float3::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2084,7 +2081,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * } } } - *r_radius = float3::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 4D Voronoi **** */ @@ -2096,7 +2093,7 @@ static float voronoi_distance(const float4 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return float4::distance(a, b); + return math::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z) + fabsf(a.w - b.w); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -2121,7 +2118,7 @@ void voronoi_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -2166,7 +2163,7 @@ void voronoi_smooth_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -2191,10 +2188,10 @@ void voronoi_smooth_f1(const float4 coord, correctionFactor /= 1.0f + 3.0f * smoothness; if (r_color != nullptr) { const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset); - smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = float4::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -2221,7 +2218,7 @@ void voronoi_f2(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2270,7 +2267,7 @@ void voronoi_f2(const float4 coord, void voronoi_distance_to_edge(const float4 coord, const float randomness, float *r_distance) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float4 vectorToClosest = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2307,7 +2304,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float const float4 perpendicularToEdge = vectorToPoint - vectorToClosest; if (dot_v4v4(perpendicularToEdge, perpendicularToEdge) > 0.0001f) { const float distanceToEdge = dot_v4v4((vectorToClosest + vectorToPoint) / 2.0f, - float4::normalize(perpendicularToEdge)); + math::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2319,7 +2316,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *r_radius) { - const float4 cellPosition = float4::floor(coord); + const float4 cellPosition = math::floor(coord); const float4 localPosition = coord - cellPosition; float4 closestPoint = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2333,7 +2330,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float4::distance(pointPosition, localPosition); + const float distanceToPoint = math::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2357,7 +2354,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * const float4 pointPosition = cellOffset + hash_float_to_float4(cellPosition + cellOffset) * randomness; - const float distanceToPoint = float4::distance(closestPoint, pointPosition); + const float distanceToPoint = math::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2366,7 +2363,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * } } } - *r_radius = float4::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /** \} */ diff --git a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc index 70e3a99e57a..eac3faa6d15 100644 --- a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc +++ b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc @@ -21,10 +21,9 @@ extern "C" { #define DO_RANDOM_TESTS 0 #include "BLI_array.hh" -#include "BLI_double2.hh" #include "BLI_math_boolean.hh" #include "BLI_math_mpq.hh" -#include "BLI_mpq2.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_vector.hh" #include "BLI_delaunay_2d.h" diff --git a/source/blender/blenlib/tests/BLI_math_vec_types_test.cc b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc new file mode 100644 index 00000000000..8aa1f90fde2 --- /dev/null +++ b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc @@ -0,0 +1,149 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +#include "BLI_math_vec_types.hh" + +namespace blender::tests { + +using namespace blender::math; + +TEST(math_vec_types, ScalarConstructorUnsigned) +{ + float2 u(5u); + EXPECT_EQ(u[0], 5.0f); + EXPECT_EQ(u[1], 5.0f); +} + +TEST(math_vec_types, ScalarConstructorInt) +{ + float2 i(-5); + EXPECT_EQ(i[0], -5.0f); + EXPECT_EQ(i[1], -5.0f); +} + +TEST(math_vec_types, ScalarConstructorFloat) +{ + float2 f(5.2f); + EXPECT_FLOAT_EQ(f[0], 5.2f); + EXPECT_FLOAT_EQ(f[1], 5.2f); +} + +TEST(math_vec_types, ScalarConstructorDouble) +{ + float2 d(5.2); + EXPECT_FLOAT_EQ(d[0], 5.2f); + EXPECT_FLOAT_EQ(d[1], 5.2f); +} + +TEST(math_vec_types, MultiScalarConstructorVec2) +{ + int2 i(5.5f, -1.8); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); +} + +TEST(math_vec_types, MultiScalarConstructorVec3) +{ + int3 i(5.5f, -1.8, 6u); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); + EXPECT_EQ(i[2], 6); +} + +TEST(math_vec_types, MultiScalarConstructorVec4) +{ + int4 i(5.5f, -1.8, 6u, 0.888f); + EXPECT_EQ(i[0], 5); + EXPECT_EQ(i[1], -1); + EXPECT_EQ(i[2], 6); + EXPECT_EQ(i[3], 0); +} + +TEST(math_vec_types, MixedScalarVectorConstructorVec3) +{ + float3 fl_v2(float2(5.5f), 1.8f); + EXPECT_FLOAT_EQ(fl_v2[0], 5.5f); + EXPECT_FLOAT_EQ(fl_v2[1], 5.5f); + EXPECT_FLOAT_EQ(fl_v2[2], 1.8f); + + float3 v2_fl(1.8f, float2(5.5f)); + EXPECT_FLOAT_EQ(v2_fl[0], 1.8f); + EXPECT_FLOAT_EQ(v2_fl[1], 5.5f); + EXPECT_FLOAT_EQ(v2_fl[2], 5.5f); +} + +TEST(math_vec_types, MixedScalarVectorConstructorVec4) +{ + int4 v2_fl_fl(float2(1), 2, 3); + EXPECT_EQ(v2_fl_fl[0], 1); + EXPECT_EQ(v2_fl_fl[1], 1); + EXPECT_EQ(v2_fl_fl[2], 2); + EXPECT_EQ(v2_fl_fl[3], 3); + + float4 fl_v2_fl(1, int2(2), 3); + EXPECT_EQ(fl_v2_fl[0], 1); + EXPECT_EQ(fl_v2_fl[1], 2); + EXPECT_EQ(fl_v2_fl[2], 2); + EXPECT_EQ(fl_v2_fl[3], 3); + + double4 fl_fl_v2(1, 2, double2(3)); + EXPECT_EQ(fl_fl_v2[0], 1); + EXPECT_EQ(fl_fl_v2[1], 2); + EXPECT_EQ(fl_fl_v2[2], 3); + EXPECT_EQ(fl_fl_v2[3], 3); + + int4 v2_v2(float2(1), uint2(2)); + EXPECT_EQ(v2_v2[0], 1); + EXPECT_EQ(v2_v2[1], 1); + EXPECT_EQ(v2_v2[2], 2); + EXPECT_EQ(v2_v2[3], 2); + + float4 v3_fl(uint3(1), 2); + EXPECT_EQ(v3_fl[0], 1); + EXPECT_EQ(v3_fl[1], 1); + EXPECT_EQ(v3_fl[2], 1); + EXPECT_EQ(v3_fl[3], 2); + + uint4 fl_v3(1, float3(2)); + EXPECT_EQ(fl_v3[0], 1); + EXPECT_EQ(fl_v3[1], 2); + EXPECT_EQ(fl_v3[2], 2); + EXPECT_EQ(fl_v3[3], 2); +} + +TEST(math_vec_types, ComponentMasking) +{ + int4 i(0, 1, 2, 3); + float2 f2 = float2(i); + EXPECT_EQ(f2[0], 0.0f); + EXPECT_EQ(f2[1], 1.0f); +} + +TEST(math_vec_types, PointerConversion) +{ + float array[3] = {1.0f, 2.0f, 3.0f}; + float3 farray(array); + EXPECT_EQ(farray[0], 1.0f); + EXPECT_EQ(farray[1], 2.0f); + EXPECT_EQ(farray[2], 3.0f); +} + +TEST(math_vec_types, PointerArrayConversion) +{ + float array[1][3] = {{1.0f, 2.0f, 3.0f}}; + float(*ptr)[3] = array; + float3 fptr(ptr); + EXPECT_EQ(fptr[0], 1.0f); + EXPECT_EQ(fptr[1], 2.0f); + EXPECT_EQ(fptr[2], 3.0f); +} + +TEST(math_vec_types, VectorTypeConversion) +{ + double2 d(int2(float2(5.75f, -1.57f))); + EXPECT_EQ(d[0], 5.0); + EXPECT_EQ(d[1], -1.0); +} + +} // namespace blender::tests diff --git a/source/blender/blenlib/tests/BLI_memory_utils_test.cc b/source/blender/blenlib/tests/BLI_memory_utils_test.cc index 207f310d902..74e54151a06 100644 --- a/source/blender/blenlib/tests/BLI_memory_utils_test.cc +++ b/source/blender/blenlib/tests/BLI_memory_utils_test.cc @@ -1,6 +1,6 @@ /* Apache License, Version 2.0 */ -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_memory_utils.hh" #include "BLI_strict_flags.h" #include "testing/testing.h" diff --git a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc index d759f0c3be4..2b8fb3dbea4 100644 --- a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc @@ -11,8 +11,8 @@ #include "BLI_array.hh" #include "BLI_map.hh" #include "BLI_math_mpq.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_boolean.hh" -#include "BLI_mpq3.hh" #include "BLI_vector.hh" #ifdef WITH_GMP diff --git a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc index 68111fb8eb1..d2d76593129 100644 --- a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc @@ -10,8 +10,8 @@ #include "BLI_array.hh" #include "BLI_math_mpq.hh" +#include "BLI_math_vec_mpq_types.hh" #include "BLI_mesh_intersect.hh" -#include "BLI_mpq3.hh" #include "BLI_task.h" #include "BLI_vector.hh" diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index 1c3a28670df..794bf1b23bc 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -18,7 +18,7 @@ #pragma once -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "DNA_vec_types.h" diff --git a/source/blender/draw/intern/draw_cache_impl_curve.cc b/source/blender/draw/intern/draw_cache_impl_curve.cc index 1108d40125b..33cf0e9a3cd 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.cc +++ b/source/blender/draw/intern/draw_cache_impl_curve.cc @@ -26,8 +26,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BLI_span.hh" #include "BLI_utildefines.h" diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc index ea702e5efdd..b846da3f016 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc @@ -25,9 +25,7 @@ #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BKE_attribute.h" diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 4834ca3174a..02d68189997 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -28,9 +28,9 @@ #include "DNA_anim_types.h" #include "DNA_node_types.h" -#include "BLI_float2.hh" #include "BLI_linklist.h" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_vector.hh" diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index 0f542734f66..740d1fbb6f9 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -23,7 +23,7 @@ #pragma once -#include "BLI_float2.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "BKE_node.h" @@ -43,9 +43,6 @@ struct bNodeLink; struct bNodeSocket; struct wmGizmoGroupType; struct wmKeyConfig; -namespace blender { -struct float2; -} struct wmWindow; /** Temporary data used in node link drag modal operator. */ diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index 334ca1f76ee..803cf38c53a 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -111,11 +111,13 @@ static bNode *node_under_mouse_select(bNodeTree &ntree, int mx, int my) static bNode *node_under_mouse_tweak(bNodeTree &ntree, const float2 &mouse) { + using namespace blender::math; + LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) { if (node->type == NODE_REROUTE) { bNodeSocket *socket = (bNodeSocket *)node->inputs.first; const float2 location{socket->locx, socket->locy}; - if (float2::distance(mouse, location) < 24.0f) { + if (distance(mouse, location) < 24.0f) { return node; } } diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc index ee623083db7..ede8756a9da 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc @@ -19,9 +19,8 @@ #include "MEM_guardedalloc.h" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_hash.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_string_ref.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index 7cc2d8d0b48..f4b5ff819ed 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -17,8 +17,7 @@ #include #include -#include "BLI_float2.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BKE_geometry_set.hh" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc index 36c7f1057df..556c0b0d5ca 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc @@ -123,9 +123,7 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float2 cell) { - return float2::distance_squared(cell, value) > threshold_sq; - }, + [&](const float2 cell) { return math::distance_squared(cell, value) > threshold_sq; }, prev_mask, new_indices); break; @@ -155,9 +153,7 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float threshold_sq = row_filter.threshold; apply_filter_operation( column_data.typed(), - [&](const float3 cell) { - return float3::distance_squared(cell, value) > threshold_sq; - }, + [&](const float3 cell) { return math::distance_squared(cell, value) > threshold_sq; }, prev_mask, new_indices); break; diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc index 058fb76af2b..0bbfbc8cb10 100644 --- a/source/blender/functions/intern/cpp_types.cc +++ b/source/blender/functions/intern/cpp_types.cc @@ -18,9 +18,8 @@ #include "FN_field_cpp_type.hh" #include "BLI_color.hh" -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" namespace blender::fn { diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc index f031648d2ed..7868bade8c1 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc @@ -23,9 +23,8 @@ * \ingroup bgpencil */ -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "BLI_span.hh" @@ -283,7 +282,7 @@ float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, bGPDstroke *gps) const float2 screen_ex = gpencil_3D_point_to_2D(&pt->x); const float2 v1 = screen_co - screen_ex; - float radius = v1.length(); + float radius = math::length(v1); BKE_gpencil_free_stroke(gps_perimeter); return MAX2(radius, 1.0f); diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.hh b/source/blender/io/gpencil/intern/gpencil_io_base.hh index 09557cd7a4d..ae54d5056dc 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_base.hh +++ b/source/blender/io/gpencil/intern/gpencil_io_base.hh @@ -22,9 +22,8 @@ * \ingroup bgpencil */ -#include "BLI_float2.hh" -#include "BLI_float3.hh" #include "BLI_float4x4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_vector.hh" #include "DNA_space_types.h" /* for FILE_MAX */ diff --git a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc index 941d1137f4d..455ebb7c3cb 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc @@ -21,8 +21,8 @@ * \ingroup bgpencil */ -#include "BLI_float3.hh" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "BLI_span.hh" #include "DNA_gpencil_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh index 9a4dfe3efe3..e6d2853d040 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh @@ -22,7 +22,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utility_mixins.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index b99d41e0c72..5b710939e00 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -21,8 +21,8 @@ #include "BKE_image.h" #include "BKE_node.h" -#include "BLI_float3.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_path_util.h" #include "DNA_material_types.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh index 2f62d189bd1..a84dcb80a48 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh @@ -20,8 +20,8 @@ #pragma once -#include "BLI_float3.hh" #include "BLI_map.hh" +#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" #include "BLI_vector.hh" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc index 91aabd8fa76..ec690115115 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc @@ -18,9 +18,9 @@ * \ingroup obj */ -#include "BLI_float3.hh" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_math_vec_types.hh" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc index 778b5746471..910b52dea67 100644 --- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc +++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc @@ -197,8 +197,8 @@ static float compute_voxel_size(const ModifierEvalContext *ctx, /* Compute the voxel size based on the desired number of voxels and the approximated bounding box * of the volume. */ const BoundBox *bb = BKE_object_boundbox_get(mvmd->object); - const float diagonal = float3::distance(transform * float3(bb->vec[6]), - transform * float3(bb->vec[0])); + const float diagonal = math::distance(transform * float3(bb->vec[6]), + transform * float3(bb->vec[0])); const float approximate_volume_side_length = diagonal + mvmd->exterior_band_width * 2.0f; const float voxel_size = approximate_volume_side_length / mvmd->voxel_amount / volume_simplify; return voxel_size; diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index cee5d0be65d..49528845197 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -28,8 +28,8 @@ #include "MEM_guardedalloc.h" #include "BLI_array.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_multi_value_map.hh" #include "BLI_set.hh" #include "BLI_string.h" diff --git a/source/blender/nodes/NOD_math_functions.hh b/source/blender/nodes/NOD_math_functions.hh index a0a2e6f81f8..6ea89beee2e 100644 --- a/source/blender/nodes/NOD_math_functions.hh +++ b/source/blender/nodes/NOD_math_functions.hh @@ -18,9 +18,9 @@ #include "DNA_node_types.h" -#include "BLI_float3.hh" #include "BLI_math_base_safe.h" #include "BLI_math_rotation.h" +#include "BLI_math_vec_types.hh" #include "BLI_string_ref.hh" namespace blender::nodes { @@ -240,6 +240,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -259,40 +261,21 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation case NODE_VECTOR_MATH_MULTIPLY: return dispatch([](float3 a, float3 b) { return a * b; }); case NODE_VECTOR_MATH_DIVIDE: - return dispatch([](float3 a, float3 b) { - return float3(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return safe_divide(a, b); }); case NODE_VECTOR_MATH_CROSS_PRODUCT: - return dispatch([](float3 a, float3 b) { return float3::cross_high_precision(a, b); }); + return dispatch([](float3 a, float3 b) { return cross_high_precision(a, b); }); case NODE_VECTOR_MATH_PROJECT: - return dispatch([](float3 a, float3 b) { - float length_squared = b.length_squared(); - return (length_squared != 0.0) ? (float3::dot(a, b) / length_squared) * b : float3(0.0f); - }); + return dispatch([](float3 a, float3 b) { return project(a, b); }); case NODE_VECTOR_MATH_REFLECT: - return dispatch([](float3 a, float3 b) { - b.normalize(); - return a.reflected(b); - }); + return dispatch([](float3 a, float3 b) { return reflect(a, normalize(b)); }); case NODE_VECTOR_MATH_SNAP: - return dispatch([](float3 a, float3 b) { - return float3(floor(safe_divide(a.x, b.x)), - floor(safe_divide(a.y, b.y)), - floor(safe_divide(a.z, b.z))) * - b; - }); + return dispatch([](float3 a, float3 b) { return floor(safe_divide(a, b)) * b; }); case NODE_VECTOR_MATH_MODULO: - return dispatch([](float3 a, float3 b) { - return float3(safe_modf(a.x, b.x), safe_modf(a.y, b.y), safe_modf(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return mod(a, b); }); case NODE_VECTOR_MATH_MINIMUM: - return dispatch([](float3 a, float3 b) { - return float3(min_ff(a.x, b.x), min_ff(a.y, b.y), min_ff(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return min(a, b); }); case NODE_VECTOR_MATH_MAXIMUM: - return dispatch([](float3 a, float3 b) { - return float3(max_ff(a.x, b.x), max_ff(a.y, b.y), max_ff(a.z, b.z)); - }); + return dispatch([](float3 a, float3 b) { return max(a, b); }); default: return false; } @@ -306,6 +289,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -319,9 +304,9 @@ inline bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation switch (operation) { case NODE_VECTOR_MATH_DOT_PRODUCT: - return dispatch([](float3 a, float3 b) { return float3::dot(a, b); }); + return dispatch([](float3 a, float3 b) { return dot(a, b); }); case NODE_VECTOR_MATH_DISTANCE: - return dispatch([](float3 a, float3 b) { return float3::distance(a, b); }); + return dispatch([](float3 a, float3 b) { return distance(a, b); }); default: return false; } @@ -335,6 +320,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -354,7 +341,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOpera return float3(wrapf(a.x, b.x, c.x), wrapf(a.y, b.y, c.y), wrapf(a.z, b.z, c.z)); }); case NODE_VECTOR_MATH_FACEFORWARD: - return dispatch([](float3 a, float3 b, float3 c) { return float3::faceforward(a, b, c); }); + return dispatch([](float3 a, float3 b, float3 c) { return faceforward(a, b, c); }); default: return false; } @@ -368,6 +355,8 @@ template inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -381,8 +370,7 @@ inline bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperat switch (operation) { case NODE_VECTOR_MATH_REFRACT: - return dispatch( - [](float3 a, float3 b, float c) { return float3::refract(a, b.normalized(), c); }); + return dispatch([](float3 a, float3 b, float c) { return refract(a, normalize(b), c); }); default: return false; } @@ -396,6 +384,8 @@ template inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -409,7 +399,7 @@ inline bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation oper switch (operation) { case NODE_VECTOR_MATH_LENGTH: - return dispatch([](float3 in) { return in.length(); }); + return dispatch([](float3 in) { return length(in); }); default: return false; } @@ -450,6 +440,8 @@ template inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback) { + using namespace blender::math; + const FloatMathOperationInfo *info = get_float3_math_operation_info(operation); if (info == nullptr) { return false; @@ -463,20 +455,15 @@ inline bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation ope switch (operation) { case NODE_VECTOR_MATH_NORMALIZE: - return dispatch([](float3 in) { - float3 out = in; - out.normalize(); - return out; - }); /* Should be safe. */ + return dispatch([](float3 in) { return normalize(in); }); /* Should be safe. */ case NODE_VECTOR_MATH_FLOOR: - return dispatch([](float3 in) { return float3(floor(in.x), floor(in.y), floor(in.z)); }); + return dispatch([](float3 in) { return floor(in); }); case NODE_VECTOR_MATH_CEIL: - return dispatch([](float3 in) { return float3(ceil(in.x), ceil(in.y), ceil(in.z)); }); + return dispatch([](float3 in) { return ceil(in); }); case NODE_VECTOR_MATH_FRACTION: - return dispatch( - [](float3 in) { return in - float3(floor(in.x), floor(in.y), floor(in.z)); }); + return dispatch([](float3 in) { return fract(in); }); case NODE_VECTOR_MATH_ABSOLUTE: - return dispatch([](float3 in) { return float3::abs(in); }); + return dispatch([](float3 in) { return abs(in); }); case NODE_VECTOR_MATH_SINE: return dispatch([](float3 in) { return float3(sinf(in.x), sinf(in.y), sinf(in.z)); }); case NODE_VECTOR_MATH_COSINE: diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh index c0580a2c919..a1972c66ca2 100644 --- a/source/blender/nodes/NOD_socket_declarations.hh +++ b/source/blender/nodes/NOD_socket_declarations.hh @@ -21,7 +21,7 @@ #include "RNA_types.h" #include "BLI_color.hh" -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" namespace blender::nodes::decl { diff --git a/source/blender/nodes/function/node_function_util.hh b/source/blender/nodes/function/node_function_util.hh index acde9c4b55b..69c617b4f01 100644 --- a/source/blender/nodes/function/node_function_util.hh +++ b/source/blender/nodes/function/node_function_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc index f4ce8d2f35a..bcc035e6ede 100644 --- a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc +++ b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc @@ -69,14 +69,14 @@ static void align_rotations_auto_pivot(IndexMask mask, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = vector.normalized(); - float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); + const float3 new_axis = math::normalize(vector); + float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc index 3bb46511eeb..7c09bace756 100644 --- a/source/blender/nodes/function/nodes/node_fn_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_compare.cc @@ -265,7 +265,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Than - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) < comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) < comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -283,7 +283,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Than - Length", - [](float3 a, float3 b) { return a.length() < b.length(); }}; + [](float3 a, float3 b) { return math::length(a) < math::length(b); }}; return &fn; } } @@ -299,7 +299,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Less Equal - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) <= comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) <= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -317,7 +317,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Less Equal - Length", - [](float3 a, float3 b) { return a.length() <= b.length(); }}; + [](float3 a, float3 b) { return math::length(a) <= math::length(b); }}; return &fn; } } @@ -333,7 +333,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Than - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) > comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) > comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -351,7 +351,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Than - Length", - [](float3 a, float3 b) { return a.length() > b.length(); }}; + [](float3 a, float3 b) { return math::length(a) > math::length(b); }}; return &fn; } } @@ -367,7 +367,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SO fn{ "Greater Equal - Dot Product", - [](float3 a, float3 b, float comp) { return float3::dot(a, b) >= comp; }}; + [](float3 a, float3 b, float comp) { return math::dot(a, b) >= comp; }}; return &fn; } case NODE_COMPARE_MODE_DIRECTION: { @@ -385,7 +385,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SO fn{ "Greater Equal - Length", - [](float3 a, float3 b) { return a.length() >= b.length(); }}; + [](float3 a, float3 b) { return math::length(a) >= math::length(b); }}; return &fn; } } @@ -402,7 +402,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(float3::dot(a, b) - comp) <= epsilon; + return abs(math::dot(a, b) - comp) <= epsilon; }}; return &fn; } @@ -424,7 +424,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(a.length() - b.length()) <= epsilon; + return abs(math::length(a) - math::length(b)) <= epsilon; }}; return &fn; } @@ -442,7 +442,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_DOT_PRODUCT: { static fn::CustomMF_SI_SI_SI_SI_SO fn{ "Not Equal - Dot Product", [](float3 a, float3 b, float comp, float epsilon) { - return abs(float3::dot(a, b) - comp) >= epsilon; + return abs(math::dot(a, b) - comp) >= epsilon; }}; return &fn; } @@ -464,7 +464,7 @@ static const fn::MultiFunction *get_multi_function(bNode &node) case NODE_COMPARE_MODE_LENGTH: { static fn::CustomMF_SI_SI_SI_SO fn{ "Not Equal - Length", [](float3 a, float3 b, float epsilon) { - return abs(a.length() - b.length()) > epsilon; + return abs(math::length(a) - math::length(b)) > epsilon; }}; return &fn; } diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh index 1c2a8f521c0..dddc3527124 100644 --- a/source/blender/nodes/geometry/node_geometry_util.hh +++ b/source/blender/nodes/geometry/node_geometry_util.hh @@ -18,7 +18,7 @@ #include -#include "BLI_float3.hh" +#include "BLI_math_vec_types.hh" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc index 36ad4605a4b..1d064586238 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_align_rotation_to_vector.cc @@ -90,14 +90,14 @@ static void align_rotations_auto_pivot(const VArray &vectors, float3 old_axis; mul_v3_m3v3(old_axis, old_rotation, local_main_axis); - const float3 new_axis = vector.normalized(); - float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis); + const float3 new_axis = math::normalize(vector); + float3 rotation_axis = math::cross_high_precision(old_axis, new_axis); if (is_zero_v3(rotation_axis)) { /* The vectors are linearly dependent, so we fall back to another axis. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(1, 0, 0)); if (is_zero_v3(rotation_axis)) { /* This is now guaranteed to not be zero. */ - rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0)); + rotation_axis = math::cross_high_precision(old_axis, float3(0, 1, 0)); } } diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc index 74dac73f255..20f500b1bd8 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_proximity.cc @@ -81,7 +81,7 @@ static void calculate_mesh_proximity(const VArray &positions, for (int i : range) { /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = float3::distance_squared(nearest.co, positions[i]); + nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[i]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[i], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc index b0210f2eb94..a85a7c56cb9 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_attribute_transfer.cc @@ -229,7 +229,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = float3::distance_squared(position, mvert.co); + const float distance_sq = math::distance_squared(position, float3(mvert.co)); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc index 8555d7cc8a3..1e6b7f92a77 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_curve_to_points.cc @@ -241,13 +241,13 @@ static void copy_uniform_sample_point_attributes(Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent.normalize(); + tangent = math::normalize(tangent); } spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals.normalize(); + normals = math::normalize(normals); } } }); diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc index 7b1bbed8ae4..f54ffc53a6e 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_points_to_volume.cc @@ -161,7 +161,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = float3::distance(min, max); + const float diagonal = math::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc index dd03092a594..cfae88e0625 100644 --- a/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc +++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_legacy_raycast.cc @@ -107,7 +107,7 @@ static void raycast_to_mesh(const Mesh &mesh, for (const int i : ray_origins.index_range()) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = ray_directions[i].normalized(); + const float3 ray_direction = math::normalize(ray_directions[i]); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc index 7e09721273a..929d9046f98 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc @@ -16,7 +16,7 @@ #include "BLI_array.hh" #include "BLI_delaunay_2d.h" -#include "BLI_double2.hh" +#include "BLI_math_vec_types.hh" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc index 1a44fce86a6..68b609f8045 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc @@ -122,9 +122,9 @@ static Array calculate_directions(const Span positions) Array directions(size); for (const int i : IndexRange(size - 1)) { - directions[i] = (positions[i + 1] - positions[i]).normalized(); + directions[i] = math::normalize(positions[i + 1] - positions[i]); } - directions[size - 1] = (positions[0] - positions[size - 1]).normalized(); + directions[size - 1] = math::normalize(positions[0] - positions[size - 1]); return directions; } @@ -135,9 +135,9 @@ static Array calculate_axes(const Span directions) const int size = directions.size(); Array axes(size); - axes[0] = float3::cross(-directions[size - 1], directions[0]).normalized(); + axes[0] = math::normalize(math::cross(-directions[size - 1], directions[0])); for (const int i : IndexRange(1, size - 1)) { - axes[i] = float3::cross(-directions[i - 1], directions[i]).normalized(); + axes[i] = math::normalize(math::cross(-directions[i - 1], directions[i])); } return axes; @@ -248,8 +248,8 @@ static void limit_radii(FilletData &fd, const bool cyclic) if (cyclic) { /* Calculate lengths between adjacent control points. */ - const float len_prev = float3::distance(positions[0], positions[size - 1]); - const float len_next = float3::distance(positions[0], positions[1]); + const float len_prev = math::distance(positions[0], positions[size - 1]); + const float len_next = math::distance(positions[0], positions[1]); /* Calculate tangent lengths of fillets in control points. */ const float tan_len = radii[0] * tan(angles[0] / 2.0f); @@ -271,16 +271,16 @@ static void limit_radii(FilletData &fd, const bool cyclic) } /* Initialize max_radii to largest possible radii. */ - float prev_dist = float3::distance(positions[1], positions[0]); + float prev_dist = math::distance(positions[1], positions[0]); for (const int i : IndexRange(1, size - 2)) { - const float temp_dist = float3::distance(positions[i], positions[i + 1]); + const float temp_dist = math::distance(positions[i], positions[i + 1]); max_radii[i] = std::min(prev_dist, temp_dist) / tan(angles[i] / 2.0f); prev_dist = temp_dist; } /* Max radii calculations for each index. */ for (const int i : IndexRange(start, fillet_count - 1)) { - const float len_next = float3::distance(positions[i], positions[i + 1]); + const float len_next = math::distance(positions[i], positions[i + 1]); const float tan_len = radii[i] * tan(angles[i] / 2.0f); const float tan_len_next = radii[i + 1] * tan(angles[i + 1] / 2.0f); @@ -415,7 +415,8 @@ static void update_bezier_positions(const FilletData &fd, const float3 center = get_center(dst_spline.positions()[i_dst] - positions[i_src], fd, i_src); /* Calculate the vector of the radius formed by the first vertex. */ float3 radius_vec = dst_spline.positions()[i_dst] - center; - const float radius = radius_vec.normalize_and_get_length(); + float radius; + radius_vec = math::normalize_and_get_length(radius_vec, radius); dst_spline.handle_types_right().slice(1, count - 2).fill(BezierSpline::HandleType::Align); dst_spline.handle_types_left().slice(1, count - 2).fill(BezierSpline::HandleType::Align); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc index a7fb493c7d7..7b5d1a1dc80 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc @@ -101,8 +101,8 @@ static void node_update(bNodeTree *ntree, bNode *node) static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3) { - const float3 a = (p2 - p1).normalized(); - const float3 b = (p3 - p1).normalized(); + const float3 a = math::normalize(p2 - p1); + const float3 b = math::normalize(p3 - p1); return (ELEM(a, b, b * -1.0f)); } @@ -122,18 +122,18 @@ static std::unique_ptr create_point_circle_curve( float3 center; /* Midpoints of `P1->P2` and `P2->P3`. */ - const float3 q1 = float3::interpolate(p1, p2, 0.5f); - const float3 q2 = float3::interpolate(p2, p3, 0.5f); + const float3 q1 = math::interpolate(p1, p2, 0.5f); + const float3 q2 = math::interpolate(p2, p3, 0.5f); /* Normal Vectors of `P1->P2` and `P2->P3` */ - const float3 v1 = (p2 - p1).normalized(); - const float3 v2 = (p3 - p2).normalized(); + const float3 v1 = math::normalize(p2 - p1); + const float3 v2 = math::normalize(p3 - p2); /* Normal of plane of main 2 segments P1->P2 and `P2->P3`. */ - const float3 v3 = float3::cross(v1, v2).normalized(); + const float3 v3 = math::normalize(math::cross(v1, v2)); /* Normal of plane of first perpendicular bisector and `P1->P2`. */ - const float3 v4 = float3::cross(v3, v1).normalized(); + const float3 v4 = math::normalize(math::cross(v3, v1)); /* Determine Center-point from the intersection of 3 planes. */ float plane_1[4], plane_2[4], plane_3[4]; @@ -148,7 +148,7 @@ static std::unique_ptr create_point_circle_curve( } /* Get the radius from the center-point to p1. */ - const float r = float3::distance(p1, center); + const float r = math::distance(p1, center); const float theta_step = ((2 * M_PI) / (float)resolution); for (const int i : IndexRange(resolution)) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc index ff9218b1ac2..d35fa0a2fdc 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc @@ -100,7 +100,7 @@ static std::unique_ptr create_direction_line_curve(const float3 start spline->resize(2); MutableSpan positions = spline->positions(); positions[0] = start; - positions[1] = direction.normalized() * length + start; + positions[1] = math::normalize(direction) * length + start; spline->radii().fill(1.0f); spline->tilts().fill(0.0f); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc index 084d27e9d24..885d92a111b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc @@ -58,9 +58,9 @@ static std::unique_ptr create_quadratic_bezier_curve(const float3 p1, const float step = 1.0f / resolution; for (const int i : IndexRange(resolution + 1)) { const float factor = step * i; - const float3 q1 = float3::interpolate(p1, p2, factor); - const float3 q2 = float3::interpolate(p2, p3, factor); - positions[i] = float3::interpolate(q1, q2, factor); + const float3 q1 = math::interpolate(p1, p2, factor); + const float3 q2 = math::interpolate(p2, p3, factor); + positions[i] = math::interpolate(q1, q2, factor); } curve->add_spline(std::move(spline)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc index 038f7625825..56fbc50f033 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc @@ -185,7 +185,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_tangents = splines[spline_indices[i]]->evaluated_tangents(); - sampled_tangents[i] = sample_with_lookup(lookup, evaluated_tangents).normalized(); + sampled_tangents[i] = math::normalize(sample_with_lookup(lookup, evaluated_tangents)); } } @@ -193,7 +193,7 @@ class SampleCurveFunction : public fn::MultiFunction { for (const int i : mask) { const Spline::LookupResult &lookup = lookups[i]; const Span evaluated_normals = splines[spline_indices[i]]->evaluated_normals(); - sampled_normals[i] = sample_with_lookup(lookup, evaluated_normals).normalized(); + sampled_normals[i] = math::normalize(sample_with_lookup(lookup, evaluated_normals)); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc index 40dde645756..257a5b8df00 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc @@ -96,7 +96,7 @@ static void calculate_nurbs_lengths(const NURBSpline &spline, MutableSpan float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { lengths[i] = length; - length += float3::distance(positions[i], positions[i + 1]); + length += math::distance(positions[i], positions[i + 1]); } lengths.last() = length; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc index a8553b636a4..19efd4b7508 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc @@ -285,7 +285,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { - tangent.normalize(); + tangent = math::normalize(tangent); } } @@ -293,7 +293,7 @@ static void copy_uniform_sample_point_attributes(const Span splines, spline.sample_with_index_factors( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { - normals.normalize(); + normals = math::normalize(normals); } } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc index 28a8fb80294..624a8b6b0f6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc @@ -21,7 +21,7 @@ #include "BKE_image.h" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "BLI_threads.h" #include "BLI_timeit.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc index 5116e78fdda..8a2b054ece0 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc @@ -155,8 +155,8 @@ static void node_geo_exec(GeoNodeExecParams params) if (count_mode == GEO_NODE_MESH_LINE_COUNT_RESOLUTION) { /* Don't allow asymptotic count increase for low resolution values. */ const float resolution = std::max(params.extract_input("Resolution"), 0.0001f); - const int count = total_delta.length() / resolution + 1; - const float3 delta = total_delta.normalized() * resolution; + const int count = math::length(total_delta) / resolution + 1; + const float3 delta = math::normalize(total_delta) * resolution; mesh = create_line_mesh(start, delta, count); } else if (count_mode == GEO_NODE_MESH_LINE_COUNT_TOTAL) { @@ -204,7 +204,7 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count) MutableSpan edges{mesh->medge, mesh->totedge}; short normal[3]; - normal_float_to_short_v3(normal, delta.normalized()); + normal_float_to_short_v3(normal, math::normalize(delta)); for (const int i : verts.index_range()) { copy_v3_v3(verts[i].co, start + delta * i); diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc index dda4543d5e1..c165bcf8e35 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc @@ -166,7 +166,7 @@ static float compute_voxel_size(const GeoNodeExecParams ¶ms, } /* The voxel size adapts to the final size of the volume. */ - const float diagonal = float3::distance(min, max); + const float diagonal = math::distance(min, max); const float extended_diagonal = diagonal + 2.0f * radius; const float voxel_size = extended_diagonal / voxel_amount; return voxel_size; diff --git a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc index e0117c4726d..772638ef240 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc @@ -85,7 +85,7 @@ static bool calculate_mesh_proximity(const VArray &positions, for (int i : range) { const int index = mask[i]; /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest.dist_sq = float3::distance_squared(nearest.co, positions[index]); + nearest.dist_sq = math::distance_squared(float3(nearest.co), positions[index]); BLI_bvhtree_find_nearest( bvh_data.tree, positions[index], &nearest, bvh_data.nearest_callback, &bvh_data); diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc index 2c35ca0afc9..c38503f688c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc @@ -163,7 +163,7 @@ static void raycast_to_mesh(IndexMask mask, for (const int i : mask) { const float ray_length = ray_lengths[i]; const float3 ray_origin = ray_origins[i]; - const float3 ray_direction = ray_directions[i].normalized(); + const float3 ray_direction = math::normalize(ray_directions[i]); BVHTreeRayHit hit; hit.index = -1; diff --git a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc index 331460296a6..6867051ecfe 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc @@ -296,7 +296,7 @@ static void get_closest_mesh_corners(const Mesh &mesh, const MLoop &loop = mesh.mloop[loop_index]; const int vertex_index = loop.v; const MVert &mvert = mesh.mvert[vertex_index]; - const float distance_sq = float3::distance_squared(position, mvert.co); + const float distance_sq = math::distance_squared(position, float3(mvert.co)); if (distance_sq < min_distance_sq) { min_distance_sq = distance_sq; closest_loop_index = loop_index; diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc index 7f866ea6f4a..6187a2eacf9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc @@ -37,7 +37,7 @@ namespace blender::nodes { static bool use_translate(const float3 rotation, const float3 scale) { - if (compare_ff(rotation.length_squared(), 0.0f, 1e-9f) != 1) { + if (compare_ff(math::length_squared(rotation), 0.0f, 1e-9f) != 1) { return false; } if (compare_ff(scale.x, 1.0f, 1e-9f) != 1 || compare_ff(scale.y, 1.0f, 1e-9f) != 1 || @@ -49,7 +49,7 @@ static bool use_translate(const float3 rotation, const float3 scale) static void translate_mesh(Mesh &mesh, const float3 translation) { - if (!translation.is_zero()) { + if (!math::is_zero(translation)) { BKE_mesh_translate(&mesh, translation, false); } } diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc index 6a6b6e3d3cc..ed72580ccf1 100644 --- a/source/blender/nodes/intern/node_socket.cc +++ b/source/blender/nodes/intern/node_socket.cc @@ -26,8 +26,8 @@ #include "DNA_node_types.h" #include "BLI_color.hh" -#include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_math_vec_types.hh" #include "BLI_string.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/node_shader_util.hh b/source/blender/nodes/shader/node_shader_util.hh index 9d4d57d01dd..5a5b4f613f3 100644 --- a/source/blender/nodes/shader/node_shader_util.hh +++ b/source/blender/nodes/shader/node_shader_util.hh @@ -29,9 +29,9 @@ #include "BLI_blenlib.h" #include "BLI_color.hh" -#include "BLI_float3.hh" #include "BLI_math.h" #include "BLI_math_base_safe.h" +#include "BLI_math_vec_types.hh" #include "BLI_rand.h" #include "BLI_threads.h" #include "BLI_utildefines.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc index 3276a1bfd72..bc7ca661a77 100644 --- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc +++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc @@ -272,7 +272,7 @@ class MapRangeVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -315,8 +315,8 @@ class MapRangeSteppedVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(6, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); - factor = float3::safe_divide(float3::floor(factor * (steps[i] + 1.0f)), steps[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + factor = math::safe_divide(math::floor(factor * (steps[i] + 1.0f)), steps[i]); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; } @@ -355,7 +355,7 @@ class MapRangeSmoothstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = (float3(3.0f) - 2.0f * factor) * (factor * factor); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; @@ -390,7 +390,7 @@ class MapRangeSmootherstepVectorFunction : public blender::fn::MultiFunction { blender::MutableSpan results = params.uninitialized_single_output(5, "Vector"); for (int64_t i : mask) { - float3 factor = float3::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); + float3 factor = math::safe_divide(values[i] - from_min[i], from_max[i] - from_min[i]); clamp_v3(factor, 0.0f, 1.0f); factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f); results[i] = factor * (to_max[i] - to_min[i]) + to_min[i]; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc index 61b1613c11a..81a69ef18da 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc @@ -19,8 +19,7 @@ #include "node_shader_util.hh" -#include "BLI_float2.hh" -#include "BLI_float4.hh" +#include "BLI_math_vec_types.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc index 85e0f262ca7..53be5bc09d9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc @@ -130,7 +130,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - const float r = std::max(0.999999f - vector[i].length(), 0.0f); + const float r = std::max(0.999999f - math::length(vector[i]), 0.0f); fac[i] = r * r; } break; @@ -140,7 +140,7 @@ class GradientFunction : public fn::MultiFunction { /* Bias a little bit for the case where input is a unit length vector, * to get exactly zero instead of a small random value depending * on float precision. */ - fac[i] = std::max(0.999999f - vector[i].length(), 0.0f); + fac[i] = std::max(0.999999f - math::length(vector[i]), 0.0f); } break; } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc index 0e549859a39..1c703313edf 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc @@ -176,14 +176,14 @@ class NoiseFunction : public fn::MultiFunction { const VArray &vector = params.readonly_single_input(0, "Vector"); if (compute_factor) { for (int64_t i : mask) { - const float2 position = vector[i] * scale[i]; + const float2 position = float2(vector[i] * scale[i]); r_factor[i] = noise::perlin_fractal_distorted( position, detail[i], roughness[i], distortion[i]); } } if (compute_color) { for (int64_t i : mask) { - const float2 position = vector[i] * scale[i]; + const float2 position = float2(vector[i] * scale[i]); const float3 c = noise::perlin_float3_fractal_distorted( position, detail[i], roughness[i], distortion[i]); r_color[i] = ColorGeometry4f(c[0], c[1], c[2], 1.0f); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc index 2b5c1ddfe21..209f96449cd 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc @@ -313,7 +313,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -345,7 +345,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -380,7 +380,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -416,7 +416,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -446,7 +446,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -479,7 +479,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -519,7 +519,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -560,7 +560,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -604,7 +604,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -837,7 +837,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -868,7 +868,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -902,7 +902,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - pos = float2::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); r_position[i] = float3(pos.x, pos.y, 0.0f); } } @@ -937,7 +937,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -966,7 +966,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } break; @@ -999,7 +999,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position) { - r_position[i] = float3::safe_divide(r_position[i], scale[i]); + r_position[i] = math::safe_divide(r_position[i], scale[i]); } } } @@ -1040,7 +1040,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1080,7 +1080,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } @@ -1123,7 +1123,7 @@ class VoronoiMetricFunction : public fn::MultiFunction { r_color[i] = ColorGeometry4f(col[0], col[1], col[2], 1.0f); } if (calc_position || calc_w) { - pos = float4::safe_divide(pos, scale[i]); + pos = math::safe_divide(pos, scale[i]); if (calc_position) { r_position[i] = float3(pos.x, pos.y, pos.z); } -- cgit v1.2.3 From 1552b86b55c04bfab77666b423b60461d9a18166 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 12 Jan 2022 12:34:56 +0100 Subject: Cleanup: Not needed if statement around delete. --- source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index 5b710939e00..48136dad5f7 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -353,9 +353,7 @@ MTLMaterial mtlmaterial_for_material(const Material *material) const nodes::NodeRef *bsdf_node = find_bsdf_node(nodetree); store_bsdf_properties(bsdf_node, material, mtlmat); store_image_textures(bsdf_node, nodetree, material, mtlmat); - if (nodetree) { - delete nodetree; - } + delete nodetree; return mtlmat; } -- cgit v1.2.3 From 08820690953db8e28586fb2446a41d5160c70750 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 12 Jan 2022 12:36:47 +0100 Subject: Cleanup: codestyle obj_exporter_tests.cc. --- source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index f9151bb97f8..e7db1c36203 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -197,7 +197,7 @@ static std::string read_temp_file_in_string(const std::string &file_path) TEST(obj_exporter_writer, header) { /* Because testing doesn't fully initialize Blender, we need the following. */ - BKE_tempdir_init(NULL); + BKE_tempdir_init(nullptr); std::string out_file_path = blender::tests::flags_test_release_dir() + "/" + temp_file_path; { OBJExportParamsDefault _export; @@ -235,19 +235,19 @@ TEST(obj_exporter_writer, mtllib) /* Return true if string #a and string #b are equal after their first newline. */ static bool strings_equal_after_first_lines(const std::string &a, const std::string &b) { - /* If `dbg_level > 0` then a failing test will print context around the first mismatch. */ - const int dbg_level = 0; + /* If `dbg_level` is true then a failing test will print context around the first mismatch. */ + const bool dbg_level = false; const size_t a_len = a.size(); const size_t b_len = b.size(); const size_t a_next = a.find_first_of('\n'); const size_t b_next = b.find_first_of('\n'); if (a_next == std::string::npos || b_next == std::string::npos) { - if (dbg_level > 0) { + if (dbg_level) { std::cout << "Couldn't find newline in one of args\n"; } return false; } - if (dbg_level > 0) { + if (dbg_level) { if (a.compare(a_next, a_len - a_next, b, b_next, b_len - b_next) != 0) { for (int i = 0; i < a_len - a_next && i < b_len - b_next; ++i) { if (a[a_next + i] != b[b_next + i]) { @@ -284,7 +284,7 @@ class obj_exporter_regression_test : public obj_exporter_test { return; } /* Because testing doesn't fully initialize Blender, we need the following. */ - BKE_tempdir_init(NULL); + BKE_tempdir_init(nullptr); std::string tempdir = std::string(BKE_tempdir_base()); std::string out_file_path = tempdir + BLI_path_basename(golden_obj.c_str()); strncpy(params.filepath, out_file_path.c_str(), FILE_MAX - 1); -- cgit v1.2.3 From ec5560db738bb0329402f1bb3c86ca6a679fdb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 12 Jan 2022 13:03:07 +0100 Subject: DRW: Add DRW_gpu_wrapper.hh This adds wrapper classes that make it easier to use GPU objects in C++. ####Motivations:#### - Easier handling of GPU objects. - EEVEE rewrite already makes use of similar wrappers. - There is the ongoing effort to use more C++ in the codebase and lans to port more engines to it. - The shader code refactor will make use of many UBOs with shared struct declaration. This helps managing them. - Safer handling of `TextureFromPool` which can't be bound as normal texture (only texture ref) and can be better tracked in the future. ####Considerations:#### - I chose the `blender::draw` namespace because `blender::gpu` already has private classes (i.e: `gpu::Texture`). - Theses are wrappers that manage a GPU object internally. They might be confused with actual `Texture`. However, the name `TextureWrapper` is a bit too much verbose in my opinion. I'm open to suggestion about better name. Reviewed By: jbakker Differential Revision: http://developer.blender.org/D13805 --- source/blender/draw/CMakeLists.txt | 1 + source/blender/draw/intern/DRW_gpu_wrapper.hh | 812 ++++++++++++++++++++++++++ 2 files changed, 813 insertions(+) create mode 100644 source/blender/draw/intern/DRW_gpu_wrapper.hh (limited to 'source/blender') diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 2a243eb9202..7b55981ba6b 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -197,6 +197,7 @@ set(SRC DRW_engine.h DRW_select_buffer.h + intern/DRW_gpu_wrapper.hh intern/DRW_render.h intern/draw_cache.h intern/draw_cache_extract.h diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh new file mode 100644 index 00000000000..01c57406dac --- /dev/null +++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh @@ -0,0 +1,812 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +#pragma once + +/** \file + * \ingroup draw + * + * Wrapper classes that make it easier to use GPU objects in C++. + * + * All Buffers need to be sent to GPU memory before being used. This is done by using the + * `push_update()`. + * + * A Storage[Array]Buffer can hold much more data than a Uniform[Array]Buffer + * which can only holds 16KB of data. + * + * All types are not copyable and Buffers are not Movable. + * + * drw::UniformArrayBuffer + * Uniform buffer object containing an array of T with len elements. + * Data can be accessed using the [] operator. + * + * drw::UniformBuffer + * A uniform buffer object class inheriting from T. + * Data can be accessed just like a normal T object. + * + * drw::StorageArrayBuffer + * Storage buffer object containing an array of T with len elements. + * The item count can be changed after creation using `resize()`. + * However, this requires the invalidation of the whole buffer and + * discarding all data inside it. + * Data can be accessed using the [] operator. + * + * drw::StorageBuffer + * A storage buffer object class inheriting from T. + * Data can be accessed just like a normal T object. + * + * drw::Texture + * A simple wrapper to GPUTexture. A drw::Texture can be created without allocation. + * The `ensure_[1d|2d|3d|cube][_array]()` method is here to make sure the underlying texture + * will meet the requirements and create (or recreate) the GPUTexture if needed. + * + * drw::TextureFromPool + * A GPUTexture from the viewport texture pool. This texture can be shared with other engines + * and its content is undefined when aquiring it. + * A drw::TextureFromPool is acquired for rendering using `acquire()` and released once the + * rendering is done using `release()`. The same texture can be acquired & released multiple + * time in one draw loop. + * The `sync()` method *MUST* be called once during the cache populate (aka: Sync) phase. + * + * drw::Framebuffer + * Simple wrapper to GPUFramebuffer that can be moved. + * + */ + +#include "MEM_guardedalloc.h" + +#include "draw_texture_pool.h" + +#include "BLI_float4.hh" +#include "BLI_int2.hh" +#include "BLI_int3.hh" +#include "BLI_int4.hh" +#include "BLI_span.hh" +#include "BLI_utildefines.h" +#include "BLI_utility_mixins.hh" + +#include "GPU_framebuffer.h" +#include "GPU_texture.h" +#include "GPU_uniform_buffer.h" +#include "GPU_vertex_buffer.h" + +namespace blender::draw { + +/* -------------------------------------------------------------------- */ +/** \name Implementation Details + * \{ */ + +namespace detail { + +template< + /** Type of the values stored in this uniform buffer. */ + typename T, + /** The number of values that can be stored in this uniform buffer. */ + int64_t len, + /** True if the buffer only resides on GPU memory and cannot be accessed. */ + bool device_only> +class DataBuffer { + protected: + T *data_ = nullptr; + int64_t len_ = len; + + BLI_STATIC_ASSERT((sizeof(T) % 16) == 0, "Type need to be aligned to size of float4."); + + public: + /** + * Get the value at the given index. This invokes undefined behavior when the + * index is out of bounds. + */ + const T &operator[](int64_t index) const + { + BLI_STATIC_ASSERT(!device_only, ""); + BLI_assert(index >= 0); + BLI_assert(index < len); + return data_[index]; + } + + T &operator[](int64_t index) + { + BLI_STATIC_ASSERT(!device_only, ""); + BLI_assert(index >= 0); + BLI_assert(index < len); + return data_[index]; + } + + /** + * Get a pointer to the beginning of the array. + */ + const T *data() const + { + BLI_STATIC_ASSERT(!device_only, ""); + return data_; + } + T *data() + { + BLI_STATIC_ASSERT(!device_only, ""); + return data_; + } + + /** + * Iterator + */ + const T *begin() const + { + BLI_STATIC_ASSERT(!device_only, ""); + return data_; + } + const T *end() const + { + BLI_STATIC_ASSERT(!device_only, ""); + return data_ + len; + } + + T *begin() + { + BLI_STATIC_ASSERT(!device_only, ""); + return data_; + } + T *end() + { + BLI_STATIC_ASSERT(!device_only, ""); + return data_ + len; + } + + operator Span() const + { + BLI_STATIC_ASSERT(!device_only, ""); + return Span(data_, len); + } +}; + +template +class UniformCommon : public DataBuffer, NonMovable, NonCopyable { + protected: + GPUUniformBuf *ubo_; + +#ifdef DEBUG + const char *name_ = typeid(T).name(); +#else + constexpr static const char *name_ = "UniformBuffer"; +#endif + + public: + UniformCommon() + { + ubo_ = GPU_uniformbuf_create_ex(sizeof(T) * len, nullptr, name_); + } + + ~UniformCommon() + { + GPU_uniformbuf_free(ubo_); + } + + void push_update(void) + { + GPU_uniformbuf_update(ubo_, this->data_); + } + + /* To be able to use it with DRW_shgroup_*_ref(). */ + operator GPUUniformBuf *() const + { + return ubo_; + } + + /* To be able to use it with DRW_shgroup_*_ref(). */ + GPUUniformBuf **operator&() + { + return &ubo_; + } +}; + +template +class StorageCommon : public DataBuffer, NonMovable, NonCopyable { + protected: + /* Use vertex buffer for now. Until there is a complete GPUStorageBuf implementation. */ + GPUVertBuf *ssbo_; + +#ifdef DEBUG + const char *name_ = typeid(T).name(); +#else + constexpr static const char *name_ = "StorageBuffer"; +#endif + + public: + StorageCommon() + { + init(len); + } + + ~StorageCommon() + { + GPU_vertbuf_discard(ssbo_); + } + + void resize(int64_t new_size) + { + BLI_assert(new_size > 0); + if (new_size != this->len_) { + GPU_vertbuf_discard(ssbo_); + this->init(new_size); + } + } + + operator GPUVertBuf *() const + { + return ssbo_; + } + /* To be able to use it with DRW_shgroup_*_ref(). */ + GPUVertBuf **operator&() + { + return &ssbo_; + } + + private: + void init(int64_t new_size) + { + this->len_ = new_size; + + GPUVertFormat format = {0}; + GPU_vertformat_attr_add(&format, "dummy", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); + + GPUUsageType usage = device_only ? GPU_USAGE_DEVICE_ONLY : GPU_USAGE_DYNAMIC; + ssbo_ = GPU_vertbuf_create_with_format_ex(&format, usage); + GPU_vertbuf_data_alloc(ssbo_, divide_ceil_u(sizeof(T) * this->len_, 4)); + if (!device_only) { + this->data_ = (T *)GPU_vertbuf_get_data(ssbo_); + GPU_vertbuf_use(ssbo_); + } + } +}; + +} // namespace detail + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Uniform Buffers + * \{ */ + +template< + /** Type of the values stored in this uniform buffer. */ + typename T, + /** The number of values that can be stored in this uniform buffer. */ + int64_t len + /** True if the buffer only resides on GPU memory and cannot be accessed. */ + /* TODO(fclem): Currently unsupported. */ + /* bool device_only = false */> +class UniformArrayBuffer : public detail::UniformCommon { + public: + UniformArrayBuffer() + { + /* TODO(fclem) We should map memory instead. */ + this->data_ = MEM_mallocN_aligned(this->name_); + } +}; + +template< + /** Type of the values stored in this uniform buffer. */ + typename T + /** True if the buffer only resides on GPU memory and cannot be accessed. */ + /* TODO(fclem): Currently unsupported. */ + /* bool device_only = false */> +class UniformBuffer : public T, public detail::UniformCommon { + public: + UniformBuffer() + { + /* TODO(fclem) How could we map this? */ + this->data_ = static_cast(this); + } + + UniformBuffer &operator=(const T &other) + { + *static_cast(this) = other; + return *this; + } +}; + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Storage Buffer + * \{ */ + +template< + /** Type of the values stored in this uniform buffer. */ + typename T, + /** The number of values that can be stored in this uniform buffer. */ + int64_t len, + /** True if created on device and no memory host memory is allocated. */ + bool device_only = false> +class StorageArrayBuffer : public detail::StorageCommon { + public: + void push_update(void) + { + BLI_assert(!device_only); + /* Get the data again to tag for update. The actual pointer should not + * change. */ + this->data_ = (T *)GPU_vertbuf_get_data(this->ssbo_); + GPU_vertbuf_use(this->ssbo_); + } +}; + +template< + /** Type of the values stored in this uniform buffer. */ + typename T, + /** True if created on device and no memory host memory is allocated. */ + bool device_only = false> +class StorageBuffer : public T, public detail::StorageCommon { + public: + void push_update(void) + { + BLI_assert(!device_only); + /* TODO(fclem): Avoid a full copy. */ + T &vert_data = *(T *)GPU_vertbuf_get_data(this->ssbo_); + vert_data = *this; + + GPU_vertbuf_use(this->ssbo_); + } + + StorageBuffer &operator=(const T &other) + { + *static_cast(this) = other; + return *this; + } +}; + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Texture + * \{ */ + +class Texture : NonCopyable { + protected: + GPUTexture *tx_ = nullptr; + const char *name_; + + public: + Texture(const char *name = "gpu::Texture") : name_(name) + { + } + + Texture(const char *name, + eGPUTextureFormat format, + int extent, + float *data = nullptr, + bool cubemap = false, + int mips = 1) + : name_(name) + { + tx_ = create(extent, 0, 0, mips, format, data, false, cubemap); + } + + Texture(const char *name, + eGPUTextureFormat format, + int extent, + int layers, + float *data = nullptr, + bool cubemap = false, + int mips = 1) + : name_(name) + { + tx_ = create(extent, layers, 0, mips, format, data, true, cubemap); + } + + Texture( + const char *name, eGPUTextureFormat format, int2 extent, float *data = nullptr, int mips = 1) + : name_(name) + { + tx_ = create(UNPACK2(extent), 0, mips, format, data, false, false); + } + + Texture(const char *name, + eGPUTextureFormat format, + int2 extent, + int layers, + float *data = nullptr, + int mips = 1) + : name_(name) + { + tx_ = create(UNPACK2(extent), layers, mips, format, data, true, false); + } + + Texture( + const char *name, eGPUTextureFormat format, int3 extent, float *data = nullptr, int mips = 1) + : name_(name) + { + tx_ = create(UNPACK3(extent), mips, format, data, false, false); + } + + ~Texture() + { + free(); + } + + /* To be able to use it with DRW_shgroup_uniform_texture(). */ + operator GPUTexture *() const + { + BLI_assert(tx_ != nullptr); + return tx_; + } + + /* To be able to use it with DRW_shgroup_uniform_texture_ref(). */ + GPUTexture **operator&() + { + return &tx_; + } + + Texture &operator=(Texture &&a) + { + if (*this != a) { + this->tx_ = a.tx_; + this->name_ = a.name_; + a.tx_ = nullptr; + } + return *this; + } + + /** + * Ensure the texture has the correct properties. Recreating it if needed. + * Return true if a texture has been created. + */ + bool ensure_1d(eGPUTextureFormat format, int extent, float *data = nullptr, int mips = 1) + { + return ensure_impl(extent, 0, 0, mips, format, data, false, false); + } + + /** + * Ensure the texture has the correct properties. Recreating it if needed. + * Return true if a texture has been created. + */ + bool ensure_1d_array( + eGPUTextureFormat format, int extent, int layers, float *data = nullptr, int mips = 1) + { + return ensure_impl(extent, layers, 0, mips, format, data, true, false); + } + + /** + * Ensure the texture has the correct properties. Recreating it if needed. + * Return true if a texture has been created. + */ + bool ensure_2d(eGPUTextureFormat format, const int2 &extent, float *data = nullptr, int mips = 1) + { + return ensure_impl(UNPACK2(extent), 0, mips, format, data, false, false); + } + + /** + * Ensure the texture has the correct properties. Recreating it if needed. + * Return true if a texture has been created. + */ + bool ensure_2d_array(eGPUTextureFormat format, + const int2 &extent, + int layers, + float *data = nullptr, + int mips = 1) + { + return ensure_impl(UNPACK2(extent), layers, mips, format, data, true, false); + } + + /** + * Ensure the texture has the correct properties. Recreating it if needed. + * Return true if a texture has been created. + */ + bool ensure_3d(eGPUTextureFormat format, const int3 &extent, float *data = nullptr, int mips = 1) + { + return ensure_impl(UNPACK3(extent), mips, format, data, false, false); + } + + /** + * Ensure the texture has the correct properties. Recreating it if needed. + * Return true if a texture has been created. + */ + bool ensure_cube(eGPUTextureFormat format, int extent, float *data = nullptr, int mips = 1) + { + return ensure_impl(extent, extent, 0, mips, format, data, false, true); + } + + /** + * Ensure the texture has the correct properties. Recreating it if needed. + * Return true if a texture has been created. + */ + bool ensure_cube_array( + eGPUTextureFormat format, int extent, int layers, float *data = nullptr, int mips = 1) + { + return ensure_impl(extent, extent, layers, mips, format, data, false, true); + } + + /** + * Returns true if the texture has been allocated or acquired from the pool. + */ + bool is_valid(void) const + { + return tx_ != nullptr; + } + + int width(void) const + { + return GPU_texture_width(tx_); + } + + int height(void) const + { + return GPU_texture_height(tx_); + } + + bool depth(void) const + { + return GPU_texture_depth(tx_); + } + + bool is_stencil(void) const + { + return GPU_texture_stencil(tx_); + } + + bool is_integer(void) const + { + return GPU_texture_integer(tx_); + } + + bool is_cube(void) const + { + return GPU_texture_cube(tx_); + } + + bool is_array(void) const + { + return GPU_texture_array(tx_); + } + + int3 size(int miplvl = 0) const + { + int3 size(0); + GPU_texture_get_mipmap_size(tx_, miplvl, size); + return size; + } + + /** + * Clear the entirety of the texture using one pixel worth of data. + */ + void clear(float4 values) + { + GPU_texture_clear(tx_, GPU_DATA_FLOAT, &values[0]); + } + + /** + * Clear the entirety of the texture using one pixel worth of data. + */ + void clear(uint4 values) + { + GPU_texture_clear(tx_, GPU_DATA_UINT, &values[0]); + } + + /** + * Clear the entirety of the texture using one pixel worth of data. + */ + void clear(uchar4 values) + { + GPU_texture_clear(tx_, GPU_DATA_UBYTE, &values[0]); + } + + /** + * Clear the entirety of the texture using one pixel worth of data. + */ + void clear(int4 values) + { + GPU_texture_clear(tx_, GPU_DATA_INT, &values[0]); + } + + /** + * Returns a buffer containing the texture data for the specified miplvl. + * The memory block needs to be manually freed by MEM_freeN(). + */ + template T *read(eGPUDataFormat format, int miplvl = 0) + { + return reinterpret_cast(GPU_texture_read(tx_, format, miplvl)); + } + + void filter_mode(bool do_filter) + { + GPU_texture_filter_mode(tx_, do_filter); + } + + /** + * Free the internal texture but not the drw::Texture itself. + */ + void free() + { + GPU_TEXTURE_FREE_SAFE(tx_); + } + + private: + bool ensure_impl(int w, + int h = 0, + int d = 0, + int mips = 1, + eGPUTextureFormat format = GPU_RGBA8, + float *data = nullptr, + bool layered = false, + bool cubemap = false) + + { + /* TODO(fclem) In the future, we need to check if mip_count did not change. + * For now it's ok as we always define all mip level.*/ + if (tx_) { + int3 size = this->size(); + if (size != int3(w, h, d) || GPU_texture_format(tx_) != format || + GPU_texture_cube(tx_) != cubemap || GPU_texture_array(tx_) != layered) { + GPU_TEXTURE_FREE_SAFE(tx_); + } + } + if (tx_ == nullptr) { + tx_ = create(w, h, d, mips, format, data, layered, cubemap); + if (mips > 1) { + /* TODO(fclem) Remove once we have immutable storage or when mips are + * generated on creation. */ + GPU_texture_generate_mipmap(tx_); + } + return true; + } + return false; + } + + GPUTexture *create(int w, + int h, + int d, + int mips, + eGPUTextureFormat format, + float *data, + bool layered, + bool cubemap) + { + if (h == 0) { + return GPU_texture_create_1d(name_, w, mips, format, data); + } + else if (d == 0) { + if (layered) { + return GPU_texture_create_1d_array(name_, w, h, mips, format, data); + } + else { + return GPU_texture_create_2d(name_, w, h, mips, format, data); + } + } + else if (cubemap) { + if (layered) { + return GPU_texture_create_cube_array(name_, w, d, mips, format, data); + } + else { + return GPU_texture_create_cube(name_, w, mips, format, data); + } + } + else { + if (layered) { + return GPU_texture_create_2d_array(name_, w, h, d, mips, format, data); + } + else { + return GPU_texture_create_3d(name_, w, h, d, mips, format, GPU_DATA_FLOAT, data); + } + } + } +}; + +class TextureFromPool : public Texture, NonMovable { + private: + GPUTexture *tx_tmp_saved_ = nullptr; + + public: + TextureFromPool(const char *name = "gpu::Texture") : Texture(name){}; + + /* Always use `release()` after rendering. */ + void acquire(int w, int h, eGPUTextureFormat format, void *owner_) + { + if (this->tx_ == nullptr) { + if (tx_tmp_saved_ != nullptr) { + this->tx_ = tx_tmp_saved_; + return; + } + DrawEngineType *owner = (DrawEngineType *)owner_; + this->tx_ = DRW_texture_pool_query_2d(w, h, format, owner); + } + } + + void release(void) + { + tx_tmp_saved_ = this->tx_; + this->tx_ = nullptr; + } + + /** + * Clears any reference. Workaround for pool texture not being able to release on demand. + * Needs to be called at during the sync phase. + */ + void sync(void) + { + tx_tmp_saved_ = nullptr; + } + + /** Remove methods that are forbidden with this type of textures. */ + bool ensure_1d(int, int, eGPUTextureFormat, float *) = delete; + bool ensure_1d_array(int, int, int, eGPUTextureFormat, float *) = delete; + bool ensure_2d(int, int, int, eGPUTextureFormat, float *) = delete; + bool ensure_2d_array(int, int, int, int, eGPUTextureFormat, float *) = delete; + bool ensure_3d(int, int, int, int, eGPUTextureFormat, float *) = delete; + bool ensure_cube(int, int, eGPUTextureFormat, float *) = delete; + bool ensure_cube_array(int, int, int, eGPUTextureFormat, float *) = delete; + void filter_mode(bool) = delete; + void free() = delete; + /** + * Forbid the use of DRW_shgroup_uniform_texture. + * Use DRW_shgroup_uniform_texture_ref instead. + */ + operator GPUTexture *() const = delete; +}; + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Framebuffer + * \{ */ + +class Framebuffer : NonCopyable { + private: + GPUFrameBuffer *fb_ = nullptr; + const char *name_; + + public: + Framebuffer() : name_(""){}; + Framebuffer(const char *name) : name_(name){}; + + ~Framebuffer() + { + GPU_FRAMEBUFFER_FREE_SAFE(fb_); + } + + void ensure(GPUAttachment depth = GPU_ATTACHMENT_NONE, + GPUAttachment color1 = GPU_ATTACHMENT_NONE, + GPUAttachment color2 = GPU_ATTACHMENT_NONE, + GPUAttachment color3 = GPU_ATTACHMENT_NONE, + GPUAttachment color4 = GPU_ATTACHMENT_NONE, + GPUAttachment color5 = GPU_ATTACHMENT_NONE, + GPUAttachment color6 = GPU_ATTACHMENT_NONE, + GPUAttachment color7 = GPU_ATTACHMENT_NONE, + GPUAttachment color8 = GPU_ATTACHMENT_NONE) + { + GPU_framebuffer_ensure_config( + &fb_, {depth, color1, color2, color3, color4, color5, color6, color7, color8}); + } + + Framebuffer &operator=(Framebuffer &&a) + { + if (*this != a) { + this->fb_ = a.fb_; + this->name_ = a.name_; + a.fb_ = nullptr; + } + return *this; + } + + operator GPUFrameBuffer *() const + { + return fb_; + } +}; + +/** \} */ + +} // namespace blender::draw -- cgit v1.2.3 From 5f7ad4baaaab38f1a4250dcad17a96d11ee32e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 12 Jan 2022 17:24:57 +0100 Subject: BLI_math: Fix building when WITH_GMP is off --- source/blender/blenlib/BLI_math_vec_mpq_types.hh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/BLI_math_vec_mpq_types.hh b/source/blender/blenlib/BLI_math_vec_mpq_types.hh index 36eb0cac83c..392c647fe0d 100644 --- a/source/blender/blenlib/BLI_math_vec_mpq_types.hh +++ b/source/blender/blenlib/BLI_math_vec_mpq_types.hh @@ -20,10 +20,11 @@ * \ingroup bli */ +#include "BLI_math_vec_types.hh" + #ifdef WITH_GMP # include "BLI_math_mpq.hh" -# include "BLI_math_vec_types.hh" namespace blender { -- cgit v1.2.3 From a909ab984ce4007c0dbd70ee085c1d4d780c4014 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 12 Jan 2022 17:59:46 +0100 Subject: Outliner: Add way to display warning icon for items. While theorically fairly generic, current code is only enabled for bledfile and liboverride views, and only used to display messages from library IDs. Reviewed By: Severin Differential Revision: https://developer.blender.org/D13766 --- .../blender/editors/space_outliner/outliner_draw.c | 102 +++++++++++++++++++-- .../editors/space_outliner/outliner_intern.h | 2 + .../blender/editors/space_outliner/outliner_tree.c | 40 ++++++++ .../editors/space_outliner/tree/tree_display.cc | 7 ++ .../editors/space_outliner/tree/tree_display.h | 10 ++ .../editors/space_outliner/tree/tree_display.hh | 6 +- .../space_outliner/tree/tree_display_libraries.cc | 7 +- .../tree/tree_display_override_library.cc | 5 +- 8 files changed, 167 insertions(+), 12 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index a586f268128..8bcd50161bd 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -79,6 +79,7 @@ #include "RNA_access.h" #include "outliner_intern.h" +#include "tree/tree_display.h" /* Disable - this is far too slow - campbell. */ /* #define USE_GROUP_SELECT */ @@ -2143,6 +2144,80 @@ static void outliner_draw_mode_column(const bContext *C, } } +/* Returns `true` if some warning was drawn for that element or one of its sub-elements (if it is + * not open). */ +static bool outliner_draw_warning_tree_element(uiBlock *block, + SpaceOutliner *space_outliner, + TreeElement *te, + TreeStoreElem *tselem, + const bool use_mode_column, + const int te_ys) +{ + if ((te->flag & TE_HAS_WARNING) == 0) { + /* If given element has no warning, recusively try to display the first sub-elements' warning. + */ + if (!TSELEM_OPEN(tselem, space_outliner)) { + LISTBASE_FOREACH (TreeElement *, sub_te, &te->subtree) { + TreeStoreElem *sub_tselem = TREESTORE(sub_te); + + if (outliner_draw_warning_tree_element( + block, space_outliner, sub_te, sub_tselem, use_mode_column, te_ys)) { + return true; + } + } + } + return false; + } + + int icon = ICON_NONE; + const char *tip = ""; + const bool has_warning = outliner_element_warnings_get(te, &icon, &tip); + BLI_assert(has_warning); + UNUSED_VARS_NDEBUG(has_warning); + + /* Move the warnings a unit left in view layer mode. */ + const short mode_column_offset = (use_mode_column && (space_outliner->outlinevis == SO_SCENES)) ? + UI_UNIT_X : + 0; + + UI_block_emboss_set(block, UI_EMBOSS_NONE_OR_STATUS); + uiBut *but = uiDefIconBut(block, + UI_BTYPE_ICON_TOGGLE, + 0, + icon, + mode_column_offset, + te_ys, + UI_UNIT_X, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + tip); + /* No need for undo here, this is a pure info widget. */ + UI_but_flag_disable(but, UI_BUT_UNDO); + + return true; +} + +static void outliner_draw_warning_column(const bContext *C, + uiBlock *block, + SpaceOutliner *space_outliner, + const bool use_mode_column, + ListBase *tree) +{ + LISTBASE_FOREACH (TreeElement *, te, tree) { + TreeStoreElem *tselem = TREESTORE(te); + + outliner_draw_warning_tree_element(block, space_outliner, te, tselem, use_mode_column, te->ys); + + if (TSELEM_OPEN(tselem, space_outliner)) { + outliner_draw_warning_column(C, block, space_outliner, use_mode_column, &te->subtree); + } + } +} + /* ****************************************************** */ /* Normal Drawing... */ @@ -3612,17 +3687,22 @@ static void outliner_draw_tree(bContext *C, SpaceOutliner *space_outliner, const float restrict_column_width, const bool use_mode_column, + const bool use_warning_column, TreeElement **te_edit) { const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; int starty, startx; /* Move the tree a unit left in view layer mode */ - short mode_column_offset = (use_mode_column && (space_outliner->outlinevis == SO_SCENES)) ? - UI_UNIT_X : - 0; + short columns_offset = (use_mode_column && (space_outliner->outlinevis == SO_SCENES)) ? + UI_UNIT_X : + 0; if (!use_mode_column && (space_outliner->outlinevis == SO_VIEW_LAYER)) { - mode_column_offset -= UI_UNIT_X; + columns_offset -= UI_UNIT_X; + } + + if (use_warning_column) { + columns_offset += UI_UNIT_X; } GPU_blend(GPU_BLEND_ALPHA); /* Only once. */ @@ -3650,12 +3730,12 @@ static void outliner_draw_tree(bContext *C, /* Draw hierarchy lines for collections and object children. */ starty = (int)region->v2d.tot.ymax - OL_Y_OFFSET; - startx = mode_column_offset + UI_UNIT_X / 2 - (U.pixelsize + 1) / 2; + startx = columns_offset + UI_UNIT_X / 2 - (U.pixelsize + 1) / 2; outliner_draw_hierarchy_lines(space_outliner, &space_outliner->tree, startx, &starty); /* Items themselves. */ starty = (int)region->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET; - startx = mode_column_offset; + startx = columns_offset; LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { outliner_draw_tree_element(C, block, @@ -3786,6 +3866,10 @@ void draw_outliner(const bContext *C) const bool use_mode_column = (space_outliner->flag & SO_MODE_COLUMN) && (ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES)); + const bool use_warning_column = + ELEM(space_outliner->outlinevis, SO_LIBRARIES, SO_OVERRIDES_LIBRARY) && + outliner_tree_display_warnings_poll(space_outliner->runtime->tree_display); + /* Draw outliner stuff (background, hierarchy lines and names). */ const float restrict_column_width = outliner_restrict_columns_width(space_outliner); outliner_back(region); @@ -3797,6 +3881,7 @@ void draw_outliner(const bContext *C) space_outliner, restrict_column_width, use_mode_column, + use_warning_column, &te_edit); /* Compute outliner dimensions after it has been drawn. */ @@ -3841,6 +3926,11 @@ void draw_outliner(const bContext *C) outliner_draw_mode_column(C, block, &tvc, space_outliner, &space_outliner->tree); } + /* Draw warning icons */ + if (use_warning_column) { + outliner_draw_warning_column(C, block, space_outliner, use_mode_column, &space_outliner->tree); + } + UI_block_emboss_set(block, UI_EMBOSS); /* Draw edit buttons if necessary. */ diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index e331887319e..24e86e06f68 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -158,6 +158,8 @@ enum { /* Child elements of the same type in the icon-row are drawn merged as one icon. * This flag is set for an element that is part of these merged child icons. */ TE_ICONROW_MERGED = (1 << 7), + /* This element has some warning to be displayed. */ + TE_HAS_WARNING = (1 << 8), }; /* button events */ diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index 3353726de18..e461eb4c69e 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -74,6 +74,7 @@ #include "RNA_access.h" #include "UI_interface.h" +#include "UI_resources.h" #include "outliner_intern.h" #include "tree/tree_display.h" @@ -812,6 +813,41 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner, } } +bool outliner_element_warnings_get(TreeElement *te, int *r_icon, const char **r_message) +{ + TreeStoreElem *tselem = TREESTORE(te); + + if (tselem->type != TSE_SOME_ID) { + return false; + } + if (te->idcode != ID_LI) { + return false; + } + + Library *library = (Library *)tselem->id; + if (library->tag & LIBRARY_TAG_RESYNC_REQUIRED) { + if (r_icon) { + *r_icon = ICON_ERROR; + } + if (r_message) { + *r_message = TIP_( + "Contains linked library overrides that need to be resynced, updating the library is " + "recommended"); + } + return true; + } + if (library->id.tag & LIB_TAG_MISSING) { + if (r_icon) { + *r_icon = ICON_ERROR; + } + if (r_message) { + *r_message = TIP_("Missing library"); + } + return true; + } + return false; +} + TreeElement *outliner_add_element(SpaceOutliner *space_outliner, ListBase *lb, void *idv, @@ -1115,6 +1151,10 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, } } + if (outliner_element_warnings_get(te, NULL, NULL)) { + te->flag |= TE_HAS_WARNING; + } + return te; } diff --git a/source/blender/editors/space_outliner/tree/tree_display.cc b/source/blender/editors/space_outliner/tree/tree_display.cc index 003afd5bdec..e192929c7cf 100644 --- a/source/blender/editors/space_outliner/tree/tree_display.cc +++ b/source/blender/editors/space_outliner/tree/tree_display.cc @@ -66,3 +66,10 @@ ListBase outliner_tree_display_build_tree(TreeDisplay *tree_display, TreeSourceD { return reinterpret_cast(tree_display)->buildTree(*source_data); } + +bool outliner_tree_display_warnings_poll(const TreeDisplay *tree_display) +{ + const AbstractTreeDisplay *abstract_tree_display = reinterpret_cast( + tree_display); + return abstract_tree_display->has_warnings; +} diff --git a/source/blender/editors/space_outliner/tree/tree_display.h b/source/blender/editors/space_outliner/tree/tree_display.h index b6dc33ba7b7..7b959576a4b 100644 --- a/source/blender/editors/space_outliner/tree/tree_display.h +++ b/source/blender/editors/space_outliner/tree/tree_display.h @@ -47,6 +47,16 @@ void outliner_tree_display_destroy(TreeDisplay **tree_display); ListBase outliner_tree_display_build_tree(TreeDisplay *tree_display, TreeSourceData *source_data); +/** Accessor to whether given tree has some warnings to display. */ +bool outliner_tree_display_warnings_poll(const struct TreeDisplay *tree_display); + +/** Get actual warning data of a tree element, if any. + * + * \param r_icon The icon to display as warning. + * \param r_message The message to display as warning. + * \return true if there is a warning, false otherwise. */ +bool outliner_element_warnings_get(struct TreeElement *te, int *r_icon, const char **r_message); + /* The following functions are needed to build the tree. They are calls back into C; the way * elements are created should be refactored and ported to C++ with a new design/API too. */ /** diff --git a/source/blender/editors/space_outliner/tree/tree_display.hh b/source/blender/editors/space_outliner/tree/tree_display.hh index 54e64655b18..bf9cf18948c 100644 --- a/source/blender/editors/space_outliner/tree/tree_display.hh +++ b/source/blender/editors/space_outliner/tree/tree_display.hh @@ -65,6 +65,8 @@ class AbstractTreeDisplay { */ virtual ListBase buildTree(const TreeSourceData &source_data) = 0; + bool has_warnings = false; + protected: /** All derived classes will need a handle to this, so storing it in the base for convenience. */ SpaceOutliner &space_outliner_; @@ -105,7 +107,7 @@ class TreeDisplayLibraries final : public AbstractTreeDisplay { ListBase buildTree(const TreeSourceData &source_data) override; private: - TreeElement *add_library_contents(Main &, ListBase &, Library *) const; + TreeElement *add_library_contents(Main &, ListBase &, Library *); bool library_id_filter_poll(const Library *lib, ID *id) const; short id_filter_get() const; }; @@ -123,7 +125,7 @@ class TreeDisplayOverrideLibrary final : public AbstractTreeDisplay { ListBase buildTree(const TreeSourceData &source_data) override; private: - TreeElement *add_library_contents(Main &, ListBase &, Library *) const; + TreeElement *add_library_contents(Main &, ListBase &, Library *); bool override_library_id_filter_poll(const Library *lib, ID *id) const; short id_filter_get() const; }; diff --git a/source/blender/editors/space_outliner/tree/tree_display_libraries.cc b/source/blender/editors/space_outliner/tree/tree_display_libraries.cc index 836f0937cf4..461104e6bad 100644 --- a/source/blender/editors/space_outliner/tree/tree_display_libraries.cc +++ b/source/blender/editors/space_outliner/tree/tree_display_libraries.cc @@ -104,9 +104,7 @@ ListBase TreeDisplayLibraries::buildTree(const TreeSourceData &source_data) return tree; } -TreeElement *TreeDisplayLibraries::add_library_contents(Main &mainvar, - ListBase &lb, - Library *lib) const +TreeElement *TreeDisplayLibraries::add_library_contents(Main &mainvar, ListBase &lb, Library *lib) { const short filter_id_type = id_filter_get(); @@ -149,6 +147,9 @@ TreeElement *TreeDisplayLibraries::add_library_contents(Main &mainvar, tenlib = outliner_add_element(&space_outliner_, &lb, &mainvar, nullptr, TSE_ID_BASE, 0); tenlib->name = IFACE_("Current File"); } + if (tenlib->flag & TE_HAS_WARNING) { + has_warnings = true; + } } /* Create data-block list parent element on demand. */ diff --git a/source/blender/editors/space_outliner/tree/tree_display_override_library.cc b/source/blender/editors/space_outliner/tree/tree_display_override_library.cc index 943e182277c..bf9fba30c9f 100644 --- a/source/blender/editors/space_outliner/tree/tree_display_override_library.cc +++ b/source/blender/editors/space_outliner/tree/tree_display_override_library.cc @@ -112,7 +112,7 @@ ListBase TreeDisplayOverrideLibrary::buildTree(const TreeSourceData &source_data TreeElement *TreeDisplayOverrideLibrary::add_library_contents(Main &mainvar, ListBase &lb, - Library *lib) const + Library *lib) { const short filter_id_type = id_filter_get(); @@ -152,6 +152,9 @@ TreeElement *TreeDisplayOverrideLibrary::add_library_contents(Main &mainvar, tenlib = outliner_add_element(&space_outliner_, &lb, &mainvar, nullptr, TSE_ID_BASE, 0); tenlib->name = IFACE_("Current File"); } + if (tenlib->flag & TE_HAS_WARNING) { + has_warnings = true; + } } /* Create data-block list parent element on demand. */ -- cgit v1.2.3 From bab47b60cb69c500869a3339654ad7d48dddf385 Mon Sep 17 00:00:00 2001 From: Simon Lenz Date: Wed, 12 Jan 2022 18:02:08 +0100 Subject: DNA: Add space clip editor defaults This is my attempt of adding defaults for the space clip editor struct (in line with https://developer.blender.org/T80164). It adds the default allocation for `SpaceClip` and `node_composite_movieclip.cc`. This also solves the error below (for C++ files using the DNA_default_alloc), which was put forward by Sergey Sharybin. Differential Revision: https://developer.blender.org/D13367 Reviewed by: Julian Eisel --- source/blender/blenkernel/intern/mask.c | 3 +- source/blender/blenkernel/intern/movieclip.c | 2 +- .../blenkernel/intern/tracking_region_tracker.c | 3 +- source/blender/compositor/CMakeLists.txt | 3 + .../operations/COM_KeyingScreenOperation.cc | 6 +- .../operations/COM_MovieDistortionOperation.cc | 4 +- .../operations/COM_PlaneTrackOperation.cc | 4 +- .../operations/COM_TrackPositionOperation.cc | 4 +- source/blender/editors/space_clip/CMakeLists.txt | 3 + source/blender/editors/space_clip/clip_editor.c | 9 +-- source/blender/editors/space_clip/clip_ops.c | 3 +- source/blender/editors/space_clip/space_clip.c | 11 +--- source/blender/makesdna/DNA_defaults.h | 4 +- source/blender/makesdna/DNA_movieclip_defaults.h | 28 +++++++++ source/blender/makesdna/DNA_space_defaults.h | 67 ++++++++++++++++++++++ source/blender/makesdna/intern/CMakeLists.txt | 1 + source/blender/makesdna/intern/dna_defaults.c | 16 ++++++ source/blender/makesrna/intern/CMakeLists.txt | 3 + source/blender/makesrna/intern/rna_mask.c | 3 +- source/blender/makesrna/intern/rna_tracking.c | 3 +- source/blender/nodes/CMakeLists.txt | 3 + source/blender/nodes/composite/CMakeLists.txt | 3 + .../composite/nodes/node_composite_movieclip.cc | 3 +- source/blender/sequencer/intern/render.c | 5 +- 24 files changed, 166 insertions(+), 28 deletions(-) create mode 100644 source/blender/makesdna/DNA_space_defaults.h (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 6f498c5c9e7..12bbab57cf2 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -38,6 +38,7 @@ #include "BLT_translation.h" +#include "DNA_defaults.h" #include "DNA_mask_types.h" #include "BKE_animsys.h" @@ -1308,7 +1309,7 @@ void BKE_mask_point_parent_matrix_get(MaskSplinePoint *point, MovieTrackingObject *ob = BKE_tracking_object_get_named(tracking, parent->parent); if (ob) { - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); float clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, ctime); BKE_movieclip_user_set_frame(&user, ctime); diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index e8975c82c46..88da789cdc4 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -953,7 +953,7 @@ static MovieClip *movieclip_alloc(Main *bmain, const char *name) static void movieclip_load_get_size(MovieClip *clip) { int width, height; - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); user.framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, 1); BKE_movieclip_get_size(clip, &user, &width, &height); diff --git a/source/blender/blenkernel/intern/tracking_region_tracker.c b/source/blender/blenkernel/intern/tracking_region_tracker.c index 2265c05463b..4b23f74bc8f 100644 --- a/source/blender/blenkernel/intern/tracking_region_tracker.c +++ b/source/blender/blenkernel/intern/tracking_region_tracker.c @@ -26,6 +26,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_defaults.h" #include "DNA_movieclip_types.h" #include "BLI_threads.h" @@ -322,7 +323,7 @@ void BKE_tracking_refine_marker(MovieClip *clip, int search_area_height, search_area_width; int clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS; int reference_framenr; - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); double dst_pixel_x[5], dst_pixel_y[5]; bool tracked; diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 905d1443002..af0ac6aee2e 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -40,6 +40,9 @@ set(INC ../../../intern/atomic ../../../intern/guardedalloc ../../../intern/clog + + # dna_type_offsets.h + ${CMAKE_CURRENT_BINARY_DIR}/../makesdna/intern ) set(INC_SYS diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.cc b/source/blender/compositor/operations/COM_KeyingScreenOperation.cc index aa92c5c0c2b..5d12f29b83f 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.cc +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.cc @@ -18,6 +18,8 @@ #include "COM_KeyingScreenOperation.h" +#include "DNA_defaults.h" + #include "BKE_movieclip.h" #include "BKE_tracking.h" @@ -75,7 +77,7 @@ void KeyingScreenOperation::deinit_execution() KeyingScreenOperation::TriangulationData *KeyingScreenOperation::build_voronoi_triangulation() { - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); TriangulationData *triangulation; MovieTracking *tracking = &movie_clip_->tracking; MovieTrackingTrack *track; @@ -301,7 +303,7 @@ void KeyingScreenOperation::determine_canvas(const rcti &preferred_area, rcti &r r_area = COM_AREA_NONE; if (movie_clip_) { - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); int width, height; int clip_frame = BKE_movieclip_remap_scene_to_clip_frame(movie_clip_, framenumber_); diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.cc b/source/blender/compositor/operations/COM_MovieDistortionOperation.cc index d04a970bc03..b25073394a2 100644 --- a/source/blender/compositor/operations/COM_MovieDistortionOperation.cc +++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.cc @@ -18,6 +18,8 @@ #include "COM_MovieDistortionOperation.h" +#include "DNA_defaults.h" + #include "BKE_movieclip.h" namespace blender::compositor { @@ -36,7 +38,7 @@ void MovieDistortionOperation::init_data() { if (movie_clip_) { MovieTracking *tracking = &movie_clip_->tracking; - MovieClipUser clip_user = {0}; + MovieClipUser clip_user = *DNA_struct_default_get(MovieClipUser); int calibration_width, calibration_height; BKE_movieclip_user_set_frame(&clip_user, framenumber_); diff --git a/source/blender/compositor/operations/COM_PlaneTrackOperation.cc b/source/blender/compositor/operations/COM_PlaneTrackOperation.cc index 28da200c615..cb73fa9af7b 100644 --- a/source/blender/compositor/operations/COM_PlaneTrackOperation.cc +++ b/source/blender/compositor/operations/COM_PlaneTrackOperation.cc @@ -18,6 +18,8 @@ #include "COM_PlaneTrackOperation.h" +#include "DNA_defaults.h" + #include "BKE_movieclip.h" #include "BKE_tracking.h" @@ -80,7 +82,7 @@ void PlaneTrackCommon::determine_canvas(const rcti &preferred_area, rcti &r_area r_area = COM_AREA_NONE; if (movie_clip_) { int width, height; - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); BKE_movieclip_user_set_frame(&user, framenumber_); BKE_movieclip_get_size(movie_clip_, &user, &width, &height); r_area = preferred_area; diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.cc b/source/blender/compositor/operations/COM_TrackPositionOperation.cc index fc6be97a29c..61ce750a2f4 100644 --- a/source/blender/compositor/operations/COM_TrackPositionOperation.cc +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cc @@ -18,6 +18,8 @@ #include "COM_TrackPositionOperation.h" +#include "DNA_defaults.h" + #include "BKE_movieclip.h" #include "BKE_node.h" #include "BKE_tracking.h" @@ -50,7 +52,7 @@ void TrackPositionOperation::calc_track_position() { is_track_position_calculated_ = true; MovieTracking *tracking = nullptr; - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); MovieTrackingObject *object; track_position_ = 0; diff --git a/source/blender/editors/space_clip/CMakeLists.txt b/source/blender/editors/space_clip/CMakeLists.txt index 8c7f59d61dd..06179ffdd95 100644 --- a/source/blender/editors/space_clip/CMakeLists.txt +++ b/source/blender/editors/space_clip/CMakeLists.txt @@ -31,6 +31,9 @@ set(INC ../../windowmanager ../../../../intern/glew-mx ../../../../intern/guardedalloc + + # dna_type_offsets.h + ${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern ) set(SRC diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 09daed7e2e7..d22e4864ecf 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -34,6 +34,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_defaults.h" #include "DNA_mask_types.h" #include "BLI_fileops.h" @@ -686,7 +687,7 @@ static bool check_prefetch_break(void) static uchar *prefetch_read_file_to_memory( MovieClip *clip, int current_frame, short render_size, short render_flag, size_t *r_size) { - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); user.framenr = current_frame; user.render_size = render_size; user.render_flag = render_flag; @@ -733,7 +734,7 @@ static int prefetch_find_uncached_frame(MovieClip *clip, short direction) { int current_frame; - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); user.render_size = render_size; user.render_flag = render_flag; @@ -833,7 +834,7 @@ static void prefetch_task_func(TaskPool *__restrict pool, void *task_data) while ((mem = prefetch_thread_next_frame(queue, clip, &size, ¤t_frame))) { ImBuf *ibuf; - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); int flag = IB_rect | IB_multilayer | IB_alphamode_detect | IB_metadata; int result; char *colorspace_name = NULL; @@ -915,7 +916,7 @@ static bool prefetch_movie_frame(MovieClip *clip, short render_flag, short *stop) { - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); if (check_prefetch_break() || *stop) { return false; diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 0aa7e35aed6..ef522e57d02 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -33,6 +33,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_defaults.h" #include "DNA_scene_types.h" /* min/max frames */ #include "DNA_userdef_types.h" @@ -1321,7 +1322,7 @@ static uchar *proxy_thread_next_frame(ProxyQueue *queue, BLI_spin_lock(&queue->spin); if (!*queue->stop && queue->cfra <= queue->efra) { - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); char name[FILE_MAX]; size_t size; int file; diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index 847cba32c69..b6dbda79a2d 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -24,6 +24,8 @@ #include #include +#include "DNA_defaults.h" + #include "DNA_mask_types.h" #include "DNA_movieclip_types.h" #include "DNA_scene_types.h" @@ -239,14 +241,7 @@ static SpaceLink *clip_create(const ScrArea *area, const Scene *scene) ARegion *region; SpaceClip *sc; - sc = MEM_callocN(sizeof(SpaceClip), "initclip"); - sc->spacetype = SPACE_CLIP; - sc->flag = SC_SHOW_MARKER_PATTERN | SC_SHOW_TRACK_PATH | SC_SHOW_GRAPH_TRACKS_MOTION | - SC_SHOW_GRAPH_FRAMES | SC_SHOW_ANNOTATION; - sc->zoom = 1.0f; - sc->path_length = 20; - sc->scopes.track_preview_height = 120; - sc->around = V3D_AROUND_CENTER_MEDIAN; + sc = DNA_struct_default_alloc(SpaceClip); /* header */ region = MEM_callocN(sizeof(ARegion), "header for clip"); diff --git a/source/blender/makesdna/DNA_defaults.h b/source/blender/makesdna/DNA_defaults.h index 6e986129143..ef7f573e7a8 100644 --- a/source/blender/makesdna/DNA_defaults.h +++ b/source/blender/makesdna/DNA_defaults.h @@ -48,7 +48,9 @@ uint8_t *_DNA_struct_default_alloc_impl(const uint8_t *data_src, #define DNA_struct_default_alloc(struct_name) \ (struct_name *)_DNA_struct_default_alloc_impl( \ - DNA_default_table[SDNA_TYPE_FROM_STRUCT(struct_name)], sizeof(struct_name), __func__) + (const uint8_t *)DNA_default_table[SDNA_TYPE_FROM_STRUCT(struct_name)], \ + sizeof(struct_name), \ + __func__) #ifdef __cplusplus } diff --git a/source/blender/makesdna/DNA_movieclip_defaults.h b/source/blender/makesdna/DNA_movieclip_defaults.h index 753147eb072..e9013b08d79 100644 --- a/source/blender/makesdna/DNA_movieclip_defaults.h +++ b/source/blender/makesdna/DNA_movieclip_defaults.h @@ -45,6 +45,34 @@ .frame_offset = 0, \ } +#define _DNA_DEFAULT_MovieClipUser \ + { \ + .framenr = 1, \ + .render_size = MCLIP_PROXY_RENDER_SIZE_FULL, \ + .render_flag = 0, \ + } + +#define _DNA_DEFAULT_MovieClipScopes \ + { \ + .ok = 0, \ + .use_track_mask = 0, \ + .track_preview_height = 120, \ + .frame_width = 0, \ + .frame_height = 0, \ + .undist_marker = _DNA_DEFAULT_MovieTrackingMarker, \ + .track_pos = {0, 0}, \ + .track_disabled = 0, \ + .track_locked = 0, \ + .scene_framenr = 0, \ + .slide_scale = {0.0f, 0.0f}, \ + } + +/* initialise as all zeros */ +#define _DNA_DEFAULT_MovieTrackingMarker \ + { \ + 0, \ + } + /** \} */ /* clang-format on */ diff --git a/source/blender/makesdna/DNA_space_defaults.h b/source/blender/makesdna/DNA_space_defaults.h new file mode 100644 index 00000000000..94577adc0d1 --- /dev/null +++ b/source/blender/makesdna/DNA_space_defaults.h @@ -0,0 +1,67 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup DNA + */ + +#pragma once + +/* Struct members on own line. */ +/* clang-format off */ + +/* -------------------------------------------------------------------- */ +/** \name Spaceclip Struct + * \{ */ + +#define _DNA_DEFAULT_MaskSpaceInfo \ + { \ + .draw_flag = 0, \ + .draw_type = MASK_DT_OUTLINE, \ + .overlay_mode = MASK_OVERLAY_ALPHACHANNEL, \ + } + +#define _DNA_DEFAULT_SpaceClip \ + { \ + .spacetype = SPACE_CLIP, \ + .link_flag = 0, \ + .xof = 0, \ + .yof = 0, \ + .xlockof = 0, \ + .ylockof = 0, \ + .zoom = 1.0f, \ + .user = _DNA_DEFAULT_MovieClipUser, \ + .scopes = _DNA_DEFAULT_MovieClipScopes, \ + .flag = SC_SHOW_MARKER_PATTERN | SC_SHOW_TRACK_PATH | SC_SHOW_GRAPH_TRACKS_MOTION | \ + SC_SHOW_GRAPH_FRAMES | SC_SHOW_ANNOTATION, \ + .mode = SC_MODE_TRACKING, \ + .view = SC_VIEW_CLIP, \ + .path_length = 20, \ + .loc = {0, 0}, \ + .scale = 0, \ + .angle = 0, \ + .stabmat = _DNA_DEFAULT_UNIT_M4, \ + .unistabmat = _DNA_DEFAULT_UNIT_M4, \ + .postproc_flag = 0, \ + .gpencil_src = SC_GPENCIL_SRC_CLIP, \ + .around = V3D_AROUND_CENTER_MEDIAN, \ + .cursor = {0, 0}, \ + .mask_info = _DNA_DEFAULT_MaskSpaceInfo, \ + } + +/** \} */ + +/* clang-format on */ diff --git a/source/blender/makesdna/intern/CMakeLists.txt b/source/blender/makesdna/intern/CMakeLists.txt index db34cf83fa9..a3c54e91780 100644 --- a/source/blender/makesdna/intern/CMakeLists.txt +++ b/source/blender/makesdna/intern/CMakeLists.txt @@ -159,6 +159,7 @@ set(SRC ../DNA_pointcloud_defaults.h ../DNA_scene_defaults.h ../DNA_simulation_defaults.h + ../DNA_space_defaults.h ../DNA_speaker_defaults.h ../DNA_texture_defaults.h ../DNA_vec_defaults.h diff --git a/source/blender/makesdna/intern/dna_defaults.c b/source/blender/makesdna/intern/dna_defaults.c index 1d4257328a4..cc060e1241c 100644 --- a/source/blender/makesdna/intern/dna_defaults.c +++ b/source/blender/makesdna/intern/dna_defaults.c @@ -103,6 +103,7 @@ #include "DNA_light_types.h" #include "DNA_lightprobe_types.h" #include "DNA_linestyle_types.h" +#include "DNA_mask_types.h" #include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_meta_types.h" @@ -144,6 +145,7 @@ #include "DNA_pointcloud_defaults.h" #include "DNA_scene_defaults.h" #include "DNA_simulation_defaults.h" +#include "DNA_space_defaults.h" #include "DNA_speaker_defaults.h" #include "DNA_texture_defaults.h" #include "DNA_volume_defaults.h" @@ -208,6 +210,9 @@ SDNA_DEFAULT_DECL_STRUCT(MetaBall); /* DNA_movieclip_defaults.h */ SDNA_DEFAULT_DECL_STRUCT(MovieClip); +SDNA_DEFAULT_DECL_STRUCT(MovieClipUser); +SDNA_DEFAULT_DECL_STRUCT(MovieClipScopes); +SDNA_DEFAULT_DECL_STRUCT(MovieTrackingMarker); /* DNA_object_defaults.h */ SDNA_DEFAULT_DECL_STRUCT(Object); @@ -225,6 +230,10 @@ SDNA_DEFAULT_DECL_STRUCT(ToolSettings); /* DNA_simulation_defaults.h */ SDNA_DEFAULT_DECL_STRUCT(Simulation); +/* DNA_space_defaults.h */ +SDNA_DEFAULT_DECL_STRUCT(MaskSpaceInfo); +SDNA_DEFAULT_DECL_STRUCT(SpaceClip); + /* DNA_speaker_defaults.h */ SDNA_DEFAULT_DECL_STRUCT(Speaker); @@ -406,11 +415,18 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = { /* DNA_mesh_defaults.h */ SDNA_DEFAULT_DECL(Mesh), + /* DNA_space_defaults.h */ + SDNA_DEFAULT_DECL(SpaceClip), + SDNA_DEFAULT_DECL_EX(MaskSpaceInfo, SpaceClip.mask_info), + SDNA_DEFAULT_DECL_EX(MovieClipUser, SpaceClip.user), + SDNA_DEFAULT_DECL_EX(MovieClipScopes, SpaceClip.scopes), + /* DNA_meta_defaults.h */ SDNA_DEFAULT_DECL(MetaBall), /* DNA_movieclip_defaults.h */ SDNA_DEFAULT_DECL(MovieClip), + SDNA_DEFAULT_DECL_EX(MovieTrackingMarker, MovieClipScopes.undist_marker), /* DNA_object_defaults.h */ SDNA_DEFAULT_DECL(Object), diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 7e6d0aea2ee..f057d8e9d4c 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -203,6 +203,9 @@ set(INC ../../blenloader ${CMAKE_BINARY_DIR}/source/blender/makesdna/intern + + # dna_type_offsets.h + ${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern ) set(INC_SYS diff --git a/source/blender/makesrna/intern/rna_mask.c b/source/blender/makesrna/intern/rna_mask.c index 9c90c209389..21bacf2e6be 100644 --- a/source/blender/makesrna/intern/rna_mask.c +++ b/source/blender/makesrna/intern/rna_mask.c @@ -23,6 +23,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_defaults.h" #include "DNA_mask_types.h" #include "DNA_object_types.h" /* SELECT */ #include "DNA_scene_types.h" @@ -84,7 +85,7 @@ static void rna_Mask_update_parent(Main *bmain, Scene *scene, PointerRNA *ptr) if (track) { MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_framenr); float marker_pos_ofs[2], parmask_pos[2]; - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); BKE_movieclip_user_set_frame(&user, scene->r.cfra); diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c index 03f4acdae79..2d4d5ee766f 100644 --- a/source/blender/makesrna/intern/rna_tracking.c +++ b/source/blender/makesrna/intern/rna_tracking.c @@ -32,6 +32,7 @@ #include "rna_internal.h" +#include "DNA_defaults.h" #include "DNA_movieclip_types.h" #include "DNA_object_types.h" /* SELECT */ #include "DNA_scene_types.h" @@ -609,7 +610,7 @@ static MovieTrackingTrack *add_track_to_base( MovieClip *clip, MovieTracking *tracking, ListBase *tracksbase, const char *name, int frame) { int width, height; - MovieClipUser user = {0}; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); MovieTrackingTrack *track; user.framenr = 1; diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index f965302be5e..957c5b78342 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -48,6 +48,9 @@ set(INC ../windowmanager ../../../intern/glew-mx ../../../intern/guardedalloc + + # dna_type_offsets.h + ${CMAKE_CURRENT_BINARY_DIR}/../makesdna/intern ) diff --git a/source/blender/nodes/composite/CMakeLists.txt b/source/blender/nodes/composite/CMakeLists.txt index c2d9c8a71bb..0374f913d4b 100644 --- a/source/blender/nodes/composite/CMakeLists.txt +++ b/source/blender/nodes/composite/CMakeLists.txt @@ -33,6 +33,9 @@ set(INC ../../render ../../windowmanager ../../../../intern/guardedalloc + + # dna_type_offsets.h + ${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern ) diff --git a/source/blender/nodes/composite/nodes/node_composite_movieclip.cc b/source/blender/nodes/composite/nodes/node_composite_movieclip.cc index 94f32ae8db4..f6f00864839 100644 --- a/source/blender/nodes/composite/nodes/node_composite_movieclip.cc +++ b/source/blender/nodes/composite/nodes/node_composite_movieclip.cc @@ -23,6 +23,7 @@ #include "BKE_context.h" #include "BKE_lib_id.h" +#include "DNA_defaults.h" #include "RNA_access.h" @@ -47,7 +48,7 @@ static void init(const bContext *C, PointerRNA *ptr) { bNode *node = (bNode *)ptr->data; Scene *scene = CTX_data_scene(C); - MovieClipUser *user = MEM_cnew(__func__); + MovieClipUser *user = DNA_struct_default_alloc(MovieClipUser); node->id = (ID *)scene->clip; id_us_plus(node->id); diff --git a/source/blender/sequencer/intern/render.c b/source/blender/sequencer/intern/render.c index 9f4e07820fa..482425e70d3 100644 --- a/source/blender/sequencer/intern/render.c +++ b/source/blender/sequencer/intern/render.c @@ -29,6 +29,7 @@ #include "MEM_guardedalloc.h" #include "DNA_anim_types.h" +#include "DNA_defaults.h" #include "DNA_mask_types.h" #include "DNA_scene_types.h" #include "DNA_sequence_types.h" @@ -1188,15 +1189,13 @@ static ImBuf *seq_render_movieclip_strip(const SeqRenderData *context, bool *r_is_proxy_image) { ImBuf *ibuf = NULL; - MovieClipUser user; + MovieClipUser user = *DNA_struct_default_get(MovieClipUser); IMB_Proxy_Size psize = SEQ_rendersize_to_proxysize(context->preview_render_size); if (!seq->clip) { return NULL; } - memset(&user, 0, sizeof(MovieClipUser)); - BKE_movieclip_user_set_frame(&user, frame_index + seq->anim_startofs + seq->clip->start_frame); user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL; -- cgit v1.2.3 From a72a9e099c7a7d2bc74830c42d37dd3a46d26f45 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 12 Jan 2022 18:35:37 +0100 Subject: Cleanup: Correct indentation --- source/blender/makesdna/DNA_space_defaults.h | 48 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesdna/DNA_space_defaults.h b/source/blender/makesdna/DNA_space_defaults.h index 94577adc0d1..8b5c6dc1de5 100644 --- a/source/blender/makesdna/DNA_space_defaults.h +++ b/source/blender/makesdna/DNA_space_defaults.h @@ -36,30 +36,30 @@ #define _DNA_DEFAULT_SpaceClip \ { \ - .spacetype = SPACE_CLIP, \ - .link_flag = 0, \ - .xof = 0, \ - .yof = 0, \ - .xlockof = 0, \ - .ylockof = 0, \ - .zoom = 1.0f, \ - .user = _DNA_DEFAULT_MovieClipUser, \ - .scopes = _DNA_DEFAULT_MovieClipScopes, \ - .flag = SC_SHOW_MARKER_PATTERN | SC_SHOW_TRACK_PATH | SC_SHOW_GRAPH_TRACKS_MOTION | \ - SC_SHOW_GRAPH_FRAMES | SC_SHOW_ANNOTATION, \ - .mode = SC_MODE_TRACKING, \ - .view = SC_VIEW_CLIP, \ - .path_length = 20, \ - .loc = {0, 0}, \ - .scale = 0, \ - .angle = 0, \ - .stabmat = _DNA_DEFAULT_UNIT_M4, \ - .unistabmat = _DNA_DEFAULT_UNIT_M4, \ - .postproc_flag = 0, \ - .gpencil_src = SC_GPENCIL_SRC_CLIP, \ - .around = V3D_AROUND_CENTER_MEDIAN, \ - .cursor = {0, 0}, \ - .mask_info = _DNA_DEFAULT_MaskSpaceInfo, \ + .spacetype = SPACE_CLIP, \ + .link_flag = 0, \ + .xof = 0, \ + .yof = 0, \ + .xlockof = 0, \ + .ylockof = 0, \ + .zoom = 1.0f, \ + .user = _DNA_DEFAULT_MovieClipUser, \ + .scopes = _DNA_DEFAULT_MovieClipScopes, \ + .flag = SC_SHOW_MARKER_PATTERN | SC_SHOW_TRACK_PATH | SC_SHOW_GRAPH_TRACKS_MOTION | \ + SC_SHOW_GRAPH_FRAMES | SC_SHOW_ANNOTATION, \ + .mode = SC_MODE_TRACKING, \ + .view = SC_VIEW_CLIP, \ + .path_length = 20, \ + .loc = {0, 0}, \ + .scale = 0, \ + .angle = 0, \ + .stabmat = _DNA_DEFAULT_UNIT_M4, \ + .unistabmat = _DNA_DEFAULT_UNIT_M4, \ + .postproc_flag = 0, \ + .gpencil_src = SC_GPENCIL_SRC_CLIP, \ + .around = V3D_AROUND_CENTER_MEDIAN, \ + .cursor = {0, 0}, \ + .mask_info = _DNA_DEFAULT_MaskSpaceInfo, \ } /** \} */ -- cgit v1.2.3 From a0dcd0bf2c6952595c871197757bf9878c0c1914 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 12 Jan 2022 18:36:37 +0100 Subject: Fix warnings after bab47b60cb69 It's not really clear how this part of the defaults code should be used, I think this is fine now and solves the warnings. --- source/blender/makesdna/intern/dna_defaults.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesdna/intern/dna_defaults.c b/source/blender/makesdna/intern/dna_defaults.c index cc060e1241c..5bc5de7a20b 100644 --- a/source/blender/makesdna/intern/dna_defaults.c +++ b/source/blender/makesdna/intern/dna_defaults.c @@ -212,7 +212,6 @@ SDNA_DEFAULT_DECL_STRUCT(MetaBall); SDNA_DEFAULT_DECL_STRUCT(MovieClip); SDNA_DEFAULT_DECL_STRUCT(MovieClipUser); SDNA_DEFAULT_DECL_STRUCT(MovieClipScopes); -SDNA_DEFAULT_DECL_STRUCT(MovieTrackingMarker); /* DNA_object_defaults.h */ SDNA_DEFAULT_DECL_STRUCT(Object); @@ -231,7 +230,6 @@ SDNA_DEFAULT_DECL_STRUCT(ToolSettings); SDNA_DEFAULT_DECL_STRUCT(Simulation); /* DNA_space_defaults.h */ -SDNA_DEFAULT_DECL_STRUCT(MaskSpaceInfo); SDNA_DEFAULT_DECL_STRUCT(SpaceClip); /* DNA_speaker_defaults.h */ @@ -418,14 +416,14 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = { /* DNA_space_defaults.h */ SDNA_DEFAULT_DECL(SpaceClip), SDNA_DEFAULT_DECL_EX(MaskSpaceInfo, SpaceClip.mask_info), - SDNA_DEFAULT_DECL_EX(MovieClipUser, SpaceClip.user), - SDNA_DEFAULT_DECL_EX(MovieClipScopes, SpaceClip.scopes), /* DNA_meta_defaults.h */ SDNA_DEFAULT_DECL(MetaBall), /* DNA_movieclip_defaults.h */ SDNA_DEFAULT_DECL(MovieClip), + SDNA_DEFAULT_DECL(MovieClipUser), + SDNA_DEFAULT_DECL(MovieClipScopes), SDNA_DEFAULT_DECL_EX(MovieTrackingMarker, MovieClipScopes.undist_marker), /* DNA_object_defaults.h */ -- cgit v1.2.3 From fa8c2c78857989c23262915921722cf69399d58d Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 12 Jan 2022 09:41:46 -0800 Subject: Fix T94071: Area Split Improvements Allow area Split to be initiated in any area and give better feedback when not allowed. See D13599 for more details and usage examples. Differential Revision: https://developer.blender.org/D13599 Reviewed by Campbell Barton --- source/blender/editors/screen/screen_ops.c | 51 ++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index b9c92c1664d..757b1a4c0c4 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -2083,15 +2083,31 @@ typedef struct sAreaSplitData { } sAreaSplitData; +static bool area_split_allowed(const ScrArea *area, const eScreenAxis dir_axis) +{ + if (!area || area->global) { + /* Must be a non-global area. */ + return false; + } + + if ((dir_axis == SCREEN_AXIS_V && area->winx <= 2 * AREAMINX) || + (dir_axis == SCREEN_AXIS_H && area->winy <= 2 * ED_area_headersize())) { + /* Must be at least double minimum sizes to split into two. */ + return false; + } + + return true; +} + static void area_split_draw_cb(const struct wmWindow *UNUSED(win), void *userdata) { const wmOperator *op = userdata; sAreaSplitData *sd = op->customdata; - if (sd->sarea) { - const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction"); - float fac = RNA_float_get(op->ptr, "factor"); + const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction"); + if (area_split_allowed(sd->sarea, dir_axis)) { + float fac = RNA_float_get(op->ptr, "factor"); screen_draw_split_preview(sd->sarea, dir_axis, fac); } } @@ -2121,18 +2137,6 @@ static bool area_split_init(bContext *C, wmOperator *op) /* required properties */ const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction"); - /* minimal size */ - if (dir_axis == SCREEN_AXIS_V) { - if (area->winx < 2 * AREAMINX) { - return false; - } - } - else { - if (area->winy < 2 * ED_area_headersize()) { - return false; - } - } - /* custom data */ sAreaSplitData *sd = (sAreaSplitData *)MEM_callocN(sizeof(sAreaSplitData), "op_area_split"); op->customdata = sd; @@ -2189,6 +2193,10 @@ static bool area_split_apply(bContext *C, wmOperator *op) float fac = RNA_float_get(op->ptr, "factor"); const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction"); + if (!area_split_allowed(sd->sarea, dir_axis)) { + return false; + } + sd->narea = area_split(win, screen, sd->sarea, dir_axis, fac, false); /* false = no merge */ if (sd->narea == NULL) { @@ -2254,9 +2262,15 @@ static void area_split_exit(bContext *C, wmOperator *op) static void area_split_preview_update_cursor(bContext *C, wmOperator *op) { - wmWindow *win = CTX_wm_window(C); + sAreaSplitData *sd = (sAreaSplitData *)op->customdata; const eScreenAxis dir_axis = RNA_enum_get(op->ptr, "direction"); - WM_cursor_set(win, (dir_axis == SCREEN_AXIS_H) ? WM_CURSOR_H_SPLIT : WM_CURSOR_V_SPLIT); + if (area_split_allowed(sd->sarea, dir_axis)) { + WM_cursor_set(CTX_wm_window(C), + (dir_axis == SCREEN_AXIS_H) ? WM_CURSOR_H_SPLIT : WM_CURSOR_V_SPLIT); + } + else { + WM_cursor_set(CTX_wm_window(C), WM_CURSOR_STOP); + } } /* UI callback, adds new handler */ @@ -2509,6 +2523,9 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event) if (sd->sarea) { ED_area_tag_redraw(sd->sarea); } + + area_split_preview_update_cursor(C, op); + /* area context not set */ sd->sarea = BKE_screen_find_area_xy(CTX_wm_screen(C), SPACE_TYPE_ANY, event->xy); -- cgit v1.2.3 From a311fa96aa428b611bc07c4d7f8a002dd3e6b462 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 12 Jan 2022 10:37:52 -0800 Subject: Fix T85706: wm_window_make_drawable update DPI When drawing windows on monitors that differ in DPI, we can sometimes have UI elements draw at an incorrect scale. This patch just ensures that `wm_window_make_drawable` always updates DPI. See D10483 for more details. Differential Revision: https://developer.blender.org/D10483 Reviewed by Brecht Van Lommel --- source/blender/windowmanager/intern/wm_window.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 29c9f53f735..a1854a8ed86 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -1033,7 +1033,9 @@ void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win) } wm_window_set_drawable(wm, win, true); + } + if (win->ghostwin) { /* this can change per window */ WM_window_set_dpi(win); } -- cgit v1.2.3 From 97c2c39916202f8d3d8e1f651ab9dfa171953af2 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 12 Jan 2022 13:46:13 -0600 Subject: Fix T94624: Object as font instances don't work The fundamental limitation is that we can only have one instance ("dupli") generator at a time. Because the mesh output of a curve object is output as an instances, the geometry set instances existed, replacing the object as font instances. The "fix" is to reverse the order. The behavior won't be perfect still, but at least the old behavior will be preserved, which is really what matters for a feature like this. One way to take this change further would be completely disabling regular geometry evaluation while this option is active. However, it doesn't seem like that would actually improve the state of the code. Differential Revision: https://developer.blender.org/D13768 --- source/blender/blenkernel/intern/object_dupli.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc index 20fdda8bdc7..05b20a6879c 100644 --- a/source/blender/blenkernel/intern/object_dupli.cc +++ b/source/blender/blenkernel/intern/object_dupli.cc @@ -1650,6 +1650,14 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx) return nullptr; } + /* Give "Object as Font" instances higher priority than geometry set instances, to retain + * the behavior from before curve object meshes were processed as instances internally. */ + if (transflag & OB_DUPLIVERTS) { + if (ctx->object->type == OB_FONT) { + return &gen_dupli_verts_font; + } + } + if (ctx->object->runtime.geometry_set_eval != nullptr) { if (BKE_object_has_geometry_set_instances(ctx->object)) { return &gen_dupli_geometry_set; @@ -1663,9 +1671,6 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx) if (ctx->object->type == OB_MESH) { return &gen_dupli_verts; } - if (ctx->object->type == OB_FONT) { - return &gen_dupli_verts_font; - } if (ctx->object->type == OB_POINTCLOUD) { return &gen_dupli_verts_pointcloud; } -- cgit v1.2.3