示例#1
0
文件: CLIPRECT.CPP 项目: mhjlam1/bam
// Find the intersection with another rect and fill in the intersect rect
//	if requested (not NULL)
//
bool
TClipRect::Intersect(Rectangle* pTargetRect, Rectangle* pIntRect)
{
	coord l;
	coord t;
	coord r;
	coord b;
	bool	ret = FALSE;

	if (IsEmpty() == FALSE)
	{
		// we have a rect to check
		l = AMax(x1, pTargetRect->x1);
		t = AMin(x2 - 1, pTargetRect->x2);
		r = AMax(y1, pTargetRect->y1);
		b = AMin(y2 - 1, pTargetRect->y2);

		if (r >= l && b >= t)
		{
			if (pIntRect)
			{
				pIntRect->x1 = l;
				pIntRect->y1 = t;
				pIntRect->x2 = r;
				pIntRect->y2 = b;
			}
			ret = TRUE;
		}
	}

	return ret;
}
示例#2
0
文件: RECT.CPP 项目: mhjlam1/bam
// Clip this rectangle to be within the passed clipRect
//
void
Rectangle::Clip(Rectangle* clipRect)
{
	x1 = AMax(x1, clipRect->x1);
	y1 = AMax(y1, clipRect->y1);
	x2 = AMax(AMin(x2, clipRect->x2), x1);
	y2 = AMax(AMin(y2, clipRect->y2), y1);
}
示例#3
0
文件: CLIPRECT.CPP 项目: mhjlam1/bam
// Clip this rectangle to be within the passed TClipRect
//
void
TClipRect::Clip(TClipRect* pClipRect)
{
	x1 = AMax(x1, pClipRect->x1);
	y1 = AMax(y1, pClipRect->y1);
	x2 = AMax(AMin(x2, pClipRect->x2), x1);
	y2 = AMax(AMin(y2, pClipRect->y2), y1);
}
示例#4
0
文件: CLIPRECT.CPP 项目: mhjlam1/bam
// Clip this rectangle to be within the passed TClipRect
//
void
TClipRect::Clip(Rectangle* pClipRect)
{
	x1 = AMax(x1, pClipRect->x1);
	y1 = AMax(y1, pClipRect->y1);
	x2 = AMax(AMin(x2, pClipRect->x2 + 1), x1);
	y2 = AMax(AMin(y2, pClipRect->y2 + 1), y1);
}
示例#5
0
文件: RECT.CPP 项目: mhjlam1/bam
// Enlarge to bound second rect
void
Rectangle::Unite(Rectangle* pRect2)
{
	x1 = AMin(x1, pRect2->x1);
	y1 = AMin(y1, pRect2->y1);
	x2 = AMax(x2, pRect2->x2);
	y2 = AMax(y2, pRect2->y2);
	area = CalcArea();
}
示例#6
0
文件: CLIPRECT.CPP 项目: mhjlam1/bam
// Enlarge to bound second rect
void
TClipRect::Unite(TClipRect* pRect2)
{
	x1 = AMin(x1, pRect2->x1);
	y1 = AMin(y1, pRect2->y1);
	x2 = AMax(x2, pRect2->x2);
	y2 = AMax(y2, pRect2->y2);
	area = CalcArea();
}
示例#7
0
文件: RECT.CPP 项目: mhjlam1/bam
// Calculate the area of a rect large enough to contain this rect
// and another rect.
uint
Rectangle::AreaBounds(Rectangle* pRect2)
{
	coord	t, l, b, r;

	l = AMin(x1, pRect2->x1);
	t = AMin(y1, pRect2->y1);
	r = AMax(x2, pRect2->x2);
	b = AMax(y2, pRect2->y2);

	return ((b - t + 1) * (r - l + 1));
}
示例#8
0
文件: CLIPRECT.CPP 项目: mhjlam1/bam
// Calculate the area of a rect large enough to contain this rect
// and another rect.
uint
TClipRect::AreaBounds(TClipRect* pRect2)
{
	coord	t, l, b, r;

	l = AMin(x1, pRect2->x1);
	t = AMin(y1, pRect2->y1);
	r = AMax(x2, pRect2->x2);
	b = AMax(y2, pRect2->y2);

	return ((b - t) * (r - l));
}
示例#9
0
/*=========================================================
 * enlarge_array -- Make array large enough for [space] elements
 *=======================================================*/
void
enlarge_array (ARRAY array, INT space)
{
	int newsize = AMax(array);
	void ** ptr;
	int i;
	while (newsize <= space)
		newsize <<= 2;
	if (newsize<AMax(array)) return;
	ptr = (void **)stdalloc(newsize * sizeof(AData(array)[0]));
	for (i = 0; i < ASize(array); i++)
		ptr[i] = AData(array)[i];
	stdfree(AData(array));
	AData(array) = ptr;
	AMax(array) = newsize;
}
示例#10
0
文件: RECT.CPP 项目: mhjlam1/bam
// Find the intersection with another rect and fill in the intersect rect
//	if requested (not NULL)
//
bool
Rectangle::Intersect(Rectangle* pTargetRect, Rectangle* pIntRect)
{
	coord l = AMax(x1, pTargetRect->x1);
	coord t = AMin(x2, pTargetRect->x2);
	coord r = AMax(y1, pTargetRect->y1);
	coord b = AMin(y2, pTargetRect->y2);
	bool	ret = FALSE;

	if (r >= l && b >= t)
	{
		if (pIntRect)
		{
			pIntRect->x1 = l;
			pIntRect->y1 = t;
			pIntRect->x2 = r;
			pIntRect->y2 = b;
		}
		ret = TRUE;
	}
	return ret;
}
示例#11
0
/*=========================================================
 * create_array_objval -- Create array (which holds objects)
 *=======================================================*/
ARRAY
create_array_objval (INT size)
{
	ARRAY array = 0;
	if (!size) size=20;
	ASSERT(size >= 1);
	array = (ARRAY)stdalloc(sizeof(*array));
	memset(array, 0, sizeof(*array));
	array->vtable = &vtable_for_array;
	ASize(array) = 0;
	AMax(array) = size;
	AData(array) = (void **)stdalloc(size * sizeof(AData(array)[0]));
	return array;
}
示例#12
0
/*=========================================================
 * set_array_obj -- Set element (object) in array
 *  grow if necessary
 *=======================================================*/
