feat(api): make ImVec2/ImVec4 math operations immutable (#317)

resolves #302 

Updated math operations (`plus`, `minus`, `times`, `div`) for `ImVec2` and `ImVec4` to return new instances instead of modifying the existing ones, ensuring immutability.
This commit is contained in:
SpaiR authored and GitHub committed 2025-01-29 20:35:53 +02:00
1 parent 02691fdabe
commit d27e3aa10b
6 files changed
+147 -65

No files matched your search

@@ -31,9 +31,7 @@ public final class ImVec2 implements Cloneable {
}
public ImVec2 plus(final float x, final float y) {
this.x += x;
this.y += y;
return this;
return new ImVec2(this.x + x, this.y + y);
}
public ImVec2 plus(final ImVec2 value) {
@@ -41,9 +39,7 @@ public final class ImVec2 implements Cloneable {
}
public ImVec2 minus(final float x, final float y) {
this.x -= x;
this.y -= y;
return this;
return new ImVec2(this.x - x, this.y -y);
}
public ImVec2 minus(final ImVec2 value) {
@@ -51,15 +47,21 @@ public final class ImVec2 implements Cloneable {
}
public ImVec2 times(final float x, final float y) {
this.x *= x;
this.y *= y;
return this;
return new ImVec2(this.x * x, this.y * y);
}
public ImVec2 times(final ImVec2 value) {
return times(value.x, value.y);
}
public ImVec2 div(final float x, final float y) {
return new ImVec2(this.x / x, this.y / y);
}
public ImVec2 div(final ImVec2 value) {
return div(value.x, value.y);
}
@Override
public String toString() {
return "ImVec2{"
@@ -35,11 +35,7 @@ public final class ImVec4 implements Cloneable {
}
public ImVec4 plus(final float x, final float y, final float z, final float w) {
this.x += x;
this.y += y;
this.z += z;
this.w += w;
return this;
return new ImVec4(this.x + x, this.y + y, this.z + z, this.w + w);
}
public ImVec4 plus(final ImVec4 value) {
@@ -47,11 +43,7 @@ public final class ImVec4 implements Cloneable {
}
public ImVec4 minus(final float x, final float y, final float z, final float w) {
this.x -= x;
this.y -= y;
this.z -= z;
this.w -= w;
return this;
return new ImVec4(this.x - x, this.y - y, this.z - z, this.w - w);
}
public ImVec4 minus(final ImVec4 value) {
@@ -59,17 +51,21 @@ public final class ImVec4 implements Cloneable {
}
public ImVec4 times(final float x, final float y, final float z, final float w) {
this.x *= x;
this.y *= y;
this.z *= z;
this.w *= w;
return this;
return new ImVec4(this.x * x, this.y * y, this.z * z, this.w * w);
}
public ImVec4 times(final ImVec4 value) {
return times(value.x, value.y, value.z, value.w);
}
public ImVec4 div(final float x, final float y, final float z, final float w) {
return new ImVec4(this.x / x, this.y / y, this.z / z, this.w / w);
}
public ImVec4 div(final ImVec4 value) {
return div(value.x, value.y, value.z, value.w);
}
@Override
public String toString() {
return "ImVec4{"