<commit_before>#ifndef _SPATIAL_MATH_RECT_INL_
#define _SPATIAL_MATH_RECT_INL_

#include <limits>
#include <algorithm>

namespace sm
{

template <typename T>
Rect<T>::Rect()
{
	MakeEmpty();
}

template <typename T>
Rect<T>::Rect(T width, T height)
{
	Build(width, height);
}

template <typename T>
Rect<T>::Rect(const Vector2<T>& center, T width, T height)
{
	Build(width, height);
	Translate(center);
}

template <typename T>
Rect<T>::Rect(const Vector2<T>& v0, const Vector2<T>& v1)
{
	xmin = (std::min)(v0.x, v1.x);
	ymin = (std::min)(v0.y, v1.y);
	xmax = (std::max)(v0.x, v1.x);
	ymax = (std::max)(v0.y, v1.y);
}

template <typename T>
bool Rect<T>::operator == (const Rect<T>& r) const
{
	return xmin == r.xmin
		&& xmax == r.xmax
		&& ymin == r.ymin
		&& ymax == r.ymax;
}

template <typename T>
void Rect<T>::Build(T width, T height)
{
	T hw = width * 0.5f,
	  hh = height * 0.5f;
	xmin = -hw;
	xmax =  hw;
	ymin = -hh;
	ymax =  hh;	
}

template <typename T>
void Rect<T>::MakeEmpty()
{
	xmin = ymin = std::numeric_limits<T>::max();
	xmax = ymax = -std::numeric_limits<T>::max();
}

template <typename T>
bool Rect<T>::IsValid() const
{
	return xmin != std::numeric_limits<T>::max() && ymin != std::numeric_limits<T>::max()
		&& xmax != -std::numeric_limits<T>::max() && ymax != -std::numeric_limits<T>::max()
		&& xmin <= xmax && ymin <= ymax;
}

template <typename T>
void Rect<T>::Combine(const Vector2<T>& v)
{
	if (v.x < xmin) xmin = v.x;
	if (v.x > xmax) xmax = v.x;
	if (v.y < ymin) ymin = v.y;
	if (v.y > ymax) ymax = v.y;
}

template <typename T>
void Rect<T>::Combine(const Rect<T>& r)
{
	if (r.xmin < xmin) xmin = r.xmin;
	if (r.xmax > xmax) xmax = r.xmax;
	if (r.ymin < ymin) ymin = r.ymin;
	if (r.ymax > ymax) ymax = r.ymax;
}

template <typename T>
Vector2<T> Rect<T>::Size() const
{
	return Vector2<T>(xmax - xmin, ymax - ymin);
}

template <typename T>
Vector2<T> Rect<T>::Center() const
{
	return Vector2<T>((xmin + xmax) * 0.5f, (ymin + ymax) * 0.5f);	
}

template <typename T>
void Rect<T>::Translate(const Vector2<T>& offset)
{
	xmin += offset.x;
	xmax += offset.x;
	ymin += offset.y;
	ymax += offset.y;
}

template <typename T>
void Rect<T>::Scale(T sx, T sy)
{
	xmin *= sx;
	xmax *= sx;
	ymin *= sy;
	ymax *= sy;
}

template <typename T>
void Rect<T>::Shear(T kx, T ky)
{
	MakeEmpty();
	// x' = x + y*kx
	// y' = x*ky + y
	sm ::vec2 v[4];
	v[0].x = xmin + ymin * kx;
	v[0].y = xmin * ky + ymin;
	v[1].x = xmax + ymin * kx;
	v[1].y = xmax * ky + ymin;
	v[2].x = xmax + ymax * kx;
	v[2].y = xmax * ky + ymax;
	v[3].x = xmin + ymax * kx;
	v[3].y = xmin * ky + ymax;
	for (int i = 0; i < 4; ++i) {
		Combine(v[i]);
	}
}

}

#endif // _SPATIAL_MATH_RECT_INL_<commit_msg>[FIXED] rect shear<commit_after>#ifndef _SPATIAL_MATH_RECT_INL_
#define _SPATIAL_MATH_RECT_INL_

