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

◆ getRectangleAlongCentreLine()

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

Definition at line 31 of file centreline_rect_item.cpp.

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

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

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