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

View file

@ -15,8 +15,9 @@
axon. & oblique drawing modes. axon. & oblique drawing modes.
by Bill Kendrick <bill@newbreedsoftware.com> 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> #include <stdio.h>
@ -1527,6 +1528,7 @@ void n_pt_persp_draw_points(magic_api * api, int tool, SDL_Surface * canvas) {
x2 = 0; x2 = 0;
} }
if (a1_pt_x != x1) {
slope = ((float) a1_pt_y - (float) y1) / ((float) a1_pt_x - (float) x1); slope = ((float) a1_pt_y - (float) y1) / ((float) a1_pt_x - (float) x1);
y2 = y1 + (x2 - x1) * slope; 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) { } else if (tool == TOOL_2PT_SELECT) {
/* 2-point perspective */ /* 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++) { for (i = 0; i < 2; i++) {
n_pt_persp_draw_one_point(api, canvas, a2_pt_x[i], a2_pt_y[i], 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; x = (a2_pt_x[0] + a2_pt_x[1]) / 2;
/* Perpendicular-to-horizon line */ /* 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; x1 = x;
y1 = 0; y1 = 0;
x2 = x; x2 = x;