/** * Interpolates between the given colors using the * {@link ColorRGBA#lerpLocal(ReadOnlyColorRGBA, ReadOnlyColorRGBA, float)} method. */ @Override protected void interpolate(final ReadOnlyColorRGBA from, final ReadOnlyColorRGBA to, final double delta, final Mesh caller) { assert (null != from) : "parameter 'from' can not be null"; assert (null != to) : "parameter 'to' can not be null"; assert (null != caller) : "parameter 'caller' can not be null"; final ColorRGBA color = ColorRGBA.fetchTempInstance().set(caller.getDefaultColor()); color.lerpLocal(from, to, (float) delta); caller.setDefaultColor(color); ColorRGBA.releaseTempInstance(color); }
/** * Interpolates between the given colors using the * {@link ColorRGBA#lerpLocal(ReadOnlyColorRGBA, ReadOnlyColorRGBA, float)} method. */ @Override protected void interpolate(final ReadOnlyColorRGBA from, final ReadOnlyColorRGBA to, final double delta, final Mesh caller) { assert (null != from) : "parameter 'from' can not be null"; assert (null != to) : "parameter 'to' can not be null"; assert (null != caller) : "parameter 'caller' can not be null"; final ColorRGBA color = ColorRGBA.fetchTempInstance().set(caller.getDefaultColor()); color.lerpLocal(from, to, (float) delta); caller.setDefaultColor(color); ColorRGBA.releaseTempInstance(color); }
@Test public void testLerp() { final ColorRGBA clr1 = new ColorRGBA(8, 3, -2, 2); final ColorRGBA clr2 = new ColorRGBA(2, 1, 0, -2); assertEquals(new ColorRGBA(5, 2, -1, 0), clr1.lerp(clr2, 0.5f, null)); assertEquals(new ColorRGBA(5, 2, -1, 0), clr1.lerp(clr2, 0.5f, new ColorRGBA())); assertEquals(new ColorRGBA(5, 2, -1, 0), ColorRGBA.lerp(clr1, clr2, 0.5f, null)); assertEquals(new ColorRGBA(5, 2, -1, 0), ColorRGBA.lerp(clr1, clr2, 0.5f, new ColorRGBA())); clr1.set(14, 5, 4, 2); clr1.lerpLocal(clr2, 0.25f); assertEquals(new ColorRGBA(11, 4, 3, 1), clr1); clr1.set(15, 7, 6, 8); final ColorRGBA clr3 = new ColorRGBA(-1, -1, -1, -1); clr3.lerpLocal(clr1, clr2, 0.5f); assertEquals(new ColorRGBA(8.5f, 4.0f, 3.0f, 3.0f), clr3); // coverage assertEquals(clr1.lerp(clr1, .25f, null), clr1); assertEquals(clr2.lerpLocal(clr2, .25f), clr2); assertEquals(clr2.lerpLocal(clr2, clr2, .25f), clr2); assertEquals(ColorRGBA.lerp(clr1, clr1, .25f, null), clr1); }