// Math2Disp module Ver.0.20 by fujidig #module Math2Disp #deffunc _init@Math2Disp xSize = 32.0 ySize = -32.0 xPos = double( ginfo_sx ) / 2 yPos = double( ginfo_sy ) / 2 return // 1マスあたりのピクセルを設定 #define global m2d_SetSize( %1, %2, %3 = 1, %4 = 1 ) _m2d_SetSize %1, %2, %3, %4 #deffunc _m2d_SetSize double dispX, double dispY, double mathX, double mathY if( ( dispX * dispY * mathX * mathY ) == 0.0 ) { // どれか少なくとも一つが 0 なら return 1 // エラー } xSize = dispX / mathX ySize = -( dispY / mathY ) return 0 // 1マスあたりのピクセルを取得 #define global m2d_GetSizeX( %1 = 1 ) _m2d_GetSizeX %1 #defcfunc _m2d_GetSizeX double mathX return xSize * mathX #define global m2d_GetSizeY( %1 = 1 ) _m2d_GetSizeY %1 #defcfunc _m2d_GetSizeY double mathY return ySize * mathY // 原点の位置(ピクセル)を指定 #define global m2d_SetPos( %1, %2, %3 = 0, %4 = 0 ) _m2d_SetPos %1, %2, %3, %4 #deffunc _m2d_SetPos double dispX, double dispY, double mathX, double mathY xPos = dispX - xSize * MathX yPos = dispY - ySize * MathY return // 二点の座標とそれに対応する数学座標から位置とサイズを設定 #deffunc m2d_Set double dispX1, double dispY1, double mathX1, double mathY1, \ double dispX2, double dispY2, double mathX2, double mathY2 m2d_SetSize dispX2 - dispX1, dispY2 - dispY1, mathX2 - mathX1, mathY1 - mathY2 if ( stat == 1 ) : return 1 m2d_SetPos dispX1, dispY1, mathX1, mathY1 return 0 // 数学座標からディスプレイ座標を取得 #defcfunc m2d_GetDispX double x return xPos + xSize * x #defcfunc m2d_GetDispY double y return yPos + ySize * y // ディスプレイ座標から数学座標を取得 #defcfunc m2d_GetMathX double x return ( x - xPos ) / xSize #defcfunc m2d_GetMathY double Y return ( y - yPos ) / ySize // 画面端の数学座標 #deffunc m2d_GetEdgeMathX var minMathX, var maxMathX, local MathXDispLeft, local MathXDispRight MathXDispLeft = m2d_GetMathX( 0 ) MathXDispRight = m2d_GetMathX( ginfo_sx - 1 ) if ( MathXDispRight > MathXDispLeft ) { minMathX = MathXDispLeft maxMathX = MathXDispRight } else { minMathX = MathXDispRight maxMathX = MathXDispLeft } return #deffunc m2d_GetEdgeMathY var minMathY, var maxMathY, local MathXDispTop, local MathXDispBottom MathXDispTop = m2d_GetMathY( 0 ) MathXDispBottom = m2d_GetMathY( ginfo_sy - 1 ) if ( MathXDispBottom > MathXDispTop ) { minMathY = MathXDispTop maxMathY = MathXDispBottom } else { minMathY = MathXDispBottom maxMathY = MathXDispTop } return // 指定座標が画面内か #defcfunc m2d_IsXInScreen double mathX, local dispX dispX = m2d_GetDispX( mathX ) if ( ( dispX < 0 ) || ( dispX >= ginfo_sx ) ) { return 0 } return 1 #defcfunc m2d_IsYInScreen double mathY, local dispY dispY = m2d_GetDispY( mathY ) if ( ( dispY < 0 ) || ( dispY >= ginfo_sy ) ) { return 0 } return 1 #defcfunc m2d_IsPtInScreen double mathX, double mathY return IsXInScreen( mathX ) && IsYInScreen( mathY ) // グリッドを描画する #deffunc drawGridX@Math2Disp local mathX, local mathXInc, local mathEndX, local dispX, local dispXInc, local fDrawGraduation, local GraduationPosY m2d_GetEdgeMathX mathX, mathEndX mathXInc = 1.0 mathX = double( int( mathX / mathXInc ) ) * mathXInc dispX = m2d_GetDispX( mathX ) dispXInc = xSize * mathXInc fDrawGraduation = m2d_IsYInScreen( 0 ) if ( fDrawGraduation ) { GraduationPosY = m2d_GetDispY( 0 ) font "Times New Roman", 16 } repeat if ( mathX == 0.0 ) { color } else { color 224, 224, 224 } line dispX, ginfo_sy, dispX, 0 if ( fDrawGraduation ) { color pos dispX, GraduationPosY mes strf( "%g", mathX ) } if( mathX > mathEndX ) { break } mathX += mathXInc dispX += dispXInc loop return #deffunc drawGridY@Math2Disp local mathY, local mathYInc, local mathEndY, local dispY, local dispYInc, local fDrawGraduation, local GraduationPosX m2d_GetEdgeMathY mathY, mathEndY mathYInc = 1.0 mathY = double( int( mathY / mathYInc ) ) * mathYInc dispY = m2d_GetDispY( mathY ) dispYInc = ySize * mathYInc fDrawGraduation = m2d_IsXInScreen( 0 ) if ( fDrawGraduation ) { GraduationPosX = m2d_GetDispX( 0 ) font "Times New Roman", 16 } repeat if ( mathY == 0.0 ) { color } else { color 224, 224, 224 } line ginfo_sx, dispY, 0, dispY if ( fDrawGraduation ) { color pos m2d_GetDispX( 0 ), dispY mes strf( "%g", mathY ) } if( mathY > mathEndY ) { break } mathY += mathYInc dispY += dispYInc loop return #deffunc m2d_DrawGrid drawGridX drawGridY return #global _init@Math2Disp