Skip to content

Instantly share code, notes, and snippets.

@AugmentedFifth
Created July 19, 2017 22:31
Show Gist options
  • Save AugmentedFifth/df9272f15974074b0c2f4b3ea226eb78 to your computer and use it in GitHub Desktop.
Save AugmentedFifth/df9272f15974074b0c2f4b3ea226eb78 to your computer and use it in GitHub Desktop.
horrible. dont do this
/**
* Decides if the given rectangle contains the given point within it.
*
* The rectangle is specified by the x-value of the upper-left corner, then the
* y-value, then the width, and then the height, in that order. After that, the
* point whose containment or non-containment is to be determined is specified.
* These values can each be specified either as two separate `number`s or as a
* single `V2`, mixing and matching arbitrarily.
*
* @return {boolean}
*/
Rect.contains = function(arg1, arg2, arg3, arg4, arg5, arg6) {
"use strict";
let rectX, rectY, width, height, x, y;
if (typeof arg1 === "number") {
rectX = arg1;
rectY = arg2;
if (typeof arg3 === "number") {
width = arg3;
height = arg4;
if (typeof arg5 === "number") {
x = arg5;
y = arg6;
} else {
x = arg5.x;
y = arg5.y;
}
} else {
width = arg3.x;
height = arg3.y;
if (typeof arg4 === "number") {
x = arg4;
y = arg5;
} else {
x = arg4.x;
y = arg4.y;
}
}
} else {
rectX = arg1.x;
rectY = arg1.y;
if (typeof arg2 === "number") {
width = arg2;
height = arg3;
if (typeof arg4 === "number") {
x = arg4;
y = arg5;
} else {
x = arg4.x;
y = arg4.y;
}
} else {
width = arg2.x;
height = arg2.y;
if (typeof arg3 === "number") {
x = arg3;
y = arg4;
} else {
x = arg3.x;
y = arg3.y;
}
}
}
return x >= rectX &&
y >= rectY &&
x <= rectX + width &&
y <= rectY + height;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment