17f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* 27f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 37f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * 47f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 57f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * you may not use this file except in compliance with the License. 67f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * You may obtain a copy of the License at 77f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * 87f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 97f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * 107f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software 117f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 127f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * See the License for the specific language governing permissions and 147f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project * limitations under the License. 157f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project */ 167f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 177f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- includes ----------------------------------------------------------- */ 187f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 197f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project#include "b_TensorEm/Int16Vec2D.h" 207f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project#include "b_BasicEm/Math.h" 217f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project#include "b_BasicEm/Memory.h" 227f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project#include "b_BasicEm/Functions.h" 237f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 247f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 257f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 267f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 277f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 287f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- \ghd{ auxiliary functions } ---------------------------------------- */ 297f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 307f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 317f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 327f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 337f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 347f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 357f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 367f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- \ghd{ constructor / destructor } ----------------------------------- */ 377f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 387f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 397f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 407f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 417f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 427f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectvoid bts_Int16Vec2D_init( struct bts_Int16Vec2D* ptrA ) 437f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 447f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project ptrA->xE = 0; 457f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project ptrA->yE = 0; 467f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 477f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 487f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 497f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 507f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectvoid bts_Int16Vec2D_exit( struct bts_Int16Vec2D* ptrA ) 517f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 527f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project ptrA->xE = 0; 537f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project ptrA->yE = 0; 547f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 557f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 567f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 577f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 587f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 597f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 607f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- \ghd{ operators } -------------------------------------------------- */ 617f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 627f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 637f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 647f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 657f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 667f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 677f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 687f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- \ghd{ query functions } -------------------------------------------- */ 697f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 707f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 717f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 727f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 737f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 747f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 757f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 767f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- \ghd{ modify functions } ------------------------------------------- */ 777f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 787f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 797f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 807f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 817f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 827f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 837f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 847f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- \ghd{ I/O } -------------------------------------------------------- */ 857f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 867f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 877f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 887f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 897f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 907f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectuint32 bts_Int16Vec2D_memSize( struct bbs_Context* cpA, 917f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project const struct bts_Int16Vec2D *ptrA ) 927f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 937f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return bbs_SIZEOF16( struct bts_Int16Vec2D ); 947f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 957f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 967f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 977f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 987f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectuint32 bts_Int16Vec2D_memWrite( struct bbs_Context* cpA, 997f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project const struct bts_Int16Vec2D* ptrA, 1007f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project uint16* memPtrA ) 1017f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1027f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project memPtrA += bbs_memWrite16( &ptrA->xE, memPtrA ); 1037f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project memPtrA += bbs_memWrite16( &ptrA->yE, memPtrA ); 1047f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return bbs_SIZEOF16( *ptrA ); 1057f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1067f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1077f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1087f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1097f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectuint32 bts_Int16Vec2D_memRead( struct bbs_Context* cpA, 1107f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project struct bts_Int16Vec2D* ptrA, 1117f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project const uint16* memPtrA ) 1127f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1137f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project if( bbs_Context_error( cpA ) ) return 0; 1147f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project memPtrA += bbs_memRead16( &ptrA->xE, memPtrA ); 1157f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project memPtrA += bbs_memRead16( &ptrA->yE, memPtrA ); 1167f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return bbs_SIZEOF16( *ptrA ); 1177f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1187f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1197f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1207f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1217f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 1227f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 1237f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ---- \ghd{ exec functions } --------------------------------------------- */ 1247f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* */ 1257f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 1267f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1277f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1287f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1297f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectint32 bts_Int16Vec2D_dotPrd( const struct bts_Int16Vec2D* vec1PtrA, 1307f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project const struct bts_Int16Vec2D* vec2PtrA ) 1317f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1327f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return ( int32 ) vec1PtrA->xE * vec2PtrA->xE + ( int32 ) vec1PtrA->yE * vec2PtrA->yE; 1337f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1347f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1357f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1367f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1377f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectuint32 bts_Int16Vec2D_norm2( const struct bts_Int16Vec2D* ptrA ) 1387f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1397f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return ( int32 ) ptrA->xE * ptrA->xE + ( int32 ) ptrA->yE * ptrA->yE; 1407f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1417f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1427f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1437f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1447f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectuint16 bts_Int16Vec2D_norm( const struct bts_Int16Vec2D* ptrA ) 1457f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1467f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return bbs_sqrt32( ( int32 ) ptrA->xE * ptrA->xE + ( int32 ) ptrA->yE * ptrA->yE ); 1477f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1487f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1497f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1507f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1517f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectvoid bts_Int16Vec2D_normalize( struct bts_Int16Vec2D* ptrA, int32 bbpA ) 1527f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1537f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project int32 normL = bbs_sqrt32( ( int32 ) ptrA->xE * ptrA->xE + ( int32 ) ptrA->yE * ptrA->yE ); 1547f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project int32 xL = ( ( int32 ) ptrA->xE << 16 ) / normL; 1557f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project int32 yL = ( ( int32 ) ptrA->yE << 16 ) / normL; 1567f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project ptrA->xE = xL >> ( 16 - bbpA ); 1577f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project ptrA->yE = yL >> ( 16 - bbpA ); 1587f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1597f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1607f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1617f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1627f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectstruct bts_Int16Vec2D bts_Int16Vec2D_normalized( const struct bts_Int16Vec2D* ptrA, int32 bbpA ) 1637f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1647f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project struct bts_Int16Vec2D vecL = *ptrA; 1657f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project bts_Int16Vec2D_normalize( &vecL, bbpA ); 1667f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return vecL; 1677f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1687f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1697f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1707f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1717f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectphase16 bts_Int16Vec2D_angle( const struct bts_Int16Vec2D* vecPtrA ) 1727f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1737f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return bbs_phase16( vecPtrA->xE, vecPtrA->yE ); 1747f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1757f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1767f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1777f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1787f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Projectphase16 bts_Int16Vec2D_enclosedAngle( const struct bts_Int16Vec2D* vec1PtrA, 1797f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project const struct bts_Int16Vec2D* vec2PtrA ) 1807f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project{ 1817f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project int32 xL = ( int32 ) vec1PtrA->xE * vec2PtrA->xE + ( int32 ) vec1PtrA->yE * vec2PtrA->yE; 1827f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project int32 yL = ( int32 ) vec1PtrA->yE * vec2PtrA->xE - ( int32 ) vec1PtrA->xE * vec2PtrA->yE; 1837f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project return bbs_phase16( xL, yL ); 1847f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project} 1857f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1867f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ------------------------------------------------------------------------- */ 1877f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1887f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project/* ========================================================================= */ 1897f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 1907f81d9b6fa7f2ec161b682622db577a28c90b49fThe Android Open Source Project 191