mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 02:45:36 +01:00
added min() and max() for float and int arrays, also openStreamGZ
This commit is contained in:
@@ -2863,57 +2863,109 @@ public class PApplet extends Applet
|
||||
}
|
||||
|
||||
|
||||
static public final float max(float a, float b) {
|
||||
//return Math.max(a, b);
|
||||
static public final int max(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
static public final float max(float a, float b, float c) {
|
||||
//return Math.max(a, Math.max(b, c));
|
||||
static public final float max(float a, float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
|
||||
static public final int max(int a, int b, int c) {
|
||||
return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
|
||||
}
|
||||
|
||||
static public final float min(float a, float b) {
|
||||
//return Math.min(a, b);
|
||||
static public final float max(float a, float b, float c) {
|
||||
return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the maximum value in an array.
|
||||
* @param list the source array
|
||||
* @return The maximum value, or 0 if the array is length zero.
|
||||
*/
|
||||
static public final int max(int[] list) {
|
||||
if (list.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
int max = list[0];
|
||||
for (int i = 1; i < list.length; i++) {
|
||||
if (list[i] > max) max = list[i];
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the maximum value in an array.
|
||||
* @param list the source array
|
||||
* @return The maximum value, or Float.NaN if the array is length zero.
|
||||
*/
|
||||
static public final float max(float[] list) {
|
||||
if (list.length == 0) {
|
||||
return Float.NaN;
|
||||
}
|
||||
float max = list[0];
|
||||
for (int i = 1; i < list.length; i++) {
|
||||
if (list[i] > max) max = list[i];
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
static public final int min(int a, int b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
static public final float min(float a, float b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
|
||||
static public final int min(int a, int b, int c) {
|
||||
return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
|
||||
}
|
||||
|
||||
static public final float min(float a, float b, float c) {
|
||||
//return Math.min(a, Math.min(b, c));
|
||||
return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
|
||||
}
|
||||
|
||||
|
||||
static public final float lerp(float start, float stop, float amt) {
|
||||
return start + (stop-start) * amt;
|
||||
/**
|
||||
* Find the minimum value in an array.
|
||||
* @param list the source array
|
||||
* @return The minimum value, or 0 if the array is length zero.
|
||||
*/
|
||||
static public final int min(int[] list) {
|
||||
if (list.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
int min = list[0];
|
||||
for (int i = 1; i < list.length; i++) {
|
||||
if (list[i] < min) min = list[i];
|
||||
}
|
||||
return min;
|
||||
}
|
||||
/**
|
||||
* Find the minimum value in an array.
|
||||
* @param list the source array
|
||||
* @return The minimum value, or Float.NaN if the array is length zero.
|
||||
*/
|
||||
static public final float min(float[] list) {
|
||||
if (list.length == 0) {
|
||||
return Float.NaN;
|
||||
}
|
||||
float min = list[0];
|
||||
for (int i = 1; i < list.length; i++) {
|
||||
if (list[i] < min) min = list[i];
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Used only in release 0119, will be removed.
|
||||
*/
|
||||
/*
|
||||
static public final float unlerp(float start, float stop, float value) {
|
||||
return (value - start) / (stop - start);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Normalize a value to exist between 0 and 1 (inclusive).
|
||||
* Mathematically the opposite of lerp(), figures out what proportion
|
||||
* a particular value is relative to start and stop coordinates.
|
||||
*/
|
||||
static public final float norm(float value, float start, float stop) {
|
||||
return (value - start) / (stop - start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to map a variable from one coordinate space
|
||||
* to another. Equivalent to unlerp() followed by lerp().
|
||||
*/
|
||||
static public final float map(float value,
|
||||
float istart, float istop,
|
||||
float ostart, float ostop) {
|
||||
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
|
||||
static public final int constrain(int amt, int low, int high) {
|
||||
return (amt < low) ? low : ((amt > high) ? high : amt);
|
||||
}
|
||||
|
||||
static public final float constrain(float amt, float low, float high) {
|
||||
@@ -2921,64 +2973,32 @@ public class PApplet extends Applet
|
||||
}
|
||||
|
||||
|
||||
static public final int max(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
static public final int max(int a, int b, int c) {
|
||||
return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
|
||||
}
|
||||
|
||||
static public final int min(int a, int b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
static public final int min(int a, int b, int c) {
|
||||
return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
|
||||
}
|
||||
|
||||
static public final int constrain(int amt, int low, int high) {
|
||||
return (amt < low) ? low : ((amt > high) ? high : amt);
|
||||
}
|
||||
|
||||
|
||||
static public final float sin(float angle) {
|
||||
//if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
|
||||
static public final float cos(float angle) {
|
||||
//if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
|
||||
static public final float tan(float angle) {
|
||||
//if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
return (float)Math.tan(angle);
|
||||
}
|
||||
|
||||
|
||||
static public final float asin(float value) {
|
||||
//return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
//((float)Math.asin(value) * RAD_TO_DEG) : (float)Math.asin(value);
|
||||
return (float)Math.asin(value);
|
||||
}
|
||||
|
||||
static public final float acos(float value) {
|
||||
//return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
//((float)Math.acos(value) * RAD_TO_DEG) : (float)Math.acos(value);
|
||||
return (float)Math.acos(value);
|
||||
}
|
||||
|
||||
static public final float atan(float value) {
|
||||
//return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
// ((float)Math.atan(value) * RAD_TO_DEG) : (float)Math.atan(value);
|
||||
return (float)Math.atan(value);
|
||||
}
|
||||
|
||||
static public final float atan2(float a, float b) {
|
||||
//return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
//((float)Math.atan2(a, b) * RAD_TO_DEG) : (float)Math.atan2(a, b);
|
||||
return (float)Math.atan2(a, b);
|
||||
}
|
||||
|
||||
@@ -3024,6 +3044,30 @@ public class PApplet extends Applet
|
||||
}
|
||||
|
||||
|
||||
static public final float lerp(float start, float stop, float amt) {
|
||||
return start + (stop-start) * amt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a value to exist between 0 and 1 (inclusive).
|
||||
* Mathematically the opposite of lerp(), figures out what proportion
|
||||
* a particular value is relative to start and stop coordinates.
|
||||
*/
|
||||
static public final float norm(float value, float start, float stop) {
|
||||
return (value - start) / (stop - start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to map a variable from one coordinate space
|
||||
* to another. Equivalent to unlerp() followed by lerp().
|
||||
*/
|
||||
static public final float map(float value,
|
||||
float istart, float istop,
|
||||
float ostart, float ostop) {
|
||||
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -4160,23 +4204,6 @@ public class PApplet extends Applet
|
||||
}
|
||||
|
||||
|
||||
static public InputStream openStream(File file) {
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
|
||||
} catch (IOException e) {
|
||||
if (file == null) {
|
||||
throw new RuntimeException("File passed to openStream() was null");
|
||||
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Couldn't openStream() for " +
|
||||
file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simplified method to open a Java InputStream.
|
||||
* <P>
|
||||
@@ -4339,6 +4366,45 @@ public class PApplet extends Applet
|
||||
}
|
||||
|
||||
|
||||
static public InputStream openStream(File file) {
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
|
||||
} catch (IOException e) {
|
||||
if (file == null) {
|
||||
throw new RuntimeException("File passed to openStream() was null");
|
||||
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Couldn't openStream() for " +
|
||||
file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public InputStream openStreamGZ(String filename) {
|
||||
try {
|
||||
return new GZIPInputStream(openStream(filename));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Couldn't openStreamGZ() for " +
|
||||
filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public InputStream openStreamGZ(File file) {
|
||||
try {
|
||||
return new GZIPInputStream(openStream(file));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Couldn't openStreamGZ() for " +
|
||||
file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public byte[] loadBytes(String filename) {
|
||||
InputStream is = openStream(filename);
|
||||
if (is != null) return loadBytes(is);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
0124 core
|
||||
0125 core
|
||||
X more blend() modes (the five listed on the thread below?)
|
||||
X http://dev.processing.org/bugs/show_bug.cgi?id=132
|
||||
X figure out what the modes should actually be:
|
||||
@@ -63,7 +63,23 @@ X or textAlign(LEFT, MIDDLE); -> this one seems best
|
||||
X add reference for new param, and update keywords.txt
|
||||
X given to andy
|
||||
|
||||
0125p3
|
||||
0125pX (will be 3)
|
||||
X PImage.save() method is not working with get()
|
||||
X http://dev.processing.org/bugs/show_bug.cgi?id=558
|
||||
X NullPointerException in Create Font with "All Characters" enabled
|
||||
X http://dev.processing.org/bugs/show_bug.cgi?id=564
|
||||
X added min() and max() for float and int arrays
|
||||
_ need to update reference
|
||||
X moved around min/max functions
|
||||
|
||||
_ add gluegen-rt back to the applet export
|
||||
_ http://download.java.net/media/jogl/builds/nightly/javadoc_public/com/sun/opengl/util/JOGLAppletLauncher.html
|
||||
|
||||
_ look into jogl anti-aliasing on osx
|
||||
_ smoothMode(2) and smoothMode(4), right after size()?
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1175552759
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1164236069
|
||||
|
||||
_ re-disable P2D before distributing
|
||||
|
||||
_ ortho() behaving differently in P3D vs OPENGL
|
||||
@@ -141,6 +157,9 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=530
|
||||
_ set modified to true on endDraw() so that image updates properly
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=526
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1171574044
|
||||
_ when drawing into a JAVA2D surface, have to call loadPixels()
|
||||
_ to draw it later with P3D (or OPENGL prolly)
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1171574044
|
||||
_ problems with depth buffer and createGraphics with P3D
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=482
|
||||
_ ARGB problems with createGraphics
|
||||
@@ -226,7 +245,9 @@ _ probably need to integrate over a rolling array of 10 frames or so
|
||||
_ frameRate() speeds up temporarily if CPU load drops dramatically
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=297
|
||||
_ perhaps add a hint(DISABLE_FRAMERATE_DAMPER)
|
||||
|
||||
_ size of sketch different in setup() and draw() on linux
|
||||
_ make sure that the sketch isn't being sized based on bad insets
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=341
|
||||
|
||||
point()
|
||||
_ gl point stuff is a problem
|
||||
@@ -825,8 +846,6 @@ _ set(x, y, image) y reversed in openGL
|
||||
_ background(image) also broken
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=91
|
||||
_ also textMode(SCREEN)
|
||||
_ look into jogl anti-aliasing on osx
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1164236069
|
||||
_ in opengl mode, use its tesselator
|
||||
_ because the vertex calls can just come right back to regular vertex calls
|
||||
_ this way we can also implement breakShape() for opengl
|
||||
|
||||
Reference in New Issue
Block a user