"lazy man" (good enough for schematics) aproximated polygon clipping using the underlying xorg 16 bit integer poly clipping engine, by projecting outer vertices to the 16 bit signed coordinate system edges
This commit is contained in:
parent
f9f9de3371
commit
fe1f7c57a7
32
src/clip.c
32
src/clip.c
|
|
@ -69,6 +69,38 @@ int clip( double *xa,double *ya,double *xb,double *yb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clip_xy_to_short(double x, double y, short *sx, short *sy)
|
||||||
|
{
|
||||||
|
double ax, ay;
|
||||||
|
double r;
|
||||||
|
ax = fabs(x);
|
||||||
|
ay = fabs(y);
|
||||||
|
|
||||||
|
if(ax > ay) {
|
||||||
|
if( x > SHRT_MAX) {
|
||||||
|
r = SHRT_MAX / x;
|
||||||
|
} else if(x < SHRT_MIN) {
|
||||||
|
r = SHRT_MIN / x;
|
||||||
|
} else {
|
||||||
|
r = 1.0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if( y > SHRT_MAX) {
|
||||||
|
r = SHRT_MAX / y;
|
||||||
|
} else if(y < SHRT_MIN) {
|
||||||
|
r = SHRT_MIN / y;
|
||||||
|
} else {
|
||||||
|
r = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*sx = x * r;
|
||||||
|
*sy = y * r;
|
||||||
|
}
|
||||||
|
|
||||||
|
short clip_to_short(double n)
|
||||||
|
{
|
||||||
|
return n > SHRT_MAX ? SHRT_MAX : n < SHRT_MIN ? SHRT_MIN : n;
|
||||||
|
}
|
||||||
|
|
||||||
int rectclip(int x1,int y1,int x2,int y2,
|
int rectclip(int x1,int y1,int x2,int y2,
|
||||||
double *xa,double *ya,double *xb,double *yb)
|
double *xa,double *ya,double *xb,double *yb)
|
||||||
|
|
|
||||||
12
src/draw.c
12
src/draw.c
|
|
@ -1361,6 +1361,7 @@ void drawpolygon(int c, int what, double *x, double *y, int points, int poly_fil
|
||||||
double x1,y1,x2,y2;
|
double x1,y1,x2,y2;
|
||||||
XPoint *p;
|
XPoint *p;
|
||||||
int i;
|
int i;
|
||||||
|
short sx, sy;
|
||||||
if(!has_x) return;
|
if(!has_x) return;
|
||||||
|
|
||||||
polygon_bbox(x, y, points, &x1,&y1,&x2,&y2);
|
polygon_bbox(x, y, points, &x1,&y1,&x2,&y2);
|
||||||
|
|
@ -1375,8 +1376,9 @@ void drawpolygon(int c, int what, double *x, double *y, int points, int poly_fil
|
||||||
|
|
||||||
p = my_malloc(38, sizeof(XPoint) * points);
|
p = my_malloc(38, sizeof(XPoint) * points);
|
||||||
for(i=0;i<points; i++) {
|
for(i=0;i<points; i++) {
|
||||||
p[i].x = X_TO_SCREEN(x[i]);
|
clip_xy_to_short(X_TO_SCREEN(x[i]), Y_TO_SCREEN(y[i]), &sx, &sy);
|
||||||
p[i].y = Y_TO_SCREEN(y[i]);
|
p[i].x = sx;
|
||||||
|
p[i].y = sy;
|
||||||
}
|
}
|
||||||
if(dash) {
|
if(dash) {
|
||||||
char dash_arr[2];
|
char dash_arr[2];
|
||||||
|
|
@ -1406,6 +1408,7 @@ void drawtemppolygon(GC g, int what, double *x, double *y, int points)
|
||||||
double x1,y1,x2,y2;
|
double x1,y1,x2,y2;
|
||||||
XPoint *p;
|
XPoint *p;
|
||||||
int i;
|
int i;
|
||||||
|
short sx, sy;
|
||||||
if(!has_x) return;
|
if(!has_x) return;
|
||||||
polygon_bbox(x, y, points, &x1,&y1,&x2,&y2);
|
polygon_bbox(x, y, points, &x1,&y1,&x2,&y2);
|
||||||
x1=X_TO_SCREEN(x1);
|
x1=X_TO_SCREEN(x1);
|
||||||
|
|
@ -1415,8 +1418,9 @@ void drawtemppolygon(GC g, int what, double *x, double *y, int points)
|
||||||
p = my_malloc(39, sizeof(XPoint) * points);
|
p = my_malloc(39, sizeof(XPoint) * points);
|
||||||
if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) ) {
|
if( rectclip(xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) ) {
|
||||||
for(i=0;i<points; i++) {
|
for(i=0;i<points; i++) {
|
||||||
p[i].x = X_TO_SCREEN(x[i]);
|
clip_xy_to_short(X_TO_SCREEN(x[i]), Y_TO_SCREEN(y[i]), &sx, &sy);
|
||||||
p[i].y = Y_TO_SCREEN(y[i]);
|
p[i].x = sx;
|
||||||
|
p[i].y = sy;
|
||||||
}
|
}
|
||||||
XDrawLines(display, xctx->window, g, p, points, CoordModeOrigin);
|
XDrawLines(display, xctx->window, g, p, points, CoordModeOrigin);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -860,8 +860,9 @@ extern void draw_temp_symbol(int what, GC gc, int n,int layer,
|
||||||
extern void draw_temp_string(GC gc,int what, const char *str, short rot, short flip, int hcenter, int vcenter,
|
extern void draw_temp_string(GC gc,int what, const char *str, short rot, short flip, int hcenter, int vcenter,
|
||||||
double x1, double y1, double xscale, double yscale);
|
double x1, double y1, double xscale, double yscale);
|
||||||
|
|
||||||
|
|
||||||
extern void draw(void);
|
extern void draw(void);
|
||||||
|
extern short clip_to_short(double n);
|
||||||
|
extern void clip_xy_to_short(double x, double y, short *sx, short *sy);
|
||||||
extern int clip( double*,double*,double*,double*);
|
extern int clip( double*,double*,double*,double*);
|
||||||
extern int textclip(int x1,int y1,int x2,int y2,
|
extern int textclip(int x1,int y1,int x2,int y2,
|
||||||
double xa,double ya,double xb,double yb);
|
double xa,double ya,double xb,double yb);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue