Skip to content

Commit

Permalink
Merge pull request #29 from umjammer/0.8.13
Browse files Browse the repository at this point in the history
0.8.13
  • Loading branch information
umjammer authored Apr 6, 2024
2 parents 6c3b754 + f1ea7c3 commit 8e5c0ec
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.rococoa</groupId>
<artifactId>rococoa-parent</artifactId>
<version>0.8.12</version>
<version>0.8.13</version>
<packaging>pom</packaging>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion rococoa-cocoa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.rococoa</groupId>
<artifactId>rococoa-parent</artifactId>
<version>0.8.12</version>
<version>0.8.13</version>
</parent>

<name>Rococoa Cocoa Mappings</name>
Expand Down
2 changes: 1 addition & 1 deletion rococoa-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.rococoa</groupId>
<artifactId>rococoa-parent</artifactId>
<version>0.8.12</version>
<version>0.8.13</version>
</parent>

<name>Rococoa Contrib</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion rococoa-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.rococoa</groupId>
<artifactId>rococoa-parent</artifactId>
<version>0.8.12</version>
<version>0.8.13</version>
</parent>

<name>Rococoa Core</name>
Expand Down
5 changes: 2 additions & 3 deletions rococoa-core/src/main/java/org/rococoa/cocoa/CGFloat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8e5c0ec

Please sign in to comment.