Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for nasty ternary closure codegen for min/max on Lua target #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Vec2.hx
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,56 @@ abstract Vec2(Vec2Data) to Vec2Data from Vec2Data {
return (this: Vec2) - d * ((this: Vec2) / d).floor();
}
public extern overload inline function min(b: Vec2): Vec2 {
#if lua
return new Vec2(
lua.Math.min(b.x, x),
lua.Math.min(b.y, y)
);
#else
return new Vec2(
b.x < x ? b.x : x,
b.y < y ? b.y : y
);
#end
}
public extern overload inline function min(b: Float): Vec2 {
#if lua
return new Vec2(
lua.Math.min(b, x),
lua.Math.min(b, y)
);
#else
return new Vec2(
b < x ? b : x,
b < y ? b : y
);
#end
}
public extern overload inline function max(b: Vec2): Vec2 {
#if lua
return new Vec2(
lua.Math.max(b.x, x),
lua.Math.max(b.y, y)
);
#else
return new Vec2(
x < b.x ? b.x : x,
y < b.y ? b.y : y
);
#end
}
public extern overload inline function max(b: Float): Vec2 {
#if lua
return new Vec2(
lua.Math.max(b, x),
lua.Math.max(b, y)
);
#else
return new Vec2(
x < b ? b : x,
y < b ? b : y
);
#end
}
public extern overload inline function clamp(minLimit: Vec2, maxLimit: Vec2) {
return max(minLimit).min(maxLimit);
Expand Down
32 changes: 32 additions & 0 deletions Vec3.hx
Original file line number Diff line number Diff line change
Expand Up @@ -187,32 +187,64 @@ abstract Vec3(Vec3Data) to Vec3Data from Vec3Data {
return (this: Vec3) - d * ((this: Vec3) / d).floor();
}
public extern overload inline function min(b: Vec3): Vec3 {
#if lua
return new Vec3(
lua.Math.min(b.x, x),
lua.Math.min(b.y, y),
lua.Math.min(b.z, z)
);
#else
return new Vec3(
b.x < x ? b.x : x,
b.y < y ? b.y : y,
b.z < z ? b.z : z
);
#end
}
public extern overload inline function min(b: Float): Vec3 {
#if lua
return new Vec3(
lua.Math.min(b, x),
lua.Math.min(b, y),
lua.Math.min(b, z)
);
#else
return new Vec3(
b < x ? b : x,
b < y ? b : y,
b < z ? b : z
);
#end
}
public extern overload inline function max(b: Vec3): Vec3 {
#if lua
return new Vec3(
lua.Math.max(b.x, x),
lua.Math.max(b.y, y),
lua.Math.max(b.z, z)
);
#else
return new Vec3(
x < b.x ? b.x : x,
y < b.y ? b.y : y,
z < b.z ? b.z : z
);
#end
}
public extern overload inline function max(b: Float): Vec3 {
#if lua
return new Vec3(
lua.Math.max(b, x),
lua.Math.max(b, y),
lua.Math.max(b, z)
);
#else
return new Vec3(
x < b ? b : x,
y < b ? b : y,
z < b ? b : z
);
#end
}
public extern overload inline function clamp(minLimit: Vec3, maxLimit: Vec3) {
return max(minLimit).min(maxLimit);
Expand Down
36 changes: 36 additions & 0 deletions Vec4.hx
Original file line number Diff line number Diff line change
Expand Up @@ -200,36 +200,72 @@ abstract Vec4(Vec4Data) to Vec4Data from Vec4Data {
return (this: Vec4) - d * ((this: Vec4) / d).floor();
}
public extern overload inline function min(b: Vec4): Vec4 {
#if lua
return new Vec4(
lua.Math.min(b.x, x),
lua.Math.min(b.y, y),
lua.Math.min(b.z, z),
lua.Math.min(b.w, w)
);
#else
return new Vec4(
b.x < x ? b.x : x,
b.y < y ? b.y : y,
b.z < z ? b.z : z,
b.w < w ? b.w : w
);
#end
}
public extern overload inline function min(b: Float): Vec4 {
#if lua
return new Vec4(
lua.Math.min(b, x),
lua.Math.min(b, y),
lua.Math.min(b, z),
lua.Math.min(b, w)
);
#else
return new Vec4(
b < x ? b : x,
b < y ? b : y,
b < z ? b : z,
b < w ? b : w
);
#end
}
public extern overload inline function max(b: Vec4): Vec4 {
#if lua
return new Vec4(
lua.Math.max(b.x, x),
lua.Math.max(b.y, y),
lua.Math.max(b.z, z),
lua.Math.max(b.w, w)
);
#else
return new Vec4(
x < b.x ? b.x : x,
y < b.y ? b.y : y,
z < b.z ? b.z : z,
w < b.w ? b.w : w
);
#end
}
public extern overload inline function max(b: Float): Vec4 {
#if lua
return new Vec4(
lua.Math.max(b, x),
lua.Math.max(b, y),
lua.Math.max(b, z),
lua.Math.max(b, w)
);
#else
return new Vec4(
x < b ? b : x,
y < b ? b : y,
z < b ? b : z,
w < b ? b : w
);
#end
}
public extern overload inline function clamp(minLimit: Vec4, maxLimit: Vec4) {
return max(minLimit).min(maxLimit);
Expand Down