123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- #include "sys-defines.h"
- #include "extern.h"
- #define ROUNDING_FUZZ 0.0000001
- #define OTHER_FUZZ 0.0000001
- int
- _API_fspace2 (R___(Plotter *_plotter) double x0, double y0, double x1, double y1, double x2, double y2)
- {
- double s[6];
- double v0x, v0y, v1x, v1y, v2x, v2y;
- double cross;
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "fspace2: invalid operation");
- return -1;
- }
-
- v0x = x0;
- v0y = y0;
- v1x = x1 - x0;
- v1y = y1 - y0;
- v2x = x2 - x0;
- v2y = y2 - y0;
- cross = v1x * v2y - v1y * v2x;
- if (cross == 0.0)
- {
- _plotter->error (R___(_plotter) "the requested singular affine transformation cannot be performed");
- return -1;
- }
-
- s[0] = v2y / cross;
- s[1] = -v1y / cross;
- s[2] = -v2x / cross;
- s[3] = v1x / cross;
-
- s[4] = - (v0x * v2y - v0y * v2x) / cross;
- s[5] = (v0x * v1y - v0y * v1x) / cross;
-
- return _API_fsetmatrix (R___(_plotter)
- s[0], s[1], s[2], s[3], s[4], s[5]);
- }
- int
- _API_fspace (R___(Plotter *_plotter) double x0, double y0, double x1, double y1)
- {
- return _API_fspace2 (R___(_plotter) x0, y0, x1, y0, x0, y1);
- }
- int
- _API_fsetmatrix (R___(Plotter *_plotter) double m0, double m1, double m2, double m3, double m4, double m5)
- {
- int i;
- double s[6], t[6];
- double norm, min_sing_val, max_sing_val;
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "fsetmatrix: invalid operation");
- return -1;
- }
-
- s[0] = m0;
- s[1] = m1;
- s[2] = m2;
- s[3] = m3;
-
- s[4] = m4;
- s[5] = m5;
-
- for (i = 0; i < 6; i++)
- _plotter->drawstate->transform.m_user_to_ndc[i] = s[i];
-
- _matrix_product (s, _plotter->data->m_ndc_to_device, t);
- for (i = 0; i < 6; i++)
- _plotter->drawstate->transform.m[i] = t[i];
-
-
- _plotter->drawstate->transform.axes_preserved =
- (t[1] == 0.0 && t[2] == 0.0) ? true : false;
-
- #define IS_ZERO(arg) (IS_ZERO1(arg) && IS_ZERO2(arg))
- #define IS_ZERO1(arg) (FABS(arg) < OTHER_FUZZ * DMAX(t[0] * t[0], t[1] * t[1]))
- #define IS_ZERO2(arg) (FABS(arg) < OTHER_FUZZ * DMAX(t[2] * t[2], t[3] * t[3]))
- /* if row vectors are of equal length and orthogonal... */
- if (IS_ZERO(t[0] * t[0] + t[1] * t[1] - t[2] * t[2] - t[3] * t[3])
- &&
- IS_ZERO(t[0] * t[2] + t[1] * t[3]))
- /* map's scaling is uniform */
- _plotter->drawstate->transform.uniform = true;
- else
-
- _plotter->drawstate->transform.uniform = false;
-
- {
- double det;
-
- det = t[0] * t[3] - t[1] * t[2];
- _plotter->drawstate->transform.nonreflection
- = ((_plotter->data->flipped_y ? -1 : 1) * det >= 0) ? true : false;
- }
-
-
-
-
- _matrix_sing_vals (s, &min_sing_val, &max_sing_val);
- norm = min_sing_val;
-
- if (_plotter->data->display_coors_type
- == (int)DISP_DEVICE_COORS_INTEGER_LIBXMI)
-
- _plotter->drawstate->default_line_width = 0.0;
- else
-
- {
- if (norm == 0.0)
- _plotter->drawstate->default_line_width = 0.0;
- else
- _plotter->drawstate->default_line_width
- = PL_DEFAULT_LINE_WIDTH_AS_FRACTION_OF_DISPLAY_SIZE / norm;
- }
- if (_plotter->data->linewidth_invoked == false)
-
- {
-
- _API_flinewidth (R___(_plotter) -1.0);
-
- _plotter->data->linewidth_invoked = false;
- }
- else
-
- _API_flinewidth (R___(_plotter) _plotter->drawstate->line_width);
-
- if (norm == 0.0)
- _plotter->drawstate->default_font_size = 0.0;
- else
- _plotter->drawstate->default_font_size
- = PL_DEFAULT_FONT_SIZE_AS_FRACTION_OF_DISPLAY_SIZE / norm;
-
- if (_plotter->data->fontsize_invoked == false)
- _plotter->drawstate->font_size = _plotter->drawstate->default_font_size;
-
- return 0;
- }
- int
- _API_fconcat (R___(Plotter *_plotter) double m0, double m1, double m2, double m3, double m4, double m5)
- {
- double m[6], s[6];
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "fconcat: invalid operation");
- return -1;
- }
- m[0] = m0;
- m[1] = m1;
- m[2] = m2;
- m[3] = m3;
- m[4] = m4;
- m[5] = m5;
-
- _matrix_product (m, _plotter->drawstate->transform.m_user_to_ndc, s);
-
- return _API_fsetmatrix (R___(_plotter)
- s[0], s[1], s[2], s[3], s[4], s[5]);
- }
- bool
- _compute_ndc_to_device_map (plPlotterData *data)
- {
- double t[6];
- double map_1[6], map_2[6], map_1a[6], map_1b[6], map_1ab[6], map_1c[6];
- double device_x_left, device_x_right, device_y_bottom, device_y_top;
- const char *rotation_s;
- double rotation_angle;
- int i;
-
- switch (data->display_model_type)
- {
- case (int)DISP_MODEL_PHYSICAL:
-
- {
- device_x_left = data->xmin;
- device_x_right = data->xmax;
- device_y_bottom = data->ymin;
- device_y_top = data->ymax;
- }
- break;
- case (int)DISP_MODEL_VIRTUAL:
- default:
-
- {
- switch ((int)data->display_coors_type)
- {
- case (int)DISP_DEVICE_COORS_REAL:
- default:
-
- device_x_left = data->xmin;
- device_x_right = data->xmax;
- device_y_bottom = data->ymin;
- device_y_top = data->ymax;
- break;
- case (int)DISP_DEVICE_COORS_INTEGER_LIBXMI:
- case (int)DISP_DEVICE_COORS_INTEGER_NON_LIBXMI:
-
- {
-
- double x_sign = (data->imin < data->imax ? 1.0 : -1.0);
- double y_sign = (data->jmin < data->jmax ? 1.0 : -1.0);
-
- device_x_left = ((double)(data->imin)
- + x_sign * (- 0.5 + ROUNDING_FUZZ));
- device_x_right = ((double)(data->imax)
- + x_sign * (0.5 - ROUNDING_FUZZ));
- device_y_bottom = ((double)(data->jmin)
- + y_sign * (- 0.5 + ROUNDING_FUZZ));
- device_y_top = ((double)(data->jmax)
- + y_sign * (0.5 - ROUNDING_FUZZ));
- }
- break;
- }
- }
- break;
- }
-
-
- rotation_s = (const char *)_get_plot_param (data, "ROTATION");
- if (rotation_s == NULL)
- rotation_s = (const char *)_get_default_plot_param ("ROTATION");
- if (strcmp (rotation_s, "no") == 0)
- rotation_angle = 0.0;
- else if (strcmp (rotation_s, "yes") == 0)
- rotation_angle = 90.0;
- else if (sscanf (rotation_s, "%lf", &rotation_angle) <= 0)
- rotation_angle = 0.0;
- rotation_angle *= (M_PI / 180.0);
- map_1a[0] = map_1a[3] = 1.0;
- map_1a[1] = map_1a[2] = 0.0;
- map_1a[4] = map_1a[5] = -0.5;
-
- map_1b[0] = cos (rotation_angle);
- map_1b[1] = sin (rotation_angle);
- map_1b[2] = - sin (rotation_angle);
- map_1b[3] = cos (rotation_angle);
- map_1b[4] = map_1b[5] = 0.0;
-
- map_1c[0] = map_1c[3] = 1.0;
- map_1c[1] = map_1c[2] = 0.0;
- map_1c[4] = map_1c[5] = 0.5;
-
- _matrix_product (map_1a, map_1b, map_1ab);
- _matrix_product (map_1ab, map_1c, map_1);
-
-
-
- map_2[4] = device_x_left;
- map_2[5] = device_y_bottom;
-
- map_2[0] = device_x_right - device_x_left;
- map_2[1] = 0.0;
-
- map_2[2] = 0.0;
- map_2[3] = device_y_top - device_y_bottom;
-
-
- _matrix_product (map_1, map_2, t);
-
- for (i = 0; i < 6; i++)
- data->m_ndc_to_device[i] = t[i];
- return true;
- }
|