#include <limits>
#include <algorithm>

namespace sm
{

template <typename T>
Rect<T>::Rect()
{
	MakeEmpty();
}

template <typename T>
Rect<T>::Rect(T width, T height)
{
	Build(width, height);
}

template <typename T>
Rect<T>::Rect(const Vector2<T>& center, T width, T height)
{
	Build(width, height);
	Translate(center);
}

template <typename T>
Rect<T>::Rect(const Vector2<T>& v0, const Vector2<T>& v1)
{
	xmin = (std::min)(v0.x, v1.x);
	ymin = (std::min)(v0.y, v1.y);
	xmax = (std::max)(v0.x, v1.x);
	ymax = (std::max)(v0.y, v1.y);
}

template <typename T>
bool Rect<T>::operator == (const Rect<T>& r) const
{
	return xmin == r.xmin
		&& xmax == r.xmax
		&& ymin == r.ymin
		&& ymax == r.ymax;
}

template <typename T>
void Rect<T>::Build(T width, T height)
{
	T hw = width * 0.5f,
	  hh = height * 0.5f;
	xmin = -hw;
	xmax =  hw;
	ymin = -hh;
	ymax =  hh;	
}

template <typename T>
void Rect<T>::MakeEmpty()
{
	xmin = ymin = std::numeric_limits<T>::max();
	xmax = ymax = -std::numeric_limits<T>::max();
}

template <typename T>
bool Rect<T>::IsValid() const
{
	return xmin != std::numeric_limits<T>::max() && ymin != std::numeric_limits<T>::max()
		&& xmax != -std::numeric_limits<T>::max() && ymax != -std::numeric_limits<T>::max()
		&& xmin <= xmax && ymin <= ymax;
}

template <typename T>
void Rect<T>::Combine(const Vector2<T>& v)
{
	if (v.x < xmin) xmin = v.x;
	if (v.x > xmax) xmax = v.x;
	if (v.y < ymin) ymin = v.y;
	if (v.y > ymax) ymax = v.y;
}

template <typename T>
void Rect<T>::Combine(const Rect<T>& r)
{
	if (r.xmin < xmin) xmin = r.xmin;
	if (r.xmax > xmax) xmax = r.xmax;
	if (r.ymin < ymin) ymin = r.ymin;
	if (r.ymax > ymax) ymax = r.ymax;
}

template <typename T>
Vector2<T> Rect<T>::Size() const
{
	return Vector2<T>(xmax - xmin, ymax - ymin);
}

template <typename T>
Vector2<T> Rect<T>::Center() const
{
	return Vector2<T>((xmin + xmax) * 0.5f, (ymin + ymax) * 0.5f);	
}

template <typename T>
void Rect<T>::Translate(const Vector2<T>& offset)
{
	xmin += offset.x;
	xmax += offset.x;
	ymin += offset.y;
	ymax += offset.y;
}

template <typename T>
void Rect<T>::Scale(T sx, T sy)
{
	xmin *= sx;
	xmax *= sx;
	ymin *= sy;
	ymax *= sy;
}

template <typename T>
void Rect<T>::Shear(T kx, T ky)
{
	// x' = x + y*kx
	// y' = x*ky + y
	sm ::vec2 v[4];
	v[0].x = xmin + ymin * kx;
	v[0].y = xmin * ky + ymin;
	v[1].x = xmax + ymin * kx;
	v[1].y = xmax * ky + ymin;
	v[2].x = xmax + ymax * kx;
	v[2].y = xmax * ky + ymax;
	v[3].x = xmin + ymax * kx;
	v[3].y = xmin * ky + ymax;

	MakeEmpty();
	for (int i = 0; i < 4; ++i) {
		Combine(v[i]);
	}
}

}

#endif // _SPATIAL_MATH_RECT_INL_
{'fraction_non_alphanumeric': 0.21319985168705968, 'fraction_numerical': 0.014460511679644048, 'mean_word_length': 3.6913043478260867, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '853694', 'n_tokens_mistral': 2564, 'n_tokens_neox': 2520, 'n_words': 597}