1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Syncing with Processing 1.0.9 (revision 5766).

This commit is contained in:
David A. Mellis
2009-10-22 00:56:16 +00:00
parent 7f58e2213e
commit 2e26a2d994
38 changed files with 16818 additions and 901 deletions

View File

@ -2687,6 +2687,12 @@ public class PApplet extends Applet
return (a > b) ? a : b;
}
/*
static public final double max(double a, double 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);
@ -2732,6 +2738,26 @@ public class PApplet extends Applet
}
/**
* Find the maximum value in an array.
* Throws an ArrayIndexOutOfBoundsException if the array is length 0.
* @param list the source array
* @return The maximum value
*/
/*
static public final double max(double[] list) {
if (list.length == 0) {
throw new ArrayIndexOutOfBoundsException(ERROR_MIN_MAX);
}
double 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;
}
@ -2740,6 +2766,12 @@ public class PApplet extends Applet
return (a < b) ? a : b;
}
/*
static public final double min(double a, double 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);
@ -2749,6 +2781,12 @@ public class PApplet extends Applet
return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
}
/*
static public final double min(double a, double b, double c) {
return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
}
*/
/**
* Find the minimum value in an array.
@ -2766,6 +2804,8 @@ public class PApplet extends Applet
}
return min;
}
/**
* Find the minimum value in an array.
* Throws an ArrayIndexOutOfBoundsException if the array is length 0.
@ -2784,6 +2824,25 @@ public class PApplet extends Applet
}
/**
* Find the minimum value in an array.
* Throws an ArrayIndexOutOfBoundsException if the array is length 0.
* @param list the source array
* @return The minimum value
*/
/*
static public final double min(double[] list) {
if (list.length == 0) {
throw new ArrayIndexOutOfBoundsException(ERROR_MIN_MAX);
}
double min = list[0];
for (int i = 1; i < list.length; i++) {
if (list[i] < min) min = list[i];
}
return min;
}
*/
static public final int constrain(int amt, int low, int high) {
return (amt < low) ? low : ((amt > high) ? high : amt);
}
@ -2888,11 +2947,13 @@ public class PApplet extends Applet
}
/*
static public final double map(double value,
double istart, double istop,
double ostart, double ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}
*/
@ -4355,18 +4416,34 @@ public class PApplet extends Applet
* Saves bytes to a specific File location specified by the user.
*/
static public void saveBytes(File file, byte buffer[]) {
File tempFile = null;
try {
File parentDir = file.getParentFile();
tempFile = File.createTempFile(file.getName(), null, parentDir);
/*
String filename = file.getAbsolutePath();
createPath(filename);
OutputStream output = new FileOutputStream(file);
if (file.getName().toLowerCase().endsWith(".gz")) {
output = new GZIPOutputStream(output);
}
*/
OutputStream output = createOutput(tempFile);
saveBytes(output, buffer);
output.close();
output = null;
if (!tempFile.renameTo(file)) {
System.err.println("Could not rename temporary file " +
tempFile.getAbsolutePath());
}
} catch (IOException e) {
System.err.println("error saving bytes to " + file);
if (tempFile != null) {
tempFile.delete();
}
e.printStackTrace();
}
}
@ -4393,6 +4470,8 @@ public class PApplet extends Applet
static public void saveStrings(File file, String strings[]) {
saveStrings(createOutput(file), strings);
/*
try {
String location = file.getAbsolutePath();
createPath(location);
@ -4406,18 +4485,17 @@ public class PApplet extends Applet
} catch (IOException e) {
e.printStackTrace();
}
*/
}
static public void saveStrings(OutputStream output, String strings[]) {
try {
OutputStreamWriter osw = new OutputStreamWriter(output, "UTF-8");
PrintWriter writer = new PrintWriter(osw);
PrintWriter writer = createWriter(output);
for (int i = 0; i < strings.length; i++) {
writer.println(strings[i]);
}
writer.flush();
} catch (UnsupportedEncodingException e) { } // will not happen
writer.close();
}

View File

@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2004-08 Ben Fry and Casey Reas
Copyright (c) 2004-09 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This library is free software; you can redistribute it and/or

View File

@ -358,12 +358,12 @@ public class PGraphics3D extends PGraphics {
cameraInv = new PMatrix3D();
// set up the default camera
camera();
// camera();
// defaults to perspective, if the user has setup up their
// own projection, they'll need to fix it after resize anyway.
// this helps the people who haven't set up their own projection.
perspective();
// perspective();
}
@ -478,6 +478,12 @@ public class PGraphics3D extends PGraphics {
forwardTransform = modelview;
reverseTransform = modelviewInv;
// set up the default camera
camera();
// defaults to perspective, if the user has setup up their
// own projection, they'll need to fix it after resize anyway.
// this helps the people who haven't set up their own projection.
perspective();
// easiest for beginners
@ -1344,7 +1350,7 @@ public class PGraphics3D extends PGraphics {
boolean bClipped = false;
int clippedCount = 0;
cameraNear = -8;
// cameraNear = -8;
if (vertices[a][VZ] > cameraNear) {
aClipped = true;
clippedCount++;
@ -1358,8 +1364,15 @@ public class PGraphics3D extends PGraphics {
clippedCount++;
}
if (clippedCount == 0) {
// if (vertices[a][VZ] < cameraFar &&
// vertices[b][VZ] < cameraFar &&
// vertices[c][VZ] < cameraFar) {
addTriangleWithoutClip(a, b, c);
// }
// } else if (true) {
// return;
} else if (clippedCount == 3) {
// In this case there is only one visible point. |/|
// So we'll have to make two new points on the clip line <| |
@ -3502,6 +3515,7 @@ public class PGraphics3D extends PGraphics {
0, y, 0, ty,
0, 0, z, tz,
0, 0, 0, 1);
updateProjection();
frustumMode = false;
}
@ -3569,6 +3583,12 @@ public class PGraphics3D extends PGraphics {
0, (2*znear)/(top-bottom), (top+bottom)/(top-bottom), 0,
0, 0, -(zfar+znear)/(zfar-znear),-(2*zfar*znear)/(zfar-znear),
0, 0, -1, 0);
updateProjection();
}
/** Called after the 'projection' PMatrix3D has changed. */
protected void updateProjection() {
}

View File

@ -182,6 +182,7 @@ public class PImage implements PConstants, Cloneable {
raster.getDataElements(0, 0, width, height, pixels);
} else { // go the old school java 1.0 route
// System.out.println(img.getClass().getName());
width = img.getWidth(null);
height = img.getHeight(null);
pixels = new int[width * height];
@ -690,7 +691,7 @@ public class PImage implements PConstants, Cloneable {
throw new RuntimeException("Use filter(POSTERIZE, int levels) " +
"instead of filter(POSTERIZE)");
case RGB:
case OPAQUE:
for (int i = 0; i < pixels.length; i++) {
pixels[i] |= 0xff000000;
}

View File

@ -430,6 +430,11 @@ public class PVector {
}
static public float dot(PVector v1, PVector v2) {
return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
}
/**
* Return a vector composed of the cross product between this and another.
*/