2-Pt Persp. select: Avoid div-by-zero crash
h/t Pere
This commit is contained in:
parent
4496e007a1
commit
f8c8b9b6a7
2 changed files with 27 additions and 19 deletions
|
|
@ -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/)
|
||||||
|
|
|
||||||
|
|
@ -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,32 +1528,38 @@ void n_pt_persp_draw_points(magic_api * api, int tool, SDL_Surface * canvas) {
|
||||||
x2 = 0;
|
x2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
slope = ((float) a1_pt_y - (float) y1) / ((float) a1_pt_x - (float) x1);
|
if (a1_pt_x != x1) {
|
||||||
y2 = y1 + (x2 - x1) * slope;
|
slope = ((float) a1_pt_y - (float) y1) / ((float) a1_pt_x - (float) x1);
|
||||||
|
y2 = y1 + (x2 - x1) * slope;
|
||||||
|
|
||||||
api->line((void *) api, tool, canvas, NULL,
|
api->line((void *) api, tool, canvas, NULL,
|
||||||
x1, y1, x2, y2, 6,
|
x1, y1, x2, y2, 6,
|
||||||
n_pt_persp_line_xor_callback);
|
n_pt_persp_line_xor_callback);
|
||||||
|
|
||||||
/* Some vertical lines between the diagonals */
|
/* Some vertical lines between the diagonals */
|
||||||
if (l == 0) {
|
if (l == 0) {
|
||||||
for (m = 0; m < 8; m++) {
|
for (m = 0; m < 8; m++) {
|
||||||
int xx, yy1, yy2;
|
int xx, yy1, yy2;
|
||||||
int m_scale[8] = {-8,-4,-2,-1,1,2,4,8};
|
int m_scale[8] = {-8,-4,-2,-1,1,2,4,8};
|
||||||
|
|
||||||
xx = a1_pt_x + ((float) (canvas->w / 10) * (float) m_scale[m]);
|
xx = a1_pt_x + ((float) (canvas->w / 10) * (float) m_scale[m]);
|
||||||
yy1 = a1_pt_y + (a1_pt_x - xx) * slope;
|
yy1 = a1_pt_y + (a1_pt_x - xx) * slope;
|
||||||
yy2 = a1_pt_y + (xx - a1_pt_x) * slope;
|
yy2 = a1_pt_y + (xx - a1_pt_x) * slope;
|
||||||
|
|
||||||
api->line((void *) api, tool, canvas, NULL,
|
api->line((void *) api, tool, canvas, NULL,
|
||||||
xx, yy1, xx, yy2, 3,
|
xx, yy1, xx, yy2, 3,
|
||||||
n_pt_persp_line_xor_callback);
|
n_pt_persp_line_xor_callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue