예제 #1
0
  inline pos2<T> clop(const pos2<T>& pos, const rect<T>& r, T resolution=1) {
	pos2<T> cloped(pos);
	if (cloped.x_ >= r.right()) cloped.x_ = r.right() - resolution;
	if (cloped.y_ >= r.bottom()) cloped.y_ = r.bottom() - resolution;
	if (cloped.x_ < r.left()) cloped.x_ = r.left();
	if (cloped.y_ < r.top()) cloped.y_ = r.top();
	return cloped;
  }
예제 #2
0
	constexpr bool contains(
		rect< PositionType, SizeType > const& reference,
		rect< PositionType, SizeType > const& test
	){
		return
			test.left()   >= reference.left()  &&
			test.top()    >= reference.top()   &&
			test.right()  <= reference.right() &&
			test.bottom() <= reference.bottom();
	}
예제 #3
0
	constexpr rect< PositionType, SizeType > join(
		rect< PositionType, SizeType > const& lhs,
		rect< PositionType, SizeType > const& rhs
	){
		return rect< PositionType, SizeType >(
			point< PositionType >(
				std::min(lhs.left(), rhs.left()),
				std::min(lhs.top(), rhs.top())
			),
			point< PositionType >(
				std::max(lhs.right(), rhs.right()),
				std::max(lhs.bottom(), rhs.bottom())
			)
		);
	}
예제 #4
0
	constexpr bool contains(
		rect< PositionType, SizeType > const& rect,
		point< DataType > const& point
	){
		return
			point.x() >= rect.left()  &&
			point.y() >= rect.top()   &&
			point.x() <  rect.right() &&
			point.y() <  rect.bottom();
	}
예제 #5
0
파일: rect.cpp 프로젝트: zxiy/gml
	int rect::hit_test(const rect& other) const
	{
		int intersect_other = 0;
		if (other.hit_test(left(),  top()))		intersect_other++;
		if (other.hit_test(left(),  bottom()))	intersect_other++;
		if (other.hit_test(right(), top()))		intersect_other++;
		if (other.hit_test(right(), bottom()))	intersect_other++;

		if (intersect_other == 0)
			return outside;
		else if (intersect_other == 4)
			return inside;

		intersect_other = 0;
		if (hit_test(other.left(),  other.top()))		intersect_other++;
		if (hit_test(other.left(),  other.bottom()))	intersect_other++;
		if (hit_test(other.right(), other.top()))		intersect_other++;
		if (hit_test(other.right(), other.bottom()))	intersect_other++;

		if (intersect_other == 4)
			return contain;
		else //
			return intersect;
	}