KiCad PCB EDA Suite
centreline_rect_item.cpp File Reference

Go to the source code of this file.

Functions

static SHAPE_POLY_SET getRectangleAlongCentreLine (const VECTOR2D &aClStart, const VECTOR2D &aClEnd, double aAspect)
 

Function Documentation

static SHAPE_POLY_SET getRectangleAlongCentreLine ( const VECTOR2D aClStart,
const VECTOR2D aClEnd,
double  aAspect 
)
static

Definition at line 33 of file centreline_rect_item.cpp.

References SHAPE_POLY_SET::Append(), SHAPE_POLY_SET::NewOutline(), and VECTOR2< T >::Rotate().

Referenced by KIGFX::PREVIEW::CENTRELINE_RECT_ITEM::getOutline().

35 {
36  SHAPE_POLY_SET poly;
37  poly.NewOutline();
38 
39  /*
40  * The point layout of the rectangle goes like this,
41  * but start/end don't have to be horz/vert
42  *
43  * 0 ---------------- 1 -----
44  * | | ^
45  * s--------cl------->e |cl|/aspect
46  * | | v
47  * 3----------------- 2 -----
48  */
49 
50  // vector down the centre line of the rectangle
51  const VECTOR2D cl = aClEnd - aClStart;
52 
53  // the "side" of the rectangle is the centre line rotated by 90 deg
54  // and scaled by the aspect ratio
55  const VECTOR2D side = cl.Rotate( M_PI / 2.0 ) * aAspect;
56 
57  VECTOR2D pt = aClStart + ( side / 2.0 );
58  poly.Append( pt );
59 
60  pt += cl;
61  poly.Append( pt );
62 
63  pt -= side;
64  poly.Append( pt );
65 
66  pt -= cl;
67  poly.Append( pt );
68 
69  return poly;
70 }
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:373
Class SHAPE_POLY_SET.
int NewOutline()
Creates a new empty polygon in the set and returns its index
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...