1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-30 07:11:52 +02:00

sch2fig/dwg.c (rx, ry): avoid floating-point errors

Even small errors (i.e., one unit), can cause very visible changes in the
graphical output. Perhaps fig2dev is over-reacting at times.
This commit is contained in:
Werner Almesberger 2016-07-29 19:33:00 -03:00
parent d63d183198
commit 8721964568

View File

@ -14,7 +14,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <math.h>
#include <assert.h> #include <assert.h>
#include "util.h" #include "util.h"
@ -292,17 +291,37 @@ static int make_box(enum box_type box, int h, int *vx, int *vy)
static int rx(int x, int y, int rot) static int rx(int x, int y, int rot)
{ {
float a = rot / 180.0 * M_PI; switch (rot) {
case 0:
return x;
case 90:
return y;
case 180:
return -x;
case 270:
return -y;
default:
assert(0);
return cos(a) * x + sin(a) * y; }
} }
static int ry(int x, int y, int rot) static int ry(int x, int y, int rot)
{ {
float a = rot / 180.0 * M_PI; switch (rot) {
case 0:
return y;
case 90:
return -x;
case 180:
return -y;
case 270:
return x;
default:
assert(0);
return -sin(a) * x + cos(a) * y; }
} }