hlfw.ca

binpack

Download patch

ref: 0eb5f5fe9d1ad7ca3462dafc0681e635ea008d80
parent: 71df30b892b684311f65e661d0fe9a37bde9a632
author: Halfwit <michaelmisch1985@gmail.com>
date: Sun Oct 15 17:43:45 PDT 2017

Initial attempts at push/pop, will test tomorrow

--- a/bin_utils.c
+++ b/bin_utils.c
@@ -57,3 +57,22 @@
 		}
     }
 }
+
+struct Input pop(struct Input in[]) {
+	size_t len = sizeof(*in)/sizeof(in[0]);
+	struct Input temp = in[1];
+	for (size_t i = 1; i < len - 1; i++) {
+		in[i] = in[i+1];
+	}
+	in[len].minw = 0;
+	in[len].maxw = 0;
+	in[len].minh = 0;
+	in[len].maxh = 0;
+	in[len].wid  = 0;
+	return temp;
+}
+
+void push(struct Input in[], struct Input temp) {
+	size_t len = sizeof(*in)/sizeof(in[0]);
+	in[len] = temp;
+}
--- a/binpack.c
+++ b/binpack.c
@@ -8,6 +8,7 @@
 
 }
 
+// Make sure we pass with one or fewer elements
 bool
 bin_pack(unsigned width, unsigned height, struct Output out[], struct Input in[]) {
 	return true;
--- a/binpack.h
+++ b/binpack.h
@@ -26,3 +26,5 @@
 void print_bin(struct Output out[], size_t length);
 void offset(struct Output out[], unsigned w);
 size_t init_bins(struct Input r[]);
+struct Input pop(struct Input in[]);
+void push(struct Input in[], struct Input temp);
--- a/main.c
+++ b/main.c
@@ -65,27 +65,27 @@
 		print_bin(out_a, sizeof(out_a)/sizeof(out_a[0]));
 		print_bin(out_b, sizeof(out_b)/sizeof(out_b[0]));
 	 }
-/* Need to implement something sane for pop/push
+
 	if (screens == 3) {
-		unsigned temp = 0;
+		struct Input temp;
 		bool bin_switch = true;
 		// Ugly logic - while bin_pack fails, we pop out into flanking bins
 		// bin_pack will pass if it has <= 1 element to keep logic clean
 		while (!bin_pack(width/3, height, output, input)) {
-//			temp = pop(input);
-//			(bin_switch) ? push(in_a, temp) : push(in_b, temp);
+			temp = pop(input);
+			(bin_switch) ? push(in_a, temp) : push(in_b, temp);
 			bin_switch = !bin_switch;
 		}
 		binary_bin_pack(width/3, height, out_a, in_a);
 		binary_bin_pack(width/3, height, out_b, in_b);
-		center(width/3, height, &output, gaps);
-		center(width/3, height, &out_a, gaps);
-		center(width/3, height, &out_b, gaps);
-		offset(&output, width/3);
-		offset(&out_b, width*2/3);
+		center(width/3, height, output, gaps);
+		center(width/3, height, out_a, gaps);
+		center(width/3, height, out_b, gaps);
+		offset(output, width/3);
+		offset(out_b, width*2/3);
 		print_bin(output, sizeof(output)/sizeof(output[0]));
 		print_bin(out_a, sizeof(out_a)/sizeof(out_a[0]));
 		print_bin(out_b, sizeof(out_b)/sizeof(out_b[0]));
 	}
-*/
+
 }