Created
November 7, 2013 05:55
-
-
Save keigen-shu/7349698 to your computer and use it in GitHub Desktop.
Rectangle alignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////// | |
// rectangle alignment :: alignXY | |
// where X = Left, Center, Right; Y = Top, Center, Bottom | |
//////// clan::Rectx -> clan::Sizex -> clan::Rectx | |
template <typename T> | |
inline clan::Rectx<T> alignLT (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.left; | |
T r = area.left + size.width; | |
T u = area.top; | |
T d = area.top + size.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignLC (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.left; | |
T r = area.left + size.width; | |
T u = (area.get_height() - size.height) / T(2) + area.top; | |
T d = (3 * area.get_height() + size.height) / T(2) - area.bottom; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignLB (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.left; | |
T r = area.left + size.width; | |
T u = area.bottom - size.height; | |
T d = area.bottom; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignCT (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = (area.get_width() - size.width) / T(2) + area.left; | |
T r = (3 * area.get_width() + size.width) / T(2) - area.right; | |
T u = area.top; | |
T d = area.top + size.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignCC (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = (area.get_width() - size.width) / T(2) + area.left; | |
T r = (3 * area.get_width() + size.width) / T(2) - area.right; | |
T u = (area.get_height() - size.height) / T(2) + area.top; | |
T d = (3 * area.get_height() + size.height) / T(2) - area.bottom; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignCB (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = (area.get_width() - size.width) / T(2) + area.left; | |
T r = (3 * area.get_width() + size.width) / T(2) - area.right; | |
T u = area.bottom - size.height; | |
T d = area.bottom; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignRT (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.right - size.width; | |
T r = area.right; | |
T u = area.top; | |
T d = area.top + size.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignRC (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.right - size.width; | |
T r = area.right; | |
T u = (area.get_height() - size.height) / T(2) + area.top; | |
T d = (3 * area.get_height() + size.height) / T(2) - area.bottom; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignRB (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.right - size.width; | |
T r = area.right; | |
T u = area.bottom - size.height; | |
T d = area.bottom; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
//////////////////////////////////////////////////////////// | |
//////// clan::Sizex -> clan::Sizex -> clan::Rectx | |
template <typename T> | |
inline clan::Rectx<T> alignLT (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = 0; | |
T r = size.width; | |
T u = 0; | |
T d = size.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignLC (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = 0; | |
T r = size.width; | |
T u = (area.height - size.height) / T(2); | |
T d = (area.height + size.height) / T(2); | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignLB (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = 0; | |
T r = size.width; | |
T u = area.height - size.height; | |
T d = area.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignCT (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = (area.width - size.width) / T(2); | |
T r = (area.width + size.width) / T(2); | |
T u = 0; | |
T d = size.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignCC (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = (area.width - size.width) / T(2); | |
T r = (area.width + size.width) / T(2); | |
T u = (area.height - size.height) / T(2); | |
T d = (area.height + size.height) / T(2); | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignCB (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = (area.width - size.width) / T(2); | |
T r = (area.width + size.width) / T(2); | |
T u = area.height - size.height; | |
T d = area.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignRT (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.width - size.width; | |
T r = area.width; | |
T u = 0; | |
T d = size.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignRC (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.width - size.width; | |
T r = area.width; | |
T u = (area.height - size.height) / T(2); | |
T d = (area.height + size.height) / T(2); | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
template <typename T> | |
inline clan::Rectx<T> alignRB (const clan::Sizex<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.width - size.width; | |
T r = area.width; | |
T u = area.height - size.height; | |
T d = area.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} | |
//////////////////////////////////////////////////////////// | |
// Rect scaling | |
template <typename T> | |
inline clan::Rectx<T> product (const clan::Rectx<T> &area, const clan::Sizex<T> &size) | |
{ | |
T l = area.left * size.width; | |
T r = area.right * size.width; | |
T u = area.top * size.height; | |
T d = area.bottom * size.height; | |
return clan::Rectx<T>(l,u,r,d); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment