25#ifndef __SHAPE_SEGMENT_H
26#define __SHAPE_SEGMENT_H
28#include <geometry/seg.h>
29#include <geometry/shape.h>
31#include <math/vector2d.h>
62 const BOX2I BBox(
int aClearance = 0 )
const override
64 return BOX2I( m_seg.A, m_seg.B - m_seg.A ).
Inflate( aClearance + ( m_width + 1 ) / 2 );
72 bool Collide(
const SHAPE* aShape,
int aClearance = 0,
int* aActual =
nullptr,
73 VECTOR2I* aLocation =
nullptr )
const override
78 bool Collide(
const SEG& aSeg,
int aClearance = 0,
int* aActual =
nullptr,
79 VECTOR2I* aLocation =
nullptr )
const override
81 if( aSeg.A == aSeg.B )
82 return Collide( aSeg.A, aClearance, aActual, aLocation );
84 int min_dist = ( m_width + 1 ) / 2 + aClearance;
85 ecoord dist_sq = m_seg.SquaredDistance( aSeg );
87 if( dist_sq == 0 || dist_sq < SEG::Square( min_dist ) )
93 *aActual = std::max( 0, (
int) sqrt( dist_sq ) - ( m_width + 1 ) / 2 );
102 VECTOR2I* aLocation =
nullptr )
const override
104 int min_dist = ( m_width + 1 ) / 2 + aClearance;
105 ecoord dist_sq = m_seg.SquaredDistance( aP );
107 if( dist_sq == 0 || dist_sq < SEG::Square( min_dist ) )
113 *aActual = std::max( 0, (
int) sqrt( dist_sq ) - ( m_width + 1 ) / 2 );
121 void SetSeg(
const SEG& aSeg )
126 const SEG& GetSeg()
const
131 void SetWidth(
int aWidth )
141 bool IsSolid()
const override
151 m_seg.A = m_seg.A.
Rotate( aAngle );
152 m_seg.B = m_seg.B.
Rotate( aAngle );
158 void Move(
const VECTOR2I& aVector )
override
164 virtual const std::string Format( )
const override;
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:281
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition seg.cpp:227
Definition shape_segment.h:36
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition shape_segment.h:57
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
Definition shape_segment.h:78
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Definition shape_segment.h:146
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Definition shape_segment.h:62
bool Collide(const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
Definition shape_segment.h:67
bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition shape_segment.h:101
An abstract shape on 2D plane.
Definition shape.h:117
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition shape.h:165
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition vector2d.h:365