mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Projektstruktur an Gradle angepasst
This commit is contained in:
BIN
src/main/resources/Icon.afdesign
Normal file
BIN
src/main/resources/Icon.afdesign
Normal file
Binary file not shown.
BIN
src/main/resources/icon_128.png
Normal file
BIN
src/main/resources/icon_128.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
src/main/resources/icon_32.png
Normal file
BIN
src/main/resources/icon_32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
BIN
src/main/resources/icon_512.png
Normal file
BIN
src/main/resources/icon_512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 159 KiB |
BIN
src/main/resources/icon_64.png
Normal file
BIN
src/main/resources/icon_64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
227
src/test/java/schule/ngb/zm/ColorTest.java
Normal file
227
src/test/java/schule/ngb/zm/ColorTest.java
Normal file
@@ -0,0 +1,227 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ColorTest {
|
||||
|
||||
@Test
|
||||
public void init() {
|
||||
Color c;
|
||||
|
||||
c = new Color();
|
||||
assertEquals(0, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(0, c.getBlue());
|
||||
assertEquals(255, c.getAlpha());
|
||||
|
||||
c = Color.BLUE;
|
||||
assertEquals(0, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(255, c.getBlue());
|
||||
assertEquals(255, c.getAlpha());
|
||||
|
||||
c = new Color(50, 133, 64, 33);
|
||||
assertEquals(50, c.getRed());
|
||||
assertEquals(133, c.getGreen());
|
||||
assertEquals(64, c.getBlue());
|
||||
assertEquals(33, c.getAlpha());
|
||||
|
||||
c = new Color(255, 0, 0);
|
||||
assertEquals(Color.RED, c);
|
||||
|
||||
c = new Color(33, 50);
|
||||
assertEquals(33, c.getRed());
|
||||
assertEquals(33, c.getGreen());
|
||||
assertEquals(33, c.getBlue());
|
||||
assertEquals(50, c.getAlpha());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse() {
|
||||
Color c;
|
||||
|
||||
c = Color.getRGBColor(0x00FF00FF);
|
||||
assertEquals(0x00FF00FF, c.getRGBA());
|
||||
assertEquals(255, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(255, c.getBlue());
|
||||
assertEquals(0, c.getAlpha());
|
||||
|
||||
c = Color.getRGBColor(0x33FF3333);
|
||||
assertEquals(0x33FF3333, c.getRGBA());
|
||||
assertEquals(255, c.getRed());
|
||||
assertEquals(51, c.getGreen());
|
||||
assertEquals(51, c.getBlue());
|
||||
assertEquals(51, c.getAlpha());
|
||||
|
||||
c = Color.parseHexcode("FF00FF");
|
||||
assertEquals(0xFFFF00FF, c.getRGBA());
|
||||
assertEquals(255, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(255, c.getBlue());
|
||||
assertEquals(255, c.getAlpha());
|
||||
|
||||
c = Color.parseHexcode("#FF00FF00");
|
||||
assertEquals(0x00FF00FF, c.getRGBA());
|
||||
assertEquals(255, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(255, c.getBlue());
|
||||
assertEquals(0, c.getAlpha());
|
||||
|
||||
c = Color.parseHexcode("#333");
|
||||
assertEquals(0xFF333333, c.getRGBA());
|
||||
assertEquals(51, c.getRed());
|
||||
assertEquals(51, c.getGreen());
|
||||
assertEquals(51, c.getBlue());
|
||||
assertEquals(255, c.getAlpha());
|
||||
|
||||
c = Color.parseHexcode("#33FF0033");
|
||||
assertEquals(0x3333FF00, c.getRGBA());
|
||||
assertEquals(51, c.getRed());
|
||||
assertEquals(255, c.getGreen());
|
||||
assertEquals(0, c.getBlue());
|
||||
assertEquals(51, c.getAlpha());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
Color c1 = new Color(254, 98, 12);
|
||||
Color c2 = new Color(254, 98, 12);
|
||||
assertNotSame(c1, c2);
|
||||
assertEquals(c1, c2);
|
||||
assertEquals(c1, c1);
|
||||
c2 = new Color(c1);
|
||||
assertNotSame(c1, c2);
|
||||
assertEquals(c1, c2);
|
||||
|
||||
Color yellow = new Color(255, 255, 0);
|
||||
assertEquals(java.awt.Color.YELLOW, yellow);
|
||||
assertNotEquals(java.awt.Color.YELLOW, Color.YELLOW);
|
||||
}
|
||||
|
||||
@Test
|
||||
void construct() {
|
||||
Color c;
|
||||
// Empty color is white
|
||||
c = new Color();
|
||||
assertEquals(Color.BLACK, c);
|
||||
// One arg is shade of gray
|
||||
c = new Color(255);
|
||||
assertEquals(Color.WHITE, c);
|
||||
c = new Color(0);
|
||||
assertEquals(Color.BLACK, c);
|
||||
c = new Color(64);
|
||||
assertEquals(Color.DARKGRAY, c);
|
||||
c = new Color(192);
|
||||
assertEquals(Color.LIGHTGRAY, c);
|
||||
// RGB colors
|
||||
c = new Color(0,0,0);
|
||||
assertEquals(Color.BLACK, c);
|
||||
c = new Color(255,0,0);
|
||||
assertEquals(java.awt.Color.RED, c.getJavaColor());
|
||||
c = new Color(0,255,0);
|
||||
assertEquals(java.awt.Color.GREEN, c.getJavaColor());
|
||||
c = new Color(0,0,255);
|
||||
assertEquals(java.awt.Color.BLUE, c.getJavaColor());
|
||||
// From java.awt.Color
|
||||
c = new Color(java.awt.Color.YELLOW);
|
||||
assertEquals(java.awt.Color.YELLOW, c.getJavaColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRGBColor() {
|
||||
Color c1 = Color.getRGBColor(0xFFFF0000);
|
||||
assertEquals(Color.RED, c1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getHSBColor() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getHSLColor() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseHexcode() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void morph() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void RGBtoHSL() {
|
||||
Color c;
|
||||
float[] hsl;
|
||||
|
||||
c = Color.RED;
|
||||
hsl = Color.RGBtoHSL(c.getRGBA(), null);
|
||||
assertArrayEquals(new float[]{0f,1f,.5f}, hsl, 0.0001f);
|
||||
|
||||
c = new Color(255, 33, 64);
|
||||
hsl = Color.RGBtoHSL(c.getRGBA(), null);
|
||||
assertEquals(352, hsl[0], 1.0f);
|
||||
assertEquals(1.0f, hsl[1], .0001f);
|
||||
assertEquals(.5647f, hsl[2], .0001f);
|
||||
}
|
||||
|
||||
@Test
|
||||
void HSLtoRGB() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHSLtoRGB() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void copy() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRGBA() {
|
||||
Color yellow = new Color(255, 255, 0);
|
||||
assertEquals(java.awt.Color.YELLOW.getRGB(), Color.YELLOW.getRGBA());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRed() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getGreen() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBlue() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAlpha() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getJavaColor() {
|
||||
assertEquals(java.awt.Color.YELLOW, Color.YELLOW.getJavaColor());
|
||||
assertEquals(new java.awt.Color(255, 31, 124), new Color(255, 31, 124).getJavaColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
void brighter() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBrighter() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void darker() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDarker() {
|
||||
}
|
||||
|
||||
}
|
||||
131
src/test/java/schule/ngb/zm/ConstantsTest.java
Normal file
131
src/test/java/schule/ngb/zm/ConstantsTest.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ConstantsTest {
|
||||
|
||||
@Test
|
||||
void min() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void max() {
|
||||
assertEquals(5.0, Constants.max(5.0, 0.0), 0.000001);
|
||||
assertEquals(5.0, Constants.max(5.0, 4.0), 0.000001);
|
||||
assertEquals(5.0, Constants.max(5.0, 5.0), 0.000001);
|
||||
assertEquals(100.0, Constants.max(100.0, -100.0), 0.000001);
|
||||
assertEquals(0.0, Constants.max(0.0, 0.0), 0.000001);
|
||||
|
||||
assertEquals(5.0, Constants.max(new double[]{ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }), 0.000001);
|
||||
assertEquals(5.0, Constants.max(new double[]{ 5.0, 5.0, 5.0, 5.0, 5.0 }), 0.000001);
|
||||
assertEquals(5.0, Constants.max(new double[]{ 5.0 }), 0.000001);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> Constants.max(null));
|
||||
assertThrows(IllegalArgumentException.class, () -> Constants.max(new double[]{}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void abs() {
|
||||
assertEquals(5.0, Constants.abs(5.0), 0.000001);
|
||||
assertEquals(0.0, Constants.abs(0.0), 0.000001);
|
||||
assertEquals(105.0, Constants.abs(-105.0), 0.000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sign() {
|
||||
assertEquals(1.0, Constants.sign(5.0), 0.000001);
|
||||
assertEquals(0.0, Constants.sign(0.0), 0.000001);
|
||||
assertEquals(-1.0, Constants.sign(-105.0), 0.000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void morph() {
|
||||
assertEquals(0.0, Constants.interpolate(0.0, 100.0, 0.0), 0.000001);
|
||||
assertEquals(10.0, Constants.interpolate(0.0, 100.0, 0.1), 0.000001);
|
||||
assertEquals(50.0, Constants.interpolate(0.0, 100.0, 0.5), 0.000001);
|
||||
assertEquals(100.0, Constants.interpolate(0.0, 100.0, 1.0), 0.000001);
|
||||
assertEquals(-100.0, Constants.interpolate(-100.0, 100.0, 0.0), 0.000001);
|
||||
assertEquals(0.0, Constants.interpolate(-100.0, 100.0, 0.5), 0.000001);
|
||||
assertEquals(100.0, Constants.interpolate(-100.0, 100.0, 1.0), 0.000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void limit() {
|
||||
assertEquals(4, Constants.limit(4, 1, 5));
|
||||
assertEquals(1, Constants.limit(0, 1, 5));
|
||||
assertEquals(5, Constants.limit(6, 1, 5));
|
||||
assertEquals(1, Constants.limit(-6, 1, 5));
|
||||
assertEquals(-6, Constants.limit(-6, -10, 5));
|
||||
assertEquals(-10, Constants.limit(-15, -10, 5));
|
||||
assertEquals(-10, Constants.limit(-10, -10, 5));
|
||||
|
||||
assertEquals(4.0, Constants.limit(4, 1, 5), 0.000001);
|
||||
assertEquals(1.3, Constants.limit(0, 1.3, 5), 0.000001);
|
||||
assertEquals(5.0, Constants.limit(6, 1, 5), 0.000001);
|
||||
assertEquals(1.2, Constants.limit(-6, 1.2, 5), 0.000001);
|
||||
assertEquals(-6.0, Constants.limit(-6, -10, 5), 0.000001);
|
||||
assertEquals(-10.0, Constants.limit(-15, -10, 5), 0.000001);
|
||||
assertEquals(-10.3, Constants.limit(-10.3, -10.3, 5), 0.000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void b() {
|
||||
assertTrue(Constants.getBool(true));
|
||||
assertFalse(Constants.getBool(false));
|
||||
assertTrue(Constants.getBool(1));
|
||||
assertFalse(Constants.getBool(0));
|
||||
assertTrue(Constants.getBool(4.0));
|
||||
assertFalse(Constants.getBool(0.0));
|
||||
assertTrue(Constants.getBool(4.0f));
|
||||
assertFalse(Constants.getBool(0.0f));
|
||||
assertTrue(Constants.getBool(4L));
|
||||
assertFalse(Constants.getBool(0L));
|
||||
assertTrue(Constants.getBool("true"));
|
||||
assertTrue(Constants.getBool("True"));
|
||||
assertFalse(Constants.getBool("1"));
|
||||
assertFalse(Constants.getBool("false"));
|
||||
assertFalse(Constants.getBool("yes"));
|
||||
assertFalse(Constants.getBool("no"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void randomBool() {
|
||||
float t = 0f, f = 0f;
|
||||
for( int i = 0; i < 100000; i++ ) {
|
||||
if( Constants.randomBool() ) {
|
||||
t++;
|
||||
} else {
|
||||
f++;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(.5f, Math.abs(t/(t+f)), .01f);
|
||||
|
||||
t = 0f;
|
||||
f = 0f;
|
||||
for( int i = 0; i < 100000; i++ ) {
|
||||
if( Constants.randomBool(.2) ) {
|
||||
t++;
|
||||
} else {
|
||||
f++;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(.2f, Math.abs(t/(t+f)), .01f);
|
||||
|
||||
t = 0f;
|
||||
f = 0f;
|
||||
for( int i = 0; i < 100000; i++ ) {
|
||||
if( Constants.randomBool(80) ) {
|
||||
t++;
|
||||
} else {
|
||||
f++;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(.8f, Math.abs(t/(t+f)), .01f);
|
||||
}
|
||||
|
||||
}
|
||||
58
src/test/java/schule/ngb/zm/OptionsTest.java
Normal file
58
src/test/java/schule/ngb/zm/OptionsTest.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static schule.ngb.zm.Options.Direction.*;
|
||||
|
||||
class OptionsTest {
|
||||
|
||||
@Test
|
||||
void testDirections() {
|
||||
assertTrue(NORTH.in(NORTH));
|
||||
assertTrue(NORTH.in(NORTHEAST));
|
||||
assertTrue(EAST.in(NORTHEAST));
|
||||
assertTrue(NORTH.in(NORTHWEST));
|
||||
assertTrue(WEST.in(NORTHWEST));
|
||||
assertFalse(NORTH.in(SOUTH));
|
||||
assertFalse(NORTH.in(EAST));
|
||||
assertFalse(NORTH.in(WEST));
|
||||
assertFalse(NORTH.in(SOUTHWEST));
|
||||
assertFalse(NORTH.in(SOUTHEAST));
|
||||
|
||||
assertFalse(NORTHEAST.in(NORTH));
|
||||
assertFalse(NORTHEAST.in(SOUTH));
|
||||
assertFalse(NORTHEAST.in(NORTHWEST));
|
||||
assertTrue(NORTHEAST.in(NORTHEAST));
|
||||
|
||||
assertTrue(SOUTH.contains(SOUTH));
|
||||
assertFalse(SOUTH.contains(NORTH));
|
||||
assertFalse(SOUTH.contains(EAST));
|
||||
assertFalse(SOUTH.contains(WEST));
|
||||
assertFalse(SOUTH.contains(NORTHWEST));
|
||||
assertFalse(SOUTH.contains(SOUTHWEST));
|
||||
assertFalse(SOUTH.contains(SOUTHEAST));
|
||||
|
||||
assertTrue(SOUTHEAST.contains(SOUTH));
|
||||
assertTrue(SOUTHEAST.contains(EAST));
|
||||
assertTrue(SOUTHWEST.contains(SOUTH));
|
||||
assertTrue(SOUTHWEST.contains(WEST));
|
||||
assertFalse(SOUTHWEST.contains(NORTH));
|
||||
assertFalse(SOUTHWEST.contains(SOUTHEAST));
|
||||
assertTrue(SOUTHWEST.contains(SOUTHWEST));
|
||||
assertFalse(SOUTHWEST.contains(EAST));
|
||||
assertFalse(SOUTHWEST.contains(NORTHWEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOppositeDirection() {
|
||||
assertEquals(SOUTH, NORTH.inverse());
|
||||
assertEquals(NORTH, SOUTH.inverse());
|
||||
assertEquals(WEST, EAST.inverse());
|
||||
assertEquals(EAST, WEST.inverse());
|
||||
|
||||
assertEquals(SOUTHEAST, NORTHWEST.inverse());
|
||||
}
|
||||
|
||||
}
|
||||
114
src/test/java/schule/ngb/zm/TestAttraction.java
Normal file
114
src/test/java/schule/ngb/zm/TestAttraction.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import schule.ngb.zm.shapes.Rectangle;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public class TestAttraction extends Zeichenmaschine {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestAttraction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settings() {
|
||||
setSize(800, 600);
|
||||
setTitle("My test Window");
|
||||
//setFramesPerSecond(5);
|
||||
|
||||
s2dl = new Shape2DLayer();
|
||||
addLayer(s2dl);
|
||||
}
|
||||
|
||||
Shape2DLayer s2dl;
|
||||
|
||||
Vector posA, posB, velB, posC, velC;
|
||||
|
||||
double massA = 500, massB = 1, massC = 4.3, G = 5.0;
|
||||
|
||||
Rectangle recht;
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
//zeichnung.hide();
|
||||
drawing.clear(200);
|
||||
posA = new Vector(0, 0);
|
||||
posB = new Vector(-100, -100);
|
||||
velB = new Vector(10, -10);
|
||||
posC = new Vector(200, 100);
|
||||
velC = new Vector(1, 14);
|
||||
|
||||
drawing.translate(width /2, height /2);
|
||||
drawing.shear(0.1, 0.5);
|
||||
|
||||
recht = new Rectangle(50, 50, 150, 75);
|
||||
recht.setFillColor(200);
|
||||
recht.setStrokeColor(255, 0, 64);
|
||||
recht.setStrokeWeight(2.5);
|
||||
recht.setStrokeType(DASHED);
|
||||
shapes.add(recht);
|
||||
|
||||
drawing.hide();
|
||||
//schule.ngb.zm.formen.verstecken();
|
||||
|
||||
s2dl.setFillColor(64,200,128);
|
||||
s2dl.add(new Rectangle2D.Double(100, 100, 120, 80));
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
drawing.setStrokeColor(255);
|
||||
drawing.setStrokeWeight(4.0);
|
||||
drawing.setStrokeType(DASHED);
|
||||
drawing.clear(33, 33, 33, 100);
|
||||
|
||||
drawing.setFillColor(Color.ORANGE);
|
||||
drawing.pie(posA.x, posA.y, 80, 30, 60);
|
||||
drawing.setFillColor(Color.YELLOW);
|
||||
drawing.circle(posA.x, posA.y, 60);
|
||||
|
||||
Vector acc = acceleration(posA, posB, massA, massB);
|
||||
velB.add(acc);
|
||||
posB.add(velB);
|
||||
|
||||
drawing.setFillColor(Color.BLUE);
|
||||
drawing.circle(posB.x, posB.y, 20);
|
||||
|
||||
acc = acceleration(posA, posC, massA, massC);
|
||||
velC.add(acc);
|
||||
posC.add(velC);
|
||||
|
||||
drawing.setFillColor(Color.GREEN);
|
||||
drawing.circle(posC.x, posC.y, 20);
|
||||
|
||||
drawing.rotate(1);
|
||||
|
||||
shapes.clear();
|
||||
double x = recht.getX();
|
||||
x = (x+100*delta)% width;
|
||||
recht.setX(x);
|
||||
}
|
||||
|
||||
Vector acceleration( Vector a, Vector b, double ma, double mb ) {
|
||||
Vector acc = Vector.sub(a, b);
|
||||
double draw = (G*ma*mb)/acc.lengthSq();
|
||||
acc.setLength(draw*delta);
|
||||
acc.limit(3, 30);
|
||||
return acc;
|
||||
}
|
||||
|
||||
public void mouseDragged() {
|
||||
drawing.translate(mouseX - pmouseX, mouseY - pmouseY);
|
||||
}
|
||||
|
||||
boolean zoom = true;
|
||||
public void mouseClicked() {
|
||||
//canvas.translateToCanvas(mouseX-width/2.0, mouseY-height/2.0);
|
||||
if( zoom ) {
|
||||
drawing.scale(2.0);
|
||||
} else {
|
||||
drawing.scale(.5);
|
||||
}
|
||||
zoom = !zoom;
|
||||
}
|
||||
|
||||
}
|
||||
71
src/test/java/schule/ngb/zm/TestDrawing.java
Normal file
71
src/test/java/schule/ngb/zm/TestDrawing.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
public class TestDrawing extends Zeichenmaschine {
|
||||
|
||||
private final double w = 100, h = 50;
|
||||
|
||||
private double xa = 50, ya = 50;
|
||||
|
||||
private double x2 = 200, y2 = 50;
|
||||
|
||||
int frames = 0;
|
||||
long start = 0;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new TestDrawing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
drawing.setFont("AvenirNext-Medium", 14);
|
||||
drawing.setAnchor(NORTHWEST);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
ya = (ya+1)%350;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
long ms = System.currentTimeMillis();
|
||||
|
||||
drawing.clear();
|
||||
|
||||
// x2 = mouseX;
|
||||
// y2 = mouseY;
|
||||
|
||||
drawing.resetStroke();
|
||||
drawing.rect(xa, ya, w, h);
|
||||
|
||||
//drawing.image("WitchCraftIcons_122_t.PNG", width/2, height/2, .5, CENTER);
|
||||
|
||||
for( int i = 0; i < 4; i++ ) {
|
||||
//delay(1000);
|
||||
drawing.resetStroke();
|
||||
drawing.rect(x2 + i*10, y2 + i * 75, w, h);
|
||||
connect(xa + w, ya + h / 2.0, x2 + i*10, y2 + i * 75 + h / 2.0);
|
||||
drawing.text("Rect " + i, x2 + i*10 + w / 2.0, y2 + i * 75 + h / 2.0, CENTER);
|
||||
}
|
||||
|
||||
|
||||
if( (System.currentTimeMillis()-start) >= 1000 ) {
|
||||
System.out.printf("FPS: %d\n", frames);
|
||||
frames = 0;
|
||||
start = System.currentTimeMillis();
|
||||
} else {
|
||||
frames += 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void connect( double x1, double y1, double x2, double y2 ) {
|
||||
double midx = (x1 + x2) / 2.0;
|
||||
drawing.setStrokeType(DASHED);
|
||||
drawing.setStrokeWeight(2.4);
|
||||
drawing.curve(x1, y1, midx, y1, midx, y2, x2, y2);
|
||||
//drawing.curve(x1, y1, x2, y1, x1, y2, x2, y2);
|
||||
}
|
||||
|
||||
}
|
||||
46
src/test/java/schule/ngb/zm/TestInput.java
Normal file
46
src/test/java/schule/ngb/zm/TestInput.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import schule.ngb.zm.shapes.*;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
public class TestInput extends Zeichenmaschine {
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new TestInput();
|
||||
}
|
||||
|
||||
private Text text;
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
|
||||
//setFramesPerSecond(5);
|
||||
shapes.add(new Point(200, 200));
|
||||
shapes.add(new Point(200, 200));
|
||||
|
||||
shapes.getShape(0).setFillColor(GREEN);
|
||||
shapes.getShape(1).setFillColor(PINK);
|
||||
|
||||
text = new Text(10, 42, "");
|
||||
text.setFontsize(32);
|
||||
text.setAnchor(NORTHWEST);
|
||||
shapes.add(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
shapes.getShape(0).moveTo(mouseX, mouseY);
|
||||
shapes.getShape(1).moveTo(pmouseX, pmouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
drawing.line(pmouseX, pmouseY, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void keyPressed() {
|
||||
text.setText(""+key);
|
||||
}
|
||||
|
||||
}
|
||||
130
src/test/java/schule/ngb/zm/TestShapes.java
Normal file
130
src/test/java/schule/ngb/zm/TestShapes.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import schule.ngb.zm.shapes.*;
|
||||
import schule.ngb.zm.shapes.Point;
|
||||
import schule.ngb.zm.shapes.Polygon;
|
||||
import schule.ngb.zm.shapes.Rectangle;
|
||||
import schule.ngb.zm.shapes.Shape;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.Random;
|
||||
|
||||
public class TestShapes extends Zeichenmaschine {
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new TestShapes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setSize(400, 400);
|
||||
|
||||
//createShapes();
|
||||
|
||||
//add(new Triangle(200, 150, 150, 250, 250, 250));
|
||||
//add(new Rectangle(200, 200, 200, 100));
|
||||
//shapes.getShape(0).setAnchor(CENTER);
|
||||
|
||||
shapePositions();
|
||||
}
|
||||
|
||||
public void createShapes() {
|
||||
add(new Rectangle(20, 10, 40, 20));
|
||||
add(new Ellipse(40, 50, 40, 20));
|
||||
add(new Circle(40, 80, 10));
|
||||
|
||||
add(new Line(40, 100, 100, 40));
|
||||
add(new Arrow(200, 200, 105, 45));
|
||||
|
||||
shapes.add(new Point(200, 200));
|
||||
|
||||
add(new Rhombus(40, 200, 50, 120));
|
||||
add(new Kite(40, 200, 50, 120, .75));
|
||||
add(new Kite(40, 200, 50, 120, .25));
|
||||
|
||||
add(new RoundedRectangle(20, 300, 100, 60, 30));
|
||||
|
||||
add(new Arc(200, 200, 60, 90, 120));
|
||||
|
||||
add(new Polygon(250, 40, 300, 55, 321, 83, 200, 300));
|
||||
shapes.add(new Point(250, 40));
|
||||
shapes.add(new Point(300, 55));
|
||||
shapes.add(new Point(321, 83));
|
||||
shapes.add(new Point(200, 300));
|
||||
|
||||
add(new Triangle(300, 55, 355, 75, 345, 25));
|
||||
add(new Quad(300, 55, 355, 75, 345, 25, 300, 10));
|
||||
|
||||
add(new Curve(50, 50, 350, 50, 350, 350));
|
||||
add(new Curve(50, 50, 50, 350, 350, 50, 350, 350));
|
||||
|
||||
shapes.add(new Picture(300, 300, "WitchCraftIcons_122_t.PNG"));
|
||||
|
||||
add(new Text(200, 40, "Shapes 😊"));
|
||||
}
|
||||
|
||||
public void shapePositions() {
|
||||
int pad = 24;
|
||||
Rectangle bounds = new Rectangle(pad, pad, width-pad, height-pad);
|
||||
|
||||
Rectangle[] rects = new Rectangle[5];
|
||||
for( int i = 0; i < rects.length; i++ ) {
|
||||
rects[i] = new Rectangle(40 + i*15, 40 + i*15, 10, 10+i*4);
|
||||
}
|
||||
shapes.add(rects);
|
||||
|
||||
for( Rectangle r: rects ) {
|
||||
r.alignTo(bounds, LEFT);
|
||||
}
|
||||
|
||||
//Text t = new TextBox(width/2, height/2, 200, 200, "Hello,\nWorld!");
|
||||
//shapes.add(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
//shapes.getShape(Triangle.class).rotate(2);
|
||||
//shapes.getShape(0).rotate(200, 250,2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked() {
|
||||
for( Shape s : shapes.getShapes() ) {
|
||||
randomizeShape(s);
|
||||
//s.move(10, 10);
|
||||
}
|
||||
}
|
||||
|
||||
private void add( Shape s ) {
|
||||
shapes.add(randomizeShape(s));
|
||||
}
|
||||
|
||||
private Shape randomizeShape( Shape s ) {
|
||||
if( !(s instanceof Arc) && !(s instanceof Curve) && !(s instanceof Line) && !(s instanceof Arrow) ) {
|
||||
s.setFillColor(randomColor());
|
||||
}
|
||||
s.setStrokeColor(randomColor());
|
||||
s.setStrokeWeight(random(.75, 2.25));
|
||||
if( randomBool(20) ) {
|
||||
s.setStrokeType(DASHED);
|
||||
} else {
|
||||
s.setStrokeType(SOLID);
|
||||
}
|
||||
|
||||
//s.moveTo(random(20, 380), random(20, 380));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private void showDot( Point2D p ) {
|
||||
showDot(p.getX(), p.getY(), randomColor());
|
||||
}
|
||||
|
||||
private void showDot( double x, double y, Color clr ) {
|
||||
Point p = new Point(x, y);
|
||||
p.setFillColor(clr);
|
||||
p.setStrokeColor(clr);
|
||||
shapes.add(p);
|
||||
}
|
||||
|
||||
}
|
||||
78
src/test/java/schule/ngb/zm/TestTurtle.java
Normal file
78
src/test/java/schule/ngb/zm/TestTurtle.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import schule.ngb.zm.turtle.TurtleLayer;
|
||||
import schule.ngb.zm.turtle.TurtleLayer.Turtle;
|
||||
|
||||
public class TestTurtle extends Zeichenmaschine {
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new TestTurtle();
|
||||
}
|
||||
|
||||
TurtleLayer turtle;
|
||||
|
||||
TurtleLayer.Turtle t1, t2;
|
||||
|
||||
public void setup() {
|
||||
turtle = new TurtleLayer();
|
||||
addLayer(turtle);
|
||||
|
||||
t1 = turtle.getTurtle();
|
||||
t2 = turtle.newTurtle();
|
||||
|
||||
t1.setStrokeWeight(2.0);
|
||||
t2.setStrokeWeight(1.4);
|
||||
|
||||
t1.setFillColor(244, 64, 22);
|
||||
t2.setFillColor(33, 64, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
//t1.right(1);
|
||||
t1.penUp();
|
||||
t1.moveTo(100, 100);
|
||||
t1.penDown();
|
||||
|
||||
t2.penUp();
|
||||
t2.moveTo(200, 200);
|
||||
t2.penDown();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
turtle.clear();
|
||||
star(5, 80, 40, t1);
|
||||
star(5, 80, 40, t2);
|
||||
}
|
||||
|
||||
void star( int corners, int size ) {
|
||||
star(5, size, 40, t1);
|
||||
}
|
||||
|
||||
void star( int corners, int size, int angle, Turtle t ) {
|
||||
int angle2 = (180 - (360/corners) - angle) / 2;
|
||||
|
||||
t.penUp();
|
||||
t.left();
|
||||
t.fd(size*1.25);
|
||||
t.right();
|
||||
t.penDown();
|
||||
|
||||
for( int i = 0; i < corners; i++ ) {
|
||||
t.right(360/corners);
|
||||
t.right(angle2);
|
||||
t.fd(size);
|
||||
t.left(2*angle2);
|
||||
t.fd(size);
|
||||
t.right(angle2);
|
||||
}
|
||||
t.fill();
|
||||
|
||||
t.penUp();
|
||||
t.right();
|
||||
t.fd(size*1.25);
|
||||
t.left();
|
||||
t.penDown();
|
||||
}
|
||||
|
||||
}
|
||||
261
src/test/java/schule/ngb/zm/VectorTest.java
Normal file
261
src/test/java/schule/ngb/zm/VectorTest.java
Normal file
@@ -0,0 +1,261 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class VectorTest {
|
||||
|
||||
@Test
|
||||
public void init() {
|
||||
Vector vec;
|
||||
|
||||
vec = new Vector();
|
||||
assertEquals(0.0, vec.x, 0.0);
|
||||
assertEquals(0.0, vec.y, 0.0);
|
||||
|
||||
vec = new Vector(4.5, 5.1);
|
||||
assertEquals(4.5, vec.x, 0.0);
|
||||
assertEquals(5.1, vec.y, 0.0);
|
||||
|
||||
vec = new Vector(vec);
|
||||
assertEquals(4.5, vec.x, 0.0);
|
||||
assertEquals(5.1, vec.y, 0.0);
|
||||
|
||||
vec = new Vector(Double.MAX_VALUE, Double.MIN_VALUE);
|
||||
assertEquals(Double.MAX_VALUE, vec.x, 0.0);
|
||||
assertEquals(Double.MIN_VALUE, vec.y, 0.0);
|
||||
|
||||
vec = new Vector(new Point2D.Double(7.2, 3.5677));
|
||||
assertEquals(7.2, vec.x, 0.0);
|
||||
assertEquals(3.5677, vec.y, 0.0);
|
||||
|
||||
vec = new Vector(new Point2D.Float(7.2f, 3.5677f));
|
||||
assertEquals(7.2, vec.x, 0.0001);
|
||||
assertEquals(3.5677, vec.y, 0.0001);
|
||||
|
||||
vec.set(new Vector(5.1, 8.9));
|
||||
assertEquals(5.1, vec.x, 0.0001);
|
||||
assertEquals(8.9, vec.y, 0.0001);
|
||||
|
||||
Vector vec2 = vec.copy();
|
||||
assertNotSame(vec, vec2);
|
||||
assertEquals(vec, vec2);
|
||||
assertEquals(5.1, vec2.x, 0.0001);
|
||||
assertEquals(8.9, vec2.y, 0.0001);
|
||||
|
||||
assertEquals(vec, vec.set(100, 100));
|
||||
assertEquals(200, vec.set(200, 200).x, 0.0001);
|
||||
assertEquals(8.9, vec.set(vec2).y, 0.0001);
|
||||
|
||||
for( int i = 0; i < 50; i++ ) {
|
||||
vec = Vector.random();
|
||||
assertTrue(vec.x >= 0);
|
||||
assertTrue(vec.y >= 0);
|
||||
assertTrue(vec.x < 100);
|
||||
assertTrue(vec.y < 100);
|
||||
}
|
||||
|
||||
for( int i = 1; i < 50; i++ ) {
|
||||
vec = Vector.random(0, i*10);
|
||||
assertTrue(vec.x >= 0);
|
||||
assertTrue(vec.y >= 0);
|
||||
assertTrue(vec.x < i*10);
|
||||
assertTrue(vec.y < i*10);
|
||||
}
|
||||
|
||||
for( int i = 1; i < 50; i++ ) {
|
||||
vec = Vector.random(0, i*10, (i+1)*10, (i+2)*10);
|
||||
assertTrue(vec.x >= 0);
|
||||
assertTrue(vec.y >= (i+1)*10);
|
||||
assertTrue(vec.x < i*10);
|
||||
assertTrue(vec.y < (i+2)*10);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void setLength() {
|
||||
Vector vec = new Vector(2.0, 5.4);
|
||||
Vector vec2 = Vector.setLength(vec, 10);
|
||||
assertEquals(10.0, vec2.length(), 0.00001);
|
||||
Vector vec3 = Vector.setLength(vec, -10);
|
||||
assertEquals(10.0, vec3.length(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalize() {
|
||||
Vector vec = new Vector(4.0, 3.0);
|
||||
assertEquals(5.0, vec.length(), 0.00001);
|
||||
Vector vec2 = vec.normalize();
|
||||
assertSame(vec, vec2);
|
||||
assertEquals(1.0, vec.length(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void add() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void sub() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void scale() {
|
||||
Vector vec = new Vector(4.0, 3.0);
|
||||
assertEquals(5.0, vec.length(), 0.00001);
|
||||
Vector vec2 = vec.scale(10.0);
|
||||
assertSame(vec, vec2);
|
||||
assertEquals(50.0, vec.length(), 0.00001);
|
||||
vec2.scale(-10.0);
|
||||
assertEquals(500.0, vec.length(), 0.00001);
|
||||
assertEquals(-400.0, vec.x, 0.00001);
|
||||
assertEquals(-300.0, vec.y, 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void div() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void dist() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void dot() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void cross() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void rotate() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void morph() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void copy() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void set() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSet() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSet1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setX() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setY() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPunkt() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void len() {
|
||||
Vector vec = new Vector(4.0, 3.0);
|
||||
assertEquals(5.0, vec.length(), 0.00001);
|
||||
vec = new Vector(1.0, 0.0);
|
||||
assertEquals(1.0, vec.length(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lenSq() {
|
||||
Vector vec = new Vector(4.0, 3.0);
|
||||
assertEquals(25.0, vec.lengthSq(), 0.00001);
|
||||
vec = new Vector(1.0, 0.0);
|
||||
assertEquals(1.0, vec.lengthSq(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setLen() {
|
||||
Vector vec = new Vector(2.0, 5.4);
|
||||
Vector vec2 = vec.setLength(10);
|
||||
assertEquals(10.0, vec.length(), 0.00001);
|
||||
assertSame(vec, vec2);
|
||||
vec.setLength(-10);
|
||||
assertEquals(10.0, vec.length(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNormalize() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAdd() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAdd1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSub() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSub1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testScale() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDiv() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDist() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDot() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDot1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCross() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void limit() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLimit() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void angle() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRotate() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMorph() {
|
||||
}
|
||||
|
||||
}
|
||||
202
src/test/java/schule/ngb/zm/shapes/ShapeTest.java
Normal file
202
src/test/java/schule/ngb/zm/shapes/ShapeTest.java
Normal file
@@ -0,0 +1,202 @@
|
||||
package schule.ngb.zm.shapes;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import schule.ngb.zm.Options;
|
||||
|
||||
import static schule.ngb.zm.Options.Direction.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
|
||||
class ShapeTest {
|
||||
|
||||
class TestShape extends Shape {
|
||||
|
||||
public TestShape() {
|
||||
super(42, 131);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWidth() {
|
||||
return 182;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return 235;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shape copy() {
|
||||
return new TestShape();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.awt.Shape getShape() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShape() {
|
||||
Shape s = new TestShape();
|
||||
|
||||
assertEquals(42, s.getX());
|
||||
assertEquals(131, s.getY());
|
||||
assertEquals(182, s.getWidth());
|
||||
assertEquals(235, s.getHeight());
|
||||
|
||||
assertEquals(Options.Direction.CENTER, s.getAnchor());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAnchorPoint() {
|
||||
Shape s = new TestShape();
|
||||
|
||||
assertEquals(0.0, s.getAnchorPoint(CENTER).getX(), 0.00001);
|
||||
assertEquals(0.0, s.getAnchorPoint(CENTER).getY(), 0.00001);
|
||||
|
||||
assertEquals(0.0, s.getAnchorPoint(UP).getX(), 0.00001);
|
||||
assertEquals(-117.5, s.getAnchorPoint(UP).getY(), 0.00001);
|
||||
|
||||
assertEquals(-91.0, s.getAnchorPoint(LEFT).getX(), 0.00001);
|
||||
assertEquals(0.0, s.getAnchorPoint(LEFT).getY(), 0.00001);
|
||||
|
||||
assertEquals(91.0, s.getAnchorPoint(SOUTHEAST).getX(), 0.00001);
|
||||
assertEquals(117.5, s.getAnchorPoint(SOUTHEAST).getY(), 0.00001);
|
||||
|
||||
s.setAnchor(DOWN);
|
||||
|
||||
assertEquals(0.0, s.getAnchorPoint(DOWN).getX(), 0.00001);
|
||||
assertEquals(0.0, s.getAnchorPoint(DOWN).getY(), 0.00001);
|
||||
|
||||
assertEquals(0.0, s.getAnchorPoint(CENTER).getX(), 0.00001);
|
||||
assertEquals(-117.5, s.getAnchorPoint(CENTER).getY(), 0.00001);
|
||||
|
||||
assertEquals(0.0, s.getAnchorPoint(UP).getX(), 0.00001);
|
||||
assertEquals(-235.0, s.getAnchorPoint(UP).getY(), 0.00001);
|
||||
|
||||
assertEquals(-91.0, s.getAnchorPoint(LEFT).getX(), 0.00001);
|
||||
assertEquals(-117.5, s.getAnchorPoint(LEFT).getY(), 0.00001);
|
||||
|
||||
assertEquals(91.0, s.getAnchorPoint(SOUTHEAST).getX(), 0.00001);
|
||||
assertEquals(0-0, s.getAnchorPoint(SOUTHEAST).getY(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAbsAnchorPoint() {
|
||||
Shape s = new TestShape();
|
||||
|
||||
assertEquals(42.0, s.getAbsAnchorPoint(CENTER).getX(), 0.00001);
|
||||
assertEquals(131.0, s.getAbsAnchorPoint(CENTER).getY(), 0.00001);
|
||||
|
||||
assertEquals(42.0, s.getAbsAnchorPoint(UP).getX(), 0.00001);
|
||||
assertEquals(13.5, s.getAbsAnchorPoint(UP).getY(), 0.00001);
|
||||
|
||||
assertEquals(-49.0, s.getAbsAnchorPoint(LEFT).getX(), 0.00001);
|
||||
assertEquals(131.0, s.getAbsAnchorPoint(LEFT).getY(), 0.00001);
|
||||
|
||||
assertEquals(133.0, s.getAbsAnchorPoint(SOUTHEAST).getX(), 0.00001);
|
||||
assertEquals(248.5, s.getAbsAnchorPoint(SOUTHEAST).getY(), 0.00001);
|
||||
|
||||
s.setAnchor(DOWN);
|
||||
|
||||
assertEquals(42.0, s.getAbsAnchorPoint(CENTER).getX(), 0.00001);
|
||||
assertEquals(13.5, s.getAbsAnchorPoint(CENTER).getY(), 0.00001);
|
||||
|
||||
assertEquals(42.0, s.getAbsAnchorPoint(UP).getX(), 0.00001);
|
||||
assertEquals(-104.0, s.getAbsAnchorPoint(UP).getY(), 0.00001);
|
||||
|
||||
assertEquals(-49.0, s.getAbsAnchorPoint(LEFT).getX(), 0.00001);
|
||||
assertEquals(13.5, s.getAbsAnchorPoint(LEFT).getY(), 0.00001);
|
||||
|
||||
assertEquals(133.0, s.getAbsAnchorPoint(SOUTHEAST).getX(), 0.00001);
|
||||
assertEquals(131.0, s.getAbsAnchorPoint(SOUTHEAST).getY(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMoveTo() {
|
||||
Shape s1 = new TestShape();
|
||||
Shape s2 = s1.copy();
|
||||
|
||||
s1.moveTo( 100, 200);
|
||||
assertEquals(100.0, s1.x, 0.00001);
|
||||
assertEquals(200.0, s1.y, 0.00001);
|
||||
|
||||
s2.moveTo(s1);
|
||||
assertEquals(100.0, s2.x, 0.00001);
|
||||
assertEquals(200.0, s2.y, 0.00001);
|
||||
|
||||
s2.moveTo(s1, RIGHT);
|
||||
assertEquals(191.0, s2.x, 0.00001);
|
||||
assertEquals(200.0, s2.y, 0.00001);
|
||||
assertEquals(s2.getAbsAnchorPoint(CENTER), s1.getAbsAnchorPoint(RIGHT));
|
||||
assertEquals(s1.getAbsAnchorPoint(CENTER), s2.getAbsAnchorPoint(LEFT));
|
||||
|
||||
s2.moveTo(s1, RIGHT, 10.0);
|
||||
assertEquals(201.0, s2.x, 0.00001);
|
||||
assertEquals(200.0, s2.y, 0.00001);
|
||||
|
||||
s2.moveTo(s1, LEFT);
|
||||
assertEquals(9.0, s2.x, 0.00001);
|
||||
assertEquals(200.0, s2.y, 0.00001);
|
||||
|
||||
s2.moveTo(s1, LEFT, 10.0);
|
||||
assertEquals(-1.0, s2.x, 0.00001);
|
||||
assertEquals(200.0, s2.y, 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAlignTo() {
|
||||
Shape s1 = new TestShape();
|
||||
Shape s2 = new TestShape();
|
||||
|
||||
s1.moveTo(100, 200);
|
||||
|
||||
s2.alignTo(s1, LEFT, 0.0);
|
||||
assertEquals(100.0, s2.getX());
|
||||
assertEquals(131.0, s2.getY());
|
||||
assertEquals(9.0, s2.getAbsAnchorPoint(LEFT).getX(), 0.00001);
|
||||
|
||||
s2.moveTo(300, 400);
|
||||
s2.alignTo(s1, LEFT, 10.0);
|
||||
assertEquals(90.0, s2.getX());
|
||||
assertEquals(400.0, s2.getY());
|
||||
|
||||
s2.alignTo(s1, SOUTHEAST, 0.0);
|
||||
assertEquals(100.0, s2.getX());
|
||||
assertEquals(200.0, s2.getY());
|
||||
|
||||
s2.moveTo(0, 0);
|
||||
s2.alignTo(s1, DOWN, 24.0);
|
||||
assertEquals(0.0, s2.getX());
|
||||
assertEquals(224.0, s2.getY());
|
||||
|
||||
s2.setAnchor(NORTHWEST);
|
||||
s2.moveTo(0, 0);
|
||||
s2.alignTo(s1, DOWN, 24.0);
|
||||
assertEquals(0.0, s2.getX());
|
||||
assertEquals(106.5, s2.getY());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNextTo() {
|
||||
Shape s1 = new TestShape();
|
||||
Shape s2 = new TestShape();
|
||||
|
||||
s2.nextTo(s1, RIGHT, 10.0);
|
||||
assertEquals(234.0, s2.getX());
|
||||
assertEquals(131.0, s2.getY());
|
||||
|
||||
s2.nextTo(s1, LEFT, 10.0);
|
||||
assertEquals(-150.0, s2.getX());
|
||||
assertEquals(131.0, s2.getY());
|
||||
|
||||
s2.nextTo(s1, SOUTHEAST, 10.0);
|
||||
assertEquals(234.0, s2.getX());
|
||||
assertEquals(376.0, s2.getY());
|
||||
}
|
||||
|
||||
}
|
||||
127
src/test/java/schule/ngb/zm/util/ValidatorTest.java
Normal file
127
src/test/java/schule/ngb/zm/util/ValidatorTest.java
Normal file
@@ -0,0 +1,127 @@
|
||||
package schule.ngb.zm.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ValidatorTest {
|
||||
|
||||
@Test
|
||||
void requireNotNull() {
|
||||
StringBuilder sb = new StringBuilder("Message");
|
||||
|
||||
Object o1 = new Object();
|
||||
assertEquals(o1, Validator.requireNotNull(o1));
|
||||
assertEquals(o1, Validator.requireNotNull(o1, "Message"));
|
||||
assertEquals(o1, Validator.requireNotNull(o1, sb));
|
||||
assertEquals(o1, Validator.requireNotNull(o1, ()->"Message"));
|
||||
|
||||
String o2 = null;
|
||||
assertThrowsExactly(NullPointerException.class, () -> Validator.requireNotNull(o2));
|
||||
assertThrowsExactly(NullPointerException.class, () -> Validator.requireNotNull(o2, "Message"));
|
||||
assertThrowsExactly(NullPointerException.class, () -> Validator.requireNotNull(o2, ()->"Message"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requireNotEmpty() {
|
||||
StringBuilder sb = new StringBuilder("Message");
|
||||
|
||||
String s1 = "Content";
|
||||
assertEquals(s1, Validator.requireNotEmpty(s1));
|
||||
assertEquals(s1, Validator.requireNotEmpty(s1, "Message"));
|
||||
assertEquals(s1, Validator.requireNotEmpty(s1, sb));
|
||||
assertEquals(s1, Validator.requireNotEmpty(s1, ()->"Message"));
|
||||
|
||||
String s2 = "";
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotEmpty(s2));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotEmpty(s2, "Message"));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotEmpty(s2, ()->"Message"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void requirePositive() {
|
||||
int i = 1;
|
||||
assertEquals(i, Validator.requirePositive(i));
|
||||
assertEquals(i, Validator.requirePositive(i, "Message"));
|
||||
assertEquals(i, Validator.requirePositive(i, ()->"Message"));
|
||||
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requirePositive(i-1));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requirePositive(i-1, "Message"));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requirePositive(i-1, ()->"Message"));
|
||||
|
||||
double k = 1.0;
|
||||
assertEquals(k, Validator.requirePositive(i));
|
||||
assertEquals(k, Validator.requirePositive(i, "Message"));
|
||||
assertEquals(k, Validator.requirePositive(i, ()->"Message"));
|
||||
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requirePositive(k-1.0));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requirePositive(k-1.0, "Message"));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requirePositive(k-1.0, ()->"Message"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requireNotNegative() {
|
||||
int i = 0;
|
||||
assertEquals(i, Validator.requireNotNegative(i));
|
||||
assertEquals(i, Validator.requireNotNegative(i, "Message"));
|
||||
assertEquals(i, Validator.requireNotNegative(i, ()->"Message"));
|
||||
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotNegative(i-1));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotNegative(i-1, "Message"));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotNegative(i-1, ()->"Message"));
|
||||
|
||||
double k = 0.0;
|
||||
assertEquals(k, Validator.requireNotNegative(i));
|
||||
assertEquals(k, Validator.requireNotNegative(i, "Message"));
|
||||
assertEquals(k, Validator.requireNotNegative(i, ()->"Message"));
|
||||
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotNegative(k-1.0));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotNegative(k-1.0, "Message"));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireNotNegative(k-1.0, ()->"Message"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requireInRange() {
|
||||
int min = 50, max = 100;
|
||||
for( int ii = min; ii < max; ii++ ) {
|
||||
final int i = ii;
|
||||
assertEquals(i, Validator.requireInRange(i, min, max));
|
||||
assertEquals(i, Validator.requireInRange(i, min, max, "Message"));
|
||||
assertEquals(i, Validator.requireInRange(i, min, max, () -> "Message"));
|
||||
}
|
||||
for( int ii = 0; ii < min; ii++ ) {
|
||||
final int i = ii;
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(i, min, max));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(i, min, max));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(i, min, max));
|
||||
}
|
||||
for( int ii = max+1; ii < 2*max; ii++ ) {
|
||||
final int i = ii;
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(i, min, max));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(i, min, max));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(i, min, max));
|
||||
}
|
||||
|
||||
double dmin = 50, dmax = 60;
|
||||
for( double dd = dmin; dd < dmax; dd+=0.1 ) {
|
||||
final double d = dd;
|
||||
assertEquals(d, Validator.requireInRange(d, dmin, dmax));
|
||||
assertEquals(d, Validator.requireInRange(d, dmin, dmax, "Message"));
|
||||
assertEquals(d, Validator.requireInRange(d, dmin, dmax, () -> "Message"));
|
||||
}
|
||||
for( double dd = dmin-10.0; dd < dmin; dd+=0.1 ) {
|
||||
final double d = dd;
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(d, dmin, dmax));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(d, dmin, dmax));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(d, dmin, dmax));
|
||||
}
|
||||
for( double dd = dmax+0.1; dd < dmax+10.0; dd+=0.1 ) {
|
||||
final double d = dd;
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(d, dmin, dmax));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(d, dmin, dmax));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> Validator.requireInRange(d, dmin, dmax));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BIN
src/test/resources/WitchCraftIcons_122_t.PNG
Normal file
BIN
src/test/resources/WitchCraftIcons_122_t.PNG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
Reference in New Issue
Block a user