Annotation of OpenXM_contrib2/asir2000/lib/glib, Revision 1.1
1.1 ! takayama 1: /* $OpenXM$ */
! 2: /* $Id: drill,v 1.9 2000/11/20 01:44:49 taka Exp $ */
! 3:
! 4: /* Todo:
! 5: 1. Some functions should be moved to longname
! 6: */
! 7:
! 8: /* #define CLIP 1 */
! 9: /* #define DEBUG 1 */
! 10: #define LIST 4
! 11:
! 12: /* General sugar functions */
! 13: def floor(N) {
! 14: return(pari(floor,N));
! 15: }
! 16:
! 17: def join(A,B) {
! 18: if (type(B) == 0) return(A);
! 19: return(append(A,B));
! 20: }
! 21:
! 22: def eigenvalues(M) {
! 23: return(pari(eigen,M));
! 24: }
! 25:
! 26: def roots(F) {
! 27: return(pari(roots,F));
! 28: }
! 29:
! 30: /* ---------------------------------------------- */
! 31: def ox_get_errors(P) {
! 32: ox_push_cmd(P,276);
! 33: return(ox_pop_cmo(P));
! 34: }
! 35:
! 36: def reset_plot() {
! 37: extern Glib_process;
! 38: print(" Sending signal to ox_plot",0);
! 39: ox_reset(Glib_process);
! 40: print(" Done.");
! 41: }
! 42: Glib_canvas_x = 400$
! 43: Glib_canvas_y = 400$
! 44: Glib_xmin=0$ Glib_xmax=Glib_canvas_x$
! 45: Glib_ymin=0$ Glib_ymax=Glib_canvas_y$
! 46: #define START_SERVER \
! 47: extern Glib_server_started, Glib_process$ \
! 48: if (type(Glib_server_started) == 0) { \
! 49: Glib_process = ox_launch_nox(0,"ox_plot")$ \
! 50: register_handler(reset_plot); \
! 51: Glib_server_started = 1$ \
! 52: }$
! 53:
! 54: Glib_canvas = -1$
! 55: Glib_xmag = 1$ Glib_ymag=1$ Glib_xoffset=0$ Glib_yoffset=0$
! 56: Glib_safe_mode = 2 $
! 57: Glib_counter = 100$
! 58:
! 59: def open_Canvas(P,S) {
! 60: open_canvas(P,S);
! 61: R = ox_pop_cmo(P);
! 62: /*
! 63: if (ox_get_errors(P) == []) {
! 64: R = ox_pop_cmo(P);
! 65: }else{
! 66: debug;
! 67: }
! 68: */
! 69: return(R);
! 70: }
! 71:
! 72: def glib_open() {
! 73: extern Glib_canvas_x, Glib_canvas_y,
! 74: Glib_process, Glib_canvas;
! 75: START_SERVER
! 76: Glib_canvas = open_Canvas(Glib_process,[Glib_canvas_x,Glib_canvas_y])$
! 77: glib_check_strict();
! 78: return(Glib_canvas);
! 79: }
! 80:
! 81: def glib_check() {
! 82: extern Glib_process, Glib_canvas, Glib_safe_mode,
! 83: Glib_canvas_x, Glib_canvas_y, Glib_counter;
! 84: if (Glib_safe_mode == 0) {
! 85: return(0);
! 86: }
! 87: if (Glib_safe_mode == 2) {
! 88: if (Glib_counter > 0) {
! 89: Glib_counter--;
! 90: return(0);
! 91: }else{
! 92: Glib_counter=100;
! 93: }
! 94: }
! 95: glib_check_strict();
! 96: }
! 97: def glib_check_strict() {
! 98: extern Glib_process, Glib_canvas, Glib_safe_mode,
! 99: Glib_canvas_x, Glib_canvas_y, Glib_counter;
! 100: if (Glib_canvas < 0) {
! 101: glib_open();
! 102: }
! 103: E = ox_get_errors(Glib_process);
! 104: if (E != []) {
! 105: ox_pops(Glib_process,200);
! 106: print(E);
! 107: print("Warning: ",0);
! 108: print("Drawing canvas seems to be closed.");
! 109: print("Opening a new canvas.");
! 110: Glib_canvas = open_Canvas(Glib_process,[Glib_canvas_x,Glib_canvas_y])$
! 111: error("Drawing aborted");
! 112: }
! 113: }
! 114:
! 115: def glib_clear() {
! 116: extern Glib_process, Glib_canvas;
! 117: if (Glib_canvas < 0) glib_open();
! 118: clear_canvas(Glib_process,Glib_canvas);
! 119: }
! 120:
! 121: def glib_window(Xmin,Ymin,Xmax,Ymax) {
! 122: extern Glib_xmin, Glib_xmax, Glib_ymin, Glib_ymax,
! 123: Glib_canvas_x, Glib_canvas_y, Glib_process, Glib_canvas,
! 124: Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag;
! 125: if (Xmax <= Xmin) error("glib window: Invalid size");
! 126: if (Ymax <= Ymin) error("glib window: Invalid size");
! 127: Glib_xmin = Xmin; Glib_xmax = Xmax;
! 128: Glib_ymin = Ymin; Glib_ymax = Ymax;
! 129: Glib_xoffset = -Xmin;
! 130: Glib_yoffset = -Ymin;
! 131: Glib_xmag = Glib_canvas_x/(Xmax-Xmin);
! 132: Glib_ymag = Glib_canvas_y/(Ymax-Ymin);
! 133: if (Glib_canvas < 0) glib_open();
! 134: }
! 135:
! 136: def glib_putpixel(X,Y) {
! 137: extern Glib_process, Glib_canvas,
! 138: Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag;
! 139: if (Glib_canvas < 0) glib_open();
! 140: glib_check();
! 141: draw_obj(Glib_process,Glib_canvas,
! 142: [floor(Glib_xmag*(X+Glib_xoffset)),
! 143: floor(Glib_ymag*(Y+Glib_yoffset))]);
! 144: }
! 145:
! 146: def glib_line(X0,Y0,X1,Y1) {
! 147: extern Glib_xmag, Glib_ymag, Glib_xoffset, Glib_yoffset;
! 148: glib_clip_line(floor(Glib_xmag*(X0+Glib_xoffset)),
! 149: floor(Glib_ymag*(Y0+Glib_yoffset)),
! 150: floor(Glib_xmag*(X1+Glib_xoffset)),
! 151: floor(Glib_ymag*(Y1+Glib_yoffset)));
! 152: }
! 153:
! 154: def glib_clip_line(X0,Y0,X1,Y1) {
! 155: /* X0, Y0, X1, Y1 should be integers.
! 156: Coordinates are already translated. */
! 157: extern Glib_process, Glib_canvas, Glib_canvas_x, Glib_canvas_y;
! 158: if (Glib_canvas < 0) glib_open();
! 159:
! 160: #ifdef CLIP
! 161: #ifdef DEBUG
! 162: print(["clip_line",[X0,Y0,X1,Y1]]);
! 163: #endif
! 164: /* clip by x = 0 */
! 165: S = glib_clip0_x(X0,Y0,X1,Y1,0);
! 166: #ifdef DEBUG
! 167: print(["clip0_x",S]);
! 168: #endif
! 169: if (type(S) == 0) return;
! 170: X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
! 171:
! 172: S = glib_clip1_x(X0,Y0,X1,Y1,Glib_canvas_x-1);
! 173: #ifdef DEBUG
! 174: print(["clip1_x",S]);
! 175: #endif
! 176: if (type(S) == 0) return;
! 177: X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
! 178:
! 179: S = glib_clip0_y(X0,Y0,X1,Y1,0);
! 180: #ifdef DEBUG
! 181: print(["clip0_y",S]);
! 182: #endif
! 183: if (type(S) == 0) return;
! 184: X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
! 185:
! 186: S = glib_clip1_y(X0,Y0,X1,Y1,Glib_canvas_y-1);
! 187: #ifdef DEBUG
! 188: print(["clip1_y",S]);
! 189: #endif
! 190: if (type(S) == 0) return;
! 191: X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
! 192:
! 193: #ifdef DEBUG
! 194: print([X0,Y0,X1,Y1]);
! 195: #endif
! 196: #endif
! 197: glib_check();
! 198: draw_obj(Glib_process,Glib_canvas,
! 199: [floor(X0),floor(Y0),floor(X1),floor(Y1)]);
! 200:
! 201: }
! 202:
! 203: def glib_clip0_x(X0,Y0,X1,Y1,Clip) {
! 204: if (X0 < Clip && X1 < Clip) return(0);
! 205: if (X0 < Clip && X1 > Clip) {
! 206: return([Clip, Y0+(Clip-X0)*(Y1-Y0)/(X1-X0),X1,Y1]);
! 207: }
! 208: if (X1 > Clip && X1 < Clip) {
! 209: return([X0,Y0,Clip, Y1+(Clip-X1)*(Y0-Y1)/(X0-X1)]);
! 210: }
! 211: return([X0,Y0,X1,Y1]);
! 212: }
! 213: def glib_clip0_y(X0,Y0,X1,Y1,Clip) {
! 214: if (Y0 < Clip && Y1 < Clip) return(0);
! 215: if (Y0 < Clip && Y1 > Clip) {
! 216: return([X0+(Clip-Y0)*(X1-X0)/(Y1-Y0),Clip,X1,Y1]);
! 217: }
! 218: if (Y1 > Clip && Y1 < Clip) {
! 219: return([X0,Y0,X1+(Clip-Y1)*(X0-X1)/(Y0-Y1),Clip]);
! 220: }
! 221: return([X0,Y0,X1,Y1]);
! 222: }
! 223: def glib_clip1_x(X0,Y0,X1,Y1,Clip) {
! 224: if (X0 > Clip && X1 > Clip) return(0);
! 225: if (X0 > Clip && X1 < Clip) {
! 226: return([Clip, Y0+(Clip-X0)*(Y1-Y0)/(X1-X0),X1,Y1]);
! 227: }
! 228: if (X1 < Clip && X1 > Clip) {
! 229: return([X0,Y0,Clip, Y1+(Clip-X1)*(Y0-Y1)/(X0-X1)]);
! 230: }
! 231: return([X0,Y0,X1,Y1]);
! 232: }
! 233: def glib_clip1_y(X0,Y0,X1,Y1,Clip) {
! 234: if (Y0 > Clip && Y1 > Clip) return(0);
! 235: if (Y0 > Clip && Y1 < Clip) {
! 236: return([X0+(Clip-Y0)*(X1-X0)/(Y1-Y0),Clip,X1,Y1]);
! 237: }
! 238: if (Y0 < Clip && Y1 > Clip) {
! 239: return([X0,Y0,X1+(Clip-Y1)*(X0-X1)/(Y0-Y1),Clip]);
! 240: }
! 241: return([X0,Y0,X1,Y1]);
! 242: }
! 243: end$
! 244:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>