2-Pt Persp. select: Avoid div-by-zero crash

h/t Pere
This commit is contained in:
Bill Kendrick 2024-01-20 15:05:46 -08:00
parent 4496e007a1
commit f8c8b9b6a7
2 changed files with 27 additions and 19 deletions

View file

@ -6,7 +6,7 @@ Copyright (c) 2002-2024
Various contributors (see below, and AUTHORS.txt)
https://tuxpaint.org/
2024.January.16 (0.9.32)
2024.January.20 (0.9.32)
* Improvements to Magic tools:
----------------------------
* Magic tool plugin API updates
@ -66,6 +66,7 @@ https://tuxpaint.org/
- Two "Oblqiue Draw" tools are provided, offering recedings axes
to both the right and the left.
+ Code: Bill Kendrick <bill@newbreedsoftware.com>
(with help from Pere Pujal i Carabantes <perepujal@gmail.com>)
+ Sounds:
- Select: "Gummibandloop_121.wav"
(https://freesound.org/people/von_Gardener/sounds/473829/)

View file

@ -15,8 +15,9 @@
axon. & oblique drawing modes.
by Bill Kendrick <bill@newbreedsoftware.com>
with help from Pere Pujal Carabantes
December 12, 2023 - January 16, 2024
December 12, 2023 - January 20, 2024
*/
#include <stdio.h>
@ -1527,6 +1528,7 @@ void n_pt_persp_draw_points(magic_api * api, int tool, SDL_Surface * canvas) {
x2 = 0;
}
if (a1_pt_x != x1) {
slope = ((float) a1_pt_y - (float) y1) / ((float) a1_pt_x - (float) x1);
y2 = y1 + (x2 - x1) * slope;
@ -1550,9 +1552,14 @@ void n_pt_persp_draw_points(magic_api * api, int tool, SDL_Surface * canvas) {
}
}
}
}
} else if (tool == TOOL_2PT_SELECT) {
/* 2-point perspective */
if (abs(a2_pt_x[0] - a2_pt_x[1]) < SNAP) {
a2_pt_x[1] = a2_pt_x[0] + SNAP;
}
for (i = 0; i < 2; i++) {
n_pt_persp_draw_one_point(api, canvas, a2_pt_x[i], a2_pt_y[i], i);
}
@ -1571,7 +1578,7 @@ void n_pt_persp_draw_points(magic_api * api, int tool, SDL_Surface * canvas) {
x = (a2_pt_x[0] + a2_pt_x[1]) / 2;
/* Perpendicular-to-horizon line */
if (slope == 0.0 || slope == M_PI) {
if (slope == 0.0 || slope == M_PI) { // FIXME: M_PI, really? -bjk 2024.01.20
x1 = x;
y1 = 0;
x2 = x;