summaryrefslogtreecommitdiff
path: root/src/lib/ephysics/ephysics_shape.cpp
blob: e2fa6d25a6d07704de81f0ca053b38c8ef659a9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "ephysics_private.h"

#ifdef  __cplusplus
extern "C" {
#endif

struct _EPhysics_Shape {
     Eina_Inlist *points;
};

static EPhysics_Point *
_ephysics_shape_point_new(void)
{
   EPhysics_Point *point;

   point = (EPhysics_Point *)calloc(1, sizeof(EPhysics_Point));
   if (!point)
     {
        ERR("Failed to allocate point.");
        return NULL;
     }

   return point;
}

const Eina_Inlist *
ephysics_shape_points_get(const EPhysics_Shape *shape)
{
   return shape->points;
}

EAPI EPhysics_Shape *
ephysics_shape_new(void)
{
   EPhysics_Shape *shape;

   shape = (EPhysics_Shape *)calloc(1, sizeof(EPhysics_Shape));
   if (!shape)
     {
        ERR("Failed to allocate shape.");
        return NULL;
     }

   return shape;
}

EAPI void
ephysics_shape_del(EPhysics_Shape *shape)
{
   EPhysics_Point *point;

   if (!shape)
     {
        ERR("Can't delete shape, it's null.");
        return;
     }

   while (shape->points)
     {
        point = EINA_INLIST_CONTAINER_GET(shape->points, EPhysics_Point);
        shape->points = eina_inlist_remove(shape->points, shape->points);
        free(point);
     }

   free(shape);
}

EAPI Eina_Bool
ephysics_shape_point_add(EPhysics_Shape *shape, double x, double y, double z)
{
   EPhysics_Point *point;

   if (!shape)
     {
        ERR("Can't add point to shape, it's null.");
        return EINA_FALSE;;
     }

   point = _ephysics_shape_point_new();
   if (!point)
     return EINA_FALSE;;

   point->x = x;
   point->y = y;
   point->z = z;

   shape->points = eina_inlist_append(shape->points, EINA_INLIST_GET(point));

   return EINA_TRUE;
}

/* TODO: load points from file */
EAPI EPhysics_Shape *
ephysics_shape_load(const char *filename EINA_UNUSED)
{
   EPhysics_Shape *shape;

   shape = ephysics_shape_new();
   if (!shape)
     return NULL;

   return shape;
}

/* TODO: save points to file */
EAPI Eina_Bool
ephysics_shape_save(const EPhysics_Shape *shape EINA_UNUSED, const char *filename EINA_UNUSED)
{
   return EINA_TRUE;
}

#ifdef  __cplusplus
}
#endif