void
set_array_obj (ARRAY array, INT i, OBJECT obj)
{
	ASSERT(i>=0);
	ASSERT(i< 0x1000000); /* 16,777,216 */
	if (i>=AMax(array)) {
		enlarge_array(array, i);
	}
	if (i>=ASize(array)) {
		int j;
		for (j=ASize(array); j<i; ++j)
			AData(array)[j] = 0;
		ASize(array)=i+1;
	}
	AData(array)[i] = obj;
}
int test_linearRand()
{
	int Error = 0;

	glm::int32 const Min = 16;
	glm::int32 const Max = 32;

	{
		glm::u8vec2 AMin(std::numeric_limits<glm::u8>::max());
		glm::u8vec2 AMax(std::numeric_limits<glm::u8>::min());
		{
			for(std::size_t i = 0; i < 100000; ++i)
			{
				glm::u8vec2 A = glm::linearRand(glm::u8vec2(Min), glm::u8vec2(Max));
				AMin = glm::min(AMin, A);
				AMax = glm::max(AMax, A);

				if(!glm::all(glm::lessThanEqual(A, glm::u8vec2(Max))))
					++Error;
				if(!glm::all(glm::greaterThanEqual(A, glm::u8vec2(Min))))
					++Error;
				assert(!Error);
			}

			Error += glm::all(glm::equal(AMin, glm::u8vec2(Min))) ? 0 : 1;
			Error += glm::all(glm::equal(AMax, glm::u8vec2(Max))) ? 0 : 1;
			assert(!Error);
		}

		glm::u16vec2 BMin(std::numeric_limits<glm::u16>::max());
		glm::u16vec2 BMax(std::numeric_limits<glm::u16>::min());
		{
			for(std::size_t i = 0; i < 100000; ++i)
			{
				glm::u16vec2 B = glm::linearRand(glm::u16vec2(Min), glm::u16vec2(Max));
				BMin = glm::min(BMin, B);
				BMax = glm::max(BMax, B);

				if(!glm::all(glm::lessThanEqual(B, glm::u16vec2(Max))))
					++Error;
				if(!glm::all(glm::greaterThanEqual(B, glm::u16vec2(Min))))
					++Error;
				assert(!Error);
			}

			Error += glm::all(glm::equal(BMin, glm::u16vec2(Min))) ? 0 : 1;
			Error += glm::all(glm::equal(BMax, glm::u16vec2(Max))) ? 0 : 1;
			assert(!Error);
		}

		glm::u32vec2 CMin(std::numeric_limits<glm::u32>::max());
		glm::u32vec2 CMax(std::numeric_limits<glm::u32>::min());
		{
			for(std::size_t i = 0; i < 100000; ++i)
			{
				glm::u32vec2 C = glm::linearRand(glm::u32vec2(Min), glm::u32vec2(Max));
				CMin = glm::min(CMin, C);
				CMax = glm::max(CMax, C);

				if(!glm::all(glm::lessThanEqual(C, glm::u32vec2(Max))))
					++Error;
				if(!glm::all(glm::greaterThanEqual(C, glm::u32vec2(Min))))
					++Error;
				assert(!Error);
			}

			Error += glm::all(glm::equal(CMin, glm::u32vec2(Min))) ? 0 : 1;
			Error += glm::all(glm::equal(CMax, glm::u32vec2(Max))) ? 0 : 1;
			assert(!Error);
		}

		glm::u64vec2 DMin(std::numeric_limits<glm::u64>::max());
		glm::u64vec2 DMax(std::numeric_limits<glm::u64>::min());
		{
			for(std::size_t i = 0; i < 100000; ++i)
			{
				glm::u64vec2 D = glm::linearRand(glm::u64vec2(Min), glm::u64vec2(Max));
				DMin = glm::min(DMin, D);
				DMax = glm::max(DMax, D);

				if(!glm::all(glm::lessThanEqual(D, glm::u64vec2(Max))))
					++Error;
				if(!glm::all(glm::greaterThanEqual(D, glm::u64vec2(Min))))
					++Error;
				assert(!Error);
			}

			Error += glm::all(glm::equal(DMin, glm::u64vec2(Min))) ? 0 : 1;
			Error += glm::all(glm::equal(DMax, glm::u64vec2(Max))) ? 0 : 1;
			assert(!Error);
		}
	}

	{
		glm::i8vec2 AMin(std::numeric_limits<glm::i8>::max());
		glm::i8vec2 AMax(std::numeric_limits<glm::i8>::min());
		{
			for(std::size_t i = 0; i < 100000; ++i)
			{
				glm::i8vec2 A = glm::linearRand(glm::i8vec2(Min), glm::i8vec2(Max));
				AMin = glm::min(AMin, A);
				AMax = glm::max(AMax, A);

				if(!glm::all(glm::lessThanEqual(A, glm::i8vec2(Max))))
					++Error;
				if(!glm::all(glm::greaterThanEqual(A, glm::i8vec2(Min))))
					++Error;
				assert(!Error);
			}

			Error += glm::all(glm::equal(AMin, glm::i8vec2(Min))) ? 0 : 1;
			Error += glm::all(glm::equal(AMax, glm::i8vec2(Max))) ? 0 : 1;
			assert(!Error);
		}

		glm::i16vec2 BMin(std::numeric_limits<glm::i16>::max());
		glm::i16vec2 BMax(std::numeric_limits<glm::i16>::min());
		{
			for(std::size_t i = 0; i < 100000; ++i)
			{
				glm::i16vec2 B = glm::linearRand(glm::i16vec2(Min), glm::i16vec2(Max));
				BMin = glm::min(BMin, B);
				BMax = glm::max(BMax, B);

				if(!glm::all(glm::lessThanEqual(B, glm::i16vec2(Max))))
					++Error;
				if(!glm::all(glm::greaterThanEqual(B, glm::i16vec2(Min))))
					++Error;
				assert(!Error);
			}

			Error += glm::all(glm::equal(BMin, glm::i16vec2(Min))) ? 0 : 1;
			Error += glm::all(glm::equal(BMax, glm::i16vec2(Max))) ? 0 : 1;
			assert(!Error);
		}

		glm::i32vec2 CMin(std::numeric_limits<glm::i32>::max());
		glm::i32vec2 CMax(std::numeric_limits<glm::i32>::min());
		{
			for(std::size_t i = 0; i < 100000; ++i)
			{
				glm::i32vec2 C = glm::linearRand(glm::i32vec2(Min), glm::i32vec2(Max));
				CMin = glm::min(CMin, C);
				CMax = glm::max(CMax, C);

				if(!glm::all(glm::lessThanEqual(C, glm::i32vec2(Max))))
					++Error;
				if(!glm::all(glm::greaterThanEqual(C, glm::i32vec2(Min))))
					++Error;
				assert(!Error);
			}

			Error += glm::all(glm::equal(CMin, glm::i32vec2(Min))) ? 0 : 1;
			Error += glm::all(glm::equal(CMax, glm::i32vec2(Max))) ? 0 : 1;
			assert(!Error);
		}

		glm::i64vec2 DMin(std::numeric_limits<glm::i64>::max());
		glm::i64vec2 DMax(std::numeric_limits<glm::i64>::min());
		{
			for(std::size_t i = 0; i < 100000; ++i)
			{
				glm::i64vec2 D = glm::linearRand(glm::i64vec2(Min), glm::i64vec2(Max));
				DMin = glm::min(DMin, D);
				DMax = glm::max(DMax, D);

				if(!glm::all(glm::lessThanEqual(D, glm::i64vec2(Max))))
					++Error;
				if(!glm::all(glm::greaterThanEqual(D, glm::i64vec2(Min))))
					++Error;
				assert(!Error);
			}

			Error += glm::all(glm::equal(DMin, glm::i64vec2(Min))) ? 0 : 1;
			Error += glm::all(glm::equal(DMax, glm::i64vec2(Max))) ? 0 : 1;
			assert(!Error);
		}
	}

	for(std::size_t i = 0; i < 100000; ++i)
	{
		glm::f32vec2 const A(glm::linearRand(glm::f32vec2(static_cast<float>(Min)), glm::f32vec2(static_cast<float>(Max))));
		if(!glm::all(glm::lessThanEqual(A, glm::f32vec2(static_cast<float>(Max)))))
			++Error;
		if(!glm::all(glm::greaterThanEqual(A, glm::f32vec2(static_cast<float>(Min)))))
			++Error;

		glm::f64vec2 const B(glm::linearRand(glm::f64vec2(Min), glm::f64vec2(Max)));
		if(!glm::all(glm::lessThanEqual(B, glm::f64vec2(Max))))
			++Error;
		if(!glm::all(glm::greaterThanEqual(B, glm::f64vec2(Min))))
			++Error;
		assert(!Error);
	}

	{
		float ResultFloat = 0.0f;
		double ResultDouble = 0.0f;
		for(std::size_t i = 0; i < 100000; ++i)
		{
			ResultFloat += glm::linearRand(-1.0f, 1.0f);
			ResultDouble += glm::linearRand(-1.0, 1.0);
		}

		Error += glm::epsilonEqual(ResultFloat, 0.0f, 0.0001f);
		Error += glm::epsilonEqual(ResultDouble, 0.0, 0.0001);
		assert(!Error);
	}

	return Error;
}