aboutsummaryrefslogtreecommitdiff
path: root/src_c/common.h
blob: 660932fc0d31261b5eeb30461415d82d5615754e (plain) (blame)
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
#ifndef OPCUT_COMMON_H
#define OPCUT_COMMON_H

#include <stdbool.h>
#include <stdio.h>

#define OPCUT_SUCCESS 0
#define OPCUT_ERROR 1
#define OPCUT_UNSOLVABLE 2

#define OPCUT_STR_EMPTY ((opcut_str_t){.data = NULL, .len = 0})
#define OPCUT_PARAMS_EMPTY                                                     \
    ((opcut_params_t){.cut_width = 0,                                          \
                      .min_initial_usage = false,                              \
                      .panels = NULL,                                          \
                      .panels_len = 0,                                         \
                      .items = NULL,                                           \
                      .items_len = 0})
#define OPCUT_RESULT_EMPTY                                                     \
    ((opcut_result_t){.params = NULL,                                          \
                      .used = NULL,                                            \
                      .used_len = 0,                                           \
                      .unused = NULL,                                          \
                      .unused_len = 0})

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
    char *data;
    size_t len;
} opcut_str_t;

typedef struct {
    opcut_str_t id;
    double width;
    double height;

    // internal
    double area;
} opcut_panel_t;

typedef struct {
    opcut_str_t id;
    double width;
    double height;
    bool can_rotate;

    // internal
    double area;
} opcut_item_t;

typedef struct {
    double cut_width;
    bool min_initial_usage;
    opcut_panel_t *panels;
    size_t panels_len;
    opcut_item_t *items;
    size_t items_len;
} opcut_params_t;

typedef struct {
    opcut_panel_t *panel;
    opcut_item_t *item;
    double x;
    double y;
    bool rotate;
} opcut_used_t;

typedef struct {
    opcut_panel_t *panel;
    double width;
    double height;
    double x;
    double y;

    // internal
    double area;
    bool initial;
} opcut_unused_t;

typedef struct {
    opcut_params_t *params;
    opcut_used_t *used;
    size_t used_len;
    opcut_unused_t *unused;
    size_t unused_len;

    // internal
    double panels_area;
} opcut_result_t;


int opcut_str_resize(opcut_str_t *str, size_t size);
int opcut_params_init(opcut_params_t *params, opcut_str_t *json);
int opcut_result_write(opcut_result_t *result, FILE *stream);

void opcut_str_destroy(opcut_str_t *str);
void opcut_params_destroy(opcut_params_t *params);
void opcut_result_destroy(opcut_result_t *result);

#ifdef __cplusplus
}
#endif

#endif