hlfw.ca

binpack

Download patch

ref: 61c44e0b6c34ab418cfa20120622a60bac510a39
parent: 6e43aa4d46695de7c4d281e0b776c65e0d38c2d9
author: Halfwit <michaelmisch1985@gmail.com>
date: Mon Sep 17 14:58:56 PDT 2018

Clean up some erroneous bits and bytes

Signed-off-by: Halfwit <michaelmisch1985@gmail.com>

--- a/bin_utils.c
+++ b/bin_utils.c
@@ -13,7 +13,6 @@
 	// x - g, y + g, w - g, h - g for all windows 
 }
 
-// sort our input
 void sort_bins(struct Input r[], const size_t length) {
 	/* arrange rectangles largest to smallest, normalized some over min/max */
 	struct Input temp;
--- a/binpack.c
+++ b/binpack.c
@@ -97,7 +97,7 @@
 	}
 }
 
-// Should pass a pointer to the struct here
+// TODO: Should pass a pointer to the struct here
 bool
 bin_pack(unsigned width, unsigned height, struct Current c[], struct Output out[], unsigned count) {
 	
--- a/main.c
+++ b/main.c
@@ -42,6 +42,10 @@
 		return EXIT_SUCCESS;
 
 	sort_bins(input, length);
+
+	if (screens > 3) {
+		//usage;
+		return EXIT_FAILURE;
 	
 	/* Normal function */	
 	if (screens == 1) {
@@ -53,6 +57,7 @@
 		print_bin(output, length);
 		return EXIT_SUCCESS;
 	}
+	
 	/* More than one screen will need a few more data types */
 	struct Input in_a[MAX_BIN/2 + 1], in_b[MAX_BIN/2 + 1];
 	struct Output out_a[MAX_BIN/2 + 1], out_b[MAX_BIN/2 + 1];
@@ -59,11 +64,8 @@
 	
 	/* Sort into two bins and pack each seperately */
 	if (screens == 2) {
-		split(input, in_a, in_b, length);
-		//for (size_t i = 0; i <= sizeof(*in_a)/sizeof(in_a[0]); i++) {
-		//	printf("a %d b %d\n", in_a[i].maxw, in_b[i].maxw);
-		//}	
 		/* binpack.c */
+		split(input, in_a, in_b, length);
 		binary_bin_pack(width/2, height, out_a, in_a);
 		binary_bin_pack(width/2, height, out_b, in_b);
 	  	
@@ -80,7 +82,7 @@
 	/*
 	if (screens == 3) {
 		bool bin_switch = true;
-		
+
 		struct Current temp;
 		struct Current c[MAX_BIN];
 		unsigned count = sizeof(input)/sizeof(input[0]);
@@ -91,7 +93,6 @@
 		}
 		
 		// binpack.c 
-		
 		while (!bin_pack(width/3, height, c, output, count)) {
 			temp = pop(c);
 			(bin_switch) ? push(in_a, temp) : push(in_b, temp);
@@ -98,11 +99,11 @@
 			bin_switch = !bin_switch;
 		}
 
+		// TODO: Guard against empty structs
 		binary_bin_pack(width/3, height, out_a, in_a);
 		binary_bin_pack(width/3, height, out_b, in_b);
 	
 		// bin_utils.c
-
 		center(width/3, height, output, gaps);
 		center(width/3, height, out_a, gaps);
 		center(width/3, height, out_b, gaps);