/* VectorNav HSI Calibration Library v1.0.0.2
 *
 * Copyright (c) 2018 VectorNav Technologies, LLC
 *
 * This source code is proprietary to and copyrighted by VectorNav Technologies, LLC and is
 * available solely under license from VectorNav. All rights reserved. If you do not have a
 * license to use this source code from VectorNav, any use hereof is strictly prohibited by
 * U.S. law and other applicable law. This source code is restricted for use solely with the
 * products of VectorNav and as otherwise set forth in any agreement with VectorNav. Any
 * disclosure of this source code to the public or to any third party is also prohibited.
 */
#ifndef _VN_VNMATRIX_H_
#define _VN_VNMATRIX_H_

#include "vncompiler.h"
#include "vnint.h"
#include "vnenum.h"

#ifdef __cplusplus
extern "C" {
#endif

/** \brief Represents a 3x3 matrix with an underlying data type of <c>float</c>. */
union vn_mat3f
{
  float e[3*3];  /**< The matrix's elements in column-major ordering. */

  #if VN_ANONYMOUS_UNIONS

  struct
  {
    float e00;  /**< Element [0,0]. */
    float e10;  /**< Element [1,0]. */
    float e20;  /**< Element [2,0]. */
    float e01;  /**< Element [0,1]. */
    float e11;  /**< Element [1,1]. */
    float e21;  /**< Element [2,1]. */
    float e02;  /**< Element [0,2]. */
    float e12;  /**< Element [1,2]. */
    float e22;  /**< Element [2,2]. */
  };

  #endif

};

#ifndef __cplusplus
typedef union vn_mat3f vn_mat3f_t;
#endif

/**\brief Initializes a <c>vn_mat3f</c> from an array of floats.
 * \param[out] m <c>vn_mat3f</c> to initialize.
 * \param[in] fa Array of floats containing data to initialize <c>m</c>.
 *     Data must be in column-major order and contain at least 9 data elements. */
void
init_m3f_fa(
    union vn_mat3f *m,
    const float *fa);

/**\brief Negates a <c>vn_mat3f</c>.
 * \param[in] m The <c>vn_mat3f</c> to negate.
 * \return The negated matrix. */
union vn_mat3f
neg_m3f(
    union vn_mat3f m);

/**\brief Converts a <c>vn_mat3f</c> to a string.
* \param[out] out The char buffer to output the result to.
* \param[in] outSize Size of the buffer <c>out</c>.
* \param[in] m The <c>vn_mat3f</c> to convert.
* \return Any errors encountered. */
enum VnError
to_string_mat3f(
    char *out,
    size_t outSize,
    union vn_mat3f m);

#ifdef __cplusplus
}
#endif

#endif

