History

initial

rminnich committed 16 years ago

Commit 1fcdf79No parent (first commit)7733 files · +2461126 −-39Browse files

Showing the changes to sys/src/cmd/plot/libplot (35 of 7733 files). Show all

Unified · Split

35 files
  1. sys/src/cmd/plot/libplot/box.c +8 −0
  2. sys/src/cmd/plot/libplot/cfill.c +5 −0
  3. sys/src/cmd/plot/libplot/circ.c +12 −0
  4. sys/src/cmd/plot/libplot/closepl.c +4 −0
  5. sys/src/cmd/plot/libplot/color.c +4 −0
  6. sys/src/cmd/plot/libplot/disk.c +12 −0
  7. sys/src/cmd/plot/libplot/doublebuffer.c +4 −0
  8. sys/src/cmd/plot/libplot/dpoint.c +6 −0
  9. sys/src/cmd/plot/libplot/erase.c +5 −0
  10. sys/src/cmd/plot/libplot/fill.c +167 −0
  11. sys/src/cmd/plot/libplot/frame.c +16 −0
  12. sys/src/cmd/plot/libplot/grade.c +4 −0
  13. sys/src/cmd/plot/libplot/line.c +5 −0
  14. sys/src/cmd/plot/libplot/machdep.c +142 −0
  15. sys/src/cmd/plot/libplot/mkfile +40 −0
  16. sys/src/cmd/plot/libplot/move.c +5 −0
  17. sys/src/cmd/plot/libplot/mplot.h +47 −0
  18. sys/src/cmd/plot/libplot/openpl.c +12 −0
  19. sys/src/cmd/plot/libplot/parabola.c +32 −0
  20. sys/src/cmd/plot/libplot/pen.c +6 −0
  21. sys/src/cmd/plot/libplot/poly.c +17 −0
  22. sys/src/cmd/plot/libplot/ppause.c +7 −0
  23. sys/src/cmd/plot/libplot/pprompt.c +5 −0
  24. sys/src/cmd/plot/libplot/range.c +11 −0
  25. sys/src/cmd/plot/libplot/rarc.c +44 −0
  26. sys/src/cmd/plot/libplot/restore.c +5 −0
  27. sys/src/cmd/plot/libplot/rmove.c +6 −0
  28. sys/src/cmd/plot/libplot/rvec.c +6 −0
  29. sys/src/cmd/plot/libplot/save.c +5 −0
  30. sys/src/cmd/plot/libplot/sbox.c +13 −0
  31. sys/src/cmd/plot/libplot/spline.c +51 −0
  32. sys/src/cmd/plot/libplot/subr.c +78 −0
  33. sys/src/cmd/plot/libplot/text.c +39 −0
  34. sys/src/cmd/plot/libplot/vec.c +26 −0
  35. sys/src/cmd/plot/libplot/whoami.c +4 −0
