ScummVM API documentation
Sword25::Region Class Reference

#include <region.h>

Inheritance diagram for Sword25::Region:
Sword25::Persistable Sword25::WalkRegion

Public Types

enum  REGION_TYPE { RT_REGION, RT_WALKREGION }
 

Public Member Functions

virtual bool init (const Polygon &contour, const Common::Array< Polygon > *pHoles=NULL)
 
bool isValid () const
 
const VertexgetPosition () const
 
int getPosX () const
 
int getPosY () const
 
bool isPointInRegion (const Vertex &vertex) const
 
bool isPointInRegion (int x, int y) const
 
const PolygongetContour () const
 
int getHoleCount () const
 
const PolygongetHole (uint i) const
 
Vertex findClosestRegionPoint (const Vertex &point) const
 
Vertex getCentroid () const
 
bool isLineOfSight (const Vertex &a, const Vertex &b) const
 
virtual void setPos (int x, int y)
 
void setPosX (int x)
 
void setPosY (int y)
 
bool persist (OutputPersistenceBlock &writer) override
 
bool unpersist (InputPersistenceBlock &reader) override
 

Static Public Member Functions

static uint create (REGION_TYPE type)
 
static uint create (InputPersistenceBlock &reader, uint handle=0)
 

Protected Member Functions

 Region ()
 
 Region (InputPersistenceBlock &reader, uint handle)
 
void updateBoundingBox ()
 
Vertex findClosestPointOnLine (const Vertex &lineStart, const Vertex &lineEnd, const Vertex point) const
 

Protected Attributes

REGION_TYPE _type
 This specifies the type of object.
 
bool _valid
 This variable indicates whether the current object state is valid.
 
Vertex _position
 This vertex is the position of the region.
 
Common::Array< Polygon_polygons
 This array contains all the polygons that define the region. The first element of.
 
Common::Rect _boundingBox
 The bounding box for the region.
 

Detailed Description

This class is the base class of all regions.

The IsValid() method can be queried to see whether the object is in a valid state. If this is not the case, the method Init() is the only method that may be invoked. This class guarantees that the Vertecies outline of the hole, and the polygons are arranged in a clockwise direction, so that the polygon working algorithms will work properly.

Constructor & Destructor Documentation

◆ Region()

Sword25::Region::Region ( )
protected

Creates a new BS_Region object

After creation the object is invaild (IsValid() return false), but a call can be made later on to Init() to set up the region into a valid state.

Member Function Documentation

◆ init()

virtual bool Sword25::Region::init ( const Polygon contour,
const Common::Array< Polygon > *  pHoles = NULL 
)
virtual

Initializes a BS_Region object

Parameters
ContourA polygon indicating the outline of the region
pHolesA pointer to an array of polygons representing the hole state in the region. If the region has no holes, it must be passed as NULL. The default value is NULL.
Returns
Returns true if the initialisation was successful, otherwise false.
Remarks
If the region was already initialized, the old state will be deleted.

Reimplemented in Sword25::WalkRegion.

◆ isValid()

bool Sword25::Region::isValid ( ) const
inline

Specifies whether the object is in a valid state

Returns
Returns true if the object is in a valid state, otherwise false.
Remarks
Invalid objects can be made valid by calling Init with a valid state.

◆ getPosition()

const Vertex& Sword25::Region::getPosition ( ) const
inline

Returns the position of the region

◆ getPosX()

int Sword25::Region::getPosX ( ) const
inline

Returns the X position of the region

◆ getPosY()

int Sword25::Region::getPosY ( ) const
inline

Returns the Y position of the region

◆ isPointInRegion() [1/2]

bool Sword25::Region::isPointInRegion ( const Vertex vertex) const

Indicates whether a point is inside the region

Parameters
VertexA verex with the co-ordinates of the test point
Returns
Returns true if the point is within the region, otherwise false.

◆ isPointInRegion() [2/2]

bool Sword25::Region::isPointInRegion ( int  x,
int  y 
) const

Indicates whether a point is inside the region

Parameters
XThe X position
YThe Y position
Returns
Returns true if the point is within the region, otherwise false.

◆ getContour()

const Polygon& Sword25::Region::getContour ( ) const
inline

Returns the countour of the region

◆ getHoleCount()

int Sword25::Region::getHoleCount ( ) const
inline

Returns the number of polygons in the hole region

◆ getHole()

const Polygon & Sword25::Region::getHole ( uint  i) const
inline

Returns a specific hole polygon in the region

Parameters
iThe number of the hole to return. The index must be between 0 and GetHoleCount() - 1.
Returns
Returns the desired hole polygon

◆ findClosestRegionPoint()

Vertex Sword25::Region::findClosestRegionPoint ( const Vertex point) const

For a point outside the region, finds the closest point inside the region

Parameters
PointThe point that is outside the region
Returns
Returns the point within the region which is closest
Remarks
This method does not always work with pixel accuracy. One should not therefore rely on the fact that there is really no point in the region which is closer to the given point.

◆ getCentroid()

Vertex Sword25::Region::getCentroid ( ) const

Returns the centroid for the region

◆ setPos()

virtual void Sword25::Region::setPos ( int  x,
int  y 
)
virtual

Sets the position of the region

Parameters
XThe new X psoition of the region
YThe new Y psoition of the region

Reimplemented in Sword25::WalkRegion.

◆ setPosX()

void Sword25::Region::setPosX ( int  x)

Sets the X position of the region

Parameters
XThe new X position of the region

◆ setPosY()

void Sword25::Region::setPosY ( int  y)

Sets the Y position of the region

Parameters
YThe new Y position of the region

◆ updateBoundingBox()

void Sword25::Region::updateBoundingBox ( )
protected

Updates the bounding box of the region.

◆ findClosestPointOnLine()

Vertex Sword25::Region::findClosestPointOnLine ( const Vertex lineStart,
const Vertex lineEnd,
const Vertex  point 
) const
protected

Find the point on a line which is closest to another point

Parameters
LineStartThe start of the line
LineEndThe end of the line
PointThe point to be compared against
Returns
Returns the point on the line which is cloest to the passed point.

The documentation for this class was generated from the following file: