picrate 1.3.0-java → 2.0.0.pre-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/.mvn/wrapper/maven-wrapper.properties +2 -2
- data/CHANGELOG.md +2 -1
- data/Gemfile +3 -1
- data/README.md +4 -2
- data/Rakefile +8 -4
- data/bin/picrate +3 -1
- data/docs/_posts/2019-11-11-getting_started_buster.md +1 -1
- data/lib/picrate.rb +1 -1
- data/lib/picrate/app.rb +10 -3
- data/lib/picrate/creators/parameters.rb +8 -8
- data/lib/picrate/creators/sketch_factory.rb +5 -3
- data/lib/picrate/helper_methods.rb +21 -21
- data/lib/picrate/helpers/numeric.rb +2 -0
- data/lib/picrate/library.rb +5 -1
- data/lib/picrate/library_loader.rb +2 -0
- data/lib/picrate/native_folder.rb +6 -4
- data/lib/picrate/native_loader.rb +3 -0
- data/lib/picrate/runner.rb +1 -0
- data/lib/picrate/version.rb +1 -1
- data/library/boids/boids.rb +17 -8
- data/library/chooser/chooser.rb +10 -9
- data/library/color_group/color_group.rb +2 -0
- data/library/control_panel/control_panel.rb +7 -4
- data/library/dxf/dxf.rb +2 -0
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +2 -0
- data/library/slider/slider.rb +24 -23
- data/library/vector_utils/vector_utils.rb +4 -0
- data/library/video_event/video_event.rb +2 -0
- data/picrate.gemspec +14 -12
- data/pom.rb +15 -15
- data/pom.xml +5 -5
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/MathToolModule.java +1 -1
- data/src/main/java/monkstone/PicrateLibrary.java +8 -8
- data/src/main/java/monkstone/fastmath/Deglut.java +16 -16
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +3 -3
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +12 -12
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -13
- data/src/main/java/processing/awt/PSurfaceAWT.java +0 -20
- data/src/main/java/processing/core/PApplet.java +1949 -2247
- data/src/main/java/processing/core/PConstants.java +180 -180
- data/src/main/java/processing/core/PFont.java +2 -2
- data/src/main/java/processing/core/PGraphics.java +90 -90
- data/src/main/java/processing/core/PImage.java +65 -65
- data/src/main/java/processing/core/PMatrix.java +39 -39
- data/src/main/java/processing/core/PSurface.java +37 -37
- data/src/main/java/processing/core/PVector.java +2 -2
- data/src/main/java/processing/data/FloatDict.java +251 -284
- data/src/main/java/processing/data/TableRow.java +32 -32
- data/src/main/java/processing/dxf/RawDXF.java +3 -3
- data/src/main/java/processing/net/Client.java +1 -1
- data/src/main/java/processing/opengl/PGL.java +3884 -3950
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +38 -21
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +42 -61
- data/test/color_group_test.rb +4 -4
- data/test/deglut_spec_test.rb +2 -0
- data/test/helper_methods_test.rb +41 -13
- data/test/math_tool_test.rb +46 -37
- data/test/respond_to_test.rb +5 -3
- data/test/sketches/key_event.rb +2 -2
- data/test/sketches/library/my_library/my_library.rb +3 -0
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +30 -19
- data/vendors/Rakefile +2 -2
- metadata +29 -17
@@ -3651,7 +3651,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
3651
3651
|
* Ported from the implementation of textCharShapeImpl() in 1.5.1
|
3652
3652
|
*
|
3653
3653
|
* <EM>No attempt has been made to optimize this code</EM>
|
3654
|
-
*
|
3654
|
+
*
|
3655
3655
|
* TODO: Implement a FontShape class where each glyph is tessellated and
|
3656
3656
|
* stored inside a larger PShapeOpenGL object (which needs to be expanded as
|
3657
3657
|
* new glyphs are added and exceed the initial capacity in a similar way as
|
@@ -3659,18 +3659,18 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
3659
3659
|
* in shape mode, then the correct sequences of vertex indices are computed
|
3660
3660
|
* (akin to the texcoords in the texture case) and used to draw only those
|
3661
3661
|
* parts of the PShape object that are required for the text.
|
3662
|
-
*
|
3662
|
+
*
|
3663
3663
|
*
|
3664
3664
|
* Some issues of the original implementation probably remain, so they are
|
3665
3665
|
* reproduced below:
|
3666
|
-
*
|
3666
|
+
*
|
3667
3667
|
* Also a problem where some fonts seem to be a bit slight, as if the
|
3668
3668
|
* control points aren't being mapped quite correctly. Probably doing
|
3669
3669
|
* something dumb that the control points don't map to P5's control
|
3670
3670
|
* points. Perhaps it's returning b-spline data from the TrueType font?
|
3671
3671
|
* Though it seems like that would make a lot of garbage rather than
|
3672
3672
|
* just a little flattening.
|
3673
|
-
*
|
3673
|
+
*
|
3674
3674
|
* There also seems to be a bug that is causing a line (but not a filled
|
3675
3675
|
* triangle) back to the origin on some letters (i.e. a capital L when
|
3676
3676
|
* tested with Akzidenz Grotesk Light). But this won't be visible
|
@@ -5352,7 +5352,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
5352
5352
|
// showWarning() and showException() available from PGraphics.
|
5353
5353
|
|
5354
5354
|
/**
|
5355
|
-
* Report on anything from glError().Don't use this inside glBegin/glEnd
|
5355
|
+
* Report on anything from glError().Don't use this inside glBegin/glEnd
|
5356
5356
|
* otherwise it'll throw an GL_INVALID_OPERATION error.
|
5357
5357
|
* @param where
|
5358
5358
|
*/
|
@@ -6366,11 +6366,11 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
6366
6366
|
|
6367
6367
|
|
6368
6368
|
/**
|
6369
|
-
* Not an approved function, this will change or be removed in the future.This
|
6370
|
-
* utility method returns the texture associated to the renderer's. drawing
|
6371
|
-
* surface, making sure is updated to reflect the current contents off the
|
6369
|
+
* Not an approved function, this will change or be removed in the future.This
|
6370
|
+
* utility method returns the texture associated to the renderer's. drawing
|
6371
|
+
* surface, making sure is updated to reflect the current contents off the
|
6372
6372
|
* screen (or offscreen drawing surface).
|
6373
|
-
* @return
|
6373
|
+
* @return
|
6374
6374
|
*/
|
6375
6375
|
public Texture getTexture() {
|
6376
6376
|
return getTexture(true);
|
@@ -6380,7 +6380,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
6380
6380
|
/**
|
6381
6381
|
* Not an approved function either, don't use it.
|
6382
6382
|
* @param load
|
6383
|
-
* @return
|
6383
|
+
* @return
|
6384
6384
|
*/
|
6385
6385
|
public Texture getTexture(boolean load) {
|
6386
6386
|
if (load) loadTexture();
|
@@ -6393,7 +6393,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
6393
6393
|
* creating and/or updating it if needed.
|
6394
6394
|
*
|
6395
6395
|
* @param img the image to have a texture metadata associated to it
|
6396
|
-
* @return
|
6396
|
+
* @return
|
6397
6397
|
*/
|
6398
6398
|
public Texture getTexture(PImage img) {
|
6399
6399
|
Texture tex = (Texture)initCache(img);
|
@@ -6419,7 +6419,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
6419
6419
|
/**
|
6420
6420
|
* Not an approved function, test its use in libraries to grab the FB objects
|
6421
6421
|
* for offscreen PGraphics.
|
6422
|
-
* @return
|
6422
|
+
* @return
|
6423
6423
|
*/
|
6424
6424
|
public FrameBuffer getFrameBuffer() {
|
6425
6425
|
return getFrameBuffer(false);
|
@@ -6478,7 +6478,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
6478
6478
|
* This utility method creates a texture for the provided image, and adds it
|
6479
6479
|
* to the metadata cache of the image.
|
6480
6480
|
* @param img the image to have a texture metadata associated to it
|
6481
|
-
* @return
|
6481
|
+
* @return
|
6482
6482
|
*/
|
6483
6483
|
protected Texture addTexture(PImage img) {
|
6484
6484
|
Texture.Parameters params =
|
@@ -6892,6 +6892,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
6892
6892
|
OPENGL_VERSION = pgl.getString(PGL.VERSION);
|
6893
6893
|
OPENGL_EXTENSIONS = pgl.getString(PGL.EXTENSIONS);
|
6894
6894
|
GLSL_VERSION = pgl.getString(PGL.SHADING_LANGUAGE_VERSION);
|
6895
|
+
|
6895
6896
|
npotTexSupported = pgl.hasNpotTexSupport();
|
6896
6897
|
autoMipmapGenSupported = pgl.hasAutoMipmapGenSupport();
|
6897
6898
|
fboMultisampleSupported = pgl.hasFboMultisampleSupport();
|
@@ -6899,28 +6900,45 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
6899
6900
|
anisoSamplingSupported = pgl.hasAnisoSamplingSupport();
|
6900
6901
|
readBufferSupported = pgl.hasReadBuffer();
|
6901
6902
|
drawBufferSupported = pgl.hasDrawBuffer();
|
6903
|
+
|
6902
6904
|
try {
|
6903
6905
|
pgl.blendEquation(PGL.FUNC_ADD);
|
6904
6906
|
blendEqSupported = true;
|
6905
6907
|
} catch (Exception e) {
|
6906
6908
|
blendEqSupported = false;
|
6907
6909
|
}
|
6910
|
+
|
6908
6911
|
depthBits = pgl.getDepthBits();
|
6909
6912
|
stencilBits = pgl.getStencilBits();
|
6913
|
+
|
6910
6914
|
pgl.getIntegerv(PGL.MAX_TEXTURE_SIZE, intBuffer);
|
6911
6915
|
maxTextureSize = intBuffer.get(0);
|
6912
|
-
|
6913
|
-
|
6916
|
+
|
6917
|
+
// work around runtime exceptions in Broadcom's VC IV driver
|
6918
|
+
if (false == OPENGL_RENDERER.equals("VideoCore IV HW")) {
|
6919
|
+
pgl.getIntegerv(PGL.MAX_SAMPLES, intBuffer);
|
6920
|
+
maxSamples = intBuffer.get(0);
|
6921
|
+
}
|
6922
|
+
|
6914
6923
|
if (anisoSamplingSupported) {
|
6915
6924
|
pgl.getFloatv(PGL.MAX_TEXTURE_MAX_ANISOTROPY, floatBuffer);
|
6916
6925
|
maxAnisoAmount = floatBuffer.get(0);
|
6917
6926
|
}
|
6918
|
-
|
6919
|
-
|
6920
|
-
|
6921
|
-
|
6922
|
-
|
6927
|
+
|
6928
|
+
// overwrite the default shaders with vendor specific versions
|
6929
|
+
// if needed
|
6930
|
+
if (OPENGL_RENDERER.equals("VideoCore IV HW")) { // Broadcom's binary driver for Raspberry Pi
|
6931
|
+
defLightShaderVertURL =
|
6932
|
+
PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/LightVert-brcm.glsl");
|
6933
|
+
defTexlightShaderVertURL =
|
6934
|
+
PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/TexLightVert-brcm.glsl");
|
6935
|
+
} else if (OPENGL_RENDERER.contains("VC4")) { // Mesa driver for same hardware
|
6936
|
+
defLightShaderVertURL =
|
6937
|
+
PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/LightVert-vc4.glsl");
|
6938
|
+
defTexlightShaderVertURL =
|
6939
|
+
PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/TexLightVert-vc4.glsl");
|
6923
6940
|
}
|
6941
|
+
|
6924
6942
|
glParamsRead = true;
|
6925
6943
|
}
|
6926
6944
|
|
@@ -13142,7 +13160,6 @@ public class PGraphicsOpenGL extends PGraphics {
|
|
13142
13160
|
else if (type == PGL.TRIANGLES) primitive = TRIANGLES;
|
13143
13161
|
}
|
13144
13162
|
|
13145
|
-
@Override
|
13146
13163
|
public void end() {
|
13147
13164
|
if (PGL.MAX_VERTEX_INDEX1 <= vertFirst + vertCount) {
|
13148
13165
|
// We need a new index block for the new batch of
|
@@ -438,21 +438,6 @@ public class PSurfaceJOGL implements PSurface {
|
|
438
438
|
*
|
439
439
|
*/
|
440
440
|
protected void initAnimator() {
|
441
|
-
if (PApplet.platform == PConstants.WINDOWS) {
|
442
|
-
// Force Windows to keep timer resolution high by
|
443
|
-
// sleeping for time which is not a multiple of 10 ms.
|
444
|
-
// See section "Clocks and Timers on Windows":
|
445
|
-
// https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks
|
446
|
-
Thread highResTimerThread = new Thread(() -> {
|
447
|
-
try {
|
448
|
-
Thread.sleep(Long.MAX_VALUE);
|
449
|
-
} catch (InterruptedException ignore) {
|
450
|
-
}
|
451
|
-
}, "HighResTimerThread");
|
452
|
-
highResTimerThread.setDaemon(true);
|
453
|
-
highResTimerThread.start();
|
454
|
-
}
|
455
|
-
|
456
441
|
animator = new FPSAnimator(window, 60);
|
457
442
|
drawException = null;
|
458
443
|
animator.setUncaughtExceptionHandler((final GLAnimatorControl animator1, final GLAutoDrawable drawable, final Throwable cause) -> {
|
@@ -462,34 +447,31 @@ public class PSurfaceJOGL implements PSurface {
|
|
462
447
|
}
|
463
448
|
});
|
464
449
|
|
465
|
-
drawExceptionHandler = new Thread(
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
} else {
|
486
|
-
throw new RuntimeException(cause);
|
487
|
-
}
|
488
|
-
}
|
489
|
-
} catch (InterruptedException e) {
|
490
|
-
}
|
450
|
+
drawExceptionHandler = new Thread(() -> {
|
451
|
+
synchronized (drawExceptionMutex) {
|
452
|
+
try {
|
453
|
+
while (drawException == null) {
|
454
|
+
drawExceptionMutex.wait();
|
455
|
+
}
|
456
|
+
// System.err.println("Caught exception: " + drawException.getMessage());
|
457
|
+
if (drawException != null) {
|
458
|
+
Throwable cause = drawException.getCause();
|
459
|
+
if (cause instanceof ThreadDeath) {
|
460
|
+
// System.out.println("caught ThreadDeath");
|
461
|
+
// throw (ThreadDeath)cause;
|
462
|
+
} else if (cause instanceof RuntimeException) {
|
463
|
+
throw (RuntimeException) cause;
|
464
|
+
} else if (cause instanceof UnsatisfiedLinkError) {
|
465
|
+
throw new UnsatisfiedLinkError(cause.getMessage());
|
466
|
+
} else if (cause == null) {
|
467
|
+
throw new RuntimeException(drawException.getMessage());
|
468
|
+
} else {
|
469
|
+
throw new RuntimeException(cause);
|
491
470
|
}
|
471
|
+
}
|
472
|
+
} catch (InterruptedException e) {
|
492
473
|
}
|
474
|
+
}
|
493
475
|
});
|
494
476
|
drawExceptionHandler.start();
|
495
477
|
}
|
@@ -532,7 +514,7 @@ public class PSurfaceJOGL implements PSurface {
|
|
532
514
|
*
|
533
515
|
*/
|
534
516
|
protected void initIcons() {
|
535
|
-
IOUtil.ClassResources res
|
517
|
+
IOUtil.ClassResources res;
|
536
518
|
if (PJOGL.icons == null || PJOGL.icons.length == 0) {
|
537
519
|
// Default Processing icons
|
538
520
|
final int[] sizes = {16, 32, 48, 64, 128, 256, 512};
|
@@ -560,7 +542,7 @@ public class PSurfaceJOGL implements PSurface {
|
|
560
542
|
@SuppressWarnings("resource")
|
561
543
|
private String resourceFilename(String filename) {
|
562
544
|
// The code below comes from PApplet.createInputRaw() with a few adaptations
|
563
|
-
InputStream stream
|
545
|
+
InputStream stream;
|
564
546
|
try {
|
565
547
|
// First see if it's in a data folder. This may fail by throwing
|
566
548
|
// a SecurityException. If so, this whole block will be skipped.
|
@@ -592,10 +574,10 @@ public class PSurfaceJOGL implements PSurface {
|
|
592
574
|
}
|
593
575
|
|
594
576
|
stream = new FileInputStream(file);
|
595
|
-
|
577
|
+
// if (stream != null) {
|
596
578
|
stream.close();
|
597
579
|
return file.getCanonicalPath();
|
598
|
-
|
580
|
+
// }
|
599
581
|
|
600
582
|
// have to break these out because a general Exception might
|
601
583
|
// catch the RuntimeException being thrown above
|
@@ -641,29 +623,29 @@ public class PSurfaceJOGL implements PSurface {
|
|
641
623
|
try {
|
642
624
|
String path = sketch.dataPath(filename);
|
643
625
|
stream = new FileInputStream(path);
|
644
|
-
|
626
|
+
// if (stream != null) {
|
645
627
|
stream.close();
|
646
628
|
return path;
|
647
|
-
|
629
|
+
// }
|
648
630
|
} catch (IOException e2) {
|
649
631
|
}
|
650
632
|
|
651
633
|
try {
|
652
634
|
String path = sketch.sketchPath(filename);
|
653
635
|
stream = new FileInputStream(path);
|
654
|
-
if (stream != null) {
|
636
|
+
//if (stream != null) {
|
655
637
|
stream.close();
|
656
638
|
return path;
|
657
|
-
|
639
|
+
// }
|
658
640
|
} catch (IOException e) {
|
659
641
|
} // ignored
|
660
642
|
|
661
643
|
try {
|
662
644
|
stream = new FileInputStream(filename);
|
663
|
-
|
645
|
+
// if (stream != null) {
|
664
646
|
stream.close();
|
665
647
|
return filename;
|
666
|
-
|
648
|
+
// }
|
667
649
|
} catch (IOException e1) {
|
668
650
|
}
|
669
651
|
|
@@ -1389,16 +1371,15 @@ public class PSurfaceJOGL implements PSurface {
|
|
1389
1371
|
}
|
1390
1372
|
|
1391
1373
|
static Map<Integer, CursorInfo> cursors = new HashMap<>();
|
1392
|
-
static Map<Integer, String> cursorNames =
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
}
|
1374
|
+
static Map<Integer, String> cursorNames = Map.of(
|
1375
|
+
PConstants.ARROW, "arrow",
|
1376
|
+
PConstants.CROSS, "cross",
|
1377
|
+
PConstants.WAIT, "wait",
|
1378
|
+
PConstants.MOVE, "move",
|
1379
|
+
PConstants.HAND, "hand",
|
1380
|
+
PConstants.TEXT, "text"
|
1381
|
+
);
|
1382
|
+
|
1402
1383
|
|
1403
1384
|
@Override
|
1404
1385
|
public void setCursor(int kind) {
|
data/test/color_group_test.rb
CHANGED
@@ -9,21 +9,21 @@ java_import Java::Monkstone::ColorUtil
|
|
9
9
|
Dir.chdir(File.dirname(__FILE__))
|
10
10
|
|
11
11
|
PALETTE = %w[#FFFFFF #FF0000 #0000FF].freeze
|
12
|
-
COLORS = [
|
12
|
+
COLORS = [16_777_215, 16_711_680, 255].to_java(:int)
|
13
13
|
|
14
14
|
class ColorGroupTest < Minitest::Test
|
15
15
|
def test_new
|
16
16
|
group = ColorGroup.new(COLORS)
|
17
|
-
assert group.
|
17
|
+
assert group.is_a? ColorGroup
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_web_array
|
21
21
|
group = ColorGroup.from_web_array(PALETTE)
|
22
|
-
assert group.
|
22
|
+
assert group.is_a? ColorGroup
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_ruby_string
|
26
|
-
p5array = [
|
26
|
+
p5array = [16_777_215, 16_711_680, 255]
|
27
27
|
group = ColorGroup.new(COLORS)
|
28
28
|
code_string = "%w[#FFFFFF #FF0000 #0000FF]\n"
|
29
29
|
result = group.ruby_code
|
data/test/deglut_spec_test.rb
CHANGED
data/test/helper_methods_test.rb
CHANGED
@@ -10,40 +10,68 @@ include MathTool
|
|
10
10
|
Dir.chdir(File.dirname(__FILE__))
|
11
11
|
|
12
12
|
class HelperMethodsTest < Minitest::Test
|
13
|
-
|
14
|
-
|
15
|
-
def test_hex_color
|
13
|
+
ARRAY = %w[albatross dog horse].freeze
|
14
|
+
def test_hex_color
|
16
15
|
col_double = 0.5
|
17
16
|
hexcolor = 0xFFCC6600
|
18
17
|
dodgy_hexstring = '*56666'
|
19
18
|
hexstring = '#CC6600'
|
20
19
|
assert hex_color(col_double) == 0.5, 'double as a color'
|
21
|
-
assert hex_color(hexcolor) == -
|
22
|
-
assert hex_color(hexstring) == -
|
20
|
+
assert hex_color(hexcolor) == -3_381_760, 'hexadecimal fixnum color'
|
21
|
+
assert hex_color(hexstring) == -3_381_760, 'hexadecimal string color'
|
23
22
|
assert_raises(StandardError, 'Dodgy Hexstring') do
|
24
23
|
hex_color(dodgy_hexstring)
|
25
24
|
end
|
26
25
|
assert_raises(StandardError, 'Dodgy Color Conversion') do
|
27
26
|
hex_color([])
|
28
27
|
end
|
29
|
-
|
28
|
+
end
|
30
29
|
|
31
30
|
def test_dist
|
32
|
-
ax
|
31
|
+
ax = 0
|
32
|
+
ay = 0
|
33
|
+
bx = 1.0
|
34
|
+
by = 1.0
|
33
35
|
assert_in_epsilon(dist(ax, ay, bx, by), Math.sqrt(2), epsilon = 0.0001, msg = '2D distance')
|
34
36
|
by = 0.0
|
35
37
|
assert_in_epsilon(dist(ax, ay, bx, by), 1.0, epsilon = 0.0001, msg = 'when y dimension is zero')
|
36
|
-
ax
|
38
|
+
ax = 0
|
39
|
+
ay = 0
|
40
|
+
bx = 0.0
|
41
|
+
by = 0.0
|
37
42
|
assert_in_epsilon(dist(ax, ay, bx, by), 0.0, epsilon = 0.0001, msg = 'when x and y dimension are zero')
|
38
|
-
ax
|
43
|
+
ax = 1
|
44
|
+
ay = 1
|
45
|
+
bx = -2.0
|
46
|
+
by = -3.0
|
39
47
|
assert_in_epsilon(dist(ax, ay, bx, by), 5.0, epsilon = 0.0001, msg = 'classic triangle dimensions')
|
40
|
-
ax
|
48
|
+
ax = -1
|
49
|
+
ay = -1
|
50
|
+
bx = 100
|
51
|
+
by = 2.0
|
52
|
+
cx = 3.0
|
53
|
+
cy = 100
|
41
54
|
assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 5.0, epsilon = 0.0001, msg = 'classic triangle dimensions')
|
42
|
-
ax
|
55
|
+
ax = 0
|
56
|
+
ay = 0
|
57
|
+
bx = -1.0
|
58
|
+
by = -1.0
|
59
|
+
cx = 0
|
60
|
+
cy = 0
|
43
61
|
assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), Math.sqrt(2), epsilon = 0.0001, msg = '2D distance')
|
44
|
-
ax
|
62
|
+
ax = 0
|
63
|
+
ay = 0
|
64
|
+
bx = 0.0
|
65
|
+
by = 0.0
|
66
|
+
cx = 0
|
67
|
+
cy = 0
|
45
68
|
assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 0.0)
|
46
|
-
ax
|
69
|
+
ax = 0
|
70
|
+
ay = 0
|
71
|
+
bx = 1.0
|
72
|
+
by = 0.0
|
73
|
+
cx = 0
|
74
|
+
cy = 0
|
47
75
|
assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 1.0, epsilon = 0.0001, msg = 'when x and z dimension are zero')
|
48
76
|
end
|
49
77
|
|
data/test/math_tool_test.rb
CHANGED
@@ -1,73 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'test_helper'
|
2
4
|
|
3
5
|
Java::Monkstone::PicrateLibrary.new.load(JRuby.runtime, false)
|
4
6
|
|
5
7
|
# include Processing::HelperMethods
|
6
8
|
|
7
|
-
|
8
9
|
Dir.chdir(File.dirname(__FILE__))
|
9
|
-
|
10
|
-
class
|
11
|
-
|
12
|
-
|
10
|
+
# Test processing map functions
|
11
|
+
class ProcessingMapTest < Minitest::Test
|
12
|
+
include MathTool
|
13
|
+
def test_map1d
|
13
14
|
x = [0, 5, 7.5, 10]
|
14
15
|
range1 = (0..10)
|
15
16
|
range2 = (100..1)
|
16
17
|
range3 = (0..10)
|
17
18
|
range4 = (5..105)
|
18
|
-
assert_in_delta(map1d(x[0], range1, range2), 100,
|
19
|
-
assert_in_delta(map1d(x[1], range1, range2), 50.5,
|
20
|
-
assert_in_delta(map1d(x[2], range3, range4), 80.0,
|
21
|
-
assert_in_delta(map1d(x[3], range1, range2), 1,
|
22
|
-
|
19
|
+
assert_in_delta(map1d(x[0], range1, range2), 100, 0.00001, 'map to first')
|
20
|
+
assert_in_delta(map1d(x[1], range1, range2), 50.5, 0.00001, 'map to reversed intermediate')
|
21
|
+
assert_in_delta(map1d(x[2], range3, range4), 80.0, 0.00001, 'map to intermediate')
|
22
|
+
assert_in_delta(map1d(x[3], range1, range2), 1, 0.00001, 'map to last')
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
+
# as map1d except not using range input
|
26
|
+
def test_p5map
|
25
27
|
x = [0, 5, 7.5, 10]
|
26
28
|
range1 = (0..10)
|
27
29
|
range2 = (100..1)
|
28
30
|
range3 = (0..10)
|
29
31
|
range4 = (5..105)
|
30
|
-
assert_in_delta(p5map(x[0], range1.first, range1.last, range2.first, range2.last), 100,
|
31
|
-
assert_in_delta(p5map(x[1], range1.first, range1.last, range2.first, range2.last), 50.5,
|
32
|
-
assert_in_delta(p5map(x[2], range3.first, range3.last, range4.first, range4.last), 80.0,
|
33
|
-
assert_in_delta(p5map(x[3], range1.first, range1.last, range2.first, range2.last), 1,
|
32
|
+
assert_in_delta(p5map(x[0], range1.first, range1.last, range2.first, range2.last), 100, 0.00001)
|
33
|
+
assert_in_delta(p5map(x[1], range1.first, range1.last, range2.first, range2.last), 50.5, 0.00001)
|
34
|
+
assert_in_delta(p5map(x[2], range3.first, range3.last, range4.first, range4.last), 80.0, 0.00001)
|
35
|
+
assert_in_delta(p5map(x[3], range1.first, range1.last, range2.first, range2.last), 1, 0.00001)
|
34
36
|
end
|
35
37
|
|
36
38
|
def test_norm
|
37
39
|
x = [10, 140, 210]
|
38
|
-
start0
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
assert_in_delta(norm(x[
|
40
|
+
start0 = 30
|
41
|
+
last0 = 200
|
42
|
+
start_int = 0
|
43
|
+
last_int = 200
|
44
|
+
assert_in_delta(norm(x[0], start0, last0), -0.11764705882352941, 0.00001, 'unclamped map')
|
45
|
+
assert_in_delta(norm(x[1], start_int, last_int), 0.7, 0.00001, 'map to intermediate')
|
46
|
+
assert_in_delta(norm(x[2], start_int, last_int), 1.05, 0.00001, 'unclamped map')
|
43
47
|
end
|
44
48
|
|
45
49
|
def test_norm_strict
|
46
50
|
x = [10, 140, 210]
|
47
|
-
assert_in_delta(norm_strict(x[2], x[0], x[1]), 1.0,
|
48
|
-
assert_in_delta(norm_strict(x[2], x[1], x[0]), 0.0,
|
49
|
-
assert_in_delta(norm_strict(x[1], x[0], x[2]), 0.65,
|
51
|
+
assert_in_delta(norm_strict(x[2], x[0], x[1]), 1.0, 0.00001, 'clamped map to 0..1.0')
|
52
|
+
assert_in_delta(norm_strict(x[2], x[1], x[0]), 0.0, 0.00001, 'clamped map to 0..1.0')
|
53
|
+
assert_in_delta(norm_strict(x[1], x[0], x[2]), 0.65, 0.00001, 'clamped map to 0..1.0')
|
50
54
|
end
|
51
55
|
|
52
|
-
|
56
|
+
# behaviour is deliberately different to processing which is unclamped
|
57
|
+
def test_lerp
|
53
58
|
x = [0.5, 0.8, 2.0]
|
54
|
-
start0
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
assert_in_delta(lerp(
|
59
|
+
start0 = 300
|
60
|
+
last0 = 200
|
61
|
+
start_int = 0
|
62
|
+
last_int = 200
|
63
|
+
assert_in_delta(lerp(start0, last0, x[0]), 250, 0.00001, 'produces a intermediate value of a reversed range')
|
64
|
+
assert_in_delta(lerp(start_int, last_int, x[1]), 160, 0.00001, 'lerps to an intermediate value')
|
65
|
+
assert_in_delta(lerp(start_int, last_int, x[2]), 200, 0.00001, 'lerps to the last value of a range')
|
59
66
|
end
|
60
67
|
|
61
68
|
def test_constrain
|
62
69
|
x_int = [15, 2_500, -2_500]
|
63
|
-
start_int
|
64
|
-
|
65
|
-
assert_in_delta(constrain(x_int[
|
66
|
-
assert_in_delta(constrain(x_int[
|
70
|
+
start_int = 0
|
71
|
+
last_int = 200
|
72
|
+
assert_in_delta(constrain(x_int[0], start_int, last_int), 15, 0.00001)
|
73
|
+
assert_in_delta(constrain(x_int[1], start_int, last_int), 200, 0.00001)
|
74
|
+
assert_in_delta(constrain(x_int[2], start_int, last_int), 0, 0.00001)
|
67
75
|
xf = [15.0, 2_500.0, -2_500.0]
|
68
|
-
startf
|
69
|
-
|
70
|
-
assert_in_delta(constrain(xf[
|
71
|
-
assert_in_delta(constrain(xf[
|
76
|
+
startf = 0
|
77
|
+
lastf = 200.0
|
78
|
+
assert_in_delta(constrain(xf[0], startf, lastf), 15.0, 0.00001, 'constrain to 0..200')
|
79
|
+
assert_in_delta(constrain(xf[1], startf, lastf), 200.0, 0.00001, 'constrain to 0..200')
|
80
|
+
assert_in_delta(constrain(xf[2], startf, lastf), 0.0, 0.00001, 'constrain to 0..200')
|
72
81
|
end
|
73
82
|
end
|