Changeset 16256 for trunk/Ohana/src/kapa2/src/CursorOps.c
- Timestamp:
- Jan 27, 2008, 1:24:12 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/kapa2/src/CursorOps.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/kapa2/src/CursorOps.c
r16255 r16256 1 1 # include "Ximage.h" 2 2 3 void Screen_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) { 3 // input coordinates are relative to the picture bounding box 4 void Picture_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) { 4 5 5 double xs, ys,expand;6 double expand; 6 7 7 8 expand = 1.0; … … 12 13 } 13 14 14 // pixel coordinates in picture frame 15 xs = x2 - picture[0].x; 16 ys = y2 - picture[0].y; 17 18 // picture[0].X,Y is the offset relative to picture[0].Xo,Yo 19 *x1 = expand*(xs - 0.5*picture[0].dx) + picture[0].Xo - picture[0].X; 20 *y1 = expand*(ys - 0.5*picture[0].dy) + picture[0].Yo - picture[0].Y; 15 // picture[0].X,Y is the image coordinate in the center of the picture 16 *x1 = expand*(x2 - 0.5*picture[0].dx) + picture[0].X; 17 *y1 = expand*(y2 - 0.5*picture[0].dy) + picture[0].Y; 21 18 } 22 19 23 void Image_to_Screen (double *x1, double *y1, double x2, double y2, Picture *picture) { 20 // input coordinates are relative to the X window 21 void Screen_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) { 24 22 25 double xs, ys, expand; 23 double xp, yp; 24 25 // pixel coordinates in picture frame 26 xp = x2 - picture[0].x; 27 yp = y2 - picture[0].y; 28 29 Picture_to_Image (x1, y1, xp, yp, picture); 30 } 31 32 void Image_to_Picture (double *x1, double *y1, double x2, double y2, Picture *picture) { 33 34 double expand; 26 35 27 36 /* notice that here, expand is the reciprocal of the expand above */ … … 34 43 35 44 // pixel coordinates in picture frame 36 xs = expand*(x2 - picture[0].Xo + picture[0].X) + 0.5*picture[0].dx; 37 ys = expand*(y2 - picture[0].Yo + picture[0].Y) + 0.5*picture[0].dy; 45 *x1 = expand*(x2 - picture[0].X) + 0.5*picture[0].dx; 46 *y1 = expand*(y2 - picture[0].Y) + 0.5*picture[0].dy; 47 } 48 49 void Image_to_Screen (double *x1, double *y1, double x2, double y2, Picture *picture) { 50 51 double xp, yp; 52 53 Image_to_Picture (&xp, &yp, x2, y2, picture); 38 54 39 55 // pixel coordinates in screen frame 40 *x1 = x s+ picture[0].x;41 *y1 = y s+ picture[0].y;56 *x1 = xp + picture[0].x; 57 *y1 = yp + picture[0].y; 42 58 } 43 59 60 // input coordinates are relative to the picture bounding box 61 void Picture_Lower (int *i_start, int *j_start, Matrix *matrix, Picture *picture) { 62 63 double Ix, Iy, Sx, Sy; 64 65 // Ix, Iy are the image coordinates of the specified screen pixel 66 Picture_to_Image (&Ix, &Iy, 0.0, 0.0, picture); 67 68 // Ix, Iy are now limited to valid image coordinates 69 Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]); 70 Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]); 71 72 // round up to nearest pixel boundary 73 if (Ix > (int)(Ix)) Ix = (int)(Ix) + 1; 74 if (Iy > (int)(Iy)) Iy = (int)(Iy) + 1; 75 76 // Sx, Sy are the screen coordinates of the Ix,Iy pixel 77 Image_to_Picture (&Sx, &Sy, Ix, Iy, picture); 78 79 // i_start, j_start are now limited to valid screen coordinates 80 *i_start = MIN (MAX (Sx, 0), picture[0].dx); 81 *j_start = MIN (MAX (Sy, 0), picture[0].dy); 82 } 83 84 // input coordinates are relative to the picture bounding box 85 void Picture_Upper (int *i_end, int *j_end, Matrix *matrix, Picture *picture) { 86 87 double Ix, Iy, Sx, Sy; 88 89 // Ix, Iy are the image coordinates of the specified screen pixel 90 Picture_to_Image (&Ix, &Iy, picture[0].dx, picture[0].dy, picture); 91 92 // Ix, Iy are now limited to valid image coordinates 93 Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]); 94 Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]); 95 96 // round down to nearest pixel boundary 97 if (Ix > (int)(Ix)) Ix = (int)(Ix); 98 if (Iy > (int)(Iy)) Iy = (int)(Iy); 99 100 // Sx, Sy are the screen coordinates of the Ix,Iy pixel 101 Image_to_Picture (&Sx, &Sy, Ix, Iy, picture); 102 103 // i_start, j_start are now limited to valid screen coordinates 104 *i_end = MIN (MAX (Sx, 0), picture[0].dx); 105 *j_end = MIN (MAX (Sy, 0), picture[0].dy); 106 }
Note:
See TracChangeset
for help on using the changeset viewer.
