Allow overriding pkg-config
[clav.git] / quiver.h
blobbfe4161a4953d3c85cf11eccf9b3a19e3534986c
1 /*
2 * Copyright (c) 2018, S. Gilles <sgilles@math.umd.edu>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
7 * in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 /* A rational number */
20 struct rational {
21 /* Numerator */
22 int_fast8_t p;
24 /* Denominator */
25 uint_fast8_t q;
28 /* The structure for a vertex */
29 struct vertex {
30 /* A textual identifier for this vertex */
31 char *name;
33 /* Whether this vertex is `fat' or not. Expected to be 1, 2, or 3. */
34 uint_fast8_t fatness;
36 /* Drawing data: coordinates in `internal coordinates */
37 int x;
38 int y;
40 /* Drawing data: color */
41 uint_fast8_t r;
42 uint_fast8_t g;
43 uint_fast8_t b;
46 /* The cluster algebra structure */
47 struct quiver {
48 /* How many vertices there actually are in the quiver */
49 size_t v_num;
51 /* How many vertices we have allocated memory for */
52 size_t v_len;
54 /* Vertices */
55 struct vertex *v;
57 /* Edges - e_{ij} (fatness included, so E^t is not necessarily -E) */
58 struct rational *e;
60 /* For detecting if quiver_mutate() creates an edge too high */
61 unsigned int edge_weight_threshold;
64 /* Add an arrow of weight a/b from i -> j, affecting e(i,j) and e(j,i) */
65 int
66 quiver_add_to_edge(struct quiver *q, size_t i, size_t j, int_fast8_t a,
67 uint_fast8_t b, const char **out_errstr);
69 /* Add a vertex with a name and weight */
70 int
71 quiver_add_vertex(struct quiver *q, size_t *out_i, const char *name,
72 uint_fast16_t fatness, int x, int y, uint32_t argb, const
73 char **out_errstr);
75 /* Increase or decrease the fatness of a vertex, readjusting edges as well */
76 int
77 quiver_adjust_fatness(struct quiver *q, size_t i, int_fast8_t fatness, const
78 char **out_errstr);
80 /* Free all memory used by this quiver, resetting it to { 0 } */
81 int
82 quiver_clean(struct quiver *q);
84 /* Delete a vertex (and all associated edges) */
85 int
86 quiver_delete_vertex(struct quiver *q, size_t i, const char **out_errstr);
88 /* Return σ_{ij} */
89 int
90 quiver_get_sigma(const struct quiver * const q, size_t i, size_t j, struct rational *out_s);
92 /* Read quiver from file */
93 int
94 quiver_load_from_file(struct quiver *q, FILE *f, const char **out_errstr);
96 /* Rename a vertex */
97 int
98 quiver_rename_vertex(struct quiver *q, size_t i, const char *new_name, const
99 char **out_errstr);
101 /* Recolor a vertex */
103 quiver_color_vertex(struct quiver *q, size_t i, uint32_t argb, const
104 char **out_errstr);
106 /* Serialize the quiver */
108 quiver_save_to_file(struct quiver *q, FILE *f, const char **out_errstr);
110 /* Set threshold: if quiver_mutate() creates an edge above, warn_out is set */
112 quiver_set_warning_threshold(struct quiver *q, unsigned int warn_threshold,
113 const char **out_errstr);
115 /* Mutate the quiver at vertex k, setting warn_out if threshold is broken */
117 quiver_mutate(struct quiver *q, size_t k, int *out_warn, const
118 char **out_errstr);