Shape tool calculations: use floats more
This commit is contained in:
parent
649cde39ed
commit
58bb30bafc
2 changed files with 45 additions and 41 deletions
|
|
@ -6,11 +6,13 @@ Copyright (c) 2002-2023
|
||||||
Various contributors (see below, and AUTHORS.txt)
|
Various contributors (see below, and AUTHORS.txt)
|
||||||
https://tuxpaint.org/
|
https://tuxpaint.org/
|
||||||
|
|
||||||
2023.April.8 (0.9.30)
|
2023.April.9 (0.9.30)
|
||||||
* Improvements to Shape tool:
|
* Improvements to Shape tool:
|
||||||
---------------------------
|
---------------------------
|
||||||
* Octagon allows aspect ratio change
|
* Octagon allows aspect ratio change
|
||||||
|
|
||||||
|
* Slight improvement to shape calculations
|
||||||
|
|
||||||
* Localization Updates:
|
* Localization Updates:
|
||||||
---------------------
|
---------------------
|
||||||
* Chinese (Simplified) translation
|
* Chinese (Simplified) translation
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
|
|
||||||
June 14, 2002 - March 21, 2023
|
June 14, 2002 - April 9, 2023
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
@ -16066,7 +16066,8 @@ static void free_surface_array(SDL_Surface * surface_array[], int count)
|
||||||
/* Draw a shape! */
|
/* Draw a shape! */
|
||||||
static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
|
static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
|
||||||
{
|
{
|
||||||
int side, rx, ry, rmax, x1, y1, x2, y2, xp, yp, xv, yv, old_brush, step;
|
int side, rx, ry, rmax, old_brush, step;
|
||||||
|
float x1, y1, x2, y2, xp, yp, xv, yv;
|
||||||
float a1, a2, rotn_rad, init_ang, angle_skip;
|
float a1, a2, rotn_rad, init_ang, angle_skip;
|
||||||
int xx, yy, offx, offy, max_x, max_y;
|
int xx, yy, offx, offy, max_x, max_y;
|
||||||
|
|
||||||
|
|
@ -16144,19 +16145,19 @@ static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
|
||||||
{
|
{
|
||||||
a1 = (angle_skip * side + init_ang) * M_PI / 180.0;
|
a1 = (angle_skip * side + init_ang) * M_PI / 180.0;
|
||||||
a2 = (angle_skip * (side + 1) + init_ang) * M_PI / 180.0;
|
a2 = (angle_skip * (side + 1) + init_ang) * M_PI / 180.0;
|
||||||
x1 = (int) (cos(a1) * rx);
|
x1 = (cos(a1) * (float) rx);
|
||||||
y1 = (int) (-sin(a1) * ry);
|
y1 = (-sin(a1) * (float) ry);
|
||||||
|
|
||||||
if (abs(x1) > max_x)
|
if (fabsf(x1) > max_x)
|
||||||
max_x = abs(x1);
|
max_x = fabsf(x1);
|
||||||
if (abs(y1) > max_y)
|
if (fabsf(y1) > max_y)
|
||||||
max_y = abs(y1);
|
max_y = fabsf(y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_x < rx)
|
if (max_x < rx)
|
||||||
rx = (rx * rx) / max_x;
|
rx = (rx * rx) / (int) max_x;
|
||||||
if (max_y < ry)
|
if (max_y < ry)
|
||||||
ry = (ry * ry) / max_y;
|
ry = (ry * ry) / (int) max_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -16204,23 +16205,30 @@ static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
|
||||||
|
|
||||||
for (side = 0; side < shape_sides[cur_shape]; side = side + step)
|
for (side = 0; side < shape_sides[cur_shape]; side = side + step)
|
||||||
{
|
{
|
||||||
a1 = (angle_skip * side + init_ang) * M_PI / 180;
|
a1 = (angle_skip * (float) side + init_ang) * M_PI / 180.0;
|
||||||
a2 = (angle_skip * (side + 1) + init_ang) * M_PI / 180;
|
|
||||||
|
|
||||||
x1 = (int) (cos(a1) * rx);
|
x1 = (cos(a1) * (float) rx);
|
||||||
y1 = (int) (-sin(a1) * ry);
|
y1 = (-sin(a1) * (float) ry);
|
||||||
|
|
||||||
x2 = (int) (cos(a2) * rx);
|
if (side < shape_sides[cur_shape] - step) {
|
||||||
y2 = (int) (-sin(a2) * ry);
|
a2 = (angle_skip * ((float) side + 1.0) + init_ang) * M_PI / 180.0;
|
||||||
|
} else {
|
||||||
|
a2 = init_ang * M_PI / 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
xv = (int) (cos((a1 + a2) / 2) * rx * shape_valley[cur_shape] / 100);
|
x2 = (cos(a2) * (float) rx);
|
||||||
yv = (int) (-sin((a1 + a2) / 2) * ry * shape_valley[cur_shape] / 100);
|
y2 = (-sin(a2) * (float) ry);
|
||||||
|
|
||||||
|
printf("side=%d, a1=%f, a2=%f -- (%f,%f) -> (%f,%f)\n", side, a1, a2, x1, y1, x2, y2);
|
||||||
|
|
||||||
|
xv = (cos((a1 + a2) / 2.0) * (float) rx * (float) shape_valley[cur_shape]) / 100.0;
|
||||||
|
yv = (-sin((a1 + a2) / 2.0) * (float) ry * (float) shape_valley[cur_shape]) / 100.0;
|
||||||
|
|
||||||
/* Rotate the line: */
|
/* Rotate the line: */
|
||||||
|
|
||||||
if (rotn != 0)
|
if (rotn != 0)
|
||||||
{
|
{
|
||||||
rotn_rad = rotn * M_PI / 180;
|
rotn_rad = rotn * M_PI / 180.0;
|
||||||
|
|
||||||
if (shape_mode == SHAPEMODE_CENTER) {
|
if (shape_mode == SHAPEMODE_CENTER) {
|
||||||
xp = (x1 + offx) * cos(rotn_rad) - (y1 + offy) * sin(rotn_rad);
|
xp = (x1 + offx) * cos(rotn_rad) - (y1 + offy) * sin(rotn_rad);
|
||||||
|
|
@ -16286,12 +16294,10 @@ static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Brush */
|
||||||
if (shape_valley[cur_shape] == 100)
|
if (shape_valley[cur_shape] == 100)
|
||||||
/* Brush */
|
|
||||||
|
|
||||||
brush_draw(x1, y1, x2, y2, 0);
|
brush_draw(x1, y1, x2, y2, 0);
|
||||||
else
|
else
|
||||||
/* Stars */
|
|
||||||
{
|
{
|
||||||
brush_draw(x1, y1, xv, yv, 0);
|
brush_draw(x1, y1, xv, yv, 0);
|
||||||
brush_draw(xv, yv, x2, y2, 0);
|
brush_draw(xv, yv, x2, y2, 0);
|
||||||
|
|
@ -16310,34 +16316,30 @@ static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
|
||||||
|
|
||||||
for (side = 0; side < shape_sides[cur_shape]; side++)
|
for (side = 0; side < shape_sides[cur_shape]; side++)
|
||||||
{
|
{
|
||||||
a1 = (angle_skip * side + init_ang) * M_PI / 180;
|
a1 = (angle_skip * (float) side + init_ang) * M_PI / 180.0;
|
||||||
a2 = (angle_skip * (side + 1) + init_ang) * M_PI / 180;
|
a2 = (angle_skip * ((float) side + 1.0) + init_ang) * M_PI / 180.0;
|
||||||
|
|
||||||
if (yy == xx * ry / rx)
|
if (yy == xx * ry / rx)
|
||||||
{
|
{
|
||||||
x1 = (int) (cos(a1) * xx);
|
x1 = (cos(a1) * xx);
|
||||||
y1 = (int) (-sin(a1) * yy);
|
y1 = (-sin(a1) * yy);
|
||||||
|
|
||||||
x2 = (int) (cos(a2) * xx);
|
x2 = (cos(a2) * xx);
|
||||||
y2 = (int) (-sin(a2) * yy);
|
y2 = (-sin(a2) * yy);
|
||||||
|
|
||||||
xv =
|
xv = (cos((a1 + a2) / 2) * xx * shape_valley[cur_shape] / 100);
|
||||||
(int) (cos((a1 + a2) / 2) * xx * shape_valley[cur_shape] / 100);
|
yv = (-sin((a1 + a2) / 2) * yy * shape_valley[cur_shape] / 100);
|
||||||
yv =
|
|
||||||
(int) (-sin((a1 + a2) / 2) * yy * shape_valley[cur_shape] / 100);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
x1 = (int) (cos(a1) * yy);
|
x1 = (cos(a1) * yy);
|
||||||
y1 = (int) (-sin(a1) * xx);
|
y1 = (-sin(a1) * xx);
|
||||||
|
|
||||||
x2 = (int) (cos(a2) * yy);
|
x2 = (cos(a2) * yy);
|
||||||
y2 = (int) (-sin(a2) * xx);
|
y2 = (-sin(a2) * xx);
|
||||||
|
|
||||||
xv =
|
xv = (cos((a1 + a2) / 2) * yy * shape_valley[cur_shape] / 100);
|
||||||
(int) (cos((a1 + a2) / 2) * yy * shape_valley[cur_shape] / 100);
|
yv = (-sin((a1 + a2) / 2) * xx * shape_valley[cur_shape] / 100);
|
||||||
yv =
|
|
||||||
(int) (-sin((a1 + a2) / 2) * xx * shape_valley[cur_shape] / 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Rotate the line: */
|
/* Rotate the line: */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue