diff options
author | Campbell Barton <campbell@blender.org> | 2022-07-22 06:57:04 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-07-22 06:59:36 +0300 |
commit | 087f27a52f7857887e90754d87a7a73715ebc3fb (patch) | |
tree | 94940ebc70e5668049f03735474dd6502514cc17 /source/blender/bmesh | |
parent | 08c5d99e88ee3e9f807dfe69c188660eae347f31 (diff) |
Fix T87779: Asymmetric vertex positions in circles primitives
Add sin_cos_from_fraction which ensures each quadrant has matching
values when their sign is flipped.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/operators/bmo_primitive.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index 432c7590f3c..2ed0964d735 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -855,12 +855,12 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) /* one segment first */ for (a = 0; a <= tot; a++) { /* Going in this direction, then edge extruding, makes normals face outward */ - /* Calculate with doubles for higher precision, see: T87779. */ - const float phi = M_PI * ((double)a / (double)tot); + float sin_phi, cos_phi; + sin_cos_from_fraction(a, tot, &sin_phi, &cos_phi); vec[0] = 0.0; - vec[1] = rad * sinf(phi); - vec[2] = rad * cosf(phi); + vec[1] = rad * sin_phi; + vec[2] = rad * cos_phi; eve = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); BMO_vert_flag_enable(bm, eve, VERT_MARK); @@ -1262,11 +1262,9 @@ void bmo_create_circle_exec(BMesh *bm, BMOperator *op) for (a = 0; a < segs; a++) { /* Going this way ends up with normal(s) upward */ - - /* Calculate with doubles for higher precision, see: T87779. */ - const float phi = (2.0 * M_PI) * ((double)a / (double)segs); - vec[0] = -radius * sinf(phi); - vec[1] = radius * cosf(phi); + sin_cos_from_fraction(a, segs, &vec[0], &vec[1]); + vec[0] *= -radius; + vec[1] *= radius; vec[2] = 0.0f; mul_m4_v3(mat, vec); v1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); @@ -1394,15 +1392,17 @@ void bmo_create_cone_exec(BMesh *bm, BMOperator *op) for (int i = 0; i < segs; i++) { /* Calculate with doubles for higher precision, see: T87779. */ - const float phi = (2.0 * M_PI) * ((double)i / (double)segs); - vec[0] = rad1 * sinf(phi); - vec[1] = rad1 * cosf(phi); + float sin_phi, cos_phi; + sin_cos_from_fraction(i, segs, &sin_phi, &cos_phi); + + vec[0] = rad1 * sin_phi; + vec[1] = rad1 * cos_phi; vec[2] = -depth_half; mul_m4_v3(mat, vec); v1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); - vec[0] = rad2 * sinf(phi); - vec[1] = rad2 * cosf(phi); + vec[0] = rad2 * sin_phi; + vec[1] = rad2 * cos_phi; vec[2] = depth_half; mul_m4_v3(mat, vec); v2 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); |