------------------------------------------------------------------ -- -- NAME: TRANSLATION_FACTORS - BODY -- DISCREPANCY REPORTS: -- ------------------------------------------------------------------ -- file: trans_fact_b.ada -- level: all package body TRANSLATION_FACTORS is -- The package TRANSLATION_FACTORS contains functions that compute -- the scale factor and translation factor used in translating points -- from one coordinate system to another. function GET_NORMALIZATION_FACTORS (WINDOW : WC.RECTANGLE_LIMITS; VIEWPORT : NDC.RECTANGLE_LIMITS) return TRANSFORMATION_MATRIX is -- The function GET_NORMALIZATON_FACTORS computes the scale factor -- translation factor for going from world coordinates to normalized -- device coordinates. The final matrix consists of -- SX - X scale factor. -- SY - Y scale factor. -- TX - X window minimum. -- TY - Y window minimum. -- RX - X viewport minimum. -- RY - Y viewport minimum. -- The matrix to be returned is: -- SX RX TX -- RY SY TY -- Due to precision errors that caused areas to be clipped -- wrongfully, this matrix was changed to its present state. -- -- WINDOW - The window coordinates. -- -- VIEWPORT - The viewport coordinates. TEMPORARY : TRANSFORMATION_MATRIX; -- The matrix to return. begin -- The X scale factor. TEMPORARY (1,1) := (VIEWPORT.XMAX - VIEWPORT.XMIN)/ (NDC_TYPE (WINDOW.XMAX - WINDOW.XMIN)); -- The window minimum. TEMPORARY (1,2) := NDC_TYPE (WINDOW.XMIN); -- The viewport minimum. TEMPORARY (1,3) := VIEWPORT.XMIN; -- The window minimum Y. TEMPORARY (2,1) := NDC_TYPE (WINDOW.YMIN); -- The Y scale factor. TEMPORARY (2,2) := (VIEWPORT.YMAX - VIEWPORT.YMIN) / (NDC_TYPE (WINDOW.YMAX - WINDOW.YMIN)); -- The viewport minimum Y. TEMPORARY (2,3) := VIEWPORT.YMIN; return TEMPORARY; end GET_NORMALIZATION_FACTORS; function GET_NORMALIZATION_FACTORS (WINDOW : NDC.RECTANGLE_LIMITS; VIEWPORT : WC.RECTANGLE_LIMITS) return TRANSFORMATION_MATRIX is -- The function GET_NORMALIZATON_FACTORS computes the scale factor -- translation factor for going from normalized device coordinates -- to world coordinates. The final matrix consists of -- SX - X scale factor. -- SY - Y scale factor. -- TX - X window minimum. -- TY - Y window minimum. -- RX - X viewport minimum. -- RY - Y viewport minimum. -- The matrix to be returned is: -- SX RX TX -- RY SY TY -- Due to precision errors that caused areas to be clipped -- wrongfully, this matrix was changed to its present state. -- -- WINDOW - The window coordinates. -- -- VIEWPORT - The viewport coordinates. TEMPORARY : TRANSFORMATION_MATRIX; -- The matrix to be returned. begin -- X scale factor. TEMPORARY (1,1) := (NDC_TYPE (VIEWPORT.XMAX - VIEWPORT.XMIN) )/ (WINDOW.XMAX - WINDOW.XMIN); -- The window minimum. TEMPORARY (1,2) := WINDOW.XMIN; -- The viewport minimum. TEMPORARY (1,3) := NDC_TYPE (VIEWPORT.XMIN); -- The window minimum Y. TEMPORARY (2,1) := WINDOW.YMIN; -- Y scale factor. TEMPORARY (2,2) := (NDC_TYPE (VIEWPORT.YMAX - VIEWPORT.YMIN) ) / (WINDOW.YMAX - WINDOW.YMIN); -- The viewport minimum Y. TEMPORARY (2,3) := NDC_TYPE (VIEWPORT.YMIN); return TEMPORARY; end GET_NORMALIZATION_FACTORS; end TRANSLATION_FACTORS;