simplex.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /***
  2. * libccd
  3. * ---------------------------------
  4. * Copyright (c)2010 Daniel Fiser <[email protected]>
  5. *
  6. *
  7. * This file is part of libccd.
  8. *
  9. * Distributed under the OSI-approved BSD License (the "License");
  10. * see accompanying file BDS-LICENSE for details or see
  11. * <http://www.opensource.org/licenses/bsd-license.php>.
  12. *
  13. * This software is distributed WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the License for more information.
  16. */
  17. #ifndef __CCD_SIMPLEX_H__
  18. #define __CCD_SIMPLEX_H__
  19. #include <ccd/support.h>
  20. #include <ccd/compiler.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif /* __cplusplus */
  24. struct _ccd_simplex_t {
  25. ccd_support_t ps[4];
  26. int last; /*!< index of last added point*/
  27. };
  28. typedef struct _ccd_simplex_t ccd_simplex_t;
  29. _ccd_inline void ccdSimplexInit(ccd_simplex_t *s);
  30. _ccd_inline int ccdSimplexSize(const ccd_simplex_t *s);
  31. _ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s);
  32. _ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s, int idx);
  33. _ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx);
  34. _ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v);
  35. _ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_support_t *a);
  36. _ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size);
  37. _ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2);
  38. /**** INLINES ****/
  39. _ccd_inline void ccdSimplexInit(ccd_simplex_t *s)
  40. {
  41. s->last = -1;
  42. }
  43. _ccd_inline int ccdSimplexSize(const ccd_simplex_t *s)
  44. {
  45. return s->last + 1;
  46. }
  47. _ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s)
  48. {
  49. return ccdSimplexPoint(s, s->last);
  50. }
  51. _ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s, int idx)
  52. {
  53. /* here is no check on boundaries */
  54. return &s->ps[idx];
  55. }
  56. _ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx)
  57. {
  58. return &s->ps[idx];
  59. }
  60. _ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v)
  61. {
  62. /* here is no check on boundaries in sake of speed */
  63. ++s->last;
  64. ccdSupportCopy(s->ps + s->last, v);
  65. }
  66. _ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_support_t *a)
  67. {
  68. ccdSupportCopy(s->ps + pos, a);
  69. }
  70. _ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size)
  71. {
  72. s->last = size - 1;
  73. }
  74. _ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2)
  75. {
  76. ccd_support_t supp;
  77. ccdSupportCopy(&supp, &s->ps[pos1]);
  78. ccdSupportCopy(&s->ps[pos1], &s->ps[pos2]);
  79. ccdSupportCopy(&s->ps[pos2], &supp);
  80. }
  81. #ifdef __cplusplus
  82. } /* extern "C" */
  83. #endif /* __cplusplus */
  84. #endif /* __CCD_SIMPLEX_H__ */