Reformat
[clav.git] / quiver.h
blobfeab5b83835ea83aa742507c948f3e39eb9ea279
1 /*
2 * Copyright (c) 2016-2019, 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_fast32_t p;
24 /* Denominator */
25 uint_fast32_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 quiver_add_to_edge(struct quiver *q, size_t i, size_t j, int_fast32_t a,
66 uint_fast32_t b, const char **out_errstr);
68 /* Add a vertex with a name and weight */
69 int quiver_add_vertex(struct quiver *q, size_t *out_i, const char *name,
70 uint_fast16_t fatness, int x, int y, uint32_t argb, const
71 char **out_errstr);
73 /* Increase or decrease the fatness of a vertex, readjusting edges as well */
74 int quiver_adjust_fatness(struct quiver *q, size_t i, int_fast8_t fatness, const
75 char **out_errstr);
77 /* Free all memory used by this quiver, resetting it to { 0 } */
78 int quiver_clean(struct quiver *q);
80 /* Delete a vertex (and all associated edges) */
81 int quiver_delete_vertex(struct quiver *q, size_t i, const char **out_errstr);
83 /* Return σ_{ij} */
84 int quiver_get_sigma(const struct quiver * const q, size_t i, size_t j, struct
85 rational *out_s);
87 /* Read quiver from file */
88 int quiver_load_from_file(struct quiver *q, FILE *f, const char **out_errstr);
90 /* Rename a vertex */
91 int quiver_rename_vertex(struct quiver *q, size_t i, const char *new_name, const
92 char **out_errstr);
94 /* Recolor a vertex */
95 int quiver_color_vertex(struct quiver *q, size_t i, uint32_t argb, const
96 char **out_errstr);
98 /* Serialize the quiver */
99 int quiver_save_to_file(struct quiver *q, FILE *f, const char **out_errstr);
101 /* Set threshold: if quiver_mutate() creates an edge above, warn_out is set */
102 int quiver_set_warning_threshold(struct quiver *q, unsigned int warn_threshold,
103 const char **out_errstr);
105 /* Mutate the quiver at vertex k, setting warn_out if threshold is broken */
106 int quiver_mutate(struct quiver *q, size_t k, int *out_warn, const
107 char **out_errstr);