tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Vec2C.h (2317B)


      1 /** @file
      2    @brief Header
      3 
      4    Must be c-safe!
      5 
      6    @date 2014
      7 
      8    @author
      9    Sensics, Inc.
     10    <http://sensics.com/osvr>
     11 */
     12 
     13 /*
     14 // Copyright 2014 Sensics, Inc.
     15 //
     16 // Licensed under the Apache License, Version 2.0 (the "License");
     17 // you may not use this file except in compliance with the License.
     18 // You may obtain a copy of the License at
     19 //
     20 //     http://www.apache.org/licenses/LICENSE-2.0
     21 //
     22 // Unless required by applicable law or agreed to in writing, software
     23 // distributed under the License is distributed on an "AS IS" BASIS,
     24 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     25 // See the License for the specific language governing permissions and
     26 // limitations under the License.
     27 */
     28 
     29 #ifndef INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F
     30 #define INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F
     31 
     32 /* Internal Includes */
     33 #include <osvr/Util/APIBaseC.h>
     34 
     35 /* Library/third-party includes */
     36 /* none */
     37 
     38 /* Standard includes */
     39 /* none */
     40 
     41 OSVR_EXTERN_C_BEGIN
     42 
     43 /** @addtogroup UtilMath
     44    @{
     45 */
     46 /** @brief A structure defining a 2D vector, which represents position
     47 */
     48 typedef struct OSVR_Vec2 {
     49  /** @brief Internal array data. */
     50  double data[2];
     51 } OSVR_Vec2;
     52 
     53 #define OSVR_VEC_MEMBER(COMPONENT, INDEX)                             \
     54  /** @brief Accessor for Vec2 component COMPONENT */                 \
     55  OSVR_INLINE double osvrVec2Get##COMPONENT(OSVR_Vec2 const* v) {     \
     56    return v->data[INDEX];                                            \
     57  }                                                                   \
     58  /** @brief Setter for Vec2 component COMPONENT */                   \
     59  OSVR_INLINE void osvrVec2Set##COMPONENT(OSVR_Vec2* v, double val) { \
     60    v->data[INDEX] = val;                                             \
     61  }
     62 
     63 OSVR_VEC_MEMBER(X, 0)
     64 OSVR_VEC_MEMBER(Y, 1)
     65 
     66 #undef OSVR_VEC_MEMBER
     67 
     68 /** @brief Set a Vec2 to the zero vector */
     69 OSVR_INLINE void osvrVec2Zero(OSVR_Vec2* v) {
     70  osvrVec2SetX(v, 0);
     71  osvrVec2SetY(v, 0);
     72 }
     73 
     74 /** @} */
     75 
     76 OSVR_EXTERN_C_END
     77 
     78 #ifdef __cplusplus
     79 template <typename StreamType>
     80 inline StreamType& operator<<(StreamType& os, OSVR_Vec2 const& vec) {
     81  os << "(" << vec.data[0] << ", " << vec.data[1] << ")";
     82  return os;
     83 }
     84 #endif
     85 
     86 #endif  // INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F