FCL  0.6.0
Flexible Collision Library
simplex.h
1 /***
2  * libccd
3  * ---------------------------------
4  * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
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 
18 #ifndef __CCD_SIMPLEX_H__
19 #define __CCD_SIMPLEX_H__
20 
21 #include <ccd/compiler.h>
22 #include "support.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27 
29  ccd_support_t ps[4];
30  int last;
31 };
32 typedef struct _ccd_simplex_t ccd_simplex_t;
33 
34 
35 _ccd_inline void ccdSimplexInit(ccd_simplex_t *s);
36 _ccd_inline int ccdSimplexSize(const ccd_simplex_t *s);
37 _ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s);
38 _ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s, int idx);
39 _ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx);
40 
41 _ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v);
42 _ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_support_t *a);
43 _ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size);
44 _ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2);
45 
46 
47 /**** INLINES ****/
48 
49 _ccd_inline void ccdSimplexInit(ccd_simplex_t *s)
50 {
51  s->last = -1;
52 }
53 
54 _ccd_inline int ccdSimplexSize(const ccd_simplex_t *s)
55 {
56  return s->last + 1;
57 }
58 
59 _ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s)
60 {
61  return ccdSimplexPoint(s, s->last);
62 }
63 
64 _ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s, int idx)
65 {
66  // here is no check on boundaries
67  return &s->ps[idx];
68 }
69 _ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx)
70 {
71  return &s->ps[idx];
72 }
73 
74 _ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v)
75 {
76  // here is no check on boundaries in sake of speed
77  ++s->last;
78  ccdSupportCopy(s->ps + s->last, v);
79 }
80 
81 _ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_support_t *a)
82 {
83  ccdSupportCopy(s->ps + pos, a);
84 }
85 
86 _ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size)
87 {
88  s->last = size - 1;
89 }
90 
91 _ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2)
92 {
93  ccd_support_t supp;
94 
95  ccdSupportCopy(&supp, &s->ps[pos1]);
96  ccdSupportCopy(&s->ps[pos1], &s->ps[pos2]);
97  ccdSupportCopy(&s->ps[pos2], &supp);
98 }
99 
100 #ifdef __cplusplus
101 } /* extern "C" */
102 #endif /* __cplusplus */
103 
104 #endif /* __CCD_SIMPLEX_H__ */
int last
index of last added point
Definition: simplex.h:30
Definition: simplex.h:28
Definition: support.h:27