[lib_netmap] -Fix: map_j2nets: call two-net postproc at the end of mapping a 2net...
[pcb-rnd-mirror.git] / work / gpstroke / pcb_draw.c
blob54ca9f3a020f3140e6685bc577aa3069bf570275
1 #include <stdlib.h>
2 #include <math.h>
3 #include "pcb_draw.h"
4 #include "c24lib/image/image.h"
6 static void draw_thick_line(image_t * dst, int x1, int y1, int x2, int y2, double vx, double vy, double nx, double ny, int th)
8 double x, y, ymin, ymax;
10 if (y1 <= y2) {
11 ymin = y1;
12 ymax = y2;
14 else {
15 ymin = y2;
16 ymax = y1;
19 x = x1;
20 y = y1;
21 draw_pcb_fillcr(dst, x1, y1, th/2);
22 for(;;) {
23 int n;
24 double xx, yy;
25 xx = x - nx * th / 2.0;
26 yy = y - ny * th / 2.0;
27 for(n = 0; n <= th; n++) {
28 if ((xx >= 0) && (xx <= dst->sx) && (yy >= 0) && (yy <= dst->sy)) {
29 pixel_t *pixel = (dst->pixmap) + (int) xx + dst->sx * (int) yy;
30 *pixel = pixel_black;
32 xx += nx;
33 yy += ny;
36 x += vx/2.0;
37 y += vy/2.0;
38 if (x > x2)
39 break;
40 if ((y > ymax) || (y < ymin))
41 break;
44 draw_pcb_fillcr(dst, x, y, th/2);
46 return;
50 void draw_pcb_line(image_t *dst, int x1, int y1, int x2, int y2, double th)
52 double nx, ny, vx, vy;
53 double l;
54 int tmp;
56 if (x1 > x2) {
57 tmp = x1;
58 x1 = x2;
59 x2 = tmp;
60 tmp = y1;
61 y1 = y2;
62 y2 = tmp;
65 vx = x2 - x1;
66 vy = y2 - y1;
67 l = hypot(vx, vy);
68 vx /= l;
69 vy /= l;
70 nx = -vy;
71 ny = vx;
73 if ((x1 != x2) || (y1 != y2))
74 draw_thick_line(dst, x1, y1, x2, y2, vx, vy, nx, ny, th);
75 else
76 draw_pcb_fillcr(dst, x1, y1, th/2);
78 // draw_color(pixel_red);
79 // draw_line(dst, x1+nx*th/2.0, y1+ny*th, x2+nx*th, y2+ny*th/2.0);
80 // draw_line(dst, x1-nx*th/2.0, y1-ny*th, x2-nx*th, y2-ny*th/2.0);
83 int *fc_pat[1000];
85 static void fc_pat_gen(int r)
87 int y, *p;
88 p = fc_pat[r] = malloc(sizeof(int) * (r+1));
89 for(y = 0; y <= r; y++) {
90 double x = (double)r * cos(asin((double)y/(double)r));
91 p[y] = round(x);
95 void draw_pcb_fillcr(image_t *dst, int xc, int yc, int r)
97 int y, x, *pa;
98 pixel_t *p;
100 if (fc_pat[r] == NULL)
101 fc_pat_gen(r);
103 pa = fc_pat[r];
105 for(y = -r; y <= r; y++) {
106 int x1, x2, ay;
107 if (y+yc < 0)
108 continue;
109 if (y+yc >= dst->sy)
110 break;
111 ay = y < 0 ? -y : y;
112 x1 = xc - pa[ay];
113 x2 = xc + pa[ay];
114 if (x1 >= dst->sx)
115 continue;
116 if (x1 < 0)
117 x1 = 0;
118 if (x2 >= dst->sx)
119 x2 = dst->sx-1;
120 p = &image_pix(dst, x1, y+yc);
121 for(x = x1; x <= x2; x++,p++) {
122 *p = pixel_black;
125 /* p = &image_pix(dst, xc, yc);
126 *p = pixel_red;*/