qzdoom/src/m_bbox.h

96 lines
2.4 KiB
C
Raw Normal View History

2016-03-01 15:47:10 +00:00
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id:$
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// DESCRIPTION:
// Nil.
//
//-----------------------------------------------------------------------------
#ifndef __M_BBOX_H__
#define __M_BBOX_H__
2016-03-31 08:38:54 +00:00
#include <float.h>
#include "vectors.h"
#include "m_fixed.h"
2016-03-01 15:47:10 +00:00
struct line_t;
struct node_t;
class FBoundingBox
{
public:
FBoundingBox()
{
ClearBox();
}
2016-03-31 08:38:54 +00:00
FBoundingBox(double left, double bottom, double right, double top)
2016-03-01 15:47:10 +00:00
{
m_Box[BOXTOP] = top;
m_Box[BOXLEFT] = left;
m_Box[BOXRIGHT] = right;
m_Box[BOXBOTTOM] = bottom;
}
FBoundingBox(double x, double y, double radius)
{
setBox(x, y, radius);
}
2016-03-01 15:47:10 +00:00
void setBox(double x, double y, double radius)
{
2016-03-31 08:38:54 +00:00
m_Box[BOXTOP] = y + radius;
m_Box[BOXLEFT] = x - radius;
m_Box[BOXRIGHT] = x + radius;
m_Box[BOXBOTTOM] = y - radius;
}
2016-03-01 15:47:10 +00:00
void ClearBox ()
{
2016-03-31 08:38:54 +00:00
m_Box[BOXTOP] = m_Box[BOXRIGHT] = -FLT_MAX;
m_Box[BOXBOTTOM] = m_Box[BOXLEFT] = FLT_MAX;
2016-03-01 15:47:10 +00:00
}
// Returns a bounding box that encloses both bounding boxes
FBoundingBox operator | (const FBoundingBox &box2) const
{
return FBoundingBox(m_Box[BOXLEFT] < box2.m_Box[BOXLEFT] ? m_Box[BOXLEFT] : box2.m_Box[BOXLEFT],
m_Box[BOXBOTTOM] < box2.m_Box[BOXBOTTOM] ? m_Box[BOXBOTTOM] : box2.m_Box[BOXBOTTOM],
m_Box[BOXRIGHT] > box2.m_Box[BOXRIGHT] ? m_Box[BOXRIGHT] : box2.m_Box[BOXRIGHT],
m_Box[BOXTOP] > box2.m_Box[BOXTOP] ? m_Box[BOXTOP] : box2.m_Box[BOXTOP]);
}
2016-03-31 08:38:54 +00:00
void AddToBox(const DVector2 &pos);
2016-03-01 15:47:10 +00:00
2016-03-31 08:38:54 +00:00
inline double Top () const { return m_Box[BOXTOP]; }
inline double Bottom () const { return m_Box[BOXBOTTOM]; }
inline double Left () const { return m_Box[BOXLEFT]; }
inline double Right () const { return m_Box[BOXRIGHT]; }
2016-03-01 15:47:10 +00:00
bool inRange(const line_t *ld) const;
2016-03-01 15:47:10 +00:00
int BoxOnLineSide (const line_t *ld) const;
2016-03-31 08:38:54 +00:00
void Set(int index, double value) {m_Box[index] = value;}
2016-03-01 15:47:10 +00:00
protected:
2016-03-31 08:38:54 +00:00
double m_Box[4];
2016-03-01 15:47:10 +00:00
};
#endif //__M_BBOX_H__