nonbinary-tree(TM) now works in a very minimal instance
This commit is contained in:
parent
330755591b
commit
b16590fd5a
15 changed files with 132 additions and 216 deletions
143
cursetree/node.c
143
cursetree/node.c
|
|
@ -1,5 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -19,18 +18,13 @@ static inline struct ct_node *__alloc_node(void) {
|
|||
/* Returns NULL if memory allocation failed.
|
||||
* TODO: should dims be given as a parameter, or lazily computed in ct_update?
|
||||
*/
|
||||
struct ct_node *new_node(struct ct_dims *const dims,
|
||||
struct ct_bounds *const bounds,
|
||||
struct ct_node *const parent) {
|
||||
struct ct_node *__node(struct ct_dims *const dims,
|
||||
struct ct_bounds *const bounds,
|
||||
struct ct_node *const parent) {
|
||||
struct ct_node *node = __alloc_node();
|
||||
if (node != NULL) {
|
||||
*node = (struct ct_node){
|
||||
/* copy the parent's dimensions for now and request
|
||||
* cursetree resize this node appropriately afterwards
|
||||
* WARNING: new_node doesn't set the NFLAG_RESIZE request flag
|
||||
* WARNING: that should be done by a function calling new_node
|
||||
*/
|
||||
.surface = new_surface(parent->surface->dims, bounds),
|
||||
.surface = new_surface(dims, bounds),
|
||||
.flags = NFLAG_EMPTY,
|
||||
|
||||
.parent = parent,
|
||||
|
|
@ -45,6 +39,16 @@ struct ct_node *new_node(struct ct_dims *const dims,
|
|||
return node;
|
||||
}
|
||||
|
||||
struct ct_node *new_node(struct ct_bounds *const bounds,
|
||||
struct ct_node *const parent) {
|
||||
/* copy the parent's dimensions for now and request
|
||||
* cursetree resize this node appropriately afterwards
|
||||
* WARNING: new_node doesn't set the NFLAG_RESIZE request flag
|
||||
* WARNING: that should be done by a function calling new_node
|
||||
*/
|
||||
return __node(parent->surface->dims, bounds, parent);
|
||||
}
|
||||
|
||||
/* WARNING: Do NOT use __destroy_node() to destroy a node's children!
|
||||
* WARNING: Use the destroy_child_node() function instead.
|
||||
*/
|
||||
|
|
@ -61,26 +65,11 @@ void __destroy_node(struct ct_node *const node) {
|
|||
free(node);
|
||||
}
|
||||
|
||||
void satisfy_node(struct ct_node *const node, struct ct_dims *const dims) {
|
||||
double axismax;
|
||||
if (IS_PARENT_NODE(node)) {
|
||||
for (int i = 0; i < node->cindex; i++) {
|
||||
if (node->axis == AXIS_X) {
|
||||
axismax += dims->width * node->child[i]->surface->bounds->wmax;
|
||||
} else {
|
||||
assert(node->axis == AXIS_Y);
|
||||
axismax += dims->width * node->child[i]->surface->bounds->hmax;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Surface Partition Dimensions */
|
||||
/* TODO: can I use unsigned short instead of int? */
|
||||
struct ct_spdims {
|
||||
// Main Axis & Orthogonal Axis Sizes
|
||||
int axm_size;
|
||||
// int axo_size;
|
||||
bool fixed;
|
||||
int min, max;
|
||||
};
|
||||
|
|
@ -88,69 +77,66 @@ struct ct_spdims {
|
|||
/*
|
||||
*/
|
||||
int resize_node(struct ct_node *const node, struct ct_dims *const dims) {
|
||||
// if (IS_PARENT_NODE(node)) {
|
||||
// dims->width / node->cindex;
|
||||
// }
|
||||
|
||||
resize_surface(node->surface, dims);
|
||||
|
||||
if (node->surface->bounds->wmin > dims->width ||
|
||||
node->surface->bounds->hmin > dims->height) {
|
||||
node->flags |= NFLAG_SMALL;
|
||||
return 1;
|
||||
} else if (node->surface->bounds->wmax < dims->width ||
|
||||
node->surface->bounds->hmax < dims->height) {
|
||||
node->flags |= NFLAG_LARGE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!IS_PARENT_NODE(node))
|
||||
return 0;
|
||||
|
||||
if (node->cbounds.wmin_abs + node->cbounds.wmin_rel * dims->width >
|
||||
dims->width ||
|
||||
node->cbounds.hmin_abs + node->cbounds.hmin_rel * dims->height >
|
||||
dims->height) {
|
||||
node->flags |= NFLAG_TOOSMALL;
|
||||
node->flags |= NFLAG_SMALLCHILD;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int axm_size, axm_free;
|
||||
// int axo_size;
|
||||
size_t bounds_axm_min_offset, bounds_axm_max_offset;
|
||||
size_t dims_axm_pos_offset, dims_axm_size_offset;
|
||||
// size_t dims_axo_pos_offset, dims_axo_size_offset;
|
||||
|
||||
if (node->axis == AXIS_X) {
|
||||
axm_free = dims->width;
|
||||
axm_size = dims->width;
|
||||
// axo_size = dims->height;
|
||||
|
||||
bounds_axm_min_offset = offsetof(struct ct_bounds, wmin);
|
||||
bounds_axm_max_offset = offsetof(struct ct_bounds, wmax);
|
||||
|
||||
dims_axm_pos_offset = offsetof(struct ct_dims, x);
|
||||
// dims_axo_pos_offset = offsetof(struct ct_dims, y);
|
||||
dims_axm_size_offset = offsetof(struct ct_dims, width);
|
||||
// dims_axo_size_offset = offsetof(struct ct_dims, height);
|
||||
bounds_axm_min_offset = offsetof(struct ct_bounds, wmin);
|
||||
bounds_axm_max_offset = offsetof(struct ct_bounds, wmax);
|
||||
} else {
|
||||
assert(node->axis == AXIS_Y);
|
||||
axm_free = dims->height;
|
||||
axm_size = dims->height;
|
||||
// axo_size = dims->width;
|
||||
|
||||
bounds_axm_min_offset = offsetof(struct ct_bounds, hmin);
|
||||
bounds_axm_max_offset = offsetof(struct ct_bounds, hmax);
|
||||
|
||||
dims_axm_pos_offset = offsetof(struct ct_dims, y);
|
||||
// dims_axo_pos_offset = offsetof(struct ct_dims, x);
|
||||
dims_axm_size_offset = offsetof(struct ct_dims, height);
|
||||
// dims_axo_size_offset = offsetof(struct ct_dims, width);
|
||||
bounds_axm_min_offset = offsetof(struct ct_bounds, hmin);
|
||||
bounds_axm_max_offset = offsetof(struct ct_bounds, hmax);
|
||||
}
|
||||
|
||||
struct ct_spdims cspdims[node->cindex];
|
||||
// struct ct_spdims *parts[node->cindex];
|
||||
cindex parts_n = node->cindex;
|
||||
memset(cspdims, 0, sizeof(struct ct_spdims) * node->cindex);
|
||||
for (int i = 0; i < node->cindex; i++) {
|
||||
cspdims[i].min = *(int *)(node->child[i]->surface->bounds + bounds_axm_min_offset);
|
||||
cspdims[i].max = *(int *)(node->child[i]->surface->bounds + bounds_axm_max_offset);
|
||||
cspdims[i].min =
|
||||
*(int *)(node->child[i]->surface->bounds + bounds_axm_min_offset);
|
||||
cspdims[i].max =
|
||||
*(int *)(node->child[i]->surface->bounds + bounds_axm_max_offset);
|
||||
if (node->child[i]->surface->bounds->type == BOUND_RELATIVE) {
|
||||
cspdims[i].min *= axm_size;
|
||||
cspdims[i].max *= axm_size;
|
||||
}
|
||||
|
||||
cspdims[i].axm_size = 0;
|
||||
// cspdims[i].axo_size = axo_size;
|
||||
|
||||
// parts[i] = &cspdims[i];
|
||||
}
|
||||
|
||||
int split, new_size;
|
||||
|
|
@ -173,69 +159,18 @@ int resize_node(struct ct_node *const node, struct ct_dims *const dims) {
|
|||
}
|
||||
}
|
||||
|
||||
/* TODO: using axo_size this way means cspdims doesn't need an axo field!! */
|
||||
struct ct_dims * cdims = dup_dims(dims);
|
||||
struct ct_dims *cdims = dup_dims(dims);
|
||||
/* NOTE: the statements below are done implicitly by dup_dims */
|
||||
// *(int*)(cdims + dims_axm_pos_offset) = *(int*)(dims + dims_axm_pos_offset);
|
||||
// *(int*)(cdims + dims_axo_pos_offset) = *(int*)(dims + dims_axo_pos_offset);
|
||||
// *(int*)(cdims + dims_axo_size_offset) = axo_size;
|
||||
for (int i = 0; i < node->cindex; i++) {
|
||||
*(int*)(cdims + dims_axm_size_offset) = cspdims[i].axm_size;
|
||||
*(int *)(cdims + dims_axm_size_offset) = cspdims[i].axm_size;
|
||||
resize_node(node->child[i], dup_dims(cdims));
|
||||
*(int*)(cdims + dims_axm_pos_offset) += cspdims[i].axm_size;
|
||||
*(int *)(cdims + dims_axm_pos_offset) += cspdims[i].axm_size;
|
||||
}
|
||||
free(cdims);
|
||||
|
||||
// int split = axm_free / node->cindex;
|
||||
// for (int j = 0; j < node->cindex; j++) {
|
||||
// cwhdims[j].min = *(int*)(node->child[j]->surface->bounds +
|
||||
// axm_min_offset); cwhdims[j].max = *(int*)(node->child[j]->surface->bounds
|
||||
// + axm_max_offset); if (node->child[j]->surface->bounds->type ==
|
||||
// BOUND_RELATIVE) {
|
||||
// cwhdims[j].min *= axm_size;
|
||||
// cwhdims[j].max *= axm_size;
|
||||
// }
|
||||
|
||||
// cwhdims[j].axm_size = fmax(fmin(split, cwhdims[j].max), cwhdims[j].min);
|
||||
// cwhdims[j].axo_size = axo_size;
|
||||
|
||||
// axm_free -= cwhdims[j].axm_size;
|
||||
// }
|
||||
|
||||
// int delta;
|
||||
// while (axm_free) {
|
||||
// if (axm_free < cunfixedn) {
|
||||
// int progress = 0;
|
||||
// for (int j = 0; j < node->cindex; j++) {
|
||||
// if (cwhdims[j].fixed)
|
||||
// continue;
|
||||
// cwhdims[j].axm_size--;
|
||||
// axm_free--;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // split is guaranteed to be >0
|
||||
// split = axm_free / node->cindex;
|
||||
// for (int j = 0; j < node->cindex; j++) {
|
||||
// if (cwhdims[j].fixed)
|
||||
// continue;
|
||||
|
||||
// delta = cwhdims[j].axm_size - fmax(cwhdims[j].axm_size - split,
|
||||
// bounds->wmin); if (delta == 0) {
|
||||
// cwhdims[j].fixed = true;
|
||||
// cunfixedn++;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// cwhdims[j].axm_size -= delta;
|
||||
// axm_free -= delta;
|
||||
// }
|
||||
// }
|
||||
|
||||
// bifurcate_dims(dims, node->axis, node->ratio, &dims0, &dims1);
|
||||
|
||||
// resize_node(node->child[0], dims0);
|
||||
// resize_node(node->child[1], dims1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue