diff --git a/pom.xml b/pom.xml index e3281a8..9fcc586 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.rococoa rococoa-parent - 0.8.12 + 0.8.13 pom diff --git a/rococoa-cocoa/pom.xml b/rococoa-cocoa/pom.xml index 8977a0b..bf1eb57 100644 --- a/rococoa-cocoa/pom.xml +++ b/rococoa-cocoa/pom.xml @@ -10,7 +10,7 @@ org.rococoa rococoa-parent - 0.8.12 + 0.8.13 Rococoa Cocoa Mappings diff --git a/rococoa-contrib/pom.xml b/rococoa-contrib/pom.xml index 780e6d1..a1a2f38 100644 --- a/rococoa-contrib/pom.xml +++ b/rococoa-contrib/pom.xml @@ -10,7 +10,7 @@ org.rococoa rococoa-parent - 0.8.12 + 0.8.13 Rococoa Contrib diff --git a/rococoa-contrib/src/main/java/org/rococoa/cocoa/coregraphics/CGPoint.java b/rococoa-contrib/src/main/java/org/rococoa/cocoa/coregraphics/CGPoint.java index de871b4..f407b3b 100644 --- a/rococoa-contrib/src/main/java/org/rococoa/cocoa/coregraphics/CGPoint.java +++ b/rococoa-contrib/src/main/java/org/rococoa/cocoa/coregraphics/CGPoint.java @@ -34,6 +34,83 @@ public CGPoint(int x, int y) { write(); } + /** for {@link #update} */ + private final double[] buf = new double[2]; + + /** + * DON'T use for ordinary use. + * for {@link #update} + */ + public static class CGMutableFloat extends CGFloat { + + private double value; + + public CGMutableFloat() { + value = 0; + } + + public CGMutableFloat(double d) { + value = d; + } + + @Override + public int intValue() { + return (int) value; + } + + @Override + public long longValue() { + return (long) value; + } + + @Override + public float floatValue() { + return (float) value; + } + + @Override + public double doubleValue() { + return value; + } + + @Override + public int hashCode() { + return Double.hashCode(value); + } + + @Override + public boolean equals(Object other) { + // Modified Double.equals + return (other instanceof CGMutableFloat) && (Double.doubleToLongBits(((CGMutableFloat) other).value) == Double.doubleToLongBits(value)); + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + + /** + * DON'T use for ordinary use. + * for {@link #update} + */ + public CGPoint(CGMutableFloat mx, CGMutableFloat my) { + x = mx; + y = my; + } + + /** + * DON'T use for ordinary use. + * for performance, assume CGFloat SIZE is double + */ + public void update(int x, int y) { + buf[0] = x; + buf[1] = y; + getPointer().write(0, buf, 0, 2); + ((CGMutableFloat) this.x).value = x; + ((CGMutableFloat) this.y).value = y; + } + @Override public String toString() { return "CGPoint{" + diff --git a/rococoa-contrib/src/test/java/org/rococoa/cocoa/coregraphics/CoreGraphicsLibraryTest.java b/rococoa-contrib/src/test/java/org/rococoa/cocoa/coregraphics/CoreGraphicsLibraryTest.java index 2febb1e..6b1eb9b 100644 --- a/rococoa-contrib/src/test/java/org/rococoa/cocoa/coregraphics/CoreGraphicsLibraryTest.java +++ b/rococoa-contrib/src/test/java/org/rococoa/cocoa/coregraphics/CoreGraphicsLibraryTest.java @@ -27,6 +27,7 @@ import org.rococoa.cocoa.appkit.NSRunningApplication; import org.rococoa.cocoa.appkit.NSWorkspace; import org.rococoa.cocoa.corefoundation.CoreFoundation; +import org.rococoa.cocoa.coregraphics.CGPoint.CGMutableFloat; import org.rococoa.cocoa.coreimage.CIImage; import org.rococoa.cocoa.foundation.NSDictionary; import org.rococoa.cocoa.foundation.NSNotification; @@ -229,4 +230,23 @@ void test9() throws Exception { cdl.await(); } + + @Test + @EnabledIfSystemProperty(named = "vavi.test", matches = "ide") + void test10() throws Exception { + long t = System.currentTimeMillis(); + long times = 1000000L; + for (long i = 0; i < times; i++) { + new CGPoint(100, 100); + } +Debug.println("new: " + (System.currentTimeMillis() - t) + " ms"); + CGPoint p = new CGPoint(new CGMutableFloat(), new CGMutableFloat()); + t = System.currentTimeMillis(); + for (long i = 0; i < times; i++) { + p.update(111, 222); + } +Debug.println("update: " + (System.currentTimeMillis() - t) + " ms"); + assertEquals(111, p.x.intValue()); + assertEquals(222, p.y.intValue()); + } } diff --git a/rococoa-core/pom.xml b/rococoa-core/pom.xml index 89e008d..5d75e22 100644 --- a/rococoa-core/pom.xml +++ b/rococoa-core/pom.xml @@ -9,7 +9,7 @@ org.rococoa rococoa-parent - 0.8.12 + 0.8.13 Rococoa Core diff --git a/rococoa-core/src/main/java/org/rococoa/cocoa/CGFloat.java b/rococoa-core/src/main/java/org/rococoa/cocoa/CGFloat.java index 59c30bf..475c560 100644 --- a/rococoa-core/src/main/java/org/rococoa/cocoa/CGFloat.java +++ b/rococoa-core/src/main/java/org/rococoa/cocoa/CGFloat.java @@ -30,6 +30,7 @@ * @author duncan */ public class CGFloat extends Number implements NativeMapped { + // Inspired by JNA NativeLong and IntegerType public static final int SIZE = Native.LONG_SIZE; @@ -65,9 +66,7 @@ public double doubleValue() { @Override public int hashCode() { - // From Double.hashCode - long bits = Double.doubleToLongBits(value); - return (int)(bits ^ (bits >>> 32)); + return Double.hashCode(value); } @Override