From 2825c914dd797e8f4c86964aa7ba6782b664deb2 Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 2 Sep 2004 21:01:06 +0000 Subject: [PATCH] X sort() should return an array, rather than sort in place --- processing/core/PApplet.java | 158 +++++++++++++++++------------------ processing/core/todo.txt | 56 +++++++++++++ 2 files changed, 133 insertions(+), 81 deletions(-) diff --git a/processing/core/PApplet.java b/processing/core/PApplet.java index 3b17701ec..636535bb6 100644 --- a/processing/core/PApplet.java +++ b/processing/core/PApplet.java @@ -1954,97 +1954,87 @@ public class PApplet extends Applet int sort_mode; - static final int STRINGS = 0; - static final int INTS = 1; - static final int FLOATS = 2; - static final int DOUBLES = 3; + static final int BYTES = 1; + static final int CHARS = 2; + static final int INTS = 3; + static final int FLOATS = 4; + static final int STRINGS = 5; - String sort_strings[]; + byte sort_bytes[]; + char sort_chars[]; int sort_ints[]; float sort_floats[]; - double sort_doubles[]; - Object sort_objects[]; + String sort_strings[]; - /** - * Sort an array of String objects. - */ - public void sort(String what[]) { - sort(what, what.length, null); + public byte[] sort(byte what[]) { + return sort(what, what.length); } - /** - * Sort an array of String objects, along with a generic - * array of type Object. - * - * String names[] = { "orange", "black", "red" }; - * Object colors[] = { Color.orange, Color.black, Color.red }; - * sort(names, colors); - * - * result is 'names' alphabetically sorted - * and the colors[] array sorted along with it. - */ - public void sort(String what[], Object objects[]) { - sort(what, what.length, objects); + public char[] sort(char what[]) { + return sort(what, what.length); } - public void sort(int what[]) { - sort(what, what.length, null); + public int[] sort(int what[]) { + return sort(what, what.length); } - public void sort(int what[], Object objects[]) { - sort(what, what.length, objects); + public float[] sort(float what[]) { + return sort(what, what.length); } - public void sort(float what[]) { - sort(what, what.length, null); + public String[] sort(String what[]) { + return sort(what, what.length); } - public void sort(float what[], Object objects[]) { - sort(what, what.length, objects); - } + // - public void sort(double what[]) { - sort(what, what.length, null); - } - - public void sort(double what[], Object objects[]) { - sort(what, what.length, objects); - } - - - public void sort(String what[], int count, Object objects[]) { - if (count == 0) return; - sort_mode = STRINGS; - sort_strings = what; - sort_objects = objects; + public byte[] sort(byte what[], int count) { + if (count == 0) return null; + sort_mode = BYTES; + sort_bytes = new byte[count]; + System.arraycopy(what, 0, sort_bytes, 0, count); sort_internal(0, count-1); + return sort_bytes; } - public void sort(int what[], int count, Object objects[]) { - if (count == 0) return; + public char[] sort(char what[], int count) { + if (count == 0) return null; + sort_mode = CHARS; + sort_chars = new char[count]; + System.arraycopy(what, 0, sort_chars, 0, count); + sort_internal(0, count-1); + return sort_chars; + } + + public int[] sort(int what[], int count) { + if (count == 0) return null; sort_mode = INTS; - sort_ints = what; - sort_objects = objects; + sort_ints = new int[count]; + System.arraycopy(what, 0, sort_ints, 0, count); sort_internal(0, count-1); + return sort_ints; } - public void sort(float what[], int count, Object objects[]) { - if (count == 0) return; + public float[] sort(float what[], int count) { + if (count == 0) return null; sort_mode = FLOATS; - sort_floats = what; - sort_objects = objects; + sort_floats = new float[count]; + System.arraycopy(what, 0, sort_floats, 0, count); sort_internal(0, count-1); + return sort_floats; } - public void sort(double what[], int count, Object objects[]) { - if (count == 0) return; - sort_mode = DOUBLES; - sort_doubles = what; - sort_objects = objects; + public String[] sort(String what[], int count) { + if (count == 0) return null; + sort_mode = STRINGS; + sort_strings = new String[count]; + System.arraycopy(what, 0, sort_strings, 0, count); sort_internal(0, count-1); + return sort_strings; } + // protected void sort_internal(int i, int j) { int pivotIndex = (i+j)/2; @@ -2070,10 +2060,15 @@ public class PApplet extends Applet protected void sort_swap(int a, int b) { switch (sort_mode) { - case STRINGS: - String stemp = sort_strings[a]; - sort_strings[a] = sort_strings[b]; - sort_strings[b] = stemp; + case BYTES: + byte btemp = sort_bytes[a]; + sort_bytes[a] = sort_bytes[b]; + sort_bytes[b] = btemp; + break; + case CHARS: + char ctemp = sort_chars[a]; + sort_chars[a] = sort_chars[b]; + sort_chars[b] = ctemp; break; case INTS: int itemp = sort_ints[a]; @@ -2085,32 +2080,33 @@ public class PApplet extends Applet sort_floats[a] = sort_floats[b]; sort_floats[b] = ftemp; break; - case DOUBLES: - double dtemp = sort_doubles[a]; - sort_doubles[a] = sort_doubles[b]; - sort_doubles[b] = dtemp; + case STRINGS: + String stemp = sort_strings[a]; + sort_strings[a] = sort_strings[b]; + sort_strings[b] = stemp; break; } - if (sort_objects != null) { - Object otemp = sort_objects[a]; - sort_objects[a] = sort_objects[b]; - sort_objects[b] = otemp; - } } protected int sort_compare(int a, int b) { switch (sort_mode) { - case STRINGS: - return sort_strings[a].compareTo(sort_strings[b]); + case BYTES: + return sort_bytes[a] - sort_bytes[b]; + //if (sort_bytes[a] < sort_bytes[b]) return -1; + //return (sort_bytes[a] == sort_bytes[b]) ? 0 : 1; + case CHARS: + return sort_chars[a] - sort_chars[b]; + //if (sort_chars[a] < sort_chars[b]) return -1; + //return (sort_chars[a] == sort_chars[b]) ? 0 : 1; case INTS: - if (sort_ints[a] < sort_ints[b]) return -1; - return (sort_ints[a] == sort_ints[b]) ? 0 : 1; + return sort_ints[a] - sort_ints[b]; + //if (sort_ints[a] < sort_ints[b]) return -1; + //return (sort_ints[a] == sort_ints[b]) ? 0 : 1; case FLOATS: if (sort_floats[a] < sort_floats[b]) return -1; return (sort_floats[a] == sort_floats[b]) ? 0 : 1; - case DOUBLES: - if (sort_doubles[a] < sort_doubles[b]) return -1; - return (sort_doubles[a] == sort_doubles[b]) ? 0 : 1; + case STRINGS: + return sort_strings[a].compareTo(sort_strings[b]); } return 0; } diff --git a/processing/core/todo.txt b/processing/core/todo.txt index 507651927..dccd9d8a0 100644 --- a/processing/core/todo.txt +++ b/processing/core/todo.txt @@ -132,6 +132,56 @@ X http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;acti 040727 X incorporated NO_FLYING_POO line/poly hack developed for axel +040902 +X sort should return an array, rather than sort in place + +_ standalone 'alpha' function for PImage + + +The biggest problem was the key and mouse functions not working. For example: +Input: Mouse_Functions +Input: Keyboard_Functions + +Image: Edge, Image: Blur: Alpha not set? The error is easier to see on Blur + +Typography: Helix won't compile + +.... + +i wan't able to get binary() to work at all: +here are three examples: + +/ / / / + +int i = 8; +println(binary(i)); + +java.lang.StringIndexOutOfBoundsException: +String index out of range: -20 + at java.lang.String.substring(Unknown Source) + +/ / / / + +char c = 8; +println(binary(c)); + +java.lang.StringIndexOutOfBoundsException: +String index out of range: -4 + at java.lang.String.substring(Unknown Source) + +/ / / / + +char c = 8; +String s = binary(c); +println(s); + + +java.lang.StringIndexOutOfBoundsException: +String index out of range: -4 + at java.lang.String.substring(Unknown Source) + +/ / / / + _ processing.net -> PClient, PServer _ api for file-based renderers @@ -177,6 +227,9 @@ _ z-clipping _ light(x, y, z, c1, c2, c3, TYPE) _ also BLight with same constructor, and on() and off() fxn +_ image(myg, x, y) doesn't work but image(myg, x, y, w, h) does +_ (image kind prolly not set right and so image() gets pissy) +_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1091798655 //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// @@ -190,6 +243,8 @@ The graphics library was formerly called Bagel, which is an internal name. CORE / PApplet + b _ tab key not working? + b _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1091853942;start=0 b _ keypressed hanging on applets with a code folder b _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1081450102 b _ mousePressed, keyPressed, others.. queue them all @@ -341,6 +396,7 @@ CORE / PGraphics CORE / Details + 1 _ framerate(30) is still flickery and jumpy.. 1 _ fix param() to use a sketch.properties file when run as an app 1 _ make this also be used in generating the html file 1 _ fix link() to handle relative URLs