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/Int16Vec3D.h"
     20 #include "b_BasicEm/Functions.h"
     21 #include "b_BasicEm/Math.h"
     22 #include "b_BasicEm/Memory.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 /* ========================================================================= */
     43 /*                                                                           */
     44 /* ---- \ghd{ operators } -------------------------------------------------- */
     45 /*                                                                           */
     46 /* ========================================================================= */
     47 
     48 /* ------------------------------------------------------------------------- */
     49 
     50 /* ========================================================================= */
     51 /*                                                                           */
     52 /* ---- \ghd{ query functions } -------------------------------------------- */
     53 /*                                                                           */
     54 /* ========================================================================= */
     55 
     56 /* ------------------------------------------------------------------------- */
     57 
     58 /* ========================================================================= */
     59 /*                                                                           */
     60 /* ---- \ghd{ modify functions } ------------------------------------------- */
     61 /*                                                                           */
     62 /* ========================================================================= */
     63 
     64 /* ------------------------------------------------------------------------- */
     65 
     66 /* ========================================================================= */
     67 /*                                                                           */
     68 /* ---- \ghd{ I/O } -------------------------------------------------------- */
     69 /*                                                                           */
     70 /* ========================================================================= */
     71 
     72 /* ------------------------------------------------------------------------- */
     73 
     74 uint32 bts_Int16Vec3D_memSize( struct bbs_Context* cpA,
     75 							   const struct bts_Int16Vec3D *ptrA )
     76 {
     77 	return bbs_SIZEOF16( struct bts_Int16Vec3D );
     78 }
     79 
     80 /* ------------------------------------------------------------------------- */
     81 
     82 uint32 bts_Int16Vec3D_memWrite( struct bbs_Context* cpA,
     83 							    const struct bts_Int16Vec3D* ptrA,
     84 								uint16* memPtrA )
     85 {
     86 	memPtrA += bbs_memWrite16( &ptrA->xE, memPtrA );
     87 	memPtrA += bbs_memWrite16( &ptrA->yE, memPtrA );
     88 	memPtrA += bbs_memWrite16( &ptrA->zE, memPtrA );
     89 	return bbs_SIZEOF16( *ptrA );
     90 }
     91 
     92 /* ------------------------------------------------------------------------- */
     93 
     94 uint32 bts_Int16Vec3D_memRead( struct bbs_Context* cpA,
     95 							   struct bts_Int16Vec3D* ptrA,
     96 							   const uint16* memPtrA )
     97 {
     98 	if( bbs_Context_error( cpA ) ) return 0;
     99 	memPtrA += bbs_memRead16( &ptrA->xE, memPtrA );
    100 	memPtrA += bbs_memRead16( &ptrA->yE, memPtrA );
    101 	memPtrA += bbs_memRead16( &ptrA->zE, memPtrA );
    102 	return bbs_SIZEOF16( *ptrA );
    103 }
    104 
    105 /* ------------------------------------------------------------------------- */
    106 
    107 /* ========================================================================= */
    108 /*                                                                           */
    109 /* ---- \ghd{ exec functions } --------------------------------------------- */
    110 /*                                                                           */
    111 /* ========================================================================= */
    112 
    113 /* ------------------------------------------------------------------------- */
    114 
    115 uint32 bts_Int16Vec3D_norm2( const struct bts_Int16Vec3D* ptrA )
    116 {
    117 	return ( int32 ) ptrA->xE * ptrA->xE +
    118 		   ( int32 ) ptrA->yE * ptrA->yE +
    119 		   ( int32 ) ptrA->zE * ptrA->zE;
    120 }
    121 
    122 /* ------------------------------------------------------------------------- */
    123 
    124 uint16 bts_Int16Vec3D_norm( const struct bts_Int16Vec3D* ptrA )
    125 {
    126 	return bbs_sqrt32( ( int32 ) ptrA->xE * ptrA->xE +
    127 					   ( int32 ) ptrA->yE * ptrA->yE +
    128 					   ( int32 ) ptrA->zE * ptrA->zE );
    129 }
    130 
    131 /* ------------------------------------------------------------------------- */
    132 
    133 void bts_Int16Vec3D_normalize( struct bts_Int16Vec3D* ptrA, int32 bbpA )
    134 {
    135 	int32 normL = bbs_sqrt32( ( int32 ) ptrA->xE * ptrA->xE +
    136 							  ( int32 ) ptrA->yE * ptrA->yE +
    137 							  ( int32 ) ptrA->zE * ptrA->zE );
    138 
    139 	int32 xL = ( ( int32 )ptrA->xE << 16 ) / normL;
    140 	int32 yL = ( ( int32 )ptrA->yE << 16 ) / normL;
    141 	int32 zL = ( ( int32 )ptrA->zE << 16 ) / normL;
    142 	ptrA->xE = xL >> ( 16 - bbpA );
    143 	ptrA->yE = yL >> ( 16 - bbpA );
    144 	ptrA->zE = zL >> ( 16 - bbpA );
    145 }
    146 
    147 /* ------------------------------------------------------------------------- */
    148 
    149 struct bts_Int16Vec3D bts_Int16Vec3D_normalized( const struct bts_Int16Vec3D* ptrA, int32 bbpA )
    150 {
    151 	struct bts_Int16Vec3D vecL = *ptrA;
    152 	bts_Int16Vec3D_normalize( &vecL, bbpA );
    153 	return vecL;
    154 }
    155 
    156 /* ------------------------------------------------------------------------- */
    157 
    158 /* ========================================================================= */
    159 
    160