Skip to content

Commit 9a1398c

Browse files
committed
float dependency removed in M34d and CU
1 parent f9da8f1 commit 9a1398c

File tree

3 files changed

+39
-51
lines changed

3 files changed

+39
-51
lines changed

sources/net.sf.j2s.java.core/src/javajs/img/GifEncoder.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@
6767

6868
package javajs.img;
6969

70+
import java.io.IOException;
71+
import java.util.Hashtable;
72+
import java.util.Map;
73+
7074
import javajs.util.CU;
7175
import javajs.util.Lst;
7276
import javajs.util.M3;
7377
import javajs.util.P3;
7478

75-
import java.util.Hashtable;
76-
import java.util.Map;
77-
import java.io.IOException;
78-
7979
/**
8080
*
8181
* GifEncoder extensively adapted for Jmol by Bob Hanson
@@ -212,6 +212,7 @@ protected void close() {
212212
* a color point in normalized L*a*b space with a flag indicating whether it
213213
* is the background color
214214
*/
215+
@SuppressWarnings("serial")
215216
private class ColorItem extends P3 {
216217
/**
217218
*
@@ -606,7 +607,7 @@ else if (errp.x == Float.MAX_VALUE) // reuse
606607
// these could be static, but that just makes for more JavaScript code
607608

608609
protected P3 toLABnorm(int rgb) {
609-
P3 lab = CU.colorPtFromInt(rgb, null);
610+
P3 lab = P3.new3((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF);
610611
rgbToXyz(lab, lab);
611612
xyzToLab(lab, lab);
612613
// normalize to 0-100

sources/net.sf.j2s.java.core/src/javajs/util/CU.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ public static int getArgbFromString(String strColor) {
398398
.length() - 1), ",");
399399
if (tokens.length != 3)
400400
return 0;
401-
float red = PT.parseFloat(tokens[0]);
402-
float grn = PT.parseFloat(tokens[1]);
403-
float blu = PT.parseFloat(tokens[2]);
401+
double red = PT.parseDouble(tokens[0]);
402+
double grn = PT.parseDouble(tokens[1]);
403+
double blu = PT.parseDouble(tokens[2]);
404404
return colorTriadToFFRGB(red, grn, blu);
405405
}
406406
switch (len) {
@@ -429,7 +429,7 @@ public static int getArgbFromString(String strColor) {
429429
return (boxedArgb == null ? 0 : boxedArgb.intValue());
430430
}
431431

432-
public static int colorTriadToFFRGB(float x, float y, float z) {
432+
public static int colorTriadToFFRGB(double x, double y, double z) {
433433
if (x <= 1 && y <= 1 && z <= 1) {
434434
if (x > 0)
435435
x = x * 256 - 1;
@@ -445,13 +445,13 @@ public static int rgb(int red, int grn, int blu) {
445445
return 0xFF000000 | (red << 16) | (grn << 8) | blu;
446446
}
447447

448-
public final static P3 colorPtFromString(String colorName) {
448+
public final static P3d colorPtFromString(String colorName) {
449449
return colorPtFromInt(getArgbFromString(colorName), null);
450450
}
451451

452-
public final static P3 colorPtFromInt(int color, P3 pt) {
452+
public final static P3d colorPtFromInt(int color, P3d pt) {
453453
if (pt == null)
454-
pt = new P3();
454+
pt = new P3d();
455455
pt.set((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
456456
return pt;
457457
}
@@ -460,7 +460,7 @@ public static int colorPtToFFRGB(T3 pt) {
460460
return colorTriadToFFRGB(pt.x, pt.y, pt.z);
461461
}
462462

463-
public static void toRGB3f(int c, float[] f) {
463+
public static void toRGB3f(int c, double[] f) {
464464
f[0] = ((c >> 16) & 0xFF) / 255f; // red
465465
f[1] = ((c >> 8) & 0xFF) / 255f;
466466
f[2] = (c & 0xFF) / 255f;
@@ -492,62 +492,62 @@ public static int toFFGGGfromRGB(int rgb) {
492492
* set to false when just using this for
493493
* for RGB -- HSL -- HSL' -- RGB' conversion
494494
*
495-
* @return the HSL as P3 range 360 100 100
495+
* @return the HSL as P3d range 360 100 100
496496
* @author hansonr
497497
*/
498498

499-
public static P3 rgbToHSL(P3 rgb, boolean doRound) {
499+
public static P3d rgbToHSL(P3d rgb, boolean doRound) {
500500
// adapted from http://tips4java.wordpress.com/2009/07/05/hsl-color/
501501
// see http://en.wikipedia.org/wiki/HSL_color_space
502-
float r = rgb.x / 255;
503-
float g = rgb.y / 255;
504-
float b = rgb.z / 255;
505-
float min = Math.min(r, Math.min(g, b));
506-
float max = Math.max(r, Math.max(g, b));
502+
double r = rgb.x / 255;
503+
double g = rgb.y / 255;
504+
double b = rgb.z / 255;
505+
double min = Math.min(r, Math.min(g, b));
506+
double max = Math.max(r, Math.max(g, b));
507507

508508
// lightness is just p * 50
509509

510-
float p = (max + min);
511-
float q = (max - min);
510+
double p = (max + min);
511+
double q = (max - min);
512512

513-
float h = (60 * ((q == 0 ? 0 : max == r ? ((g - b) / q + 6)
513+
double h = (60 * ((q == 0 ? 0 : max == r ? ((g - b) / q + 6)
514514
: max == g ? (b - r) / q + 2 : (r - g) / q + 4))) % 360;
515515

516-
float s = q / (q == 0 ? 1 : p <= 1 ? p : 2 - p);
516+
double s = q / (q == 0 ? 1 : p <= 1 ? p : 2 - p);
517517

518518
// we round to tenths for HSL so that we can return enough
519519
// precision to get back 1-255 in RGB
520-
return (doRound ? P3.new3(Math.round(h*10)/10f, Math.round(s * 1000)/10f,
521-
Math.round(p * 500)/10f) : P3.new3(h, s * 100, p * 50));
520+
return (doRound ? P3d.new3(Math.round(h*10)/10f, Math.round(s * 1000)/10f,
521+
Math.round(p * 500)/10f) : P3d.new3(h, s * 100, p * 50));
522522
}
523523

524524
/**
525525
* Convert HSL (hue/saturation/luninance) values to RGB
526526
*
527527
* @param hsl in the range 360, 100, 100
528-
* @return the RGB as P3 range 0 to 255
528+
* @return the RGB as P3d range 0 to 255
529529
* @author hansonr
530530
*/
531-
public static P3 hslToRGB(P3 hsl) {
531+
public static P3d hslToRGB(P3d hsl) {
532532
// adapted from http://tips4java.wordpress.com/2009/07/05/hsl-color/
533533
// see http://en.wikipedia.org/wiki/HSL_color_space
534534

535535
// highly condensed
536536

537-
float h = Math.max(0, Math.min(360, hsl.x)) / 60;
538-
float s = Math.max(0, Math.min(100, hsl.y)) / 100;
539-
float l = Math.max(0, Math.min(100, hsl.z)) / 100;
537+
double h = Math.max(0, Math.min(360, hsl.x)) / 60;
538+
double s = Math.max(0, Math.min(100, hsl.y)) / 100;
539+
double l = Math.max(0, Math.min(100, hsl.z)) / 100;
540540

541-
float p = l - (l < 0.5 ? l : 1 - l) * s;
542-
float q = 2 * (l - p);
541+
double p = l - (l < 0.5 ? l : 1 - l) * s;
542+
double q = 2 * (l - p);
543543

544-
float r = toRGB(p, q, h + 2);
545-
float g = toRGB(p, q, h);
546-
float b = toRGB(p, q, h - 2);
547-
return P3.new3(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255));
544+
double r = toRGB(p, q, h + 2);
545+
double g = toRGB(p, q, h);
546+
double b = toRGB(p, q, h - 2);
547+
return P3d.new3(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255));
548548
}
549549

550-
private static float toRGB(float p, float q, float h) {
550+
private static double toRGB(double p, double q, double h) {
551551
return ((h = (h + (h < 0 ? 6 : h > 6 ? -6 : 0))) < 1 ? p + q * h
552552
: h < 3 ? p + q : h < 4 ? p + q * (4 - h) : p);
553553
}

sources/net.sf.j2s.java.core/src/javajs/util/M34d.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ public void rotate(T3d t) {
106106
rotate2(t, t);
107107
}
108108

109-
public void rotate(T3 t) {
110-
rotate2(t, t);
111-
}
112-
113109
/**
114110
* Transform the vector vec using this Matrix3f and place the result into
115111
* vecOut.
@@ -125,15 +121,6 @@ public void rotate2(T3d t, T3d result) {
125121
* t.z, m20 * t.x + m21 * t.y + m22 * t.z);
126122
}
127123

128-
public void rotate2(T3 t, T3 result) {
129-
// alias-safe
130-
result.set((float) (m00 * t.x + m01 * t.y + m02 * t.z),
131-
(float) (m10 * t.x + m11 * t.y + m12
132-
* t.z),
133-
(float) (m20 * t.x + m21 * t.y + m22 * t.z));
134-
}
135-
136-
137124
/**
138125
* Sets the value of this matrix to the double value of the Matrix3f argument.
139126
*

0 commit comments

Comments
 (0)