();
7 |
8 | // helper class for rendering
9 | ToxiclibsSupport gfx;
10 |
11 | void setup() {
12 | size(680, 382);
13 | smooth();
14 | noFill();
15 | background(255);
16 | gfx=new ToxiclibsSupport(this);
17 | // define pairs of shapes & colors
18 | // here we're making use of polymorphism since
19 | // each of these classes implements the Shape2D interface
20 | shapes.put(new Circle(new Vec2D(100, 100), 80), TColor.RED);
21 | shapes.put(new Ellipse(new Vec2D(300, 100), new Vec2D(80, 50)), TColor.GREEN);
22 | shapes.put(new Triangle2D(new Vec2D(400, 20), new Vec2D(650, 100), new Vec2D(500, 180)), TColor.BLUE);
23 | shapes.put(Rect.fromCenterExtent(new Vec2D(200,280), new Vec2D(100,60)), TColor.CYAN);
24 | shapes.put(new Circle(new Vec2D(450,280),80).toPolygon2D(5), TColor.MAGENTA);
25 | // draw shape outlines
26 | for (Shape2D s : shapes.keySet()) {
27 | gfx.polygon2D(s.toPolygon2D());
28 | }
29 | }
30 |
31 | void draw() {
32 | noStroke();
33 | // randomly sample all shapes
34 | for (Shape2D s : shapes.keySet()) {
35 | // use color associated with shape
36 | // and create a slightly modified/varying version for each dot
37 | fill(shapes.get(s).getAnalog(0.5,0.5).toARGB());
38 | gfx.circle(s.getRandomPoint(), 5);
39 | }
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/examples/core/geometry/TriangleCircumCircle/TriangleCircumCircle.pde:
--------------------------------------------------------------------------------
1 | /**
2 | * This demo shows how to construct a circle through 3 points by computing
3 | * the triangles circumcircle (a circle defined for any triangle and which
4 | * goes through all its points)
5 | *
6 | * Usage:
7 | * Move mouse to adjust size/shape of triangle
8 | *
9 | */
10 |
11 | /*
12 | * Copyright (c) 2010 Karsten Schmidt
13 | *
14 | * This library is free software; you can redistribute it and/or
15 | * modify it under the terms of the GNU Lesser General Public
16 | * License as published by the Free Software Foundation; either
17 | * version 2.1 of the License, or (at your option) any later version.
18 | *
19 | * http://creativecommons.org/licenses/LGPL/2.1/
20 | *
21 | * This library is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 | * Lesser General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU Lesser General Public
27 | * License along with this library; if not, write to the Free Software
28 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 | */
30 |
31 | import toxi.geom.*;
32 | import toxi.processing.*;
33 |
34 | ToxiclibsSupport gfx;
35 |
36 | void setup() {
37 | size(680, 382);
38 | gfx = new ToxiclibsSupport(this);
39 | noFill();
40 | }
41 |
42 | void draw() {
43 | background(255);
44 | Vec2D m=new Vec2D(mouseX, mouseY);
45 | Vec2D o=new Vec2D(width/2,height/2);
46 | Vec2D n=m.sub(o).perpendicular().normalizeTo(100);
47 | Triangle2D t = new Triangle2D(o.sub(n),m,o.add(n));
48 | stroke(255,0,0);
49 | gfx.triangle(t, true);
50 | stroke(0,224,255);
51 | gfx.ellipse(t.getCircumCircle());
52 | }
53 |
--------------------------------------------------------------------------------
/examples/core/interpolation/InterpolateGrid/InterpolateGrid.pde:
--------------------------------------------------------------------------------
1 | import toxi.math.*;
2 |
3 | //InterpolateStrategy tween=new SigmoidInterpolation(1.2);
4 | BezierInterpolation tween=new BezierInterpolation(3,-3);
5 |
6 | void setup() {
7 | size(400,400);
8 | }
9 |
10 | void draw() {
11 | tween.setCoefficients(sin(frameCount*0.05)*0.5+2,-(sin(frameCount*0.03)*0.5+2));
12 | background(0,128,255);
13 | noStroke();
14 | fill(255,100);
15 | // pythagorean: c^2=a^2+b^2
16 | float maxDist=sqrt(sq(width/2-0)+sq(height/2));
17 | for(int y=0; y<=height; y+=20) {
18 | for(int x=0; x<=width; x+=20) {
19 | float d=min(dist(width/2,height/2,x,y),maxDist)/maxDist;
20 | float r=tween.interpolate(1,16,d);
21 | ellipse(x,y,r,r);
22 | }
23 | }
24 | stroke(255,255,0);
25 | for(int x=0; x {
16 |
17 | abstract int compare(HistogramWord a, HistogramWord b);
18 |
19 | abstract int getMetric(HistogramWord w);
20 | }
21 |
22 | class FrequencyComparator extends HistogramSorter{
23 |
24 | int compare(HistogramWord a, HistogramWord b) {
25 | return b.count-a.count;
26 | }
27 |
28 | public int getMetric(HistogramWord w) {
29 | return w.count;
30 | }
31 | }
32 |
33 | class WordLengthComparator extends HistogramSorter{
34 |
35 | int compare(HistogramWord a, HistogramWord b) {
36 | return b.word.length()-a.word.length();
37 | }
38 |
39 | public int getMetric(HistogramWord w) {
40 | return w.word.length();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/examples/core/mapping/TextHistogram/data/artofwar.txt.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/mapping/TextHistogram/data/artofwar.txt.gz
--------------------------------------------------------------------------------
/examples/core/mapping/TwitterGeo/code/readme.txt:
--------------------------------------------------------------------------------
1 | Download the Twitter4j library from here:
2 |
3 | http://www.twitter4j.org
4 |
5 | Then place the library JAR file into this folder...
--------------------------------------------------------------------------------
/examples/core/mesh/MeshAlignToTriangle/MeshAlignToTriangle.pde:
--------------------------------------------------------------------------------
1 | import toxi.geom.*;
2 | import toxi.geom.mesh.*;
3 | import toxi.processing.*;
4 |
5 |
6 |
7 | Triangle3D tri;
8 | TriangleMesh mesh;
9 | ToxiclibsSupport gfx;
10 |
11 | void setup() {
12 | size(400, 400, P3D);
13 | gfx=new ToxiclibsSupport(this);
14 | randomize();
15 | }
16 |
17 | void draw() {
18 | background(0);
19 | lights();
20 | translate(width/2, height/2, 0);
21 | rotateX(mouseY*0.01);
22 | rotateY(mouseX*0.01);
23 | // draw world space axes
24 | gfx.origin(300);
25 | // get triangle center and visualize normal vector
26 | Vec3D c=tri.computeCentroid();
27 | stroke(255, 0, 255);
28 | gfx.line(c, c.add(tri.computeNormal().scale(300)));
29 | noStroke();
30 | // draw triangle & mesh
31 | fill(255, 255, 0);
32 | gfx.triangle(tri);
33 | fill(0, 255, 255);
34 | gfx.mesh(mesh);
35 | }
36 |
37 | void randomize() {
38 | // create random triangle
39 | tri=new Triangle3D(
40 | Vec3D.randomVector().scale(100),
41 | Vec3D.randomVector().scale(100),
42 | Vec3D.randomVector().scale(100)
43 | );
44 | // create box mesh around origin
45 | mesh = (TriangleMesh)new AABB(50).toMesh();
46 | // get triangle normal
47 | Vec3D n=tri.computeNormal();
48 | // rotate mesh such that the +Z axis is aligned with the triangle normal
49 | mesh.pointTowards(n);
50 | // move box in the normal direction 100 units relative from the triangle center
51 | mesh.translate(tri.computeCentroid().add(n.scale(100)));
52 | }
53 |
54 | void keyPressed() {
55 | if (key=='r') randomize();
56 | }
57 |
--------------------------------------------------------------------------------
/examples/core/mesh/STLImportTest/mesh-flipped.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/mesh/STLImportTest/mesh-flipped.stl
--------------------------------------------------------------------------------
/examples/core/mesh/STLImportTest/mesh.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/mesh/STLImportTest/mesh.stl
--------------------------------------------------------------------------------
/examples/core/mesh/TerrainBasics/TerrainBasics.pde:
--------------------------------------------------------------------------------
1 | import toxi.geom.*;
2 | import toxi.geom.mesh.*;
3 | import toxi.processing.*;
4 |
5 | int DIM=20;
6 | float NOISE_SCALE=0.15;
7 |
8 | TriangleMesh mesh;
9 | ToxiclibsSupport gfx;
10 |
11 | void setup() {
12 | size(640, 480, P3D);
13 | Terrain terrain = new Terrain(DIM, DIM, 16);
14 | // populate elevation data
15 | float[] el = new float[DIM*DIM];
16 | noiseSeed(23);
17 | for (int z = 0, i = 0; z < DIM; z++) {
18 | for (int x = 0; x < DIM; x++) {
19 | el[i++] = noise(x * NOISE_SCALE, z * NOISE_SCALE) * 100;
20 | }
21 | }
22 | terrain.setElevation(el);
23 | // create mesh
24 | mesh = new TriangleMesh();
25 | terrain.toMesh(mesh,-10);
26 | // attach drawing utils
27 | gfx = new ToxiclibsSupport(this);
28 | }
29 |
30 | void draw() {
31 | background(0);
32 | lights();
33 | translate(width/2,height/2,0);
34 | rotateX(mouseY*0.01);
35 | rotateY(mouseX*0.01);
36 | noStroke();
37 | gfx.mesh(mesh);
38 | }
39 |
--------------------------------------------------------------------------------
/examples/core/mesh/TexturedGlobe/TexturedGlobe.pde:
--------------------------------------------------------------------------------
1 | import toxi.geom.*;
2 | import toxi.geom.mesh2d.*;
3 | import toxi.geom.mesh.*;
4 | import toxi.processing.*;
5 |
6 |
7 |
8 | float EARTH_RADIUS=300;
9 | Vec2D HOME=new Vec2D(0,51);
10 |
11 | TriangleMesh globe;
12 | PImage earthTex;
13 | float texUOffset=180;
14 |
15 | ToxiclibsSupport gfx;
16 |
17 | void setup() {
18 | size(1024, 768, P3D);
19 | gfx = new ToxiclibsSupport(this);
20 | earthTex = loadImage("earth_1024.jpg");
21 | globe = (TriangleMesh)new SurfaceMeshBuilder(new SphereFunction()).createMesh(null, 36, EARTH_RADIUS);
22 | globe.computeVertexNormals();
23 | }
24 |
25 | void draw() {
26 | background(255);
27 | lights();
28 | translate(width/2, height/2, 0);
29 | rotateX(mouseY*0.01);
30 | rotateY(mouseX*0.01);
31 | fill(255);
32 | gfx.origin(400);
33 | noStroke();
34 | textureMode(NORMAL);
35 | gfx.texturedMesh(globe, earthTex, true);
36 | fill(255, 0, 255);
37 | gfx.box(new AABB(toCartesianWithOffset(HOME), 4));
38 | }
39 |
40 | Vec3D toCartesianWithOffset(Vec2D v) {
41 | return new Vec3D(EARTH_RADIUS, radians(v.x+texUOffset), radians(v.y)).toCartesian();
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/examples/core/mesh/TexturedGlobe/data/earth_1024.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/mesh/TexturedGlobe/data/earth_1024.jpg
--------------------------------------------------------------------------------
/examples/core/misc/ConfigScroller/app.properties:
--------------------------------------------------------------------------------
1 | # sample configuration file to customise application behaviour
2 |
3 | app.width=640
4 | app.height=480
5 |
6 | color.bg=ffff00
7 | color.text=000000
8 |
9 | font.name=Georgia
10 | font.size=72
11 |
12 | msg.text=toxiclibs.org
13 | msg.speed=4
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-100.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-101.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-101.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-102.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-102.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-103.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-103.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-104.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-104.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-105.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-105.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-106.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-106.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-107.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-107.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-108.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-108.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-109.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-109.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-110.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-110.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-111.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-111.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-112.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-112.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-113.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-113.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-114.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-114.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-115.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-115.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-116.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-116.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-117.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-117.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-118.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-118.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-119.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-119.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-120.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-121.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-121.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-122.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-122.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-123.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-123.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-124.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-124.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-125.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-125.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-126.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-126.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-127.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-127.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-128.png
--------------------------------------------------------------------------------
/examples/core/misc/FileSequence/data/cloud-129.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/core/misc/FileSequence/data/cloud-129.png
--------------------------------------------------------------------------------
/examples/core/misc/ShiffmanFlocking/Flock.pde:
--------------------------------------------------------------------------------
1 | // Flock class
2 | // Does very little, simply manages the ArrayList of all the boids
3 |
4 | class Flock {
5 | ArrayList boids; // An arraylist for all the boids
6 |
7 | Flock() {
8 | boids = new ArrayList(); // Initialize the arraylist
9 | }
10 |
11 | void run() {
12 | for (int i = 0; i < boids.size(); i++) {
13 | Boid b = (Boid) boids.get(i);
14 | b.run(boids); // Passing the entire list of boids to each boid individually
15 | }
16 | }
17 |
18 | void addBoid(Boid b) {
19 | boids.add(b);
20 | }
21 | }
22 |
23 |
24 |
--------------------------------------------------------------------------------
/examples/core/misc/ShiffmanFlocking3D/Flock.pde:
--------------------------------------------------------------------------------
1 | // Flock class
2 | // Does very little, simply manages the ArrayList of all the boids
3 |
4 | class Flock {
5 | ArrayList boids; // An arraylist for all the boids
6 |
7 | Flock() {
8 | boids = new ArrayList(); // Initialize the arraylist
9 | }
10 |
11 | void run() {
12 | for (int i = boids.size()-1 ; i >= 0 ; i--) {
13 | Boid b = (Boid) boids.get(i);
14 | b.run(boids); // Passing the entire list of boids to each boid individually
15 | }
16 | }
17 |
18 | void addBoid(Boid b) {
19 | boids.add(b);
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/examples/core/splines/SplineBlobTest/Spine.pde:
--------------------------------------------------------------------------------
1 | class Spine {
2 | Vec3D[] vertices;
3 | float bodyHeight;
4 |
5 | Spine(float maxOffset, float bh) {
6 | bodyHeight=bh;
7 | vertices=new Vec3D[4];
8 | vertices[0]=new Vec3D(random(-1,1)*maxOffset,0,0);
9 | vertices[1]=new Vec3D(random(-1,1)*maxOffset,0.25*bodyHeight,0);
10 | vertices[2]=new Vec3D(random(-1,1)*maxOffset,0.75*bodyHeight,0);
11 | vertices[3]=new Vec3D(random(-1,1)*maxOffset,bodyHeight,0);
12 | }
13 |
14 | float getOffsetAt(float t) {
15 | return bezierPoint(vertices[0].x,vertices[1].x,vertices[2].x,vertices[3].x,t);
16 | }
17 |
18 | void draw() {
19 | noFill();
20 | bezier(vertices[0].x,vertices[0].y,vertices[1].x,vertices[1].y,vertices[2].x,vertices[2].y,vertices[3].x,vertices[3].y);
21 | for(float t=0; t<=1.001; t+=0.05) {
22 | float x=getOffsetAt(t);
23 | ellipse(x,t*bodyHeight,5,5);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/examples/core/splines/SplineBlobTest/SpineSplineBlob.pde:
--------------------------------------------------------------------------------
1 | class SpineSplineBlob extends SplineBlob {
2 |
3 | SpineSplineBlob(float w, float h, int sd) {
4 | super(w,h,sd);
5 | init();
6 | }
7 |
8 | SpineSplineBlob(SplineBlob b) {
9 | super(b.width,b.height,b.subDiv);
10 | spline=new Spline2D(b.points);
11 | spline.updateCoefficients();
12 | spline.delta[0].set(b.points[1].x*0.75,0);
13 | spline.delta[b.numP-1].set(-b.points[numP-2].x,0);
14 | init();
15 | }
16 |
17 | void init() {
18 | spine=new Spine(width*.5,height);
19 | bodyTemplate=new ArrayList();
20 | bodyTemplate.addAll(spline.toLineStrip2D(subDiv).getVertices());
21 | bodySpine=new float[bodyTemplate.size()];
22 | Iterator it=bodyTemplate.iterator();
23 | int idx=0;
24 | while(it.hasNext()) {
25 | float offX=spine.getOffsetAt(it.next().y/height);
26 | bodySpine[idx++]=offX;
27 | }
28 | for(int i=bodyTemplate.size()-1; i>=0; i--) {
29 | float offX=bodySpine[i];
30 | Vec2D p=bodyTemplate.get(i);
31 | Vec2D q=new Vec2D(p);
32 | q.x=offX-p.x;
33 | p.x+=offX;
34 | bodyTemplate.add(q);
35 | }
36 | }
37 |
38 | void draw() {
39 | noFill();
40 | stroke(0,0,255);
41 | beginShape();
42 | Iterator i=bodyTemplate.iterator();
43 | while(i.hasNext()) {
44 | Vec2D v=(Vec2D)i.next();
45 | vertex(v.x,v.y);
46 | }
47 | endShape();
48 | spine.draw();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/examples/core/splines/SplineBlobTest/SplineBlob.pde:
--------------------------------------------------------------------------------
1 | class SplineBlob {
2 |
3 | Spline2D spline;
4 | Spine spine;
5 |
6 | Vec2D[] points;
7 | Vec2D[] coeffA,delta;
8 | float[] bi,b0,b1,b2,b3;
9 |
10 | int numP;
11 | int subDiv;
12 |
13 | List bodyTemplate;
14 | List outline;
15 | float[] bodySpine;
16 |
17 | float width,height;
18 |
19 | SplineBlob(float w, float h, int sd) {
20 | width=w;
21 | height=h;
22 | numP=6;
23 | subDiv=sd;
24 | points=new Vec2D[numP];
25 | int idx=0;
26 | points[idx++]=new Vec2D();
27 | points[idx++]=new Vec2D(random(0.5,0.85)*w,random(0.25,0.33)*h);
28 | points[idx++]=new Vec2D(random(0.6,1.2)*points[idx-2].x,random(0.45,0.6)*h);
29 | points[idx++]=new Vec2D(min(points[1].x*random(1.25,2),w),random(0.66,0.8)*h);
30 | points[idx++]=new Vec2D(points[idx-2].x*random(1.02,1.1),0.9*h);
31 | points[idx++]=new Vec2D(0,h);
32 | spline=new Spline2D(points);
33 | spline.updateCoefficients();
34 | spline.delta[0].set(points[1].x*0.75,0);
35 | spline.delta[numP-1].set(-points[numP-2].x,0);
36 | outline=spline.toLineStrip2D(subDiv).getVertices();
37 | }
38 |
39 | void draw() {
40 | noFill();
41 | stroke(255,0,0);
42 | pushMatrix();
43 | drawShape();
44 | scale(-1,1);
45 | drawShape();
46 | popMatrix();
47 | }
48 |
49 | void drawShape() {
50 |
51 | beginShape();
52 | Iterator i=outline.iterator();
53 | while(i.hasNext()) {
54 | Vec2D v=(Vec2D)i.next();
55 | vertex(v.x,v.y);
56 | }
57 | endShape();
58 | for (int k = 0; k < numP; k++) {
59 | ellipse(spline.pointList.get(k).x,spline.pointList.get(k).y,5,5);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/examples/data/TwitterSearch/TwitterSearch.pde:
--------------------------------------------------------------------------------
1 | /**
2 | * This demo uses the AtomFeed parser to load twitter search results.
3 | *
4 | * (c) 2011 Karsten Schmidt // LGPLv2 licensed
5 | */
6 |
7 | import toxi.data.feeds.*;
8 |
9 | AtomFeed feed=AtomFeed.newFromURL("http://search.twitter.com/search.atom?q=toxiclibs");
10 | println(feed.entries.size()+" entries loaded");
11 |
12 | for(AtomEntry e : feed) {
13 | println(String.format("[%s] %s", e.author.name, e.title));
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/examples/physics/BoxConstraintDemo/Box.pde:
--------------------------------------------------------------------------------
1 | class VisibleBoxConstraint extends BoxConstraint {
2 |
3 | public VisibleBoxConstraint(Vec3D min, Vec3D max) {
4 | super(min,max);
5 | }
6 |
7 | public void draw() {
8 | Vec3D m=box.getMin();
9 | Vec3D n=box.getMax();
10 | beginShape(QUAD_STRIP);
11 | stroke(0);
12 | vertex(m.x,m.y,m.z); vertex(n.x,m.y,m.z);
13 | vertex(m.x,n.y,m.z); vertex(n.x,n.y,m.z);
14 | vertex(m.x,n.y,n.z); vertex(n.x,n.y,n.z);
15 | vertex(m.x,m.y,n.z); vertex(n.x,m.y,n.z);
16 | vertex(m.x,m.y,m.z); vertex(n.x,m.y,m.z);
17 | endShape();
18 | }
19 | }
20 |
21 |
22 |
--------------------------------------------------------------------------------
/examples/physics/BoxFluidDemo/GUI.pde:
--------------------------------------------------------------------------------
1 | ControlP5 ui;
2 |
3 | void initGUI() {
4 | ui = new ControlP5(this);
5 | ui.addSlider("isoThreshold",1,12,isoThreshold,20,20,100,14).setLabel("iso threshold");
6 |
7 | ui.addToggle("showPhysics",showPhysics,20,60,14,14).setLabel("show particles");
8 | ui.addToggle("isWireFrame",isWireFrame,20,100,14,14).setLabel("wireframe");
9 | ui.addToggle("isClosed",isClosed,20,140,14,14).setLabel("closed mesh");
10 | ui.addToggle("toggleBoundary",useBoundary,20,180,14,14).setLabel("use boundary");
11 |
12 | ui.addBang("initPhysics",20,240,28,28).setLabel("restart");
13 | }
14 |
15 |
16 |
--------------------------------------------------------------------------------
/examples/physics/BoxFluidDemo/Physics.pde:
--------------------------------------------------------------------------------
1 | void initPhysics() {
2 | physics=new VerletPhysics3D();
3 | physics.setWorldBounds(new AABB(new Vec3D(),new Vec3D(DIM,DIM,DIM)));
4 | if (surface!=null) {
5 | surface.reset();
6 | mesh.clear();
7 | }
8 | boundingSphere=new SphereConstraint(new Sphere(new Vec3D(),DIM),SphereConstraint.INSIDE);
9 | gravity=new GravityBehavior3D(new Vec3D(0,1,0));
10 | physics.addBehavior(gravity);
11 | }
12 |
13 | void updateParticles() {
14 | Vec3D grav=Vec3D.Y_AXIS.copy();
15 | grav.rotateX(mouseY*0.01);
16 | grav.rotateY(mouseX*0.01);
17 | gravity.setForce(grav.scaleSelf(2));
18 | numP=physics.particles.size();
19 | if (random(1)<0.8 && numP10 && physics.springs.size()<1400) {
25 | for(int i=0; i<60; i++) {
26 | if (random(1)<0.04) {
27 | VerletParticle3D q=physics.particles.get((int)random(numP));
28 | VerletParticle3D r=q;
29 | while(q==r) {
30 | r=physics.particles.get((int)random(numP));
31 | }
32 | physics.addSpring(new VerletSpring3D(q,r,REST_LENGTH, 0.0002));
33 | }
34 | }
35 | }
36 | float len=(float)numP/NUM_PARTICLES*REST_LENGTH;
37 | for(VerletSpring3D s : physics.springs) {
38 | s.setRestLength(random(0.9,1.1)*len);
39 | }
40 | physics.update();
41 | }
42 |
--------------------------------------------------------------------------------
/examples/physics/CrashTest/data/audi.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/physics/CrashTest/data/audi.stl
--------------------------------------------------------------------------------
/examples/physics/JoinedCatenary/Voxel.pde:
--------------------------------------------------------------------------------
1 | // merge all mesh instances into a single one
2 | // convert into voxelized representation
3 | // perforate volumetric space (to make more light weight)
4 | // compute continuous threshold surface
5 | // apply laplacian smooth and export as STL file in sketch folder
6 | void saveVoxelized() {
7 | WETriangleMesh combined=new WETriangleMesh();
8 | for(ParticleMesh m : meshes) {
9 | combined.addMesh(m.mesh);
10 | }
11 | int res=160;
12 | float iso=0.1;
13 | int wall=2;
14 | VolumetricSpace volume=new MeshVoxelizer(res).setWallThickness(wall).voxelizeMesh(combined);
15 | perforateVolume(volume);
16 | // make volume water tight
17 | volume.closeSides();
18 | // compute threshold surface mesh
19 | IsoSurface surface=new ArrayIsoSurface(volume);
20 | surface.computeSurfaceMesh(combined,iso);
21 | // smooth voxelized mesh
22 | new LaplacianSmooth().filter(combined,2);
23 | combined.saveAsSTL(sketchPath("voxelized-"+res+"-"+iso+"-"+wall+".stl"));
24 | }
25 |
26 | // create interleaved holes in XY plane of voxel space (holes along Z axis)
27 | // holes are in "+" shape
28 | void perforateVolume(VolumetricSpace volume) {
29 | boolean isEven=true;
30 | for(int y=2; y0) {
18 | VerletSpring3D s=new VerletSpring3D(p,physics.particles.get(idx-1),REST_LENGTH,STRENGTH);
19 | physics.addSpring(s);
20 | }
21 | if (y>0) {
22 | VerletSpring3D s=new VerletSpring3D(p,physics.particles.get(idx-DIM),REST_LENGTH,STRENGTH);
23 | physics.addSpring(s);
24 | }
25 | idx++;
26 | }
27 | }
28 | // add spheres as constraint to all particles
29 | for(Iterator i=spheres.iterator(); i.hasNext();) {
30 | SphereConstraint s=(SphereConstraint)i.next();
31 | VerletPhysics3D.addConstraintToAll(s,physics.particles);
32 | }
33 | // add ground as constraint to all particles
34 | VerletPhysics3D.addConstraintToAll(ground,physics.particles);
35 | }
36 |
--------------------------------------------------------------------------------
/examples/physics/PhysicsType/data/ReplicaBold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/physics/PhysicsType/data/ReplicaBold.ttf
--------------------------------------------------------------------------------
/examples/physics/Shiffman_ForceDirectedGraph/Node.pde:
--------------------------------------------------------------------------------
1 | // The Nature of Code
2 | //
3 | // Spring 2010
4 | // Toxiclibs example: http://toxiclibs.org/
5 |
6 | // Force directed graph
7 | // Heavily based on: http://code.google.com/p/fidgen/
8 |
9 | // Notice how we are using inheritance here!
10 | // We could have just stored a reference to a VerletParticle object
11 | // inside the Node class, but inheritance is a nice alternative
12 |
13 | class Node extends VerletParticle2D {
14 |
15 | Node(Vec2D pos) {
16 | super(pos);
17 | }
18 |
19 | // All we're doing really is adding a display() function to a VerletParticle
20 | void display() {
21 | fill(0,150);
22 | stroke(0);
23 | ellipse(x,y,16,16);
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/examples/sim/GrayScottImage/data/ti_yong.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/sim/GrayScottImage/data/ti_yong.png
--------------------------------------------------------------------------------
/examples/volume/BoxFluidDemo/GUI.pde:
--------------------------------------------------------------------------------
1 | ControlP5 ui;
2 |
3 | void initGUI() {
4 | ui = new ControlP5(this);
5 | ui.addSlider("isoThreshold",1,12,isoThreshold,20,20,100,14).setLabel("iso threshold");
6 |
7 | ui.addToggle("showPhysics",showPhysics,20,60,14,14).setLabel("show particles");
8 | ui.addToggle("isWireFrame",isWireFrame,20,100,14,14).setLabel("wireframe");
9 | ui.addToggle("isClosed",isClosed,20,140,14,14).setLabel("closed mesh");
10 | ui.addToggle("toggleBoundary",useBoundary,20,180,14,14).setLabel("use boundary");
11 |
12 | ui.addBang("initPhysics",20,240,28,28).setLabel("restart");
13 | }
14 |
15 |
16 |
--------------------------------------------------------------------------------
/examples/volume/BoxFluidDemo/Physics.pde:
--------------------------------------------------------------------------------
1 | void initPhysics() {
2 | physics=new VerletPhysics3D();
3 | physics.setWorldBounds(new AABB(new Vec3D(),new Vec3D(DIM,DIM,DIM)));
4 | if (surface!=null) {
5 | surface.reset();
6 | mesh.clear();
7 | }
8 | boundingSphere=new SphereConstraint(new Sphere(new Vec3D(),DIM),SphereConstraint.INSIDE);
9 | gravity=new GravityBehavior3D(new Vec3D(0,1,0));
10 | physics.addBehavior(gravity);
11 | }
12 |
13 | void updateParticles() {
14 | Vec3D grav=Vec3D.Y_AXIS.copy();
15 | grav.rotateX(mouseY*0.01);
16 | grav.rotateY(mouseX*0.01);
17 | gravity.setForce(grav.scaleSelf(2));
18 | numP=physics.particles.size();
19 | if (random(1)<0.8 && numP10 && physics.springs.size()<1400) {
25 | for(int i=0; i<60; i++) {
26 | if (random(1)<0.04) {
27 | VerletParticle3D q=physics.particles.get((int)random(numP));
28 | VerletParticle3D r=q;
29 | while(q==r) {
30 | r=physics.particles.get((int)random(numP));
31 | }
32 | physics.addSpring(new VerletSpring3D(q,r,REST_LENGTH, 0.0002));
33 | }
34 | }
35 | }
36 | float len=(float)numP/NUM_PARTICLES*REST_LENGTH;
37 | for(VerletSpring3D s : physics.springs) {
38 | s.setRestLength(random(0.9,1.1)*len);
39 | }
40 | physics.update();
41 | }
42 |
--------------------------------------------------------------------------------
/examples/volume/ImageVoxelMesh/ImageVoxelMesh.pde:
--------------------------------------------------------------------------------
1 | /**
2 | * Loads a B&W image and extrudes black pixels brighter than a given threshold into
3 | * a watertight 3D mesh.
4 | *
5 | * @author Karsten Schmidt // LGPL2 licensed
6 | *
7 | * Dependencies: toxiclibscore-0020
8 | * (or newer, available from: http://toxiclibs.org/ )
9 | */
10 | import toxi.geom.*;
11 | import toxi.geom.mesh.*;
12 | import toxi.volume.*;
13 |
14 | int SCALE=8;
15 | int DEPTH=6;
16 | int THRESH=32;
17 | boolean FIXED_DEPTH=true;
18 |
19 | PImage img=loadImage("hand.png");
20 |
21 | // setup volumetric space
22 | Vec3D worldSize = new Vec3D(img.width, img.height, DEPTH).scale(SCALE);
23 | VolumetricSpace volume = new VolumetricHashMap(worldSize, img.width, img.height, DEPTH, 0.33);
24 | VolumetricBrush brush = new RoundBrush(volume, SCALE);
25 | brush.setMode(VolumetricBrush.MODE_PEAK);
26 |
27 | // parse the image
28 | for (int y = 0; y < img.height; y ++) {
29 | for (int x = 0; x < img.width; x ++) {
30 | int col=img.pixels[y * img.width + x] & 0xff;
31 | if (col > THRESH) {
32 | for (int z = 0, d=FIXED_DEPTH ? DEPTH : (int)(col/255.0*DEPTH); z < d; z++) {
33 | brush.drawAtGridPos(x, y, z, 1);
34 | }
35 | }
36 | }
37 | }
38 |
39 | // make volume watertight
40 | volume.closeSides();
41 |
42 | // compute mesh
43 | WETriangleMesh mesh = new WETriangleMesh();
44 | new HashIsoSurface(volume).computeSurfaceMesh(mesh, 1f);
45 |
46 | // apply vertex smoothing
47 | new LaplacianSmooth().filter(mesh,4);
48 |
49 | mesh.saveAsSTL(sketchPath("test.stl"), true);
50 | exit();
51 |
52 |
--------------------------------------------------------------------------------
/examples/volume/ImageVoxelMesh/data/hand.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/volume/ImageVoxelMesh/data/hand.png
--------------------------------------------------------------------------------
/examples/volume/ImplicitFunction/Volume.pde:
--------------------------------------------------------------------------------
1 | class EvaluatingVolume extends VolumetricSpace {
2 |
3 | private final float FREQ = PI * 3.8;
4 | private float upperBound;
5 | private SinCosLUT lut;
6 |
7 | public EvaluatingVolume(Vec3D scale, int res, float upperBound) {
8 | this(scale,res,res,res,upperBound);
9 | }
10 |
11 | public EvaluatingVolume(Vec3D scale, int resX, int resY, int resZ, float upperBound) {
12 | super(scale, resX, resY, resZ);
13 | this.upperBound = upperBound;
14 | this.lut=new SinCosLUT();
15 | }
16 |
17 | public void clear() {
18 | // nothing to do here
19 | }
20 |
21 | public final float getVoxelAt(int i) {
22 | return getVoxelAt(i % resX, (i % sliceRes) / resX, i / sliceRes);
23 | }
24 |
25 | public final float getVoxelAt(int x, int y, int z) {
26 | float val = 0;
27 | if (x > 0 && x < resX1 && y > 0 && y < resY1 && z > 0 && z < resZ1) {
28 | float xx = (float) x / resX - 0.5f;
29 | float yy = (float) y / resY - 0.5f;
30 | float zz = (float) z / resZ - 0.5f;
31 | val = lut.sin(xx * FREQ) + lut.cos(yy * FREQ) + lut.sin(zz * FREQ);
32 | if (val > upperBound) {
33 | val = 0;
34 | }
35 | }
36 | return val;
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/examples/volume/MRISurface/data/aneurism.raw.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/examples/volume/MRISurface/data/aneurism.raw.gz
--------------------------------------------------------------------------------
/lib/apiviz-1.3.1.GA.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/apiviz-1.3.1.GA.jar
--------------------------------------------------------------------------------
/lib/args4j-2.0.8.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/args4j-2.0.8.jar
--------------------------------------------------------------------------------
/lib/core.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/core.jar
--------------------------------------------------------------------------------
/lib/doapamine.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/doapamine.jar
--------------------------------------------------------------------------------
/lib/jaxb/activation.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jaxb/activation.jar
--------------------------------------------------------------------------------
/lib/jaxb/jaxb-api.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jaxb/jaxb-api.jar
--------------------------------------------------------------------------------
/lib/jaxb/jaxb-impl.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jaxb/jaxb-impl.jar
--------------------------------------------------------------------------------
/lib/jaxb/jaxb-xjc.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jaxb/jaxb-xjc.jar
--------------------------------------------------------------------------------
/lib/jaxb/jaxb1-impl.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jaxb/jaxb1-impl.jar
--------------------------------------------------------------------------------
/lib/jaxb/jsr173_1.0_api.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jaxb/jsr173_1.0_api.jar
--------------------------------------------------------------------------------
/lib/joal/export.txt:
--------------------------------------------------------------------------------
1 | application.linux=joal.jar,libjoal_native.so,gluegen-rt.jar,libgluegen-rt.so,audioutils.jar
2 | application.macosx=joal.jar,libjoal_native.jnilib,gluegen-rt.jar,libgluegen-rt.jnilib,audioutils.jar
3 | application.windows=joal.jar,joal_native.dll,gluegen-rt.jar,gluegen-rt.dll,audioutils.jar
--------------------------------------------------------------------------------
/lib/joal/gluegen-rt.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/joal/gluegen-rt.dll
--------------------------------------------------------------------------------
/lib/joal/gluegen-rt.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/joal/gluegen-rt.jar
--------------------------------------------------------------------------------
/lib/joal/joal.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/joal/joal.jar
--------------------------------------------------------------------------------
/lib/joal/joal_native.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/joal/joal_native.dll
--------------------------------------------------------------------------------
/lib/joal/libgluegen-rt.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/joal/libgluegen-rt.jnilib
--------------------------------------------------------------------------------
/lib/joal/libjoal_native.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/joal/libjoal_native.jnilib
--------------------------------------------------------------------------------
/lib/jogl/gluegen-rt.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/gluegen-rt.dll
--------------------------------------------------------------------------------
/lib/jogl/gluegen-rt.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/gluegen-rt.jar
--------------------------------------------------------------------------------
/lib/jogl/jogl.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/jogl.dll
--------------------------------------------------------------------------------
/lib/jogl/jogl.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/jogl.jar
--------------------------------------------------------------------------------
/lib/jogl/jogl_awt.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/jogl_awt.dll
--------------------------------------------------------------------------------
/lib/jogl/jogl_cg.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/jogl_cg.dll
--------------------------------------------------------------------------------
/lib/jogl/libgluegen-rt.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/libgluegen-rt.jnilib
--------------------------------------------------------------------------------
/lib/jogl/libgluegen-rt.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/libgluegen-rt.so
--------------------------------------------------------------------------------
/lib/jogl/libjogl.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/libjogl.jnilib
--------------------------------------------------------------------------------
/lib/jogl/libjogl.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/libjogl.so
--------------------------------------------------------------------------------
/lib/jogl/libjogl_awt.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/libjogl_awt.jnilib
--------------------------------------------------------------------------------
/lib/jogl/libjogl_awt.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/libjogl_awt.so
--------------------------------------------------------------------------------
/lib/jogl/libjogl_cg.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/libjogl_cg.jnilib
--------------------------------------------------------------------------------
/lib/jogl/libjogl_cg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/libjogl_cg.so
--------------------------------------------------------------------------------
/lib/jogl/opengl.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/jogl/opengl.jar
--------------------------------------------------------------------------------
/lib/umlgraph5.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/lib/umlgraph5.2.jar
--------------------------------------------------------------------------------
/src.audio/toxi/music/QuantizedTimeHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.music;
29 |
30 | public interface QuantizedTimeHandler {
31 |
32 | void handleBar(int beatCount);
33 |
34 | void handleBeat(int beatCount);
35 |
36 | void handleTick(int ticks);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src.audio/toxi/music/scale/MajorScale.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.music.scale;
29 |
30 | /**
31 | * seed: 0xad5 (101011010101) C# D# F F# G# A# C
32 | */
33 | public class MajorScale extends AbstractScale {
34 |
35 | public MajorScale() {
36 | super("MajorScale", new byte[] { 0, 2, 4, 5, 7, 9, 11 });
37 | }
38 | }
--------------------------------------------------------------------------------
/src.color/toxi/color/CMYKDistanceProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.color;
29 |
30 | /**
31 | * Implements the {@link DistanceProxy} interface to sort colors by CMYK
32 | * distance (used by {@link ColorList#sortByDistance(DistanceProxy, boolean)}).
33 | */
34 | public class CMYKDistanceProxy implements DistanceProxy {
35 |
36 | public float distanceBetween(ReadonlyTColor a, ReadonlyTColor b) {
37 | return a.distanceToCMYK(b);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src.color/toxi/color/DistanceProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.color;
29 |
30 | /**
31 | * A proxy interface to support the sorting of colors in different color spaces.
32 | * Used by {@link ColorList#sortByDistance(DistanceProxy, boolean)}.
33 | */
34 | public interface DistanceProxy {
35 |
36 | /**
37 | * Computes the distance between 2 colors.
38 | *
39 | * @param a
40 | * @param b
41 | * @return distance
42 | */
43 | float distanceBetween(ReadonlyTColor a, ReadonlyTColor b);
44 | }
45 |
--------------------------------------------------------------------------------
/src.color/toxi/color/HSVDistanceProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.color;
29 |
30 | /**
31 | * Implements the {@link DistanceProxy} interface to sort colors by HSV distance
32 | * (used by {@link ColorList#sortByDistance(DistanceProxy, boolean)}).
33 | */
34 | public class HSVDistanceProxy implements DistanceProxy {
35 |
36 | public float distanceBetween(ReadonlyTColor a, ReadonlyTColor b) {
37 | return a.distanceToHSV(b);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src.color/toxi/color/RGBDistanceProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.color;
29 |
30 | /**
31 | * Implements the {@link DistanceProxy} interface to sort colors by RGB distance
32 | * (used by {@link ColorList#sortByDistance(DistanceProxy, boolean)}).
33 | */
34 | public class RGBDistanceProxy implements DistanceProxy {
35 |
36 | public float distanceBetween(ReadonlyTColor a, ReadonlyTColor b) {
37 | return a.distanceToRGB(b);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/BoxIntersector.java:
--------------------------------------------------------------------------------
1 | package toxi.geom;
2 |
3 | public class BoxIntersector implements Intersector3D {
4 |
5 | private AABB box;
6 | private final IsectData3D isec;
7 |
8 | public BoxIntersector(AABB box) {
9 | this.box = box;
10 | this.isec = new IsectData3D();
11 | }
12 |
13 | /**
14 | * @return the box
15 | */
16 | public AABB getBox() {
17 | return box;
18 | }
19 |
20 | public IsectData3D getIntersectionData() {
21 | return isec;
22 | }
23 |
24 | public boolean intersectsRay(Ray3D ray) {
25 | final Vec3D pos = box.intersectsRay(ray, 0, Float.MAX_VALUE);
26 | isec.pos = pos;
27 | isec.isIntersection = pos != null;
28 | if (isec.isIntersection) {
29 | isec.normal = box.getNormalForPoint(pos);
30 | isec.dist = ray.distanceTo(pos);
31 | }
32 | return isec.isIntersection;
33 | }
34 |
35 | /**
36 | * @param box
37 | * the box to set
38 | */
39 | public void setBox(AABB box) {
40 | this.box = box;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/CoordinateExtractor.java:
--------------------------------------------------------------------------------
1 | package toxi.geom;
2 |
3 | public interface CoordinateExtractor {
4 |
5 | public float coordinate(T obj);
6 | }
7 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/GlobalGridTesselator.java:
--------------------------------------------------------------------------------
1 | package toxi.geom;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import toxi.math.MathUtils;
7 |
8 | /**
9 | * A concrete implementation of the abstract {@link GridTesselator} using a grid
10 | * in global coordinate space for generating additional points within a polygon.
11 | * The resolution setting of this class defines the axis-aligned distance
12 | * between grid points. E.g. a resolution of 10 means grid points are created a
13 | * world space positions of multiples of 10 (i.e. 0,10,20 etc.). This resolution
14 | * is used independently on polygon size, so depending on the chosen resolution
15 | * and polygon size no additional inliers MIGHT be created at all. This behavior
16 | * property is useful in cases where you want to adjust the number of resulting
17 | * triangles dynamically, e.g. based on polygon size. Use the
18 | * {@link LocalGridTesselator} for an alternative behavior.
19 | *
20 | * @see GridTesselator
21 | * @see LocalGridTesselator
22 | * @see PolygonTesselator
23 | */
24 | public class GlobalGridTesselator extends GridTesselator {
25 |
26 | public GlobalGridTesselator(float res) {
27 | super(res);
28 | }
29 |
30 | protected List createInsidePoints(Polygon2D poly, Rect bounds) {
31 | List points = new ArrayList();
32 | for (float y = bounds.y; y < bounds.getBottom(); y += res) {
33 | float yy = MathUtils.roundTo(y, res);
34 | for (float x = bounds.x; x < bounds.getRight(); x += res) {
35 | Vec2D p = new Vec2D(MathUtils.roundTo(x, res), yy);
36 | if (poly.containsPoint(p)) {
37 | points.add(p);
38 | }
39 | }
40 | }
41 | return points;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/Intersector2D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom;
29 |
30 | /**
31 | * Generic interface for ray intersection with 2D geometry
32 | */
33 | public interface Intersector2D {
34 |
35 | /**
36 | * @return intersection data parcel
37 | */
38 | public IsectData2D getIntersectionData();
39 |
40 | /**
41 | * Check if entity intersects with the given ray
42 | *
43 | * @param ray
44 | * ray to check
45 | * @return true, if ray hits the entity
46 | */
47 | public boolean intersectsRay(Ray2D ray);
48 |
49 | }
--------------------------------------------------------------------------------
/src.core/toxi/geom/LocalGridTesselator.java:
--------------------------------------------------------------------------------
1 | package toxi.geom;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import toxi.math.ScaleMap;
7 |
8 | /**
9 | * A concrete implementation of the abstract {@link GridTesselator} using a grid
10 | * in polygon-local coordinate space for generating additional points within a
11 | * polygon. The resolution setting of this class defines number of desired grid
12 | * points in X & Y direction. E.g. a resolution of 10 means up to 10x10 grid
13 | * points are created a within the polygon bounding rect. For smaller polygons,
14 | * the resulting triangles will simply be smaller too. This resolution is used
15 | * independently on polygon size. Use the {@link GlobalGridTesselator} for an
16 | * alternative behavior, resulting in more uniformly sized triangles.
17 | *
18 | * @see GridTesselator
19 | * @see GlobalGridTesselator
20 | * @see PolygonTesselator
21 | */
22 | public class LocalGridTesselator extends GridTesselator {
23 |
24 | public LocalGridTesselator(int res) {
25 | super(res);
26 | }
27 |
28 | protected List createInsidePoints(Polygon2D poly, Rect bounds) {
29 | List points = new ArrayList();
30 | int ires = (int) res;
31 | ScaleMap xmap = new ScaleMap(0, ires, bounds.getLeft(),
32 | bounds.getRight());
33 | ScaleMap ymap = new ScaleMap(0, ires, bounds.getTop(),
34 | bounds.getBottom());
35 | for (int y = 0; y < ires; y++) {
36 | float yy = (float) ymap.getMappedValueFor(y);
37 | for (int x = 0; x < ires; x++) {
38 | Vec2D p = new Vec2D((float) xmap.getMappedValueFor(x), yy);
39 | if (poly.containsPoint(p)) {
40 | points.add(p);
41 | }
42 | }
43 | }
44 | return points;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/OctreeVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom;
29 |
30 | /**
31 | * This interface is the core part of the visitor pattern application for
32 | * {@link PointOctree}s. It can be used to apply a procedure to all tree nodes
33 | * when passed to {@link PointOctree#applyVisitor(OctreeVisitor)}.
34 | */
35 | public interface OctreeVisitor {
36 |
37 | /**
38 | * Applies the procedure defined by an implementation of this interface to
39 | * the given tree node.
40 | *
41 | * @param node
42 | */
43 | void visitNode(PointOctree node);
44 | }
45 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/PlaneIntersector.java:
--------------------------------------------------------------------------------
1 | package toxi.geom;
2 |
3 | import toxi.math.MathUtils;
4 |
5 | public class PlaneIntersector implements Intersector3D {
6 |
7 | private Plane plane;
8 | private final IsectData3D isec;
9 |
10 | public PlaneIntersector(Plane p) {
11 | this.plane = p;
12 | this.isec = new IsectData3D();
13 | }
14 |
15 | public IsectData3D getIntersectionData() {
16 | return isec;
17 | }
18 |
19 | /**
20 | * @return the box
21 | */
22 | public Plane getPlane() {
23 | return plane;
24 | }
25 |
26 | public boolean intersectsRay(Ray3D ray) {
27 | float d = -plane.normal.dot(plane);
28 | float numer = plane.normal.dot(ray) + d;
29 | float denom = plane.normal.dot(ray.dir);
30 |
31 | // normal is orthogonal to vector, can't intersect
32 | if (isec.isIntersection = (MathUtils.abs(denom) >= MathUtils.EPS)) {
33 | isec.dist = -(numer / denom);
34 | isec.pos = ray.getPointAtDistance(isec.dist);
35 | isec.normal = plane.normal;
36 | }
37 | return isec.isIntersection;
38 | }
39 |
40 | /**
41 | * @param p
42 | * the plane to set
43 | */
44 | public void setPlane(Plane p) {
45 | this.plane = p;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/PolygonClipper2D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom;
29 |
30 | /**
31 | * Defines an interface for clipping 2D polygons. Currently the only
32 | * implementation for this available is {@link SutherlandHodgemanClipper}.
33 | */
34 | public interface PolygonClipper2D {
35 |
36 | /**
37 | * Creates a clipped version of the polygon to the boundary shape set.
38 | *
39 | * @param poly
40 | * polygon to be clipped
41 | * @return clipped poly
42 | */
43 | public Polygon2D clipPolygon(Polygon2D poly);
44 |
45 | }
--------------------------------------------------------------------------------
/src.core/toxi/geom/PolygonTesselator.java:
--------------------------------------------------------------------------------
1 | package toxi.geom;
2 |
3 | import java.util.List;
4 |
5 | public interface PolygonTesselator {
6 |
7 | /**
8 | * Tesselates the given polygon into a set of triangles.
9 | *
10 | * @param poly
11 | * polygon
12 | * @return list of triangles
13 | */
14 | public List tesselatePolygon(Polygon2D poly);
15 |
16 | }
--------------------------------------------------------------------------------
/src.core/toxi/geom/QuadtreeVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom;
29 |
30 | /**
31 | * This interface is the core part of the visitor pattern application for
32 | * {@link PointQuadtree}s. It can be used to apply a procedure to all tree nodes
33 | * when passed to {@link PointQuadtree#applyVisitor(QuadtreeVisitor)}.
34 | */
35 | public interface QuadtreeVisitor {
36 |
37 | /**
38 | * Applies the procedure defined by an implementation of this interface to
39 | * the given tree node.
40 | *
41 | * @param node
42 | */
43 | void visitNode(PointQuadtree node);
44 | }
45 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/Shape3D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom;
29 |
30 | /**
31 | * Interface description of common operations supported by 3D geometry types.
32 | */
33 | public interface Shape3D {
34 |
35 | /**
36 | * Checks if the point is within the given shape/volume.
37 | *
38 | * @return true, if inside
39 | */
40 | boolean containsPoint(ReadonlyVec3D p);
41 | }
42 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/SpatialIndex.java:
--------------------------------------------------------------------------------
1 | package toxi.geom;
2 |
3 | import java.util.List;
4 |
5 | public interface SpatialIndex {
6 |
7 | public void clear();
8 |
9 | public boolean index(T p);
10 |
11 | public boolean isIndexed(T item);
12 |
13 | public List itemsWithinRadius(T p, float radius, List results);
14 |
15 | public boolean reindex(T p, T q);
16 |
17 | public int size();
18 |
19 | public boolean unindex(T p);
20 |
21 | }
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/DefaultSTLColorModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom.mesh;
29 |
30 | public class DefaultSTLColorModel implements STLColorModel {
31 |
32 | public void formatHeader(byte[] header) {
33 | }
34 |
35 | public int formatRGB(int rgb) {
36 | int col15bits = (rgb >> 3 & 0x1f);
37 | col15bits |= (rgb >> 11 & 0x1f) << 5;
38 | col15bits |= (rgb >> 19 & 0x1f) << 10;
39 | col15bits |= 0x8000;
40 | return col15bits;
41 | }
42 |
43 | public int getDefaultRGB() {
44 | return 0;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/DefaultSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom.mesh;
29 |
30 | public class DefaultSelector extends VertexSelector {
31 |
32 | public DefaultSelector(Mesh3D mesh) {
33 | super(mesh);
34 | }
35 |
36 | @Override
37 | public VertexSelector selectVertices() {
38 | clearSelection();
39 | selection.addAll(mesh.getVertices());
40 | return this;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/STLColorModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom.mesh;
29 |
30 | public interface STLColorModel {
31 |
32 | void formatHeader(byte[] header);
33 |
34 | int formatRGB(int rgb);
35 |
36 | int getDefaultRGB();
37 | }
38 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/WEMeshFilterStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom.mesh;
29 |
30 | public interface WEMeshFilterStrategy {
31 |
32 | public void filter(VertexSelector selector, int numIterations);
33 |
34 | /**
35 | * Applies the vertex filter to the given mesh
36 | *
37 | * @param mesh
38 | * @param numIterations
39 | */
40 | public void filter(WETriangleMesh mesh, int numIterations);
41 |
42 | }
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/subdiv/CentroidSubdiv.java:
--------------------------------------------------------------------------------
1 | package toxi.geom.mesh.subdiv;
2 |
3 | import java.util.List;
4 |
5 | import toxi.geom.Vec3D;
6 |
7 | public class CentroidSubdiv implements NewSubdivStrategy {
8 |
9 | public List subdivideTriangle(Vec3D a, Vec3D b, Vec3D c,
10 | List resultVertices) {
11 | Vec3D centroid = a.add(b).addSelf(c).scaleSelf(1 / 3.0f);
12 | resultVertices.add(new Vec3D[] {
13 | a, b, centroid
14 | });
15 | resultVertices.add(new Vec3D[] {
16 | b, c, centroid
17 | });
18 | resultVertices.add(new Vec3D[] {
19 | c, a, centroid
20 | });
21 | return resultVertices;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/subdiv/EdgeLengthComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom.mesh.subdiv;
29 |
30 | import java.util.Comparator;
31 |
32 | import toxi.geom.mesh.WingedEdge;
33 |
34 | /**
35 | * Comparator used by {@link SubdivisionStrategy#getEdgeOrdering()} to define
36 | * the order of edges to be subdivided. This one prioritizes longer edges.
37 | */
38 | public class EdgeLengthComparator implements Comparator {
39 |
40 | public int compare(WingedEdge e1, WingedEdge e2) {
41 | return (int) (e2.getLengthSquared() - e1.getLengthSquared());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/subdiv/FaceCountComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom.mesh.subdiv;
29 |
30 | import java.util.Comparator;
31 |
32 | import toxi.geom.mesh.WingedEdge;
33 |
34 | /**
35 | * Comparator used by {@link SubdivisionStrategy#getEdgeOrdering()} to define
36 | * the order of edges to be subdivided. This one prioritizes edges with the most
37 | * faces associated.
38 | */
39 | public class FaceCountComparator implements Comparator {
40 |
41 | public int compare(WingedEdge e1, WingedEdge e2) {
42 | return (e2.faces.size() - e1.faces.size());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/subdiv/MidpointSubdiv.java:
--------------------------------------------------------------------------------
1 | package toxi.geom.mesh.subdiv;
2 |
3 | import java.util.List;
4 |
5 | import toxi.geom.Vec3D;
6 |
7 | public class MidpointSubdiv implements NewSubdivStrategy {
8 |
9 | public List subdivideTriangle(Vec3D a, Vec3D b, Vec3D c,
10 | List resultVertices) {
11 | Vec3D mab = a.interpolateTo(b, 0.5f);
12 | Vec3D mbc = b.interpolateTo(c, 0.5f);
13 | Vec3D mca = c.interpolateTo(a, 0.5f);
14 | resultVertices.add(new Vec3D[] {
15 | a, mab, mca
16 | });
17 | resultVertices.add(new Vec3D[] {
18 | mab, b, mbc
19 | });
20 | resultVertices.add(new Vec3D[] {
21 | mbc, c, mca
22 | });
23 | resultVertices.add(new Vec3D[] {
24 | mab, mbc, mca
25 | });
26 | return resultVertices;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/subdiv/MidpointSubdivision.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.geom.mesh.subdiv;
29 |
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | import toxi.geom.Vec3D;
34 | import toxi.geom.mesh.WingedEdge;
35 |
36 | /**
37 | * This subdivision strategy simply splits an edge in two equal halves.
38 | */
39 | public class MidpointSubdivision extends SubdivisionStrategy {
40 |
41 | public List computeSplitPoints(WingedEdge edge) {
42 | List mid = new ArrayList(1);
43 | mid.add(edge.getMidPoint());
44 | return mid;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/mesh/subdiv/NewSubdivStrategy.java:
--------------------------------------------------------------------------------
1 | package toxi.geom.mesh.subdiv;
2 |
3 | import java.util.List;
4 |
5 | import toxi.geom.Vec3D;
6 |
7 | public interface NewSubdivStrategy {
8 |
9 | public List subdivideTriangle(Vec3D a, Vec3D b, Vec3D c,
10 | List resultVertices);
11 | }
12 |
--------------------------------------------------------------------------------
/src.core/toxi/geom/nurbs/InterpolationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * jgeom: Geometry Library fo Java
3 | *
4 | * Copyright (C) 2005 Samuel Gerber
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU General Public License
8 | * as published by the Free Software Foundation; either version 2
9 | * of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package toxi.geom.nurbs;
21 |
22 | /**
23 | * An InterpolationException is thrown if Nurbs could not be interpolated from
24 | * the given points.
25 | *
26 | * @author sg
27 | * @version 1.0
28 | */
29 | public class InterpolationException extends Exception {
30 |
31 | private static final long serialVersionUID = 1L;
32 |
33 | public InterpolationException() {
34 | super();
35 | }
36 |
37 | public InterpolationException(String arg0) {
38 | super(arg0);
39 | }
40 |
41 | public InterpolationException(String arg0, Throwable arg1) {
42 | super(arg0, arg1);
43 | }
44 |
45 | public InterpolationException(Throwable arg0) {
46 | super(arg0);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src.core/toxi/math/LinearInterpolation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.math;
29 |
30 | /**
31 | * Implementation of the linear interpolation function
32 | *
33 | * i = a + ( b - a ) * f
34 | */
35 | public class LinearInterpolation implements InterpolateStrategy {
36 |
37 | public double interpolate(double a, double b, double f) {
38 | return a + (b - a) * f;
39 | }
40 |
41 | public final float interpolate(float a, float b, float f) {
42 | return a + (b - a) * f;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src.core/toxi/math/NonLinearScaleMap.java:
--------------------------------------------------------------------------------
1 | package toxi.math;
2 |
3 | import java.util.NavigableSet;
4 | import java.util.SortedSet;
5 | import java.util.TreeSet;
6 |
7 | public class NonLinearScaleMap {
8 |
9 | public class Sample implements Comparable {
10 |
11 | public final double x, y;
12 |
13 | public Sample(double x, double y) {
14 | this.x = x;
15 | this.y = y;
16 | }
17 |
18 | public int compareTo(Sample b) {
19 | return (int) Math.signum(x - b.x);
20 | }
21 | }
22 |
23 | private TreeSet samples;
24 |
25 | private double rangeMin = Float.MAX_VALUE;
26 | private double rangeMax = Float.MIN_VALUE;
27 |
28 | public NonLinearScaleMap() {
29 | samples = new TreeSet();
30 | }
31 |
32 | public NonLinearScaleMap addSample(double x, double y) {
33 | samples.add(new Sample(x, y));
34 | rangeMin = MathUtils.min(y, rangeMin);
35 | rangeMax = MathUtils.max(y, rangeMax);
36 | return this;
37 | }
38 |
39 | public NavigableSet getSamples() {
40 | return samples;
41 | }
42 |
43 | public double map(double x) {
44 | Sample t = new Sample(x, 0);
45 | SortedSet aset = samples.headSet(t);
46 | SortedSet bset = samples.tailSet(t);
47 | if (aset.isEmpty()) {
48 | return bset.first().y;
49 | } else {
50 | if (bset.isEmpty()) {
51 | return aset.last().y;
52 | } else {
53 | Sample a = aset.last();
54 | Sample b = bset.first();
55 | return MathUtils.lerp(a.y, b.y, (x - a.x) / (b.x - a.x));
56 | }
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src.core/toxi/math/waves/ConstantWave.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.math.waves;
29 |
30 | /**
31 | * Implements a constant value as waveform.
32 | */
33 | public class ConstantWave extends AbstractWave {
34 |
35 | public ConstantWave(float value) {
36 | super();
37 | this.value = value;
38 | }
39 |
40 | public final float update() {
41 | return value;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src.core/toxi/math/waves/Wave2D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.math.waves;
29 |
30 | import toxi.geom.Vec2D;
31 |
32 | public class Wave2D {
33 |
34 | public AbstractWave xmod, ymod;
35 | public Vec2D pos;
36 |
37 | public Wave2D(AbstractWave x, AbstractWave y) {
38 | xmod = x;
39 | ymod = y;
40 | pos = new Vec2D();
41 | }
42 |
43 | public void update() {
44 | pos.x = xmod.update();
45 | pos.y = ymod.update();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src.core/toxi/math/waves/WaveState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.math.waves;
29 |
30 | public class WaveState {
31 |
32 | public float phase;
33 | public float frequency;
34 | public float amp;
35 | public float offset;
36 |
37 | public WaveState(float phase, float frequency, float amp, float offset) {
38 | this.phase = phase;
39 | this.frequency = frequency;
40 | this.amp = amp;
41 | this.offset = offset;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src.core/toxi/util/datatypes/ItemIndex.java:
--------------------------------------------------------------------------------
1 | package toxi.util.datatypes;
2 |
3 | import java.util.List;
4 |
5 | public interface ItemIndex {
6 |
7 | public void clear();
8 |
9 | public T forID(int id);
10 |
11 | public int getID(T item);
12 |
13 | public List getItems();
14 |
15 | public int index(T item);
16 |
17 | public boolean isIndexed(T item);
18 |
19 | public int reindex(T item, T newItem);
20 |
21 | public int size();
22 |
23 | public int unindex(T item);
24 |
25 | }
--------------------------------------------------------------------------------
/src.data/toxi/data/csv/CSVAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.data.csv;
29 |
30 | public class CSVAdapter implements CSVListener {
31 |
32 | public void csvNewItemFailure(String[] fields, CSVFieldMapper map) {
33 |
34 | }
35 |
36 | public void csvNewItemParsed(String[] fields, CSVFieldMapper map) {
37 |
38 | }
39 |
40 | public void csvParseFailure(CSVParser parser) {
41 |
42 | }
43 |
44 | public void csvParseSuccess(CSVParser parser) {
45 |
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src.data/toxi/data/csv/CSVListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.data.csv;
29 |
30 | public interface CSVListener {
31 |
32 | void csvNewItemFailure(String[] fields, CSVFieldMapper map);
33 |
34 | void csvNewItemParsed(String[] fields, CSVFieldMapper map);
35 |
36 | void csvParseFailure(CSVParser parser);
37 |
38 | void csvParseSuccess(CSVParser parser);
39 | }
40 |
--------------------------------------------------------------------------------
/src.data/toxi/data/feeds/AtomAuthor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.data.feeds;
29 |
30 | import javax.xml.bind.annotation.XmlElement;
31 |
32 | public class AtomAuthor {
33 |
34 | @XmlElement(namespace = AtomFeed.NS)
35 | public String name, uri;
36 | }
37 |
--------------------------------------------------------------------------------
/src.data/toxi/data/feeds/AtomContent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.data.feeds;
29 |
30 | import javax.xml.bind.annotation.XmlAttribute;
31 | import javax.xml.bind.annotation.XmlValue;
32 |
33 | public class AtomContent {
34 |
35 | @XmlAttribute(namespace = AtomFeed.NS)
36 | public String type;
37 |
38 | @XmlValue
39 | public String value;
40 | }
41 |
--------------------------------------------------------------------------------
/src.data/toxi/data/feeds/AtomLink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.data.feeds;
29 |
30 | import javax.xml.bind.annotation.XmlAttribute;
31 |
32 | public class AtomLink {
33 |
34 | @XmlAttribute
35 | public String type, rel, href;
36 |
37 | public String toString() {
38 | return href + " (" + type + ")";
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src.data/toxi/data/feeds/RSSEnclosure.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.data.feeds;
29 |
30 | import javax.xml.bind.annotation.XmlAttribute;
31 |
32 | public class RSSEnclosure {
33 |
34 | @XmlAttribute
35 | public String url, type;
36 |
37 | @XmlAttribute
38 | public int length;
39 |
40 | public String toString() {
41 | return url + " (" + type + ")";
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src.net/com/toxi/net/ClientListener.java:
--------------------------------------------------------------------------------
1 | package com.toxi.net;
2 |
3 | public interface ClientListener {
4 | /**
5 | * Callback to trigger an update of the server managed process. This might
6 | * be called several times in a row if the client has fallen behind in time.
7 | * There should be NO rendering related tasks being called from this
8 | * callback.
9 | */
10 | public void triggerUpdate();
11 |
12 | /**
13 | * Callback to trigger the rendering of a new frame. This method will ALWAYS
14 | * be called after {{@link #triggerUpdate()} and should be purely focused on
15 | * drawing/rendering specific tasks, but no CPU intensive model updates.
16 | */
17 | public void triggerFrame();
18 |
19 | /**
20 | * Callback to confirm client has successfully connected
21 | */
22 | public void notifyConnected();
23 |
24 | /**
25 | * Callback to notify client has disconnected from the server.
26 | */
27 | public void notifyDisconnected();
28 |
29 | /**
30 | * Callback to give the client a chance to react to the encountered
31 | * exception.
32 | *
33 | * @param e
34 | * the exception which caused the callback
35 | */
36 | public void handleError(Exception e);
37 | }
38 |
--------------------------------------------------------------------------------
/src.net/com/toxi/net/ServerListenerAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.toxi.net;
5 |
6 | import java.net.DatagramPacket;
7 |
8 | /**
9 | * @author toxi
10 | *
11 | */
12 | public class ServerListenerAdapter implements ServerListener {
13 |
14 | public void clientConnected(UDPConnection conn) {
15 |
16 | }
17 |
18 | public void clientDisconnected(UDPConnection conn) {
19 | }
20 |
21 | public void clientUpdated(UDPConnection conn, DatagramPacket receivePacket) {
22 | }
23 |
24 | public byte[] getSyncPayload() {
25 | return new byte[0];
26 | }
27 |
28 | public void serverError(Exception e) {
29 | }
30 |
31 | public void serverShutdown() {
32 | }
33 |
34 | public void serverStarted() {
35 | }
36 |
37 | public void serverStateChanged(ServerState s) {
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src.net/com/toxi/net/ServerState.java:
--------------------------------------------------------------------------------
1 | package com.toxi.net;
2 |
3 | public enum ServerState {
4 | WAITING_FOR_CLIENTS, SYNCHING
5 | }
6 |
--------------------------------------------------------------------------------
/src.net/com/toxi/net/UDPConnection.java:
--------------------------------------------------------------------------------
1 | package com.toxi.net;
2 |
3 | import java.io.*;
4 | import java.net.*;
5 |
6 | /**
7 | * @author Karsten Schmidt
8 | */
9 |
10 | class UDPConnection {
11 |
12 | /**
13 | * Default time-to-live duration
14 | */
15 | static int TTL = 10000;
16 |
17 | protected InetAddress ip;
18 | protected int port;
19 |
20 | protected long lastUpdate;
21 |
22 | UDPConnection(InetAddress ip, int port) {
23 | this.ip = ip;
24 | this.port = port;
25 | lastUpdate = System.currentTimeMillis();
26 | }
27 |
28 | public boolean isAlive() {
29 | return System.currentTimeMillis() - lastUpdate < TTL;
30 | }
31 |
32 | public void update() {
33 | lastUpdate = System.currentTimeMillis();
34 | }
35 |
36 | public void send(DatagramSocket socket, byte[] data) throws IOException {
37 | DatagramPacket sendPacket = new DatagramPacket(data, data.length, ip,
38 | port);
39 | socket.send(sendPacket);
40 | }
41 |
42 | public InetAddress getIP() {
43 | return ip;
44 | }
45 |
46 | public int getPort() {
47 | return port;
48 | }
49 |
50 | public long getLastUpdate() {
51 | return lastUpdate;
52 | }
53 |
54 | public String toString() {
55 | return UDPConnection.buildHash(ip, port);
56 | }
57 |
58 | static final void setTTL(int ttl) {
59 | TTL = ttl;
60 | }
61 |
62 | public static final String buildHash(InetAddress ip, int port) {
63 | return ip.getHostAddress() + ":" + port;
64 | }
65 | }
--------------------------------------------------------------------------------
/src.net/com/toxi/nio/UDPClientState.java:
--------------------------------------------------------------------------------
1 | package com.toxi.nio;
2 |
3 | import java.net.SocketAddress;
4 |
5 | public class UDPClientState {
6 | SocketAddress addr;
7 | boolean isReady;
8 | long lastUpdate;
9 |
10 | public UDPClientState(SocketAddress a) {
11 | addr = a;
12 | isReady = true;
13 | lastUpdate = System.currentTimeMillis();
14 | System.out.println("new client: " + addr);
15 | }
16 |
17 | public SocketAddress getAddress() {
18 | return addr;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/AttributedEdge.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class AttributedEdge {
7 |
8 | public final int a, b;
9 | public List faces;
10 |
11 | public AttributedEdge(int a, int b) {
12 | this.a = a;
13 | this.b = b;
14 | }
15 |
16 | public void addFace(AttributedFace f) {
17 | if (faces == null) {
18 | faces = new ArrayList(2);
19 | }
20 | faces.add(f);
21 | }
22 |
23 | /*
24 | * (non-Javadoc)
25 | *
26 | * @see java.lang.Object#equals(java.lang.Object)
27 | */
28 | @Override
29 | public boolean equals(Object obj) {
30 | if (this == obj) {
31 | return true;
32 | }
33 | if (obj == null) {
34 | return false;
35 | }
36 | if (getClass() != obj.getClass()) {
37 | return false;
38 | }
39 | AttributedEdge other = (AttributedEdge) obj;
40 | if (a != other.a) {
41 | return false;
42 | }
43 | if (b != other.b) {
44 | return false;
45 | }
46 | return true;
47 | }
48 |
49 | /*
50 | * (non-Javadoc)
51 | *
52 | * @see java.lang.Object#hashCode()
53 | */
54 | @Override
55 | public int hashCode() {
56 | final int prime = 31;
57 | int result = prime + a;
58 | result = prime * result + b;
59 | return result;
60 | }
61 |
62 | public String toString() {
63 | return String.format("a=%d, b=%d", a, b);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/AttributedFace.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import java.util.HashMap;
4 |
5 | public class AttributedFace {
6 |
7 | public int a, b, c;
8 | public int normal = -1;
9 | public HashMap attribs;
10 |
11 | public AttributedFace(int a, int b, int c, HashMap attribs) {
12 | this.a = a;
13 | this.b = b;
14 | this.c = c;
15 | this.attribs = attribs;
16 | }
17 |
18 | public String toString() {
19 | return String.format("a=%d,b=%d,c=%d,n=%d", a, b, c, normal);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/MeshAttributeCompiler.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import toxi.util.datatypes.ItemIndex;
4 |
5 | public abstract class MeshAttributeCompiler {
6 |
7 | protected IndexedTriangleMesh mesh;
8 |
9 | public abstract void compileFace(AttributedFace f, ItemIndex> index,
10 | float[] buf, int offset);
11 |
12 | public abstract ItemIndex> getIndex();
13 |
14 | public abstract int getStride();
15 |
16 | public void setMesh(IndexedTriangleMesh mesh) {
17 | this.mesh = mesh;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/MeshFaceNormalCompiler.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import toxi.geom.Vec3D;
4 | import toxi.util.datatypes.ItemIndex;
5 |
6 | public class MeshFaceNormalCompiler extends MeshAttributeCompiler {
7 |
8 | @Override
9 | public void compileFace(AttributedFace f, ItemIndex> index, float[] buf,
10 | int offset) {
11 | Vec3D v = (Vec3D) index.forID(f.normal);
12 | buf[offset++] = v.x;
13 | buf[offset++] = v.y;
14 | buf[offset++] = v.z;
15 | buf[offset++] = v.x;
16 | buf[offset++] = v.y;
17 | buf[offset++] = v.z;
18 | buf[offset++] = v.x;
19 | buf[offset++] = v.y;
20 | buf[offset++] = v.z;
21 | }
22 |
23 | @Override
24 | public ItemIndex> getIndex() {
25 | return mesh.fnormals;
26 | }
27 |
28 | @Override
29 | public int getStride() {
30 | return 3;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/MeshUVCompiler.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import toxi.geom.Vec2D;
4 | import toxi.util.datatypes.ItemIndex;
5 |
6 | public class MeshUVCompiler extends MeshAttributeCompiler {
7 |
8 | @Override
9 | public void compileFace(AttributedFace f, ItemIndex> index, float[] buf,
10 | int offset) {
11 | int[] vn = f.attribs.get(IndexedTriangleMesh.ATTR_UVCOORDS);
12 | Vec2D v = (Vec2D) index.forID(vn[0]);
13 | buf[offset++] = v.x;
14 | buf[offset++] = v.y;
15 | v = (Vec2D) index.forID(vn[1]);
16 | buf[offset++] = v.x;
17 | buf[offset++] = v.y;
18 | v = (Vec2D) index.forID(vn[2]);
19 | buf[offset++] = v.x;
20 | buf[offset++] = v.y;
21 | }
22 |
23 | @Override
24 | public ItemIndex> getIndex() {
25 | return mesh.attributes.get(IndexedTriangleMesh.ATTR_UVCOORDS);
26 | }
27 |
28 | @Override
29 | public int getStride() {
30 | return 2;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/MeshVertexColorCompiler.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import toxi.color.ReadonlyTColor;
4 | import toxi.util.datatypes.ItemIndex;
5 |
6 | public class MeshVertexColorCompiler extends MeshAttributeCompiler {
7 |
8 | @Override
9 | public void compileFace(AttributedFace f, ItemIndex> index, float[] buf,
10 | int offset) {
11 | int[] vn = f.attribs.get(IndexedTriangleMesh.ATTR_VCOLORS);
12 | ReadonlyTColor c = (ReadonlyTColor) index.forID(vn[0]);
13 | c.toRGBAArray(buf, offset);
14 | c = (ReadonlyTColor) index.forID(vn[1]);
15 | c.toRGBAArray(buf, offset + 4);
16 | c = (ReadonlyTColor) index.forID(vn[2]);
17 | c.toRGBAArray(buf, offset + 8);
18 | }
19 |
20 | @Override
21 | public ItemIndex> getIndex() {
22 | return mesh.attributes.get(IndexedTriangleMesh.ATTR_VCOLORS);
23 | }
24 |
25 | @Override
26 | public int getStride() {
27 | return 4;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/MeshVertexCompiler.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import toxi.geom.Vec3D;
4 | import toxi.util.datatypes.ItemIndex;
5 |
6 | public class MeshVertexCompiler extends MeshAttributeCompiler {
7 |
8 | @Override
9 | public void compileFace(AttributedFace f, ItemIndex> index, float[] buf,
10 | int offset) {
11 | Vec3D v = (Vec3D) index.forID(f.a);
12 | buf[offset++] = v.x;
13 | buf[offset++] = v.y;
14 | buf[offset++] = v.z;
15 | v = (Vec3D) index.forID(f.b);
16 | buf[offset++] = v.x;
17 | buf[offset++] = v.y;
18 | buf[offset++] = v.z;
19 | v = (Vec3D) index.forID(f.c);
20 | buf[offset++] = v.x;
21 | buf[offset++] = v.y;
22 | buf[offset++] = v.z;
23 | }
24 |
25 | @Override
26 | public ItemIndex> getIndex() {
27 | return mesh.vertices;
28 | }
29 |
30 | @Override
31 | public int getStride() {
32 | return 3;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/MeshVertexNormalCompiler.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import toxi.geom.Vec3D;
4 | import toxi.util.datatypes.ItemIndex;
5 |
6 | public class MeshVertexNormalCompiler extends MeshAttributeCompiler {
7 |
8 | @Override
9 | public void compileFace(AttributedFace f, ItemIndex> index, float[] buf,
10 | int offset) {
11 | int[] vn = f.attribs.get(IndexedTriangleMesh.ATTR_VNORMALS);
12 | Vec3D v = (Vec3D) index.forID(vn[0]);
13 | buf[offset++] = v.x;
14 | buf[offset++] = v.y;
15 | buf[offset++] = v.z;
16 | v = (Vec3D) index.forID(vn[1]);
17 | buf[offset++] = v.x;
18 | buf[offset++] = v.y;
19 | buf[offset++] = v.z;
20 | v = (Vec3D) index.forID(vn[2]);
21 | buf[offset++] = v.x;
22 | buf[offset++] = v.y;
23 | buf[offset++] = v.z;
24 | }
25 |
26 | @Override
27 | public ItemIndex> getIndex() {
28 | return mesh.attributes.get(IndexedTriangleMesh.ATTR_VNORMALS);
29 | }
30 |
31 | @Override
32 | public int getStride() {
33 | return 3;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src.newmesh/toxi/newmesh/SpatialIndex.java:
--------------------------------------------------------------------------------
1 | package toxi.newmesh;
2 |
3 | import toxi.geom.Vec3D;
4 | import toxi.util.datatypes.UniqueItemIndex;
5 |
6 | public class SpatialIndex extends UniqueItemIndex {
7 |
8 | public float delta, deltaSq;
9 |
10 | public SpatialIndex(float delta) {
11 | setDelta(delta);
12 | }
13 |
14 | private int getClosestIndexed(Vec3D item) {
15 | int c = -1;
16 | float minD = deltaSq;
17 | for (int i = 0, num = index.size(); i < num; i++) {
18 | float d = index.get(i).distanceToSquared(item);
19 | if (d < minD) {
20 | minD = d;
21 | c = i;
22 | }
23 | }
24 | return c;
25 | }
26 |
27 | public float getDelta() {
28 | return delta;
29 | }
30 |
31 | @Override
32 | public int index(Vec3D item) {
33 | int id = getID(item);
34 | if (id == -1) {
35 | id = getClosestIndexed(item);
36 | }
37 | if (id != -1) {
38 | return id;
39 | } else {
40 | return super.index(item);
41 | }
42 | }
43 |
44 | public void setDelta(float delta) {
45 | this.delta = delta;
46 | this.deltaSq = delta * delta;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src.p5/toxi/processing/DashedLineModifier.java:
--------------------------------------------------------------------------------
1 | package toxi.processing;
2 |
3 | import toxi.geom.Line2D;
4 | import toxi.geom.ReadonlyVec2D;
5 | import toxi.geom.Vec2D;
6 |
7 | /**
8 | * {@link Line2DRenderModifier} implementation to draw a dashed line with
9 | * customizable step length.
10 | */
11 | public class DashedLineModifier implements Line2DRenderModifier {
12 |
13 | public float length;
14 |
15 | /**
16 | * Constructs a new instance
17 | *
18 | * @param length
19 | * step length
20 | */
21 | public DashedLineModifier(float length) {
22 | this.length = length;
23 | }
24 |
25 | public void apply(ToxiclibsSupport gfx, ReadonlyVec2D a, ReadonlyVec2D b) {
26 | int i = 0;
27 | Vec2D prev = null;
28 | for (Vec2D p : new Line2D(a, b).splitIntoSegments(null, length, true)) {
29 | if (i % 2 == 0) {
30 | prev = p;
31 | } else {
32 | gfx.line(prev, p);
33 | }
34 | i++;
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src.p5/toxi/processing/DeltaOrientationMapper.java:
--------------------------------------------------------------------------------
1 | package toxi.processing;
2 |
3 | import toxi.color.ReadonlyTColor;
4 | import toxi.color.ToneMap;
5 | import toxi.geom.Vec3D;
6 |
7 | public class DeltaOrientationMapper implements NormalMapper {
8 |
9 | protected Vec3D dir;
10 | protected ToneMap toneMap;
11 | protected double toneScale;
12 |
13 | public DeltaOrientationMapper(Vec3D dir, ToneMap toneMap) {
14 | this.dir = dir;
15 | setToneMap(toneMap);
16 | }
17 |
18 | public ReadonlyTColor getRGBForNormal(Vec3D normal) {
19 | float dot = (float) (dir.dot(normal) * toneScale + toneScale);
20 | return toneMap.getToneFor(dot);
21 | }
22 |
23 | public void setToneMap(ToneMap toneMap) {
24 | this.toneMap = toneMap;
25 | this.toneScale = toneMap.map.getInputMedian();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src.p5/toxi/processing/Line2DRenderModifier.java:
--------------------------------------------------------------------------------
1 | package toxi.processing;
2 |
3 | import toxi.geom.ReadonlyVec2D;
4 |
5 | public interface Line2DRenderModifier {
6 |
7 | public void apply(ToxiclibsSupport gfx, ReadonlyVec2D a, ReadonlyVec2D b);
8 | }
9 |
--------------------------------------------------------------------------------
/src.p5/toxi/processing/NormalMapper.java:
--------------------------------------------------------------------------------
1 | package toxi.processing;
2 |
3 | import toxi.color.ReadonlyTColor;
4 | import toxi.geom.Vec3D;
5 |
6 | public interface NormalMapper {
7 |
8 | public ReadonlyTColor getRGBForNormal(Vec3D normal);
9 | }
10 |
--------------------------------------------------------------------------------
/src.p5/toxi/processing/XYZNormalMapper.java:
--------------------------------------------------------------------------------
1 | package toxi.processing;
2 |
3 | import toxi.color.ReadonlyTColor;
4 | import toxi.color.TColor;
5 | import toxi.geom.Matrix4x4;
6 | import toxi.geom.Vec3D;
7 |
8 | public class XYZNormalMapper implements NormalMapper {
9 |
10 | public static final Matrix4x4 normalMap = new Matrix4x4().translateSelf(
11 | 0.5, 0.5, 0.5).scaleSelf(0.4999);
12 |
13 | public ReadonlyTColor getRGBForNormal(Vec3D normal) {
14 | normal = normalMap.applyTo(normal);
15 | return TColor.newRGB(normal.x, normal.y, normal.z);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src.physics/toxi/physics2d/behaviors/GravityBehavior2D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.physics2d.behaviors;
29 |
30 | import toxi.geom.Vec2D;
31 |
32 | public class GravityBehavior2D extends ConstantForceBehavior2D {
33 |
34 | public GravityBehavior2D(Vec2D gravity) {
35 | super(gravity);
36 | }
37 |
38 | public GravityBehavior2D(Vec2D gravity, float timeStep) {
39 | super(gravity);
40 | configure(timeStep);
41 | }
42 |
43 | @Override
44 | public void setForce(Vec2D force) {
45 | this.force = force;
46 | this.scaledForce = force.scale(timeStep * timeStep);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src.physics/toxi/physics2d/constraints/MaxConstraint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.physics2d.constraints;
29 |
30 | import toxi.geom.Vec2D.Axis;
31 | import toxi.physics2d.VerletParticle2D;
32 |
33 | public class MaxConstraint implements ParticleConstraint2D {
34 |
35 | public Axis axis;
36 | public float threshold;
37 |
38 | public MaxConstraint(Axis axis, float threshold) {
39 | this.axis = axis;
40 | this.threshold = threshold;
41 | }
42 |
43 | public void apply(VerletParticle2D p) {
44 | if (p.getComponent(axis) > threshold) {
45 | p.setComponent(axis, threshold);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src.physics/toxi/physics2d/constraints/MinConstraint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.physics2d.constraints;
29 |
30 | import toxi.geom.Vec2D.Axis;
31 | import toxi.physics2d.VerletParticle2D;
32 |
33 | public class MinConstraint implements ParticleConstraint2D {
34 |
35 | public Axis axis;
36 | public float threshold;
37 |
38 | public MinConstraint(Axis axis, float threshold) {
39 | this.axis = axis;
40 | this.threshold = threshold;
41 | }
42 |
43 | public void apply(VerletParticle2D p) {
44 | if (p.getComponent(axis) < threshold) {
45 | p.setComponent(axis, threshold);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src.physics/toxi/physics3d/behaviors/GravityBehavior3D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.physics3d.behaviors;
29 |
30 | import toxi.geom.Vec3D;
31 |
32 | public class GravityBehavior3D extends ConstantForceBehavior3D {
33 |
34 | public GravityBehavior3D(Vec3D gravity) {
35 | super(gravity);
36 | }
37 |
38 | public GravityBehavior3D(Vec3D gravity, float timeStep) {
39 | super(gravity);
40 | configure(timeStep);
41 | }
42 |
43 | @Override
44 | public void setForce(Vec3D force) {
45 | this.force = force;
46 | this.scaledForce = force.scale(timeStep * timeStep);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src.physics/toxi/physics3d/behaviors/ParticleBehavior3D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.physics3d.behaviors;
29 |
30 | import toxi.physics3d.VerletParticle3D;
31 |
32 | public interface ParticleBehavior3D {
33 |
34 | /**
35 | * Applies the constraint to the passed in particle. The method is assumed
36 | * to manipulate the given instance directly.
37 | *
38 | * @param p
39 | * particle
40 | */
41 | public void apply(VerletParticle3D p);
42 |
43 | public void configure(float timeStep);
44 | }
45 |
--------------------------------------------------------------------------------
/src.physics/toxi/physics3d/constraints/MaxConstraint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.physics3d.constraints;
29 |
30 | import toxi.geom.Vec3D.Axis;
31 | import toxi.physics3d.VerletParticle3D;
32 |
33 | public class MaxConstraint implements ParticleConstraint3D {
34 |
35 | public Axis axis;
36 | public float threshold;
37 |
38 | public MaxConstraint(Axis axis, float threshold) {
39 | this.axis = axis;
40 | this.threshold = threshold;
41 | }
42 |
43 | public void apply(VerletParticle3D p) {
44 | if (p.getComponent(axis) > threshold) {
45 | p.setComponent(axis, threshold);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src.physics/toxi/physics3d/constraints/MinConstraint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.physics3d.constraints;
29 |
30 | import toxi.geom.Vec3D.Axis;
31 | import toxi.physics3d.VerletParticle3D;
32 |
33 | public class MinConstraint implements ParticleConstraint3D {
34 |
35 | public Axis axis;
36 | public float threshold;
37 |
38 | public MinConstraint(Axis axis, float threshold) {
39 | this.axis = axis;
40 | this.threshold = threshold;
41 | }
42 |
43 | public void apply(VerletParticle3D p) {
44 | if (p.getComponent(axis) < threshold) {
45 | p.setComponent(axis, threshold);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src.sim/toxi/sim/automata/CARule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.sim.automata;
29 |
30 | /**
31 | * This interface defines the required API for a {@link CAMatrix} compatible
32 | * cellular automata rule implementation.
33 | */
34 | public interface CARule extends MatrixEvolver {
35 |
36 | public int getStateCount();
37 |
38 | public boolean isAutoExpire();
39 |
40 | public boolean isTiling();
41 |
42 | public void randomize();
43 |
44 | public void setAutoExpire(boolean isAutoExpire);
45 |
46 | public void setStateCount(int num);
47 |
48 | public void setTiling(boolean state);
49 | }
50 |
--------------------------------------------------------------------------------
/src.sim/toxi/sim/automata/MatrixEvolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.sim.automata;
29 |
30 | public interface MatrixEvolver {
31 |
32 | public void evolve(EvolvableMatrix m);
33 |
34 | }
--------------------------------------------------------------------------------
/src.sim/toxi/sim/dla/DLAEventAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.sim.dla;
29 |
30 | import toxi.geom.Vec3D;
31 |
32 | public class DLAEventAdapter implements DLAEventListener {
33 |
34 | public void dlaAllSegmentsProcessed(DLA dla) {
35 | }
36 |
37 | public void dlaNewParticleAdded(DLA dla, Vec3D p) {
38 | }
39 |
40 | public void dlaSegmentSwitched(DLA dla, DLASegment s) {
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src.sim/toxi/sim/dla/DLAEventListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.sim.dla;
29 |
30 | import toxi.geom.Vec3D;
31 |
32 | public interface DLAEventListener {
33 |
34 | void dlaAllSegmentsProcessed(DLA dla);
35 |
36 | void dlaNewParticleAdded(DLA dla, Vec3D p);
37 |
38 | void dlaSegmentSwitched(DLA dla, DLASegment s);
39 | }
40 |
--------------------------------------------------------------------------------
/src.sim/toxi/sim/dla/PipelineOrder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * __ .__ .__ ._____.
3 | * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4 | * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5 | * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6 | * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7 | * \/ \/ \/ \/
8 | *
9 | * Copyright (c) 2006-2011 Karsten Schmidt
10 | *
11 | * This library is free software; you can redistribute it and/or
12 | * modify it under the terms of the GNU Lesser General Public
13 | * License as published by the Free Software Foundation; either
14 | * version 2.1 of the License, or (at your option) any later version.
15 | *
16 | * http://creativecommons.org/licenses/LGPL/2.1/
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 | */
27 |
28 | package toxi.sim.dla;
29 |
30 | import java.util.Comparator;
31 |
32 | import toxi.geom.Line3D;
33 |
34 | /**
35 | * A dummy comparator enforcing a FIFO order of segments, i.e. the order they
36 | * were added to the set.
37 | */
38 | public class PipelineOrder implements Comparator {
39 |
40 | public int compare(Line3D a, Line3D b) {
41 | return 1;
42 | }
43 | }
--------------------------------------------------------------------------------
/src.test/toxi/test/ArrayUtilTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test;
2 |
3 | import java.util.Random;
4 |
5 | import junit.framework.TestCase;
6 | import toxi.util.datatypes.ArrayUtil;
7 | import toxi.util.datatypes.GenericSet;
8 | import toxi.util.datatypes.IntegerRange;
9 |
10 | public class ArrayUtilTest extends TestCase {
11 |
12 | private void dumpArray(Integer[] range) {
13 | for (int i : range) {
14 | System.out.print(i + ",");
15 | }
16 | System.out.println("");
17 | }
18 |
19 | public void testGenericSet() {
20 | GenericSet set = new GenericSet(1, 2, 23, 42, 81);
21 | assertEquals(5, set.getItems().size());
22 | int prev = 0;
23 | for (int i = 0; i < set.size(); i++) {
24 | int val = set.pickRandomUnique();
25 | assertTrue(val != prev);
26 | prev = val;
27 | }
28 | }
29 |
30 | public void testShuffle() {
31 | Integer[] range = new IntegerRange(0, 10).toArray();
32 | dumpArray(range);
33 | ArrayUtil.shuffle(range, new Random(23));
34 | dumpArray(range);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src.test/toxi/test/BilinearTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.geom.Vec2D;
5 | import toxi.math.Interpolation2D;
6 |
7 | public class BilinearTest extends TestCase {
8 |
9 | public void testBilinear() {
10 | Vec2D p = new Vec2D();
11 | Vec2D q = new Vec2D(100, 100);
12 | float val;
13 | val = Interpolation2D.bilinear(new Vec2D(10, 0), p, q, 100, 200, 200,
14 | 100);
15 | assertEquals(110f, val);
16 | val = Interpolation2D.bilinear(new Vec2D(50, 0), p, q, 100, 200, 200,
17 | 100);
18 | assertEquals(150f, val);
19 | val = Interpolation2D.bilinear(new Vec2D(90, 10), p, q, 100, 200, 200,
20 | 100);
21 | assertEquals(182f, val);
22 | val = Interpolation2D.bilinear(new Vec2D(90, 100), p, q, 100, 200, 200,
23 | 100);
24 | assertEquals(110f, val);
25 | val = Interpolation2D.bilinear(10, 10, 0, 0, 100, 100, 100, 200, 200,
26 | 100);
27 | assertEquals(118f, val);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src.test/toxi/test/Circle3.java:
--------------------------------------------------------------------------------
1 | package toxi.test;
2 |
3 | import processing.core.PApplet;
4 | import toxi.geom.Circle;
5 | import toxi.geom.Ray3D;
6 | import toxi.geom.Ray3DIntersector;
7 | import toxi.geom.Triangle2D;
8 | import toxi.geom.Vec2D;
9 | import toxi.geom.Vec3D;
10 | import toxi.processing.ToxiclibsSupport;
11 |
12 | public class Circle3 extends PApplet {
13 |
14 | private ToxiclibsSupport gfx;
15 |
16 | public void draw() {
17 | background(255);
18 | noFill();
19 | final Vec2D p1 = new Vec2D(100, 200);
20 | final Vec2D p2 = new Vec2D(200, 50);
21 | final Vec2D p3 = new Vec2D(mouseX, mouseY);
22 | gfx.triangle(new Triangle2D(p1, p2, p3));
23 | Circle circle = Circle.from3Points(p1, p2, p3);
24 | if (circle != null) {
25 | gfx.ellipse(circle);
26 | gfx.circle(p1, 3);
27 | gfx.circle(p2, 3);
28 | }
29 | }
30 |
31 | public void setup() {
32 | size(400, 400);
33 | gfx = new ToxiclibsSupport(this);
34 | Ray3D r = new Ray3D(new Vec3D(), new Vec3D(1, 0, 0));
35 | Ray3D r2 = new Ray3D(new Vec3D(10, 10, 0), new Vec3D(1, -1, 0));
36 | Ray3DIntersector ri = new Ray3DIntersector(r);
37 | ri.intersectsRay(r2);
38 | println(ri.getIntersectionData());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src.test/toxi/test/ComparatorTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test;
2 |
3 | import java.util.Comparator;
4 | import java.util.SortedSet;
5 | import java.util.TreeSet;
6 |
7 | public class ComparatorTest {
8 |
9 | static class NonComparator implements Comparator {
10 |
11 | public int compare(Float a, Float b) {
12 | return (int) (a - b);
13 | }
14 |
15 | }
16 |
17 | public static void main(String[] args) {
18 | SortedSet set = new TreeSet(new NonComparator());
19 | set.add(23f);
20 | set.add(5f);
21 | set.add(99f);
22 | set.add(42f);
23 | set.add(1f);
24 | for (Float f : set) {
25 | System.out.println(f);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src.test/toxi/test/EnvTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 | import java.util.Map;
7 |
8 | public class EnvTest {
9 |
10 | /**
11 | * @param args
12 | */
13 | public static void main(String[] args) {
14 | System.out.println("=========env=========");
15 | Map env = System.getenv();
16 | for (String id : env.keySet()) {
17 | System.out.println(id + "=" + env.get(id));
18 | }
19 | System.out.println("=========props");
20 | System.getProperties().list(System.out);
21 | // process
22 | ProcessBuilder pb = new ProcessBuilder("dot", "-V");
23 | pb.redirectErrorStream(true);
24 | Process p;
25 | try {
26 | p = pb.start();
27 | BufferedReader in = new BufferedReader(new InputStreamReader(
28 | p.getInputStream()));
29 | String line = null;
30 | while ((line = in.readLine()) != null) {
31 | System.out.println(line);
32 | }
33 | } catch (IOException e) {
34 | e.printStackTrace();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src.test/toxi/test/FileUtilsTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test;
2 |
3 | import java.util.Iterator;
4 |
5 | import junit.framework.TestCase;
6 | import toxi.util.FileSequenceDescriptor;
7 | import toxi.util.FileUtils;
8 |
9 | public class FileUtilsTest extends TestCase {
10 |
11 | public void testSequence() {
12 | FileSequenceDescriptor d = FileUtils
13 | .getFileSequenceDescriptorFor("test/img010.tga");
14 | assertEquals(3, d.getDuration());
15 | for (Iterator i = d.iterator(); i.hasNext();) {
16 | System.out.println(i.next());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src.test/toxi/test/PolyConstrain.java:
--------------------------------------------------------------------------------
1 | package toxi.test;
2 |
3 | import processing.core.PApplet;
4 | import toxi.geom.Circle;
5 | import toxi.geom.Polygon2D;
6 | import toxi.geom.Vec2D;
7 | import toxi.processing.ToxiclibsSupport;
8 | import toxi.util.DateUtils;
9 |
10 | public class PolyConstrain extends PApplet {
11 |
12 | public static void main(String[] args) {
13 | PApplet.main(new String[] {
14 | "toxi.test.PolyConstrain"
15 | });
16 | }
17 |
18 | private ToxiclibsSupport gfx;
19 |
20 | private boolean doSave;
21 |
22 | private Polygon2D poly;
23 |
24 | public void draw() {
25 | background(255);
26 | noFill();
27 | gfx.polygon2D(poly);
28 | fill(255, 0, 0);
29 | gfx.circle(new Vec2D(mouseX, mouseY).constrain(poly), 10);
30 | if (doSave) {
31 | saveFrame("PolyConstrain-" + DateUtils.timeStamp() + ".png");
32 | doSave = false;
33 | }
34 | }
35 |
36 | public void keyPressed() {
37 | switch (key) {
38 | case ' ':
39 | doSave = true;
40 | break;
41 | }
42 | }
43 |
44 | public void setup() {
45 | size(600, 600, OPENGL);
46 | gfx = new ToxiclibsSupport(this);
47 | poly = new Circle(200).toPolygon2D(9).translate(width / 2, height / 2);
48 | poly.get(0).x *= 0.66f;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src.test/toxi/test/RangeTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.util.datatypes.BiasedFloatRange;
5 | import toxi.util.datatypes.BiasedIntegerRange;
6 | import toxi.util.datatypes.FloatRange;
7 |
8 | public class RangeTest extends TestCase {
9 |
10 | private void dumpArray(Float[] range) {
11 | for (float i : range) {
12 | System.out.print(i + ",");
13 | }
14 | System.out.println("");
15 | }
16 |
17 | public void testCopy() {
18 | BiasedFloatRange r = new BiasedFloatRange();
19 | r.pickRandom();
20 | BiasedFloatRange c = r.copy();
21 | assertEquals(r.currValue, c.currValue);
22 | assertEquals(r.getBias(), c.getBias());
23 | assertEquals(r.getStandardDeviation(), c.getStandardDeviation());
24 | BiasedIntegerRange ri = new BiasedIntegerRange();
25 | ri.pickRandom();
26 | BiasedIntegerRange ci = ri.copy();
27 | assertEquals(ri.currValue, ci.currValue);
28 | assertEquals(ri.getBias(), ci.getBias());
29 | assertEquals(ri.getStandardDeviation(), ci.getStandardDeviation());
30 | }
31 |
32 | public void testRangeArray() {
33 | Float[] r = new FloatRange(0, 10).toArray(0.1f);
34 | dumpArray(r);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src.test/toxi/test/audio/JOALTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.audio;
2 |
3 | import toxi.audio.AudioBuffer;
4 | import toxi.audio.AudioSource;
5 | import toxi.audio.JOALUtil;
6 | import toxi.audio.SoundListener;
7 | import toxi.geom.ReadonlyVec3D;
8 |
9 | public class JOALTest {
10 |
11 | public static void main(String[] args) {
12 | JOALUtil audioUtil = JOALUtil.getInstance();
13 | String[] devices = audioUtil.getDeviceList();
14 | for (String d : devices) {
15 | System.out.println(d);
16 | }
17 | audioUtil.init(JOALUtil.SOFTWARE, false);
18 | SoundListener l = audioUtil.getListener();
19 | l.setGain(1);
20 | AudioBuffer b = audioUtil.loadBuffer("test/phone_ulaw.wav");
21 | int delay = b.getSampleSize() * 1000 / b.getFrequency();
22 | System.out.println(b + " length=" + delay);
23 | if (b.convertUlawToPCM(false)) {
24 | AudioSource src = audioUtil.generateSource();
25 | src.setBuffer(b);
26 | src.play();
27 | } else {
28 | System.out.println("couldn't convert buffer data");
29 | }
30 | try {
31 | Thread.sleep(delay);
32 | } catch (InterruptedException e) {
33 | e.printStackTrace();
34 | }
35 | audioUtil.shutdown();
36 | }
37 |
38 | ReadonlyVec3D pos;
39 | }
40 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/AllGeomTests.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestSuite;
5 |
6 | public class AllGeomTests {
7 |
8 | public static Test suite() {
9 | TestSuite suite = new TestSuite(AllGeomTests.class.getName());
10 | // $JUnit-BEGIN$
11 | suite.addTestSuite(AABBTest.class);
12 | suite.addTestSuite(CircleTest.class);
13 | suite.addTestSuite(Line2DTest.class);
14 | suite.addTestSuite(Line3DTest.class);
15 | suite.addTestSuite(MatrixTest.class);
16 | suite.addTestSuite(Origin3DTest.class);
17 | suite.addTestSuite(PlaneTest.class);
18 | suite.addTestSuite(PolygonTest.class);
19 | suite.addTestSuite(QuaternionTest.class);
20 | suite.addTestSuite(RectTest.class);
21 | suite.addTestSuite(SphereTest.class);
22 | suite.addTestSuite(TreeTest.class);
23 | suite.addTestSuite(Triangle2DTest.class);
24 | suite.addTestSuite(TriangleMeshTest.class);
25 | suite.addTestSuite(TriangleTest.class);
26 | suite.addTestSuite(Vec3DTest.class);
27 | suite.addTestSuite(WEMeshTest.class);
28 | // $JUnit-END$
29 | return suite;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/CircleTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.geom.Circle;
5 | import toxi.geom.Vec2D;
6 |
7 | public class CircleTest extends TestCase {
8 |
9 | private void showPoints(Vec2D[] points) {
10 | if (points != null) {
11 | for (Vec2D p : points) {
12 | System.out.println(p);
13 | }
14 | } else {
15 | System.out.println("");
16 | }
17 | }
18 |
19 | public void testCircleCircleIntersection() {
20 | Circle a = new Circle(100);
21 | Circle b = new Circle(new Vec2D(200, 100), 200);
22 | Vec2D[] isec = a.intersectsCircle(b);
23 | assertTrue(isec != null);
24 | assertTrue(isec[0].equals(new Vec2D(0, 100)));
25 | showPoints(isec);
26 | b.setRadius(100);
27 | isec = a.intersectsCircle(b);
28 | assertTrue(isec == null);
29 | b.setRadius(99).set(0, 0);
30 | isec = a.intersectsCircle(b);
31 | assertTrue(isec == null);
32 | b.x = 1;
33 | isec = a.intersectsCircle(b);
34 | assertTrue(isec != null);
35 | showPoints(isec);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/Line3DTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import java.util.HashMap;
4 |
5 | import junit.framework.TestCase;
6 | import toxi.geom.Line3D;
7 | import toxi.geom.Vec3D;
8 | import toxi.geom.mesh.WEVertex;
9 | import toxi.geom.mesh.WingedEdge;
10 | import toxi.math.MathUtils;
11 |
12 | public class Line3DTest extends TestCase {
13 |
14 | public void testClosestPoint() {
15 | Vec3D a = new Vec3D();
16 | Vec3D b = new Vec3D(100, 0, 0);
17 | Vec3D c = new Vec3D(50, 50, 0);
18 | Line3D line = new Line3D(a, b);
19 | Vec3D isec = line.closestPointTo(c);
20 | assertEquals(MathUtils.abs(isec.x - c.x) < 0.5, true);
21 | c = new Vec3D(-50, -50, 0);
22 | isec = line.closestPointTo(c);
23 | assertEquals(isec.equals(a), true);
24 | }
25 |
26 | public void testHashing() {
27 | Line3D l1 = new Line3D(new Vec3D(100, 420, -50), new Vec3D(-888, 230,
28 | 2999));
29 | Line3D l2 = new Line3D(new Vec3D(-888, 230, 2999), new Vec3D(100, 420,
30 | -50));
31 | assertTrue(l1.equals(l2));
32 | assertEquals(l1.hashCode(), l2.hashCode());
33 | l2.a = new Vec3D();
34 | assertFalse(l1.equals(l2));
35 | l1.b.clear();
36 | assertTrue(l1.equals(l2));
37 | HashMap map = new HashMap();
38 | map.put(l1, new WingedEdge(new WEVertex(l1.a, 0),
39 | new WEVertex(l1.b, 1), null, 0));
40 | WingedEdge e = map.get(l1);
41 | assertEquals(l1, e);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/MatrixTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.geom.Matrix4x4;
5 | import toxi.geom.ReadonlyVec3D;
6 | import toxi.geom.Vec3D;
7 | import toxi.math.MathUtils;
8 |
9 | public class MatrixTest extends TestCase {
10 |
11 | public void testInverse() {
12 | Matrix4x4 m = new Matrix4x4();
13 | m.translateSelf(100, 100, 0);
14 | m.rotateX(MathUtils.HALF_PI);
15 | m.scaleSelf(10, 10, 10);
16 | System.out.println(m);
17 | Vec3D v = new Vec3D(0, 1, 0);
18 | Vec3D w = m.applyTo(v);
19 | m = m.getInverted();
20 | ReadonlyVec3D v2 = m.applyTo(w);
21 | System.out.println(w);
22 | System.out.println(v2);
23 | assertTrue(v2.equalsWithTolerance(v, 0.0001f));
24 | }
25 |
26 | public void testRotate() {
27 | Matrix4x4 m = new Matrix4x4();
28 | m.rotateX(MathUtils.HALF_PI);
29 | Vec3D v = m.applyTo(new Vec3D(0, 1, 0));
30 | assertTrue(new Vec3D(0, 0, 1).equalsWithTolerance(v, 0.00001f));
31 | m.identity();
32 | m.rotateY(MathUtils.HALF_PI);
33 | v = m.applyTo(new Vec3D(1, 0, 0));
34 | assertTrue(new Vec3D(0, 0, -1).equalsWithTolerance(v, 0.00001f));
35 | m.identity();
36 | m.rotateZ(MathUtils.HALF_PI);
37 | v = m.applyTo(new Vec3D(1, 0, 0));
38 | assertTrue(new Vec3D(0, 1, 0).equalsWithTolerance(v, 0.00001f));
39 | m.identity();
40 | m.rotateAroundAxis(new Vec3D(0, 1, 0), MathUtils.HALF_PI);
41 | v = m.applyTo(new Vec3D(1, 0, 0));
42 | assertTrue(new Vec3D(0, 0, 1).equalsWithTolerance(v, 0.00001f));
43 | }
44 |
45 | public void testTranslate() {
46 | Matrix4x4 m = new Matrix4x4();
47 | m.translateSelf(100, 100, 100);
48 | assertEquals(new Vec3D(100, 100, 100), m.applyTo(new Vec3D()));
49 | }
50 | }
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/Origin3DTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.geom.Origin3D;
5 | import toxi.geom.Vec3D;
6 |
7 | public class Origin3DTest extends TestCase {
8 |
9 | public void testViewConstruct() {
10 | Origin3D o = new Origin3D(new Vec3D(0, -100, 0), new Vec3D(0, 1, 0));
11 | System.out.println(o.xAxis);
12 | System.out.println(o.yAxis);
13 | System.out.println(o.zAxis);
14 | System.out.println(o.xAxis.angleBetween(o.zAxis));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/PlaneTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.geom.Plane;
5 | import toxi.geom.Triangle3D;
6 | import toxi.geom.Vec3D;
7 |
8 | public class PlaneTest extends TestCase {
9 |
10 | public void testContainment() {
11 | Triangle3D t = new Triangle3D(new Vec3D(-100, 0, 0), new Vec3D(0, 0,
12 | -100), new Vec3D(0, 0, 100));
13 | Plane pl = new Plane(t.computeCentroid(), t.computeNormal());
14 | }
15 |
16 | public void testProjection() {
17 | Vec3D origin = new Vec3D(0, 100, 0);
18 | Plane plane = new Plane(origin, new Vec3D(0, 1, 0));
19 | Vec3D proj;
20 | proj = plane.getProjectedPoint(new Vec3D());
21 | assertEquals(origin, proj);
22 | proj = plane.getProjectedPoint(new Vec3D(0, 200, 0));
23 | assertEquals(origin, proj);
24 | proj = plane.getProjectedPoint(origin);
25 | assertEquals(origin, proj);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/RectTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.geom.Rect;
5 | import toxi.geom.Vec2D;
6 |
7 | public class RectTest extends TestCase {
8 |
9 | public void testIntersectionRect() {
10 | Rect a = new Rect(100, 100, 100, 100);
11 | Rect b = new Rect(80, 80, 100, 100);
12 | Rect i = a.intersectionRectWith(b);
13 | assertEquals(new Rect(100, 100, 80, 80), i);
14 | b = new Rect(80, 80, 20, 20);
15 | i = a.intersectionRectWith(b);
16 | assertEquals(new Vec2D(), i.getDimensions());
17 | b.width = 10;
18 | i = a.intersectionRectWith(b);
19 | assertNull(i);
20 | b = new Rect(180, 180, 30, 50);
21 | i = a.intersectionRectWith(b);
22 | assertEquals(new Rect(180, 180, 20, 20), i);
23 | }
24 |
25 | public void testIsec() {
26 | Rect a = new Rect(100, 100, 100, 100);
27 | Rect b = new Rect(110, 110, 10, 10);
28 | assertTrue(a.intersectsRect(b));
29 | assertTrue(b.intersectsRect(a));
30 | b = new Rect(80, 80, 30, 200);
31 | assertTrue(a.intersectsRect(b));
32 | }
33 |
34 | public void testRectMerge() {
35 | Rect r = new Rect(-10, 2, 3, 3);
36 | Rect s = new Rect(-8, 4, 5, 3);
37 | r = r.unionRectWith(s);
38 | assertEquals(new Rect(-10, 2, 7, 5), r);
39 | r = new Rect(0, 0, 3, 3);
40 | s = new Rect(-1, 2, 1, 1);
41 | r = r.unionRectWith(s);
42 | assertEquals(new Rect(-1, 0, 4, 3), r);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/SphereTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.geom.Ray3D;
5 | import toxi.geom.Sphere;
6 | import toxi.geom.SphereIntersectorReflector;
7 | import toxi.geom.Vec2D;
8 | import toxi.geom.Vec3D;
9 | import toxi.math.MathUtils;
10 |
11 | public class SphereTest extends TestCase {
12 |
13 | public void testIsInSphere() {
14 | Vec3D p = new Vec3D(0, -10, 0);
15 | Sphere s = new Sphere(new Vec3D(), 10);
16 | assertEquals(s.containsPoint(p), true);
17 | p.set(0, 10.1f, 0);
18 | assertEquals(s.containsPoint(p), false);
19 | }
20 |
21 | public void testReflectRay() {
22 | SphereIntersectorReflector si = new SphereIntersectorReflector(
23 | new Vec3D(0, 0, 0), 10);
24 | Ray3D r = si.reflectRay(new Ray3D(new Vec3D(100, 100, 0), new Vec3D(-1,
25 | -1, 0)));
26 | float absDiff = r.getDirection().angleBetween(new Vec3D(1, 1, 0), true);
27 | System.out.println(r + " diff: " + absDiff);
28 | assertEquals(absDiff < 0.002, true);
29 | }
30 |
31 | public void testSurfaceDistance() {
32 | Vec2D p = new Vec2D(90, 60).scale(MathUtils.DEG2RAD);
33 | Vec2D q = new Vec2D(90, 61).scale(MathUtils.DEG2RAD);
34 | Sphere e = new Sphere(Sphere.EARTH_RADIUS);
35 | double dist = (float) e.surfaceDistanceBetween(p, q);
36 | assertTrue(MathUtils.abs(dist - 111.1952) < 0.1);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/TreeTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import java.util.List;
4 |
5 | import junit.framework.TestCase;
6 | import toxi.geom.AABB;
7 | import toxi.geom.PointOctree;
8 | import toxi.geom.PointQuadtree;
9 | import toxi.geom.Rect;
10 | import toxi.geom.Sphere;
11 | import toxi.geom.Vec2D;
12 | import toxi.geom.Vec3D;
13 |
14 | public class TreeTest extends TestCase {
15 |
16 | public void testOctree() {
17 | PointOctree t = new PointOctree(new Vec3D(), 100);
18 | t.setMinNodeSize(0.5f);
19 | assertEquals(t.addPoint(new Vec3D(0, 0, 0)), true);
20 | assertEquals(t.addPoint(new Vec3D(1, 0, 0)), true);
21 | PointOctree leaf1 = t.getLeafForPoint(new Vec3D(0, 0, 0));
22 | PointOctree leaf2 = t.getLeafForPoint(new Vec3D(1, 0, 0));
23 | assertNotSame(leaf1, leaf2);
24 | assertEquals(t.addPoint(new Vec3D(0, 100, 0)), true);
25 | assertEquals(t.addPoint(new Vec3D(101, 0, 0)), false);
26 | List points = t.getPointsWithinSphere(new Sphere(new Vec3D(50,
27 | 0, 0), 50));
28 | assertEquals(points.size() == 2, true);
29 | points = t.getPointsWithinBox(new AABB(new Vec3D(50, 50, 50),
30 | new Vec3D(50, 50, 50)));
31 | assertEquals(points.size() == 3, true);
32 | }
33 |
34 | public void testQuadtree() {
35 | PointQuadtree t = new PointQuadtree(null, 0, 0, 100, 100);
36 | assertEquals(t.index(new Vec2D(0, 0)), true);
37 | assertEquals(t.index(new Vec2D(1, 1)), true);
38 | assertEquals(t.index(new Vec2D(4, 0)), true);
39 | PointQuadtree leaf1 = t.findNode(new Vec2D(0, 0));
40 | PointQuadtree leaf2 = t.findNode(new Vec2D(4, 0));
41 | assertNotSame(leaf1, leaf2);
42 | List points = t.itemsWithinRect(new Rect(0, 0, 2, 2), null);
43 | assertEquals(2, points.size());
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src.test/toxi/test/geom/Vec3DTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.geom;
2 |
3 | import java.util.List;
4 |
5 | import junit.framework.TestCase;
6 | import toxi.geom.Line3D;
7 | import toxi.geom.Vec3D;
8 |
9 | public class Vec3DTest extends TestCase {
10 |
11 | public void testClosestAxis() {
12 | assertEquals(Vec3D.Axis.X, new Vec3D(-1, 0.9f, 0.8f).getClosestAxis());
13 | assertEquals(null, new Vec3D(1, -1, 0).getClosestAxis());
14 | assertEquals(null, new Vec3D(1, 0, -1).getClosestAxis());
15 | assertEquals(Vec3D.Axis.Y,
16 | new Vec3D(0.8f, -1, -0.99999f).getClosestAxis());
17 | assertEquals(null, new Vec3D(0.8f, -1, 1).getClosestAxis());
18 | assertEquals(Vec3D.Axis.Z, new Vec3D(0.8f, -1, 1.1f).getClosestAxis());
19 | assertEquals(Vec3D.Axis.X, new Vec3D(1, 0, 0).getClosestAxis());
20 | assertEquals(Vec3D.Axis.Y, new Vec3D(0, -1, 0).getClosestAxis());
21 | assertEquals(Vec3D.Axis.Z, new Vec3D(0, 0, 1).getClosestAxis());
22 | }
23 |
24 | public void testSphericalInstance() {
25 | Vec3D v = new Vec3D(-1, 1, 1);
26 | Vec3D w = v.copy();
27 | v.toSpherical();
28 | v.toCartesian();
29 | System.out.println(v);
30 | assertTrue(v.equalsWithTolerance(w, 0.0001f));
31 | }
32 |
33 | public void testSplitSegments() {
34 | Vec3D a = new Vec3D(0, 0, 0);
35 | Vec3D b = new Vec3D(100, 0, 0);
36 | List list = Line3D.splitIntoSegments(a, b, 8, null, true);
37 | assertEquals(14, list.size());
38 | // testing adding to existing list and skipping start point
39 | Line3D.splitIntoSegments(b, a, 10, list, false);
40 | assertFalse(b.equals(list.get(14)));
41 | assertEquals(24, list.size());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src.test/toxi/test/math/MathTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.math;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.math.MathUtils;
5 |
6 | public class MathTest extends TestCase {
7 |
8 | public void testFastSin() {
9 | float maxErr = Float.MIN_VALUE;
10 | for (float i = 0; i <= 8 * 360; i++) {
11 | float theta = i * MathUtils.DEG2RAD * 0.25f;
12 | float sin = (float) Math.cos(theta);
13 | float fs = MathUtils.cos(theta);
14 | float err = (fs - sin);
15 | maxErr = MathUtils.max(MathUtils.abs(err), maxErr);
16 | System.out.println(i + ": sin=" + sin + " fastsin=" + fs + " err="
17 | + err);
18 | }
19 | System.out.println("max err: " + maxErr);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src.test/toxi/test/math/NonLinearScaleMap.java:
--------------------------------------------------------------------------------
1 | package toxi.test.math;
2 |
3 | import java.util.NavigableSet;
4 | import java.util.SortedSet;
5 | import java.util.TreeSet;
6 |
7 | public class NonLinearScaleMap {
8 |
9 | public class Sample implements Comparable {
10 |
11 | public final double x, y;
12 |
13 | public Sample(double x, double y) {
14 | this.x = x;
15 | this.y = y;
16 | }
17 |
18 | public int compareTo(Sample b) {
19 | return (int) Math.signum(x - b.x);
20 | }
21 | }
22 |
23 | private TreeSet samples;
24 |
25 | private double rangeMin = Float.MAX_VALUE;
26 | private double rangeMax = Float.MIN_VALUE;
27 |
28 | public NonLinearScaleMap() {
29 | samples = new TreeSet();
30 | }
31 |
32 | public NonLinearScaleMap addSample(double x, double y) {
33 | samples.add(new Sample(x, y));
34 | rangeMin = Math.min(y, rangeMin);
35 | rangeMax = Math.max(y, rangeMax);
36 | return this;
37 | }
38 |
39 | public NavigableSet getSamples() {
40 | return samples;
41 | }
42 |
43 | public double map(float x) {
44 | Sample t = new Sample(x, 0);
45 | SortedSet aset = samples.headSet(t);
46 | SortedSet bset = samples.tailSet(t);
47 | if (aset.isEmpty()) {
48 | return bset.first().y;
49 | } else {
50 | if (bset.isEmpty()) {
51 | return aset.last().y;
52 | } else {
53 | Sample a = aset.last();
54 | Sample b = bset.first();
55 | return a.y + (b.y - a.y) * (x - a.x) / (b.x - a.x);
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/src.test/toxi/test/math/UnitTransTest.java:
--------------------------------------------------------------------------------
1 | package toxi.test.math;
2 |
3 | import junit.framework.TestCase;
4 | import toxi.math.conversion.UnitTranslator;
5 |
6 | public class UnitTransTest extends TestCase {
7 |
8 | public void testAreaConverters() {
9 | double area = UnitTranslator.POINT_POSTSCRIPT
10 | * UnitTranslator.POINT_POSTSCRIPT;
11 | assertEquals(1d, UnitTranslator.squarePointsToInch(area));
12 | assertEquals(645.16, UnitTranslator.squarePointsToMillis(area));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src.volume/toxi/volume/AdditiveBrush.java:
--------------------------------------------------------------------------------
1 | package toxi.volume;
2 |
3 | public class AdditiveBrush implements BrushMode {
4 |
5 | public final float apply(float orig, float brush) {
6 | return orig + brush;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src.volume/toxi/volume/BrushMode.java:
--------------------------------------------------------------------------------
1 | package toxi.volume;
2 |
3 | public interface BrushMode {
4 |
5 | public float apply(float orig, float brush);
6 | }
7 |
--------------------------------------------------------------------------------
/src.volume/toxi/volume/MultiplyBrush.java:
--------------------------------------------------------------------------------
1 | package toxi.volume;
2 |
3 | public class MultiplyBrush implements BrushMode {
4 |
5 | public final float apply(float orig, float brush) {
6 | return orig * brush;
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src.volume/toxi/volume/PeakBrush.java:
--------------------------------------------------------------------------------
1 | package toxi.volume;
2 |
3 | import toxi.math.MathUtils;
4 |
5 | public class PeakBrush implements BrushMode {
6 |
7 | public final float apply(float orig, float brush) {
8 | return MathUtils.max(orig, brush);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src.volume/toxi/volume/ReplaceBrush.java:
--------------------------------------------------------------------------------
1 | package toxi.volume;
2 |
3 | public class ReplaceBrush implements BrushMode {
4 |
5 | public final float apply(float orig, float brush) {
6 | return brush;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/test/img010.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/test/img010.tga
--------------------------------------------------------------------------------
/test/img011.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/test/img011.tga
--------------------------------------------------------------------------------
/test/img012.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/test/img012.tga
--------------------------------------------------------------------------------
/test/phone_ulaw.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/test/phone_ulaw.wav
--------------------------------------------------------------------------------
/test/test.properties:
--------------------------------------------------------------------------------
1 | test.intarray=23,42,88,-12
2 |
3 | # arrays can be split over several lines
4 | test.floatarray=\
5 | 3.1415926,\
6 | qwerty,\
7 | 23.42
8 |
9 | test.emptyarray=
10 | test.stringarray=hello,,world,,dummy
11 |
--------------------------------------------------------------------------------
/test/test.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/toxiclibs/e6d6dec5a503fa76ed9ed82ca1c5c32b2085fdef/test/test.stl
--------------------------------------------------------------------------------
/test/wave.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------