/** * Brings all values (r,g,b,a) into the range [0.0f, 1.0f]. If a value is above or below this range it is replaced * with the appropriate end of the range. * * @return this color for chaining */ public ColorRGBA clampLocal() { return clamp(this); }
@Test public void testClamp() { final ColorRGBA clr1 = new ColorRGBA(-1, -1, -1, -1); final ColorRGBA clr2 = clr1.clamp(new ColorRGBA()); final ColorRGBA clr3 = clr1.clamp(null); assertNotNull(clr2); assertNotNull(clr3); assertTrue(clr2.getRed() == 0); assertTrue(clr2.getGreen() == 0); assertTrue(clr2.getBlue() == 0); assertTrue(clr2.getAlpha() == 0); clr1.set(2, .5f, 1, 0); clr1.clamp(clr2); assertTrue(clr2.getRed() == 1); assertTrue(clr2.getGreen() == .5f); assertTrue(clr2.getBlue() == 1); assertTrue(clr2.getAlpha() == 0); clr1.set(2, 2, 2, 2); clr1.clampLocal(); assertTrue(clr1.getRed() == 1); assertTrue(clr1.getGreen() == 1); assertTrue(clr1.getBlue() == 1); assertTrue(clr1.getAlpha() == 1); clr1.set(0.5f, 0.5f, 0.5f, 0.5f); assertEquals(clr1, clr1.clamp(null)); }
/** * Brings all values (r,g,b,a) into the range [0.0f, 1.0f]. If a value is above or below this range it is replaced * with the appropriate end of the range. * * @return this color for chaining */ public ColorRGBA clampLocal() { return clamp(this); }