From fe1f7c57a72b94e4e8aa87ac4b8cad9b16d3b43f Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Sat, 5 Dec 2020 13:58:44 +0100 Subject: [PATCH] "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 --- src/clip.c | 32 ++++++++++++++++++++++++++++++++ src/draw.c | 12 ++++++++---- src/xschem.h | 3 ++- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/clip.c b/src/clip.c index a6e364f0..83e3fc37 100644 --- a/src/clip.c +++ b/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, double *xa,double *ya,double *xb,double *yb) diff --git a/src/draw.c b/src/draw.c index c894ba73..4e53eff3 100644 --- a/src/draw.c +++ b/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; XPoint *p; int i; + short sx, sy; if(!has_x) return; 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); for(i=0;iareax1,xctx->areay1,xctx->areax2,xctx->areay2,&x1,&y1,&x2,&y2) ) { for(i=0;iwindow, g, p, points, CoordModeOrigin); } diff --git a/src/xschem.h b/src/xschem.h index 2dd1b1af..9b2b4fb8 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -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, double x1, double y1, double xscale, double yscale); - 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 textclip(int x1,int y1,int x2,int y2, double xa,double ya,double xb,double yb);