1 /* Copyright (C) 2001-2012 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, 8 modified or distributed except as expressly authorized under the terms 9 of the license contained in the file LICENSE in this distribution. 10 11 Refer to licensing information at http://www.artifex.com or contact 12 Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael, 13 CA 94903, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Definition of matrices and client interface to matrix routines */ 18 19 #ifndef gsmatrix_INCLUDED 20 # define gsmatrix_INCLUDED 21 22 /* See p. 65 of the PostScript manual for the semantics of */ 23 /* transformation matrices. */ 24 25 /* if you make any additions/changes to the gs_matrix_s structure or the 26 _matrix_body macro you need to make the appropriate additions/changes 27 to the gs_matrix_compare() function in gsmatrix.c */ 28 /* Structure for a transformation matrix. */ 29 #define _matrix_body\ 30 float xx, xy, yx, yy, tx, ty 31 struct gs_matrix_s { 32 _matrix_body; 33 }; 34 struct gs_matrix_double_s { 35 double xx, xy, yx, yy, tx, ty; 36 }; 37 38 #ifndef gs_matrix_DEFINED 39 # define gs_matrix_DEFINED 40 typedef struct gs_matrix_s gs_matrix; 41 #endif 42 #ifndef gs_matrix_double_DEFINED 43 # define gs_matrix_double_DEFINED 44 typedef struct gs_matrix_double_s gs_matrix_double; 45 #endif 46 47 /* Macro for initializing constant matrices */ 48 #define constant_matrix_body(xx, xy, yx, yy, tx, ty)\ 49 (float)(xx), (float)(xy), (float)(yx),\ 50 (float)(yy), (float)(tx), (float)(ty) 51 52 /* Macros for testing whether matrix coefficients are zero, */ 53 /* for shortcuts when the matrix is simple. */ 54 #define is_xxyy(pmat) is_fzero2((pmat)->xy, (pmat)->yx) 55 #define is_xyyx(pmat) is_fzero2((pmat)->xx, (pmat)->yy) 56 57 /* The identity matrix (for structure initialization) */ 58 #define identity_matrix_body\ 59 constant_matrix_body(1, 0, 0, 1, 0, 0) 60 61 /* Matrix creation */ 62 void gs_make_identity(gs_matrix *); 63 int gs_make_translation(floatp, floatp, gs_matrix *), 64 gs_make_scaling(floatp, floatp, gs_matrix *), 65 gs_make_rotation(floatp, gs_matrix *); 66 67 /* Matrix arithmetic */ 68 int gs_matrix_multiply(const gs_matrix *, const gs_matrix *, gs_matrix *), 69 gs_matrix_multiply_double(const gs_matrix_double *, const gs_matrix *, gs_matrix_double *), 70 gs_matrix_invert(const gs_matrix *, gs_matrix *), 71 gs_matrix_invert_to_double(const gs_matrix *, gs_matrix_double *), 72 gs_matrix_translate(const gs_matrix *, floatp, floatp, gs_matrix *), 73 gs_matrix_scale(const gs_matrix *, floatp, floatp, gs_matrix *), 74 gs_matrix_rotate(const gs_matrix *, floatp, gs_matrix *); 75 76 /* Matrix comparison */ 77 int gs_matrix_compare(const gs_matrix *, const gs_matrix *); 78 79 /* Coordinate transformation */ 80 int gs_point_transform(floatp, floatp, const gs_matrix *, gs_point *), 81 gs_point_transform_inverse(floatp, floatp, const gs_matrix *, gs_point *), 82 gs_distance_transform(floatp, floatp, const gs_matrix *, gs_point *), 83 gs_distance_transform_inverse(floatp, floatp, const gs_matrix *, gs_point *), 84 gs_points_bbox(const gs_point[4], gs_rect *), 85 gs_bbox_transform_only(const gs_rect *, const gs_matrix *, gs_point[4]), 86 gs_bbox_transform(const gs_rect *, const gs_matrix *, gs_rect *), 87 gs_bbox_transform_inverse(const gs_rect *, const gs_matrix *, gs_rect *); 88 89 /* Serialization */ 90 #ifndef stream_DEFINED 91 # define stream_DEFINED 92 typedef struct stream_s stream; 93 #endif 94 int sget_matrix(stream *, gs_matrix *); 95 int sput_matrix(stream *, const gs_matrix *); 96 97 #endif /* gsmatrix_INCLUDED */ 98