Skip to content

Instantly share code, notes, and snippets.

@netgfx
Created February 8, 2014 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netgfx/8887894 to your computer and use it in GitHub Desktop.
Save netgfx/8887894 to your computer and use it in GitHub Desktop.
Check max-min positions
function checkMaxMinPos(a, b, aW, aH, bW, bH, maxX, minX, maxY, minY) {
'use strict';
if (a.left < b.left) {
if (a.left < minX) {
minX = a.left;
}
} else {
if (b.left < minX) {
minX = b.left;
}
}
if (a.left + aW > b.left + bW) {
if (a.left > maxX) {
maxX = a.left + aW;
}
} else {
if (b.left + bW > maxX) {
maxX = b.left + bW;
}
}
////////////////////////////////
if (a.top < b.top) {
if (a.top < minY) {
minY = a.top;
}
} else {
if (b.top < minY) {
minY = b.top;
}
}
if (a.top + aH > b.top + bH) {
if (a.top > maxY) {
maxY = a.top + aH;
}
} else {
if (b.top + bH > maxY) {
maxY = b.top + bH;
}
}
return {
'maxX': maxX,
'minX': minX,
'maxY': maxY,
'minY': minY
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment