diff options
author | Camil Staps | 2015-04-18 13:44:44 +0200 |
---|---|---|
committer | Camil Staps | 2015-04-18 13:44:44 +0200 |
commit | 6a44b074f0169a1b0f9e92347af929c5e471746e (patch) | |
tree | ae5663fe7c69881bf4ecfedbef99c2505f8ec964 /Week8 Quadtrees/src/qtrees/QTNode.java | |
parent | Added copyright to docs (diff) |
Reorganised projects
Diffstat (limited to 'Week8 Quadtrees/src/qtrees/QTNode.java')
-rw-r--r-- | Week8 Quadtrees/src/qtrees/QTNode.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Week8 Quadtrees/src/qtrees/QTNode.java b/Week8 Quadtrees/src/qtrees/QTNode.java new file mode 100644 index 0000000..e2ad7e5 --- /dev/null +++ b/Week8 Quadtrees/src/qtrees/QTNode.java @@ -0,0 +1,63 @@ +package qtrees;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * Representation of a node in a QTree
+ * @author Sjaak Smetsers
+ * @author Camil Staps, s4498062
+ *
+ * Note: the version by Sjaak Smetsers contained a sameLeaf method. This seems to be redundant though, so I removed it.
+ */
+public abstract class QTNode {
+ protected boolean boolean_value;
+ protected String string_value;
+
+ /**
+ * Fill a (part of a) bitmap with this node
+ * In the template this was an abstract method. However, then we would use
+ * essentially the same code in BlackLeaf and WhiteLeaf. Using a concrete
+ * function here that depends on static properties is much more flexible. In
+ * GreyNode we still override this function.
+ * @param x the x coordinate of the top left corner
+ * @param y the y coordinate of the top left corner
+ * @param width the width of the part of the bitmap to fill
+ * @param bitmap the bitmap to fill
+ */
+ public void fillBitmap( int x, int y, int width, Bitmap bitmap ) {
+ int old_x = x, old_y = y;
+ for (; x < old_x + width; x++)
+ for (y = old_y; y < old_y + width; y++)
+ bitmap.setBit(x, y, boolean_value);
+ }
+
+ /**
+ * Write a node as bitstream
+ * In the template this was an abstract method. However, then we would use
+ * essentially the same code in BlackLeaf and WhiteLeaf. Using a concrete
+ * function here that depends on static properties is much more flexible. In
+ * GreyNode we still override this function.
+ * @param out Writer to write to
+ * @throws IOException is passed on from Writer
+ */
+ public void writeNode( Writer out ) throws IOException {
+ out.write("0" + string_value);
+ }
+
+ /**
+ * Fill a complete area of a bitmap with a particular value
+ * @param x the x coordinate of the top left corner
+ * @param y the y coordinate of the top left corner
+ * @param width the width (and height) of the area to fill
+ * @param bitmap the bitmap to fill
+ * @param val the value to fill the area with
+ */
+ public static void fillArea( int x, int y, int width, Bitmap bitmap, boolean val ){
+ for (int i = 0; i < width; i++) {
+ for (int j = 0; j < width; j++) {
+ bitmap.setBit(x+i, y+j, val);
+ }
+ }
+ }
+}
|