KiCad PCB EDA Suite
Loading...
Searching...
No Matches
DIRECTION_45 Class Reference

Represent route directions & corner angles in a 45-degree metric. More...

#include <direction45.h>

Public Types

enum  Directions : int {
  N = 0 , NE = 1 , E = 2 , SE = 3 ,
  S = 4 , SW = 5 , W = 6 , NW = 7 ,
  LAST = 8 , UNDEFINED = -1
}
 Available directions, there are 8 of them, as on a rectilinear map (north = up) + an extra undefined direction, reserved for traces that don't respect 45-degree routing regime. More...
 
enum  CORNER_MODE { MITERED_45 = 0 , ROUNDED_45 = 1 , MITERED_90 = 2 , ROUNDED_90 = 3 }
 Corner modes. More...
 
enum  AngleType {
  ANG_OBTUSE = 0x01 , ANG_RIGHT = 0x02 , ANG_ACUTE = 0x04 , ANG_STRAIGHT = 0x08 ,
  ANG_HALF_FULL = 0x10 , ANG_UNDEFINED = 0x20
}
 Represent kind of angle formed by vectors heading in two DIRECTION_45s. More...
 

Public Member Functions

 DIRECTION_45 (Directions aDir=UNDEFINED)
 
 DIRECTION_45 (const VECTOR2I &aVec, bool a90=false)
 
 DIRECTION_45 (const SEG &aSeg, bool a90=false)
 
 DIRECTION_45 (const SHAPE_ARC &aArc, bool a90=false)
 Create a DIRECTION_45 from the endpoints of a given arc.
 
const std::string Format () const
 Format the direction in a human readable word.
 
DIRECTION_45 Opposite () const
 Return a direction opposite (180 degree) to (this).
 
AngleType Angle (const DIRECTION_45 &aOther) const
 Return the type of angle between directions (this) and aOther.
 
bool IsObtuse (const DIRECTION_45 &aOther) const
 
bool IsDiagonal () const
 Returns true if the direction is diagonal (e.g.
 
bool IsDefined () const
 
const SHAPE_LINE_CHAIN BuildInitialTrace (const VECTOR2I &aP0, const VECTOR2I &aP1, bool aStartDiagonal=false, CORNER_MODE aMode=CORNER_MODE::MITERED_45) const
 Build a 2-segment line chain between points aP0 and aP1 and following 45-degree routing regime.
 
bool operator== (const DIRECTION_45 &aOther) const
 
bool operator!= (const DIRECTION_45 &aOther) const
 
const DIRECTION_45 Right () const
 Return the direction on the right side of this (i.e.
 
const DIRECTION_45 Left () const
 Return the direction on the left side of this (i.e.
 
const VECTOR2I ToVector () const
 
int Mask () const
 

Static Public Member Functions

static int AllDirectionsMask ()
 

Private Member Functions

void construct_ (const VECTOR2I &aVec)
 Calculate the direction from a vector.
 

Private Attributes

Directions m_dir
 Are we routing on 45 or 90 degree increments.
 
bool m_90deg
 

Detailed Description

Represent route directions & corner angles in a 45-degree metric.

Definition at line 36 of file direction45.h.

Member Enumeration Documentation

◆ AngleType

Represent kind of angle formed by vectors heading in two DIRECTION_45s.

Enumerator
ANG_OBTUSE 
ANG_RIGHT 
ANG_ACUTE 
ANG_STRAIGHT 
ANG_HALF_FULL 
ANG_UNDEFINED 

Definition at line 77 of file direction45.h.

◆ CORNER_MODE

Corner modes.

A corner can either be 45° or 90° and can be fillet/rounded or mitered

Enumerator
MITERED_45 

H/V/45 with mitered corners (default)

ROUNDED_45 

H/V/45 with filleted corners.

MITERED_90 

H/V only (90-degree corners)

ROUNDED_90 

H/V with filleted corners.

Definition at line 66 of file direction45.h.

◆ Directions

Available directions, there are 8 of them, as on a rectilinear map (north = up) + an extra undefined direction, reserved for traces that don't respect 45-degree routing regime.

Note
North represents "up" to the user looking at the application, which is the negative-y direction in the world coordinate space!
Enumerator
NE 
SE 
SW 
NW 
LAST 
UNDEFINED 

Definition at line 48 of file direction45.h.

Constructor & Destructor Documentation

◆ DIRECTION_45() [1/4]

DIRECTION_45::DIRECTION_45 ( Directions aDir = UNDEFINED)
inline

Definition at line 87 of file direction45.h.

References m_90deg, m_dir, and UNDEFINED.

Referenced by Angle(), IsObtuse(), Left(), operator!=(), operator==(), Opposite(), and Right().

◆ DIRECTION_45() [2/4]

DIRECTION_45::DIRECTION_45 ( const VECTOR2I & aVec,
bool a90 = false )
inline
Parameters
aVecvector in world space, whose direction will be translated into a DIRECTION_45.

Definition at line 92 of file direction45.h.

References construct_(), m_90deg, and VECTOR2< T >::y.

◆ DIRECTION_45() [3/4]

DIRECTION_45::DIRECTION_45 ( const SEG & aSeg,
bool a90 = false )
inline
Parameters
aSegsegment, whose direction will be translated into a DIRECTION_45.

Definition at line 103 of file direction45.h.

References SEG::A, SEG::B, construct_(), m_90deg, and VECTOR2< T >::y.

◆ DIRECTION_45() [4/4]

DIRECTION_45::DIRECTION_45 ( const SHAPE_ARC & aArc,
bool a90 = false )
inline

Create a DIRECTION_45 from the endpoints of a given arc.

Parameters
aArcwill be translated into the closest DIRECTION_45

Definition at line 116 of file direction45.h.

References construct_(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), m_90deg, and VECTOR2< T >::y.

Member Function Documentation

◆ AllDirectionsMask()

static int DIRECTION_45::AllDirectionsMask ( )
inlinestatic

Definition at line 310 of file direction45.h.

Referenced by PNS::DP_GATEWAYS::BuildGeneric().

◆ Angle()

◆ BuildInitialTrace()

const SHAPE_LINE_CHAIN DIRECTION_45::BuildInitialTrace ( const VECTOR2I & aP0,
const VECTOR2I & aP1,
bool aStartDiagonal = false,
CORNER_MODE aMode = CORNER_MODE::MITERED_45 ) const

Build a 2-segment line chain between points aP0 and aP1 and following 45-degree routing regime.

If aStartDiagonal is true, the trace starts with a diagonal segment.

Parameters
aP0starting point
aP1ending point
aStartDiagonalwhether the first segment has to be diagonal
aModeHow the corner is made. If it is a 90° corner, aStartDiagonal means start with the shorter direction first / use arc before the straight segment.
Returns
the trace

Definition at line 24 of file direction_45.cpp.

References std::abs(), ANGLE_45, ANGLE_90, SHAPE_LINE_CHAIN::Append(), SHAPE_ARC::ConstructFromStartEndAngle(), SHAPE_ARC::ConstructFromStartEndCenter(), VECTOR2< T >::EuclideanNorm(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), IsDiagonal(), KiROUND(), m_dir, M_PI, SHAPE::MIN_PRECISION_IU, MITERED_45, MITERED_90, VECTOR2< T >::Resize(), RotatePoint(), ROUNDED_45, ROUNDED_90, sign(), SHAPE_LINE_CHAIN::Simplify(), VECTOR2< T >::SquaredEuclideanNorm(), UNDEFINED, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PNS::DP_GATEWAYS::buildEntries(), PNS::DIFF_PAIR::BuildInitial(), PNS::LINE_PLACER::buildInitialLine(), PNS::coupledBypass(), PNS::dragCornerInternal(), PNS::OPTIMIZER::dragFixCorner(), PNS::OPTIMIZER::fanoutCleanup(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeStep(), PNS::LINE_PLACER::reduceTail(), and PNS::OPTIMIZER::smartPadsSingle().

◆ construct_()

void DIRECTION_45::construct_ ( const VECTOR2I & aVec)
inlineprivate

Calculate the direction from a vector.

If the vector's angle is not a multiple of 45 degrees, the direction is rounded to the nearest octant.

Parameters
aVecour vector our actual direction

Definition at line 322 of file direction45.h.

References LAST, m_dir, M_PI, UNDEFINED, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DIRECTION_45(), DIRECTION_45(), and DIRECTION_45().

◆ Format()

const std::string DIRECTION_45::Format ( ) const
inline

◆ IsDefined()

bool DIRECTION_45::IsDefined ( ) const
inline

Definition at line 218 of file direction45.h.

References m_dir, and UNDEFINED.

◆ IsDiagonal()

bool DIRECTION_45::IsDiagonal ( ) const
inline

Returns true if the direction is diagonal (e.g.

North-West, South-East, etc).

Returns
true, when diagonal.

Definition at line 213 of file direction45.h.

References m_dir.

Referenced by BuildInitialTrace(), PNS::coupledBypass(), PNS::dragCornerInternal(), PNS::DIFF_PAIR_PLACER::FixRoute(), and PNS::OPTIMIZER::mergeDpStep().

◆ IsObtuse()

bool DIRECTION_45::IsObtuse ( const DIRECTION_45 & aOther) const
inline
Returns
true, when (this) forms an obtuse angle with aOther.

Definition at line 203 of file direction45.h.

References ANG_OBTUSE, Angle(), and DIRECTION_45().

Referenced by PNS::DP_GATEWAYS::BuildGeneric(), PNS::OPTIMIZER::mergeDpStep(), and PNS::tightenSegment().

◆ Left()

const DIRECTION_45 DIRECTION_45::Left ( ) const
inline

Return the direction on the left side of this (i.e.

turns left by 45 or 90 deg).

Definition at line 269 of file direction45.h.

References DIRECTION_45(), LAST, m_90deg, m_dir, and UNDEFINED.

Referenced by PNS::DP_GATEWAY::AddTurns(), PNS::DP_GATEWAYS::BuildGeneric(), and PNS::LINE::dragSegment45().

◆ Mask()

◆ operator!=()

bool DIRECTION_45::operator!= ( const DIRECTION_45 & aOther) const
inline

Definition at line 243 of file direction45.h.

References DIRECTION_45(), and m_dir.

◆ operator==()

bool DIRECTION_45::operator== ( const DIRECTION_45 & aOther) const
inline

Definition at line 238 of file direction45.h.

References DIRECTION_45(), and m_dir.

◆ Opposite()

DIRECTION_45 DIRECTION_45::Opposite ( ) const
inline

Return a direction opposite (180 degree) to (this).

Returns
opposite direction

Definition at line 170 of file direction45.h.

References DIRECTION_45(), E, m_dir, N, NE, NW, S, SE, SW, UNDEFINED, and W.

Referenced by PNS::DP_GATEWAYS::buildDpContinuation(), PNS::DP_GATEWAYS::BuildGeneric(), PNS::DIFF_PAIR::BuildInitial(), PNS::MULTI_DRAGGER::findNewLeaderSegment(), PNS::DIFF_PAIR::getDirection(), and PNS::DIFF_PAIR_PLACER::routeHead().

◆ Right()

const DIRECTION_45 DIRECTION_45::Right ( ) const
inline

Return the direction on the right side of this (i.e.

turns right by 45 or 90 deg).

Definition at line 251 of file direction45.h.

References DIRECTION_45(), LAST, m_90deg, m_dir, and UNDEFINED.

Referenced by PNS::DP_GATEWAY::AddTurns(), PNS::DP_GATEWAYS::buildDpContinuation(), PNS::DP_GATEWAYS::BuildGeneric(), PNS::LINE::dragSegment45(), and PNS::DP_GATEWAY::Extend().

◆ ToVector()

const VECTOR2I DIRECTION_45::ToVector ( ) const
inline
Returns
a unit vector in world coordinate system corresponding to our direction.

Definition at line 287 of file direction45.h.

References E, m_dir, N, NE, NW, S, SE, SW, and W.

Referenced by PNS::DP_GATEWAY::AddTurns(), PNS::DP_GATEWAYS::buildDpContinuation(), PNS::LINE::dragSegment45(), PNS::drawGateways(), and PNS::DP_GATEWAY::Extend().

Member Data Documentation

◆ m_90deg

bool DIRECTION_45::m_90deg
private

Definition at line 354 of file direction45.h.

Referenced by DIRECTION_45(), DIRECTION_45(), DIRECTION_45(), DIRECTION_45(), Left(), and Right().

◆ m_dir

Directions DIRECTION_45::m_dir
private

Are we routing on 45 or 90 degree increments.

Definition at line 351 of file direction45.h.

Referenced by Angle(), BuildInitialTrace(), construct_(), DIRECTION_45(), Format(), IsDefined(), IsDiagonal(), Left(), Mask(), operator!=(), operator==(), Opposite(), Right(), and ToVector().


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