Apollo  6.0
Open source self driving car software
Public Member Functions | Static Public Member Functions | List of all members
apollo::common::math::Box2d Class Reference

Rectangular (undirected) bounding box in 2-D. More...

#include <box2d.h>

Collaboration diagram for apollo::common::math::Box2d:
Collaboration graph

Public Member Functions

 Box2d ()=default
 
 Box2d (const Vec2d &center, const double heading, const double length, const double width)
 Constructor which takes the center, heading, length and width. More...
 
 Box2d (const LineSegment2d &axis, const double width)
 Constructor which takes the heading-axis and the width of the box. More...
 
 Box2d (const AABox2d &aabox)
 Constructor which takes an AABox2d (axes-aligned box). More...
 
const Vec2dcenter () const
 Getter of the center of the box. More...
 
double center_x () const
 Getter of the x-coordinate of the center of the box. More...
 
double center_y () const
 Getter of the y-coordinate of the center of the box. More...
 
double length () const
 Getter of the length. More...
 
double width () const
 Getter of the width. More...
 
double half_length () const
 Getter of half the length. More...
 
double half_width () const
 Getter of half the width. More...
 
double heading () const
 Getter of the heading. More...
 
double cos_heading () const
 Getter of the cosine of the heading. More...
 
double sin_heading () const
 Getter of the sine of the heading. More...
 
double area () const
 Getter of the area of the box. More...
 
double diagonal () const
 Getter of the size of the diagonal of the box. More...
 
void GetAllCorners (std::vector< Vec2d > *const corners) const
 Getter of the corners of the box. More...
 
std::vector< Vec2dGetAllCorners () const
 Getter of the corners of the box. More...
 
bool IsPointIn (const Vec2d &point) const
 Tests points for membership in the box. More...
 
bool IsPointOnBoundary (const Vec2d &point) const
 Tests points for membership in the boundary of the box. More...
 
double DistanceTo (const Vec2d &point) const
 Determines the distance between the box and a given point. More...
 
double DistanceTo (const LineSegment2d &line_segment) const
 Determines the distance between the box and a given line segment. More...
 
double DistanceTo (const Box2d &box) const
 Determines the distance between two boxes. More...
 
bool HasOverlap (const LineSegment2d &line_segment) const
 Determines whether this box overlaps a given line segment. More...
 
bool HasOverlap (const Box2d &box) const
 Determines whether these two boxes overlap. More...
 
AABox2d GetAABox () const
 Gets the smallest axes-aligned box containing the current one. More...
 
void RotateFromCenter (const double rotate_angle)
 Rotate from center. More...
 
void Shift (const Vec2d &shift_vec)
 Shifts this box by a given vector. More...
 
void LongitudinalExtend (const double extension_length)
 Extend the box longitudinally. More...
 
void LateralExtend (const double extension_length)
 
std::string DebugString () const
 Gets a human-readable description of the box. More...
 
void InitCorners ()
 
double max_x () const
 
double min_x () const
 
double max_y () const
 
double min_y () const
 

Static Public Member Functions

static Box2d CreateAABox (const Vec2d &one_corner, const Vec2d &opposite_corner)
 Creates an axes-aligned Box2d from two opposite corners. More...
 

Detailed Description

Rectangular (undirected) bounding box in 2-D.

This class is referential-agnostic, although our convention on the use of the word "heading" in this project (permanently set to be 0 at East) forces us to assume that the X/Y frame here is East/North. For disambiguation, we call the axis of the rectangle parallel to the heading direction the "heading-axis". The size of the heading-axis is called "length", and the size of the axis perpendicular to it "width".

Constructor & Destructor Documentation

◆ Box2d() [1/4]

apollo::common::math::Box2d::Box2d ( )
default

◆ Box2d() [2/4]

apollo::common::math::Box2d::Box2d ( const Vec2d center,
const double  heading,
const double  length,
const double  width 
)

Constructor which takes the center, heading, length and width.

Parameters
centerThe center of the rectangular bounding box.
headingThe angle between the x-axis and the heading-axis, measured counter-clockwise.
lengthThe size of the heading-axis.
widthThe size of the axis perpendicular to the heading-axis.

◆ Box2d() [3/4]

apollo::common::math::Box2d::Box2d ( const LineSegment2d axis,
const double  width 
)

Constructor which takes the heading-axis and the width of the box.

Parameters
axisThe heading-axis
widthThe width of the box, which is taken perpendicularly to the heading direction.

◆ Box2d() [4/4]

apollo::common::math::Box2d::Box2d ( const AABox2d aabox)
explicit

Constructor which takes an AABox2d (axes-aligned box).

Parameters
aaboxThe input AABox2d.

Member Function Documentation

◆ area()

double apollo::common::math::Box2d::area ( ) const
inline

Getter of the area of the box.

Returns
The product of its length and width

◆ center()

const Vec2d& apollo::common::math::Box2d::center ( ) const
inline

Getter of the center of the box.

Returns
The center of the box

◆ center_x()

double apollo::common::math::Box2d::center_x ( ) const
inline

Getter of the x-coordinate of the center of the box.

Returns
The x-coordinate of the center of the box

◆ center_y()

double apollo::common::math::Box2d::center_y ( ) const
inline

Getter of the y-coordinate of the center of the box.

Returns
The y-coordinate of the center of the box

◆ cos_heading()

double apollo::common::math::Box2d::cos_heading ( ) const
inline

Getter of the cosine of the heading.

Returns
The cosine of the heading

◆ CreateAABox()

static Box2d apollo::common::math::Box2d::CreateAABox ( const Vec2d one_corner,
const Vec2d opposite_corner 
)
static

Creates an axes-aligned Box2d from two opposite corners.

Parameters
one_cornerOne of the corners
opposite_cornerThe opposite corner to the first one
Returns
An axes-aligned Box2d

◆ DebugString()

std::string apollo::common::math::Box2d::DebugString ( ) const

Gets a human-readable description of the box.

Returns
A debug-string

◆ diagonal()

double apollo::common::math::Box2d::diagonal ( ) const
inline

Getter of the size of the diagonal of the box.

Returns
The diagonal size of the box

◆ DistanceTo() [1/3]

double apollo::common::math::Box2d::DistanceTo ( const Vec2d point) const

Determines the distance between the box and a given point.

Parameters
pointThe point whose distance to the box we wish to compute
Returns
A distance

◆ DistanceTo() [2/3]

double apollo::common::math::Box2d::DistanceTo ( const LineSegment2d line_segment) const

Determines the distance between the box and a given line segment.

Parameters
line_segmentThe line segment whose distance to the box we compute
Returns
A distance

◆ DistanceTo() [3/3]

double apollo::common::math::Box2d::DistanceTo ( const Box2d box) const

Determines the distance between two boxes.

Parameters
boxThe box whose distance to this box we want to compute
Returns
A distance

◆ GetAABox()

AABox2d apollo::common::math::Box2d::GetAABox ( ) const

Gets the smallest axes-aligned box containing the current one.

Returns
An axes-aligned box

◆ GetAllCorners() [1/2]

void apollo::common::math::Box2d::GetAllCorners ( std::vector< Vec2d > *const  corners) const

Getter of the corners of the box.

Parameters
cornersThe vector where the corners are listed

◆ GetAllCorners() [2/2]

std::vector<Vec2d> apollo::common::math::Box2d::GetAllCorners ( ) const

Getter of the corners of the box.

Parameters
cornersThe vector where the corners are listed

◆ half_length()

double apollo::common::math::Box2d::half_length ( ) const
inline

Getter of half the length.

Returns
Half the length of the heading-axis

◆ half_width()

double apollo::common::math::Box2d::half_width ( ) const
inline

Getter of half the width.

Returns
Half the width of the box taken perpendicularly to the heading

◆ HasOverlap() [1/2]

bool apollo::common::math::Box2d::HasOverlap ( const LineSegment2d line_segment) const

Determines whether this box overlaps a given line segment.

Parameters
line_segmentThe line-segment
Returns
True if they overlap

◆ HasOverlap() [2/2]

bool apollo::common::math::Box2d::HasOverlap ( const Box2d box) const

Determines whether these two boxes overlap.

Parameters
line_segmentThe other box
Returns
True if they overlap

◆ heading()

double apollo::common::math::Box2d::heading ( ) const
inline

Getter of the heading.

Returns
The counter-clockwise angle between the x-axis and the heading-axis

◆ InitCorners()

void apollo::common::math::Box2d::InitCorners ( )

◆ IsPointIn()

bool apollo::common::math::Box2d::IsPointIn ( const Vec2d point) const

Tests points for membership in the box.

Parameters
pointA point that we wish to test for membership in the box
Returns
True iff the point is contained in the box

◆ IsPointOnBoundary()

bool apollo::common::math::Box2d::IsPointOnBoundary ( const Vec2d point) const

Tests points for membership in the boundary of the box.

Parameters
pointA point that we wish to test for membership in the boundary
Returns
True iff the point is a boundary point of the box

◆ LateralExtend()

void apollo::common::math::Box2d::LateralExtend ( const double  extension_length)

◆ length()

double apollo::common::math::Box2d::length ( ) const
inline

Getter of the length.

Returns
The length of the heading-axis

◆ LongitudinalExtend()

void apollo::common::math::Box2d::LongitudinalExtend ( const double  extension_length)

Extend the box longitudinally.

Parameters
extension_lengththe length to extend

◆ max_x()

double apollo::common::math::Box2d::max_x ( ) const
inline

◆ max_y()

double apollo::common::math::Box2d::max_y ( ) const
inline

◆ min_x()

double apollo::common::math::Box2d::min_x ( ) const
inline

◆ min_y()

double apollo::common::math::Box2d::min_y ( ) const
inline

◆ RotateFromCenter()

void apollo::common::math::Box2d::RotateFromCenter ( const double  rotate_angle)

Rotate from center.

Parameters
rotate_angleAngle to rotate.

◆ Shift()

void apollo::common::math::Box2d::Shift ( const Vec2d shift_vec)

Shifts this box by a given vector.

Parameters
shift_vecThe vector determining the shift

◆ sin_heading()

double apollo::common::math::Box2d::sin_heading ( ) const
inline

Getter of the sine of the heading.

Returns
The sine of the heading

◆ width()

double apollo::common::math::Box2d::width ( ) const
inline

Getter of the width.

Returns
The width of the box taken perpendicularly to the heading

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