struct vec2 Vec2FromRadians(const float radians) { struct vec2 v = svec2_rotate(svec2(0, -1), radians); // Scale Y so that they match the tile ratios v.y *= (float)TILE_HEIGHT / TILE_WIDTH; return v; }
struct vec2 NetToVec2(const NVec2 v) { return svec2(v.x, v.y); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { mxArray *blk_cell_pr; double *A, *B, *AI, *BI, *blksize; mwIndex *irA, *jcA, *irB, *jcB; int *cumblksize, *blknnz; int mblk, isspA, isspB, iscmpA; mwIndex subs[2]; mwSize nsubs=2; int m, n, n2, nsub, k, index, numblk, NZmax, type; double r2; /* CHECK FOR PROPER NUMBER OF ARGUMENTS */ if (nrhs < 2){ mexErrMsgTxt("mexsvec: requires at least 2 input arguments."); } if (nlhs > 1){ mexErrMsgTxt("mexsvec: requires 1 output argument."); } /* CHECK THE DIMENSIONS */ mblk = mxGetM(prhs[0]); if (mblk > 1) { mexErrMsgTxt("mexsvec: blk can have only 1 row."); } m = mxGetM(prhs[1]); n = mxGetN(prhs[1]); if (m != n) { mexErrMsgTxt("mexsvec: matrix must be square."); } subs[0] = 0; subs[1] = 1; index = mxCalcSingleSubscript(prhs[0],nsubs,subs); blk_cell_pr = mxGetCell(prhs[0],index); numblk = mxGetN(blk_cell_pr); blksize = mxGetPr(blk_cell_pr); if (numblk == 1) { n2 = n*(n+1)/2; } else { cumblksize = mxCalloc(numblk+1,sizeof(int)); blknnz = mxCalloc(numblk+1,sizeof(int)); cumblksize[0] = 0; blknnz[0] = 0; n = 0; n2 = 0; for (k=0; k<numblk; ++k) { nsub = (int) blksize[k]; n += nsub; n2 += nsub*(nsub+1)/2; cumblksize[k+1] = n; blknnz[k+1] = n2; } } /***** assign pointers *****/ A = mxGetPr(prhs[1]); isspA = mxIsSparse(prhs[1]); iscmpA = mxIsComplex(prhs[1]); if (isspA) { irA = mxGetIr(prhs[1]); jcA = mxGetJc(prhs[1]); NZmax = mxGetNzmax(prhs[1]); } else { NZmax = n2; } if (iscmpA) { AI = mxGetPi(prhs[1]); } if ((numblk > 1) & (!isspA)) { mexErrMsgTxt("mexsvec: matrix must be sparse for numblk > 1"); } if (nrhs > 2) { if (mxGetM(prhs[2])>1) { isspB = (int)*mxGetPr(prhs[2]); } else if (NZmax < n2/2) { isspB = 1; } else { isspB = 0; } } else { if (NZmax < n2/2) { isspB = 1; } else { isspB = 0; } } if (nrhs > 3) { type = (int)*mxGetPr(prhs[3]); } else { type = 0; } /***** create return argument *****/ if (isspB) { if (iscmpA) { plhs[0] = mxCreateSparse(n2,1,NZmax,mxCOMPLEX); } else { plhs[0] = mxCreateSparse(n2,1,NZmax,mxREAL); } B = mxGetPr(plhs[0]); irB = mxGetIr(plhs[0]); jcB = mxGetJc(plhs[0]); jcB[0] = 0; } else { if (iscmpA) { plhs[0] = mxCreateDoubleMatrix(n2,1,mxCOMPLEX); } else { plhs[0] = mxCreateDoubleMatrix(n2,1,mxREAL); } B = mxGetPr(plhs[0]); } if (iscmpA) { BI = mxGetPi(plhs[0]); } /***** Do the computations in a subroutine *****/ r2 = sqrt(2); if (type == 0) { if (iscmpA) { if (numblk == 1) { svec1cmp(n,r2,A,irA,jcA,isspA,B,irB,jcB,isspB,AI,BI); } else { svec2cmp(n,numblk,cumblksize,blknnz,r2,A,irA,jcA,isspA,B,irB,jcB,isspB,AI,BI); } } else { if (numblk == 1) { svec1(n,r2,A,irA,jcA,isspA,B,irB,jcB,isspB); } else { svec2(n,numblk,cumblksize,blknnz,r2,A,irA,jcA,isspA,B,irB,jcB,isspB); } } } else { if (iscmpA) { if (numblk == 1) { svec3cmp(n,r2,A,irA,jcA,isspA,B,irB,jcB,isspB,AI,BI); } else { svec4cmp(n,numblk,cumblksize,blknnz,r2,A,irA,jcA,isspA,B,irB,jcB,isspB,AI,BI); } } else { if (numblk == 1) { svec3(n,r2,A,irA,jcA,isspA,B,irB,jcB,isspB); } else { svec4(n,numblk,cumblksize,blknnz,r2,A,irA,jcA,isspA,B,irB,jcB,isspB); } } } return; }
struct vec2 Vec2FromRadiansScaled(const float radians) { return svec2( sinf(radians), -cosf(radians) * TILE_HEIGHT / TILE_WIDTH); }