hlfw.ca

binpack

Download patch

ref: ca37f120431bd7678e4eedb936248c5e3234aa88
parent: 77ce286ba25181f01811d04e556f374a73208a31
author: Halfwit <michaelmisch1985@gmail.com>
date: Wed Oct 25 09:38:54 PDT 2017

Need to fix the pointers quite a bit still

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

--- a/bin_utils.c
+++ b/bin_utils.c
@@ -42,12 +42,22 @@
 
 // given in[], seperate by even and odd into a[] and b[]
 void split(struct Input in[], struct Input a[], struct Input b[], size_t length) {
-	
+	bool bin_switch = true;
+	for (size_t i = 0; i < length; i++) {
+		if (bin_switch) {
+			a[i/2] = in[i];
+		} else {
+			b[i/2] = in[i];
+		}
+		bin_switch = !bin_switch;
+	}
 }
 
 // Add w width to each out[n].x (moving the window on to the next monitor)
 void offset(struct Output out[], unsigned w) {
-	
+	for (size_t i = 0; i < sizeof(*out)/sizeof(out[0]); i++) {
+		out[i].x += w;
+	}
 }
 
 // Loop through a given bin, printing all to stdout if values are present
--- a/main.c
+++ b/main.c
@@ -36,7 +36,6 @@
 	struct Output output[MAX_BIN];
 	
 	const size_t length = init_bins(input);
-	printf("here %d\n", input[0].minw);
 	
 	/* Sanity checks */
 	if (length == 0 || height == 0 || width == 0)
@@ -44,22 +43,32 @@
 
 	sort_bins(input, length);
 	
-	// Normal function	
+	/* Normal function */	
 	if (screens == 1) {
+		/* binpack.c */
 	   	binary_bin_pack(width, height, output, input);
+
+		/* bin_utils.c */
 	   	center(width, height, output, gaps);
 		print_bin(output, length);
 		return EXIT_SUCCESS;
 	}
-	// More than one screen will need a few more data types
+	/* More than one screen will need a few more data types */
 	struct Input in_a[MAX_BIN/2], in_b[MAX_BIN/2];
 	struct Output out_a[MAX_BIN/2], out_b[MAX_BIN/2];
-		
+	
+	/* Sort into two bins and pack each seperately */
 	if (screens == 2) {
 		split(input, in_a, in_b, length);
+		for (size_t i = 0; i < (length/2) - 1; i ++) {
+			printf("a %z b %z\n", in_a[i], in_b[i]);
+		}	
+		/* binpack.c */
 		binary_bin_pack(width/2, height, out_a, in_a);
 		binary_bin_pack(width/2, height, out_b, in_b);
-	  	center(width/2, height, out_a, gaps);
+	  	
+		/* bin_utils.c */
+		center(width/2, height, out_a, gaps);
 		center(width/2, height, out_b, gaps);
 		offset(out_b, width/2);			
 		print_bin(out_a, sizeof(out_a)/sizeof(out_a[0]));
@@ -66,11 +75,12 @@
 		print_bin(out_b, sizeof(out_b)/sizeof(out_b[0]));
 	 }
 
+	/* Ugly logic - while bin_pack fails, move an element into one of two flanking bins, alternating bins each time */
 	if (screens == 3) {
 		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
+		
+		/* binpack.c */
 		while (!bin_pack(width/3, height, output, input)) {
 			temp = pop(input);
 			(bin_switch) ? push(in_a, temp) : push(in_b, temp);
@@ -78,6 +88,8 @@
 		}
 		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);
--- a/test/test
+++ b/test/test
@@ -4,7 +4,7 @@
 cd "$(dirname $0)"
 for i in */in*; do
 	size="$(dirname "$i")"
-	in="$(binpack -x "${size%x*}" -y "${size#*x}" -g 6 < "$i", -s 1)"
+	in="$(~/code/binpack/binpack -x "${size%x*}" -y "${size#*x}" -g 6 < "$i" -s 2)"
 	echo "$in"
 	#grep "$in" "$size/out${i#*in*}" >/dev/null && echo "Test $size - ${i#*in*} success"
 done
\ No newline at end of file