sys/src/cmd/plot/libplot/box.c+8−0
@@ -0,0 +1,8 @@
1+#include "mplot.h"
2+void box(double x0, double y0, double x1, double y1){
3+ move(x0, y0);
4+ vec(x0, y1);
5+ vec(x1, y1);
6+ vec(x1, y0);
7+ vec(x0, y0);
8+}
sys/src/cmd/plot/libplot/cfill.c+5−0
@@ -0,0 +1,5 @@
1+#include "mplot.h"
2+void cfill(char *s){
3+ int k=bcolor(s);
4+ if(k>=0) e1->backgr=k;
5+}
sys/src/cmd/plot/libplot/circ.c+12−0
@@ -0,0 +1,12 @@
1+#include "mplot.h"
2+void circ(double xc, double yc, double r){
3+ Point p;
4+ int rad;
5+ p.x=SCX(xc);
6+ p.y=SCY(yc);
7+ if (r < 0)
8+ rad=SCR(-r);
9+ else
10+ rad=SCR(r);
11+ ellipse(screen, p, rad, rad, 0, getcolor(e1->foregr), ZP);
12+}
sys/src/cmd/plot/libplot/closepl.c+4−0
@@ -0,0 +1,4 @@
1+#include "mplot.h"
2+void closepl(void){
3+ m_finish();
4+}
sys/src/cmd/plot/libplot/color.c+4−0
@@ -0,0 +1,4 @@
1+#include "mplot.h"
2+void color(char *s){
3+ e1->foregr=bcolor(s);
4+}
sys/src/cmd/plot/libplot/disk.c+12−0
@@ -0,0 +1,12 @@
1+#include "mplot.h"
2+void plotdisc(double xc, double yc, double r){
3+ Point p;
4+ int rad;
5+ p.x=SCX(xc);
6+ p.y=SCY(yc);
7+ if (r < 0)
8+ rad=SCR(-r);
9+ else
10+ rad=SCR(r);
11+ fillellipse(screen, p, rad, rad, getcolor(e1->foregr), ZP);
12+}
sys/src/cmd/plot/libplot/doublebuffer.c+4−0
@@ -0,0 +1,4 @@
1+#include "mplot.h"
2+void doublebuffer(void){
3+ m_dblbuf();
4+}
sys/src/cmd/plot/libplot/dpoint.c+6−0
@@ -0,0 +1,6 @@
1+#include "mplot.h"
2+void dpoint(double x, double y){
3+ draw(screen, Rect(SCX(x), SCY(y), SCX(x)+1, SCY(y)+1), getcolor(e1->foregr),
4+ nil, ZP);
5+ move(x, y);
6+}
sys/src/cmd/plot/libplot/erase.c+5−0
@@ -0,0 +1,5 @@
1+#include "mplot.h"
2+void erase(void){
3+ m_swapbuf();
4+ m_clrwin(clipminx, clipminy, clipmaxx, clipmaxy, e1->backgr);
5+}
sys/src/cmd/plot/libplot/fill.c+167−0
@@ -0,0 +1,167 @@
1+/*
2+ * fill -- polygon tiler
3+ * Updating the edgelist from scanline to scanline could be quicker if no
4+ * edges cross: we can just merge the incoming edges. If the scan-line
5+ * filling routine were a parameter, we could do textured
6+ * polygons, polyblt, and other such stuff.
7+ */
8+#include "mplot.h"
9+typedef enum{
10+ Odd=1,
11+ Nonzero=~0
12+}Windrule;
13+typedef struct edge Edge;
14+struct edge{
15+ Point p; /* point of crossing current scan-line */
16+ int maxy; /* scan line at which to discard edge */
17+ int dx; /* x increment if x fraction<1 */
18+ int dx1; /* x increment if x fraction>=1 */
19+ int x; /* x fraction, scaled by den */
20+ int num; /* x fraction increment for unit y change, scaled by den */
21+ int den; /* x fraction increment for unit x change, scaled by num */
22+ int dwind; /* increment of winding number on passing this edge */
23+ Edge *next; /* next edge on current scanline */
24+ Edge *prev; /* previous edge on current scanline */
25+};
26+static void insert(Edge *ep, Edge **yp){
27+ while(*yp && (*yp)->p.x<ep->p.x) yp=&(*yp)->next;
28+ ep->next=*yp;
29+ *yp=ep;
30+ if(ep->next){
31+ ep->prev=ep->next->prev;
32+ ep->next->prev=ep;
33+ if(ep->prev)
34+ ep->prev->next=ep;
35+ }
36+ else
37+ ep->prev=0;
38+}
39+static void polygon(int cnt[], double *pts[], Windrule w, int v){
40+ Edge *edges, *ep, *nextep, **ylist, **eylist, **yp;
41+ Point p, q, p0, p1, p10;
42+ int i, dy, nbig, y, left, right, wind, nwind, nvert;
43+ int *cntp;
44+ double **ptsp, *xp;
45+ nvert=0;
46+ for(cntp=cnt;*cntp;cntp++) nvert+=*cntp;
47+ edges=(Edge *)malloc(nvert*sizeof(Edge));
48+ if(edges==0){
49+ NoSpace:
50+ fprintf(stderr, "polygon: no space\n");
51+ exits("malloc failed");
52+ }
53+ ylist=(Edge **)malloc(Dy(screen->r)*sizeof(Edge *));
54+ if(ylist==0) goto NoSpace;
55+ eylist=ylist+Dy(screen->r);
56+ for(yp=ylist;yp!=eylist;yp++) *yp=0;
57+ ep=edges;
58+ for(cntp=cnt,ptsp=pts;*cntp;cntp++,ptsp++){
59+ p.x=SCX((*ptsp)[*cntp*2-2]);
60+ p.y=SCY((*ptsp)[*cntp*2-1]);
61+ nvert=*cntp;
62+ for(xp=*ptsp,i=0;i!=nvert;xp+=2,i++){
63+ q=p;
64+ p.x=SCX(xp[0]);
65+ p.y=SCY(xp[1]);
66+ if(p.y==q.y) continue;
67+ if(p.y<q.y){
68+ p0=p;
69+ p1=q;
70+ ep->dwind=1;
71+ }
72+ else{
73+ p0=q;
74+ p1=p;
75+ ep->dwind=-1;
76+ }
77+ if(p1.y<=screen->r.min.y) continue;
78+ if(p0.y>=screen->r.max.y) continue;
79+ ep->p=p0;
80+ if(p1.y>screen->r.max.y)
81+ ep->maxy=screen->r.max.y;
82+ else
83+ ep->maxy=p1.y;
84+ p10=subpt(p1, p0);
85+ if(p10.x>=0){
86+ ep->dx=p10.x/p10.y;
87+ ep->dx1=ep->dx+1;
88+ }
89+ else{
90+ p10.x=-p10.x;
91+ ep->dx=-(p10.x/p10.y); /* this nonsense rounds toward zero */
92+ ep->dx1=ep->dx-1;
93+ }
94+ ep->x=0;
95+ ep->num=p10.x%p10.y;
96+ ep->den=p10.y;
97+ if(ep->p.y<screen->r.min.y){
98+ dy=screen->r.min.y-ep->p.y;
99+ ep->x+=dy*ep->num;
100+ nbig=ep->x/ep->den;
101+ ep->p.x+=ep->dx1*nbig+ep->dx*(dy-nbig);
102+ ep->x%=ep->den;
103+ ep->p.y=screen->r.min.y;
104+ }
105+ insert(ep, ylist+(ep->p.y-screen->r.min.y));
106+ ep++;
107+ }
108+ }
109+ left = 0;
110+ for(yp=ylist,y=screen->r.min.y;yp!=eylist;yp++,y++){
111+ wind=0;
112+ for(ep=*yp;ep;ep=nextep){
113+ nwind=wind+ep->dwind;
114+ if(nwind&w){ /* inside */
115+ if(!(wind&w)){
116+ left=ep->p.x;
117+ if(left<screen->r.min.x) left=screen->r.min.x;
118+ }
119+ }
120+ else if(wind&w){
121+ right=ep->p.x;
122+ if(right>=screen->r.max.x) right=screen->r.max.x;
123+#define BART_BUG_FIXED /* what goes on here?? -rob */
124+#ifdef BART_BUG_FIXED
125+ if(right>left)
126+ line(screen, Pt(left, y), Pt(right, y), Endsquare, Endsquare, 0, getcolor(v), ZP);
127+#else
128+ if(right>left){
129+ switch(v){
130+ default:
131+ segment(&screen, Pt(left, y), Pt(right, y),
132+ ~0, D&~S);
133+ segment(&screen, Pt(left, y), Pt(right, y),
134+ v, f);
135+ break;
136+ case 0:
137+ segment(&screen, Pt(left, y), Pt(right, y),
138+ ~0, D&~S);
139+ break;
140+ case 3:
141+ segment(&screen, Pt(left, y), Pt(right, y),
142+ v, f);
143+ break;
144+ }
145+ }
146+#endif
147+ }
148+ wind=nwind;
149+ nextep=ep->next;
150+ if(++ep->p.y!=ep->maxy){
151+ ep->x+=ep->num;
152+ if(ep->x>=ep->den){
153+ ep->x-=ep->den;
154+ ep->p.x+=ep->dx1;
155+ }
156+ else
157+ ep->p.x+=ep->dx;
158+ insert(ep, yp+1);
159+ }
160+ }
161+ }
162+ free((char *)edges);
163+ free((char *)ylist);
164+}
165+void fill(int num[], double *ff[]){
166+ polygon(num, ff, Odd, e1->foregr);
167+}
sys/src/cmd/plot/libplot/frame.c+16−0
@@ -0,0 +1,16 @@
1+#include "mplot.h"
2+void frame(double xs, double ys, double xf, double yf){
3+ register double osidex, osidey;
4+ osidex = e1->sidex;
5+ osidey = e1->sidey;
6+ e1->left = e0->left + xs * e0->sidex;
7+ e1->bottom = e0->bottom + ys * e0->sidey;
8+ e1->sidex = (xf-xs)*e0->sidex;
9+ e1->sidey = (yf-ys)*e0->sidey;
10+ e1->scalex *= (e1->sidex / osidex);
11+ e1->scaley *= (e1->sidey / osidey);
12+ e1->quantum=e0->quantum/sqrt(e1->scalex*e1->scalex +
13+ e1->scaley*e1->scaley);
14+ if(e1->quantum < .01)
15+ e1->quantum = .01;
16+}
sys/src/cmd/plot/libplot/grade.c+4−0
@@ -0,0 +1,4 @@
1+#include "mplot.h"
2+void grade(double x){
3+ e1->grade = x;
4+}
sys/src/cmd/plot/libplot/line.c+5−0
@@ -0,0 +1,5 @@
1+#include "mplot.h"
2+void plotline(double x0, double y0, double x1, double y1){
3+ move(x0, y0);
4+ vec(x1, y1);
5+}
sys/src/cmd/plot/libplot/machdep.c+142−0
@@ -0,0 +1,142 @@
1+#include "mplot.h"
2+Image *offscreen;
3+/*
4+ * Clear the window from x0, y0 to x1, y1 (inclusive) to color c
5+ */
6+void m_clrwin(int x0, int y0, int x1, int y1, int c){
7+ draw(offscreen, Rect(x0, y0, x1+1, y1+1), getcolor(c), nil, ZP);
8+}
9+/*
10+ * Draw text between pointers p and q with first character centered at x, y.
11+ * Use color c. Centered if cen is non-zero, right-justified if right is non-zero.
12+ * Returns the y coordinate for any following line of text.
13+ */
14+int m_text(int x, int y, char *p, char *q, int c, int cen, int right){
15+ Point tsize;
16+ USED(c);
17+ tsize=stringsize(font, p);
18+ if(cen) x -= tsize.x/2;
19+ else if(right) x -= tsize.x;
20+ stringn(offscreen, Pt(x, y-tsize.y/2), getcolor(c), ZP, font, p, q-p);
21+ return y+tsize.y;
22+}
23+/*
24+ * Draw the vector from x0, y0 to x1, y1 in color c.
25+ * Clipped by caller
26+ */
27+void m_vector(int x0, int y0, int x1, int y1, int c){
28+ line(offscreen, Pt(x0, y0), Pt(x1, y1), Endsquare, Endsquare, 0, getcolor(c), ZP);
29+}
30+char *scanint(char *s, int *n){
31+ while(*s<'0' || '9'<*s){
32+ if(*s=='\0'){
33+ fprint(2, "plot: bad -Wxmin,ymin,xmax,ymax\n");
34+ exits("bad arg");
35+ }
36+ s++;
37+ }
38+ *n=0;
39+ while('0'<=*s && *s<='9'){
40+ *n=*n*10+*s-'0';
41+ s++;
42+ }
43+ return s;
44+}
45+char *rdenv(char *name){
46+ char *v;
47+ int fd, size;
48+ fd=open(name, OREAD);
49+ if(fd<0) return 0;
50+ size=seek(fd, 0, 2);
51+ v=malloc(size+1);
52+ if(v==0){
53+ fprint(2, "Can't malloc: %r\n");
54+ exits("no mem");
55+ }
56+ seek(fd, 0, 0);
57+ read(fd, v, size);
58+ v[size]=0;
59+ close(fd);
60+ return v;
61+}
62+/*
63+ * Startup initialization
64+ */
65+void m_initialize(char *s){
66+ static int first=1;
67+ int dx, dy;
68+ USED(s);
69+ if(first){
70+ if(initdraw(0,0,"plot") < 0)
71+ sysfatal("initdraw: %r");
72+ einit(Emouse);
73+ clipminx=mapminx=screen->r.min.x+4;
74+ clipminy=mapminy=screen->r.min.y+4;
75+ clipmaxx=mapmaxx=screen->r.max.x-5;
76+ clipmaxy=mapmaxy=screen->r.max.y-5;
77+ dx=clipmaxx-clipminx;
78+ dy=clipmaxy-clipminy;
79+ if(dx>dy){
80+ mapminx+=(dx-dy)/2;
81+ mapmaxx=mapminx+dy;
82+ }
83+ else{
84+ mapminy+=(dy-dx)/2;
85+ mapmaxy=mapminy+dx;
86+ }
87+ first=0;
88+ offscreen = screen;
89+ }
90+}
91+/*
92+ * Clean up when finished
93+ */
94+void m_finish(void){
95+ m_swapbuf();
96+}
97+void m_swapbuf(void){
98+ if(offscreen!=screen)
99+ draw(screen, offscreen->r, offscreen, nil, offscreen->r.min);
100+ flushimage(display, 1);
101+}
102+void m_dblbuf(void){
103+ if(offscreen==screen){
104+ offscreen=allocimage(display, insetrect(screen->r, 4), screen->chan, 0, -1);
105+ if(offscreen==0){
106+ fprintf(stderr, "Can't double buffer\n");
107+ offscreen=screen;
108+ }
109+ }
110+}
111+/* Assume colormap entry because
112+ * Use cache to avoid repeated allocation.
113+ */
114+struct{
115+ int v;
116+ Image *i;
117+}icache[32];
118+
119+Image*
120+getcolor(int v)
121+{
122+ Image *i;
123+ int j;
124+
125+ for(j=0; j<nelem(icache); j++)
126+ if(icache[j].v==v && icache[j].i!=nil)
127+ return icache[j].i;
128+
129+ i = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, v);
130+ if(i == nil){
131+ fprint(2, "plot: can't allocate image for color: %r\n");
132+ exits("allocimage");
133+ }
134+ for(j=0; j<nelem(icache); j++)
135+ if(icache[j].i == nil){
136+ icache[j].v = v;
137+ icache[j].i = i;
138+ break;
139+ }
140+
141+ return i;
142+}
sys/src/cmd/plot/libplot/mkfile+40−0
@@ -0,0 +1,40 @@
1+</$objtype/mkfile
2+
3+LIB=../libplot.a$O
4+OFILES=box.$O\
5+ cfill.$O\
6+ circ.$O\
7+ closepl.$O\
8+ color.$O\
9+ disk.$O\
10+ doublebuffer.$O\
11+ dpoint.$O\
12+ erase.$O\
13+ fill.$O\
14+ frame.$O\
15+ grade.$O\
16+ line.$O\
17+ machdep.$O\
18+ move.$O\
19+ openpl.$O\
20+ parabola.$O\
21+ pen.$O\
22+ poly.$O\
23+ ppause.$O\
24+ pprompt.$O\
25+ range.$O\
26+ rarc.$O\
27+ restore.$O\
28+ rmove.$O\
29+ rvec.$O\
30+ save.$O\
31+ sbox.$O\
32+ spline.$O\
33+ subr.$O\
34+ text.$O\
35+ vec.$O\
36+ whoami.$O\
37+
38+HFILES=mplot.h\
39+
40+</sys/src/cmd/mklib
sys/src/cmd/plot/libplot/move.c+5−0
@@ -0,0 +1,5 @@
1+#include "mplot.h"
2+void move(double xx, double yy){
3+ e1->copyx = xx;
4+ e1->copyy = yy;
5+}
sys/src/cmd/plot/libplot/mplot.h+47−0
@@ -0,0 +1,47 @@
1+#include <u.h>
2+#include <libc.h>
3+#include <stdio.h>
4+#include <draw.h>
5+#include <event.h>
6+#define SCX(A) ((((A) - e1->xmin)*e1->scalex + e1->left)+.5)
7+#define SCY(A) ((((A) - e1->ymin)*e1->scaley + e1->bottom)+.5)
8+#define SCR(A) ((A)*e1->scalex+.5)
9+#define unorm(y) (double)(e1->sidey - y)
10+#define BIGINT 0x3FFFFFFF /* a large, but valid, int */
11+extern struct penvir {
12+ double left, bottom;
13+ double xmin, ymin;
14+ double scalex, scaley;
15+ double sidex, sidey;
16+ double copyx, copyy;
17+ double quantum;
18+ double grade;
19+ int pgap;
20+ double pslant;
21+ int pmode, foregr, backgr;
22+} *e0, *e1, *esave;
23+#define RADIAN 57.3 /* radians per degree */
24+struct seg {
25+ int x, y, X, Y;
26+ char stat;
27+};
28+
29+/*
30+ * display parameters
31+ */
32+int clipminx, clipminy, clipmaxx, clipmaxy; /* clipping rectangle */
33+int mapminx, mapminy, mapmaxx, mapmaxy; /* centered square */
34+/*
35+ * Prototypes
36+ */
37+#include "../plot.h"
38+void m_clrwin(int, int, int, int, int);
39+void m_finish(void);
40+void m_initialize(char *);
41+int m_text(int, int, char *, char *, int, int, int);
42+void m_vector(int, int, int, int, int);
43+void m_swapbuf(void);
44+void m_dblbuf(void);
45+int bcolor(char *);
46+void sscpy(struct penvir *, struct penvir *);
47+Image *getcolor(int);
sys/src/cmd/plot/libplot/openpl.c+12−0
@@ -0,0 +1,12 @@
1+#include "mplot.h"
2+void openpl(char *s){
3+ m_initialize(s);
4+ e0->left=mapminx;
5+ e0->bottom=mapmaxy;
6+ e0->sidex=mapmaxx-mapminx;
7+ e0->sidey=mapminy-mapmaxy;
8+ e0->scalex=e0->sidex;
9+ e0->scaley=e0->sidey;
10+ sscpy(e0, e1);
11+ move(0., 0.);
12+}
sys/src/cmd/plot/libplot/parabola.c+32−0
@@ -0,0 +1,32 @@
1+#include "mplot.h"
2+void parabola(double x0, double y0, double x1, double y1, double xb, double yb){
3+ register double x, y, t;
4+ double c0x, c0y, c1x, c1y;
5+ double dt, d2, d1;
6+ d1 = sqrt((xb - x0) * (xb - x0) + (yb - y0) * (yb - y0));
7+ d2 = sqrt((xb - x1) * (xb - x1) + (yb - y1) * (yb - y1));
8+ if (d1 <= e1->quantum || d2 <= e1->quantum) {
9+ plotline(x0, y0, x1, y1);
10+ return;
11+ }
12+ c0x = x0 + x1 - 2. * xb;
13+ c1x = 2. * (xb - x0);
14+ c0y = y0 + y1 - 2. * yb;
15+ c1y = 2. * (yb - y0);
16+ move(x0, y0);
17+ dt = e1->quantum / d1;
18+ dt /= e1->grade;
19+ for (t = dt; t < 0.5; t += dt) {
20+ x = (c0x * t + c1x) * t + x0;
21+ y = (c0y * t + c1y) * t + y0;
22+ vec(x, y);
23+ }
24+ dt = e1->quantum / d2;
25+ dt /= e1->grade;
26+ for (; t < 1.0; t += dt) {
27+ x = (c0x * t + c1x) * t + x0;
28+ y = (c0y * t + c1y) * t + y0;
29+ vec(x, y);
30+ }
31+ vec(x1, y1);
32+}
sys/src/cmd/plot/libplot/pen.c+6−0
@@ -0,0 +1,6 @@
1+#include "mplot.h"
2+void pen(char *s){
3+ /* BUG: NO OP */
4+ USED(s);
5+ /* was this error: color(s); */
6+}
sys/src/cmd/plot/libplot/poly.c+17−0
@@ -0,0 +1,17 @@
1+#include "mplot.h"
2+void plotpoly(int num[], double *ff[]){
3+ double *xp, *yp, **fp;
4+ int i, *n;
5+ n = num;
6+ fp = ff;
7+ while((i = *n++)){
8+ xp = *fp++;
9+ yp = xp+1;
10+ move(*xp, *yp);
11+ while(--i){
12+ xp += 2;
13+ yp += 2;
14+ vec(*xp, *yp);
15+ }
16+ }
17+}
sys/src/cmd/plot/libplot/ppause.c+7−0
@@ -0,0 +1,7 @@
1+#include "mplot.h"
2+void ppause(void){
3+ char aa[4];
4+ fflush(stdout);
5+ read(0, aa, 4);
6+ erase();
7+}
sys/src/cmd/plot/libplot/pprompt.c+5−0
@@ -0,0 +1,5 @@
1+#include "mplot.h"
2+void
3+pprompt(void){
4+ fprintf(stderr, ":");
5+}
sys/src/cmd/plot/libplot/range.c+11−0
@@ -0,0 +1,11 @@
1+#include "mplot.h"
2+void range(double x0, double y0, double x1, double y1){
3+ e1->xmin = x0;
4+ e1->ymin = y0;
5+ e1->scalex = e1->sidex / (x1 - x0 );
6+ e1->scaley = e1->sidey / (y1 - y0 );
7+ e1->quantum=e0->quantum/sqrt(e1->scalex*e1->scalex +
8+ e1->scaley*e1->scaley);
9+ if(e1->quantum < .01)
10+ e1->quantum = .01;
11+}
sys/src/cmd/plot/libplot/rarc.c+44−0
@@ -0,0 +1,44 @@
1+#include "mplot.h"
2+/* arc plotting routine */
3+/* from x1,y1 to x2,y2 */
4+/* with center xc,yc and radius rr */
5+/* integrates difference equation */
6+/* negative rr draws counterclockwise */
7+#define PI4 0.7854
8+void rarc(double x1, double y1, double x2, double y2, double xc, double yc, double rr){
9+ register double dx, dy, a, b;
10+ double ph, dph, rd, xnext;
11+ register int n;
12+ dx = x1 - xc;
13+ dy = y1 - yc;
14+ rd = sqrt(dx * dx + dy * dy);
15+ if (rd / e1->quantum < 1.0) {
16+ move(xc, yc);
17+ vec(xc, yc);
18+ return;
19+ }
20+ dph = acos(1.0 - (e1->quantum / rd));
21+ if (dph > PI4)
22+ dph = PI4;
23+ ph=atan2((y2-yc),(x2 - xc)) - atan2(dy, dx);
24+ if (ph < 0)
25+ ph += 6.2832;
26+ if (rr < 0)
27+ ph = 6.2832 - ph;
28+ if (ph < dph)
29+ plotline(x1, y1, x2, y2);
30+ else {
31+ n = ph / dph;
32+ a = cos(dph);
33+ b = sin(dph);
34+ if (rr < 0)
35+ b = -b;
36+ move(x1, y1);
37+ while ((n--) >= 0) {
38+ xnext = dx * a - dy * b;
39+ dy = dx * b + dy * a;
40+ dx = xnext;
41+ vec(dx + xc, dy + yc);
42+ }
43+ }
44+}
sys/src/cmd/plot/libplot/restore.c+5−0
@@ -0,0 +1,5 @@
1+#include "mplot.h"
2+void restore(void){
3+ e1--;
4+ move(e1->copyx, e1->copyy);
5+}
sys/src/cmd/plot/libplot/rmove.c+6−0
@@ -0,0 +1,6 @@
1+#include "mplot.h"
2+void rmove(double xx, double yy){
3+ e1->copyx += xx;
4+ e1->copyy += yy;
5+ move(e1->copyx, e1->copyy);
6+}
sys/src/cmd/plot/libplot/rvec.c+6−0
@@ -0,0 +1,6 @@
1+#include "mplot.h"
2+void rvec(double xx, double yy){
3+ e1->copyx += xx;
4+ e1->copyy += yy;
5+ vec(e1->copyx, e1->copyy);
6+}
sys/src/cmd/plot/libplot/save.c+5−0
@@ -0,0 +1,5 @@
1+#include "mplot.h"
2+void save(void){
3+ sscpy(e1, e1 + 1);
4+ e1++;
5+}
sys/src/cmd/plot/libplot/sbox.c+13−0
@@ -0,0 +1,13 @@
1+#include "mplot.h"
2+void sbox(double xx0, double yy0, double xx1, double yy1){
3+ int x0=SCX(xx0), y0=SCY(yy0), x1=SCX(xx1), y1=SCY(yy1);
4+ int t;
5+ if(x1<x0){ t=x0; x0=x1; x1=t; }
6+ if(y1<y0){ t=y0; y0=y1; y1=t; }
7+ if(x0<clipminx) x0=clipminx;
8+ if(y0<clipminy) y0=clipminy;
9+ if(x1>clipmaxx) x1=clipmaxx;
10+ if(y1>clipmaxy) y1=clipmaxy;
11+ if(x1<x0 || y1<y0) return;
12+ m_clrwin(x0, y0, x1, y1, e1->backgr);
13+}
sys/src/cmd/plot/libplot/spline.c+51−0
@@ -0,0 +1,51 @@
1+/*
2+Produce spline (uniform knots, second order)
3+from guiding points
4+*/
5+#include "mplot.h"
6+void splin(int mode, int num[], double *ff[]){
7+ int i, *np, n;
8+ double xa, ya, xc, yc, *xp, *yp, *xp0, *yp0, *xpe, *ype;
9+ double **fp;
10+ np = num;
11+ fp = ff;
12+ while((n = *np++)){
13+ xp = *fp++;
14+ yp = xp + 1;
15+ xp0 = xp;
16+ yp0 = yp;
17+ xpe = xp0 + 2 * (n - 1);
18+ ype = yp0 + 2 * (n - 1);
19+ if (n < 3) {
20+ plotline(*xp, *yp, *(xp + 2), *(yp + 2));
21+ continue;
22+ }
23+ if (mode == 4) { /*closed curve*/
24+ xa = 0.5 * (*xpe + *(xpe - 2));
25+ xc = 0.5 * (*xpe + *xp0);
26+ ya = 0.5 * (*ype + *(ype - 2));
27+ yc = 0.5 * (*ype + *yp0);
28+ parabola(xa, ya, xc, yc, *xpe, *ype);
29+ xa = 0.5 * (*xpe + *xp0);
30+ xc = 0.5 * (*(xp0 + 2) + *xp0);
31+ ya = 0.5 * (*ype + *yp0);
32+ yc = 0.5 * (*(yp0 + 2) + *yp0);
33+ parabola(xa, ya, xc, yc, *xp0, *yp0);
34+ }
35+ else { /*open curve with multiple endpoints*/
36+ if (mode % 2) /*odd mode makes first point double*/
37+ plotline(*xp0,*yp0,0.5*(*xp0+*(xp0+2)),0.5*(*yp0+*(yp0+2)));
38+ }
39+ xp += 2;
40+ yp += 2;
41+ for (i = 1; i < (n - 1); i++, xp += 2, yp += 2) {
42+ xa = 0.5 * (*(xp - 2) + *xp);
43+ xc = 0.5 * ( *xp + *(xp + 2));
44+ ya = 0.5 * (*(yp - 2) + *yp);
45+ yc = 0.5 * ( *yp + *(yp + 2));
46+ parabola(xa, ya, xc, yc, *xp, *yp);
47+ }
48+ if(mode >= 2 && mode != 4)
49+ plotline(0.5*(*(xpe-2)+*xpe),0.5*(*(ype-2)+*ype),*xpe,*ype);
50+ }
51+}
sys/src/cmd/plot/libplot/subr.c+78−0
@@ -0,0 +1,78 @@
1+#include "mplot.h"
2+#define pSMALL 0.5
3+struct penvir E[9] = {
4+{ 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite},
5+{ 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite},
6+{ 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite},
7+{ 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite},
8+{ 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite},
9+{ 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite},
10+{ 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite},
11+{ 0., 1024., 0., 0., 1., -1.,1024., -1024., 0., 0., pSMALL, 1., 1, 0.,1, DBlack, DWhite}
12+};
13+struct penvir *e0 = E, *e1 = &E[1], *esave;
14+bcolor(char *s){
15+ int c;
16+ while (*s != 0) {
17+ switch (*s) {
18+ case '0': case '1': case '2': case '3': case '4':
19+ case '5': case '6': case '7': case '8': case '9':
20+ c=0;
21+ while('0'<=*s && *s<='9')
22+ c=c*10+*s++-'0';
23+ if(c < 0)
24+ return DBlack;
25+ return cmap2rgba(c);
26+ case 'k': case 'z': /* zero was old name for kblack */
27+ return(DBlack);
28+ case 'r':
29+ return(DRed);
30+ case 'g':
31+ return(DGreen);
32+ case 'b':
33+ return(DBlue);
34+ case 'm':
35+ return(DMagenta);
36+ case 'y':
37+ return(DYellow);
38+ case 'c':
39+ return(DCyan);
40+ case 'w':
41+ return(DWhite);
42+ case 'R':
43+ return(atoi(s + 1));
44+ case 'G':
45+ e1->pgap = atof(s + 1);
46+ return(-1);
47+ case 'A':
48+ e1->pslant = (180. - atof(s + 1)) / RADIAN;
49+ return(-1);
50+ }
51+ while (*++s != 0)
52+ if (*s == '/') {
53+ s++;
54+ break;
55+ }
56+ }
57+ return DBlack;
58+}
59+void sscpy(struct penvir *a, struct penvir *b){ /* copy 'a' onto 'b' */
60+ b->left = a->left;
61+ b->bottom = a->bottom;
62+ b->xmin = a->xmin;
63+ b->ymin = a->ymin;
64+ b->scalex = a->scalex;
65+ b->scaley = a->scaley;
66+ b->sidex = a->sidex;
67+ b->sidey = a->sidey;
68+ b->copyx = a->copyx;
69+ b->copyy = a->copyy;
70+ b->quantum = a->quantum;
71+ b->grade = a->grade;
72+ b->pmode = a->pmode;
73+ b->foregr = a->foregr;
74+ b->backgr = a->backgr;
75+}
76+void idle(void){}
77+
78+void ptype(char *s){USED(s);}
sys/src/cmd/plot/libplot/text.c+39−0
@@ -0,0 +1,39 @@
1+/*
2+ t string Place the string so that its first character is
3+ centered on the current point (default). If
4+ string begins with `\C' (`\R'), it is centered
5+ (right-adjusted) on the current point. A
6+ backslash at the beginning of the string may be
7+ escaped with another backslash.
8+ */
9+#include "mplot.h"
10+void text(char *s){
11+ register int kx, ky;
12+ int centered, right, more;
13+ char *ss;
14+ ss=s;
15+ for(;;){
16+ centered=right=more=0;
17+ if(*ss=='\\'){
18+ ss++;
19+ switch(*ss){
20+ case 'C': centered++; ss++; break;
21+ case 'R': right++; ss++; break;
22+ case 'L': ss++; break;
23+ case 'n': --ss; break;
24+ }
25+ }
26+ for(s=ss;*ss!='\0';ss++)
27+ if(ss[0]=='\\' && ss[1]=='n'){
28+ more++;
29+ break;
30+ }
31+ kx = SCX(e1->copyx);
32+ ky = SCY(e1->copyy);
33+ ky=m_text(kx, ky, s, ss, e1->foregr, centered, right);
34+ if(!more)break;
35+ e1->copyy = ( (double)(ky) - e1->bottom)/e1->scaley + e1->ymin + .5;
36+ move(e1->copyx, e1->copyy);
37+ ss+=2;
38+ }
39+}
sys/src/cmd/plot/libplot/vec.c+26−0
@@ -0,0 +1,26 @@
1+#include "mplot.h"
2+#define code(x, y) ((x<clipminx?1:x>clipmaxx?2:0)|(y<clipminy?4:y>clipmaxy?8:0))
3+void vec(double xx, double yy){
4+ int x0, y0, x1, y1, c0, c1, c, tx, ty;
5+ double t;
6+ t=SCX(e1->copyx); if(fabs(t)>BIGINT) return; x0=t;
7+ t=SCY(e1->copyy); if(fabs(t)>BIGINT) return; y0=t;
8+ t=SCX(xx); if(fabs(t)>BIGINT) return; x1=t;
9+ t=SCY(yy); if(fabs(t)>BIGINT) return; y1=t;
10+ e1->copyx=xx;
11+ e1->copyy=yy;
12+ /* clipping -- what a concept */
13+ c0=code(x0, y0);
14+ c1=code(x1, y1);
15+ while(c0|c1){
16+ if(c0&c1) return;
17+ c=c0?c0:c1;
18+ if(c&1) ty=y0+(y1-y0)*(clipminx-x0)/(x1-x0), tx=clipminx;
19+ else if(c&2) ty=y0+(y1-y0)*(clipmaxx-x0)/(x1-x0), tx=clipmaxx;
20+ else if(c&4) tx=x0+(x1-x0)*(clipminy-y0)/(y1-y0), ty=clipminy;
21+ else tx=x0+(x1-x0)*(clipmaxy-y0)/(y1-y0), ty=clipmaxy;
22+ if(c==c0) x0=tx, y0=ty, c0=code(x0, y0);
23+ else x1=tx, y1=ty, c1=code(x1, y1);
24+ }
25+ m_vector(x0, y0, x1, y1, e1->foregr);
26+}
sys/src/cmd/plot/libplot/whoami.c+4−0
@@ -0,0 +1,4 @@
1+#include "mplot.h"
2+char *whoami(void){
3+ return("ramtek");
4+}