gmio/src/gmio_stl/internal/stl_rw_common.c

65 lines
2.1 KiB
C
Raw Normal View History

2015-03-03 00:38:33 +08:00
/****************************************************************************
2015-05-28 15:40:24 +08:00
** gmio
2015-05-01 00:19:45 +08:00
** Copyright Fougue (2 Mar. 2015)
2015-07-13 17:42:03 +08:00
** contact@fougue.pro
2015-03-03 00:38:33 +08:00
**
** This software is a reusable library whose purpose is to provide complete
** I/O support for various CAD file formats (eg. STL)
**
** This software is governed by the CeCILL-B license under French law and
** abiding by the rules of distribution of free software. You can use,
** modify and/ or redistribute the software under the terms of the CeCILL-B
** license as circulated by CEA, CNRS and INRIA at the following URL
2015-03-30 15:05:25 +08:00
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
2015-03-03 00:38:33 +08:00
****************************************************************************/
#include "stl_rw_common.h"
#include "../../gmio_core/error.h"
#include "../stl_error.h"
#include "../stl_io.h"
2016-01-29 19:47:01 +08:00
bool gmio_check_memblock(int *error, const struct gmio_memblock* mblock)
{
2016-01-29 19:47:01 +08:00
if (mblock == NULL || mblock->ptr == NULL)
*error = GMIO_ERROR_NULL_MEMBLOCK;
else if (mblock->size == 0)
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
2015-03-03 17:35:36 +08:00
return gmio_no_error(*error);
}
2016-01-29 19:47:01 +08:00
bool gmio_check_memblock_size(
int *error, const struct gmio_memblock *mblock, size_t minsize)
{
2016-01-29 19:47:01 +08:00
if (gmio_check_memblock(error, mblock) && mblock->size < minsize)
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
return gmio_no_error(*error);
}
2016-01-27 00:03:58 +08:00
bool gmio_stl_check_mesh(int *error, const struct gmio_stl_mesh* mesh)
{
2015-03-03 17:35:36 +08:00
if (mesh == NULL
|| (mesh->triangle_count > 0 && mesh->func_get_triangle == NULL))
2015-03-03 17:35:36 +08:00
{
*error = GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE;
2015-03-03 17:35:36 +08:00
}
return gmio_no_error(*error);
}
2016-01-29 19:47:01 +08:00
bool gmio_stlb_check_byteorder(int* error, enum gmio_endianness byte_order)
{
if (byte_order != GMIO_ENDIANNESS_LITTLE
&& byte_order != GMIO_ENDIANNESS_BIG)
{
*error = GMIO_STL_ERROR_UNSUPPORTED_BYTE_ORDER;
}
2016-01-29 19:47:01 +08:00
return gmio_no_error(*error);
}
2016-01-29 19:47:01 +08:00
bool gmio_stla_check_float32_precision(int *error, uint8_t prec)
{
if (prec == 0 || prec > 9)
*error = GMIO_STL_ERROR_INVALID_FLOAT32_PREC;
2015-03-03 17:35:36 +08:00
return gmio_no_error(*error);
}