aabb2.h 1.02 KB
#ifndef STIM_AABB2_H
#define STIM_AABB2_H

#include <stim/cuda/cudatools/callable.h>

namespace stim{

/// Structure for a 2D axis aligned bounding box
template<typename T>
struct aabb2{


	T low[2];						//top left corner position
	T high[2];							//dimensions along x and y


	CUDA_CALLABLE aabb2(T x, T y){					//initialize an axis aligned bounding box of size 0 at the given position
		low[0] = high[0] = x;					//set the position to the user specified coordinates
		low[1] = high[1] = y;

	//insert a point into the bounding box, growing the box appropriately
	CUDA_CALLABLE void insert(T x, T y){
		if(x < low[0]) low[0] = x;
		if(y < low[1]) low[1] = y;

		if(x > high[0]) high[0] = x;		
		if(y > high[1]) high[1] = y;

	//trim the bounding box so that the lower bounds are (x, y)
	CUDA_CALLABLE void trim_low(T x, T y){
		if(low[0] < x) low[0] = x;
		if(low[1] < y) low[1] = y;

	CUDA_CALLABLE void trim_high(T x, T y){
		if(high[0] > x) high[0] = x;
		if(high[1] > y) high[1] = y;