Home | History | Annotate | Download | only in b_TensorEm
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /* ---- includes ----------------------------------------------------------- */
     18 
     19 #include "b_TensorEm/Int16Vec2D.h"
     20 #include "b_BasicEm/Math.h"
     21 #include "b_BasicEm/Memory.h"
     22 #include "b_BasicEm/Functions.h"
     23 
     24 /* ------------------------------------------------------------------------- */
     25 
     26 /* ========================================================================= */
     27 /*                                                                           */
     28 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */
     29 /*                                                                           */
     30 /* ========================================================================= */
     31 
     32 /* ------------------------------------------------------------------------- */
     33 
     34 /* ========================================================================= */
     35 /*                                                                           */
     36 /* ---- \ghd{ constructor / destructor } ----------------------------------- */
     37 /*                                                                           */
     38 /* ========================================================================= */
     39 
     40 /* ------------------------------------------------------------------------- */
     41 
     42 void bts_Int16Vec2D_init( struct bts_Int16Vec2D* ptrA )
     43 {
     44 	ptrA->xE = 0;
     45 	ptrA->yE = 0;
     46 }
     47 
     48 /* ------------------------------------------------------------------------- */
     49 
     50 void bts_Int16Vec2D_exit( struct bts_Int16Vec2D* ptrA )
     51 {
     52 	ptrA->xE = 0;
     53 	ptrA->yE = 0;
     54 }
     55 
     56 /* ------------------------------------------------------------------------- */
     57 
     58 /* ========================================================================= */
     59 /*                                                                           */
     60 /* ---- \ghd{ operators } -------------------------------------------------- */
     61 /*                                                                           */
     62 /* ========================================================================= */
     63 
     64 /* ------------------------------------------------------------------------- */
     65 
     66 /* ========================================================================= */
     67 /*                                                                           */
     68 /* ---- \ghd{ query functions } -------------------------------------------- */
     69 /*                                                                           */
     70 /* ========================================================================= */
     71 
     72 /* ------------------------------------------------------------------------- */
     73 
     74 /* ========================================================================= */
     75 /*                                                                           */
     76 /* ---- \ghd{ modify functions } ------------------------------------------- */
     77 /*                                                                           */
     78 /* ========================================================================= */
     79 
     80 /* ------------------------------------------------------------------------- */
     81 
     82 /* ========================================================================= */
     83 /*                                                                           */
     84 /* ---- \ghd{ I/O } -------------------------------------------------------- */
     85 /*                                                                           */
     86 /* ========================================================================= */
     87 
     88 /* ------------------------------------------------------------------------- */
     89 
     90 uint32 bts_Int16Vec2D_memSize( struct bbs_Context* cpA,
     91 							   const struct bts_Int16Vec2D *ptrA )
     92 {
     93 	return bbs_SIZEOF16( struct bts_Int16Vec2D );
     94 }
     95 
     96 /* ------------------------------------------------------------------------- */
     97 
     98 uint32 bts_Int16Vec2D_memWrite( struct bbs_Context* cpA,
     99 							    const struct bts_Int16Vec2D* ptrA,
    100 								uint16* memPtrA )
    101 {
    102 	memPtrA += bbs_memWrite16( &ptrA->xE, memPtrA );
    103 	memPtrA += bbs_memWrite16( &ptrA->yE, memPtrA );
    104 	return bbs_SIZEOF16( *ptrA );
    105 }
    106 
    107 /* ------------------------------------------------------------------------- */
    108 
    109 uint32 bts_Int16Vec2D_memRead( struct bbs_Context* cpA,
    110 							   struct bts_Int16Vec2D* ptrA,
    111 							   const uint16* memPtrA )
    112 {
    113 	if( bbs_Context_error( cpA ) ) return 0;
    114 	memPtrA += bbs_memRead16( &ptrA->xE, memPtrA );
    115 	memPtrA += bbs_memRead16( &ptrA->yE, memPtrA );
    116 	return bbs_SIZEOF16( *ptrA );
    117 }
    118 
    119 /* ------------------------------------------------------------------------- */
    120 
    121 /* ========================================================================= */
    122 /*                                                                           */
    123 /* ---- \ghd{ exec functions } --------------------------------------------- */
    124 /*                                                                           */
    125 /* ========================================================================= */
    126 
    127 /* ------------------------------------------------------------------------- */
    128 
    129 int32 bts_Int16Vec2D_dotPrd( const struct bts_Int16Vec2D* vec1PtrA,
    130 							 const struct bts_Int16Vec2D* vec2PtrA )
    131 {
    132 	return ( int32 ) vec1PtrA->xE * vec2PtrA->xE + ( int32 ) vec1PtrA->yE * vec2PtrA->yE;
    133 }
    134 
    135 /* ------------------------------------------------------------------------- */
    136 
    137 uint32 bts_Int16Vec2D_norm2( const struct bts_Int16Vec2D* ptrA )
    138 {
    139 	return ( int32 ) ptrA->xE * ptrA->xE + ( int32 ) ptrA->yE * ptrA->yE;
    140 }
    141 
    142 /* ------------------------------------------------------------------------- */
    143 
    144 uint16 bts_Int16Vec2D_norm( const struct bts_Int16Vec2D* ptrA )
    145 {
    146 	return bbs_sqrt32( ( int32 ) ptrA->xE * ptrA->xE + ( int32 ) ptrA->yE * ptrA->yE );
    147 }
    148 
    149 /* ------------------------------------------------------------------------- */
    150 
    151 void bts_Int16Vec2D_normalize( struct bts_Int16Vec2D* ptrA, int32 bbpA )
    152 {
    153 	int32 normL = bbs_sqrt32( ( int32 ) ptrA->xE * ptrA->xE + ( int32 ) ptrA->yE * ptrA->yE );
    154 	int32 xL = ( ( int32 ) ptrA->xE << 16 ) / normL;
    155 	int32 yL = ( ( int32 ) ptrA->yE << 16 ) / normL;
    156 	ptrA->xE = xL >> ( 16 - bbpA );
    157 	ptrA->yE = yL >> ( 16 - bbpA );
    158 }
    159 
    160 /* ------------------------------------------------------------------------- */
    161 
    162 struct bts_Int16Vec2D bts_Int16Vec2D_normalized( const struct bts_Int16Vec2D* ptrA, int32 bbpA )
    163 {
    164 	struct bts_Int16Vec2D vecL = *ptrA;
    165 	bts_Int16Vec2D_normalize( &vecL, bbpA );
    166 	return vecL;
    167 }
    168 
    169 /* ------------------------------------------------------------------------- */
    170 
    171 phase16 bts_Int16Vec2D_angle( const struct bts_Int16Vec2D* vecPtrA )
    172 {
    173 	return bbs_phase16( vecPtrA->xE, vecPtrA->yE );
    174 }
    175 
    176 /* ------------------------------------------------------------------------- */
    177 
    178 phase16 bts_Int16Vec2D_enclosedAngle( const struct bts_Int16Vec2D* vec1PtrA,
    179 									  const struct bts_Int16Vec2D* vec2PtrA )
    180 {
    181 	int32 xL = ( int32 ) vec1PtrA->xE * vec2PtrA->xE + ( int32 ) vec1PtrA->yE * vec2PtrA->yE;
    182 	int32 yL = ( int32 ) vec1PtrA->yE * vec2PtrA->xE - ( int32 ) vec1PtrA->xE * vec2PtrA->yE;
    183 	return bbs_phase16( xL, yL );
    184 }
    185 
    186 /* ------------------------------------------------------------------------- */
    187 
    188 /* ========================================================================= */
    189 
    190 
    191