~ubuntu-branches/debian/jessie/libccd/jessie

« back to all changes in this revision

Viewing changes to src/simplex.h

  • Committer: Package Import Robot
  • Author(s): Jose Luis Rivero
  • Date: 2014-03-24 16:51:48 UTC
  • Revision ID: package-import@ubuntu.com-20140324165148-mfno979f58rv322z
Tags: upstream-2.0
ImportĀ upstreamĀ versionĀ 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
28
struct _ccd_simplex_t {
 
29
    ccd_support_t ps[4];
 
30
    int last; //!< index of last added point
 
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__ */