KiCad PCB EDA Suite
Loading...
Searching...
No Matches
GRID_GEOMETRY Struct Reference

Geometry of a regular grid (cartesian or polar) and the math operations for snapping and coverage testing. More...

#include <grid_geometry.h>

Inheritance diagram for GRID_GEOMETRY:
KIGFX::GRID_SOURCE

Public Types

enum class  KIND { CARTESIAN , POLAR }
 

Public Member Functions

VECTOR2D Snap (const VECTOR2D &aPoint) const
 Snap a point to the nearest on-grid position.
 
bool Contains (const VECTOR2D &aPoint, double aTolerance=0.0) const
 
double Area () const
 
bool TakesPrecedenceOver (const GRID_GEOMETRY &aOther) const
 

Public Attributes

KIND kind = KIND::CARTESIAN
 
VECTOR2D origin
 
VECTOR2D pitch
 Cartesian: (dx, dy); polar: (dr, dPhi rad).
 
double orientation = 0.0
 Rotation about origin, radians CCW.
 
VECTOR2D extent
 Cartesian: (dx, dy) = size/2 from origin.
 
unsigned priority = 0
 Higher wins where grids overlap.
 

Detailed Description

Geometry of a regular grid (cartesian or polar) and the math operations for snapping and coverage testing.

Definition at line 30 of file grid_geometry.h.

Member Enumeration Documentation

◆ KIND

enum class GRID_GEOMETRY::KIND
strong
Enumerator
CARTESIAN 
POLAR 

Definition at line 32 of file grid_geometry.h.

Member Function Documentation

◆ Area()

double GRID_GEOMETRY::Area ( ) const
Returns
the area of the grid's coverage region. Used as a tiebreaker between overlapping grids of equal priority - smaller wins (more specific).

Definition at line 124 of file grid_geometry.cpp.

References std::abs(), CARTESIAN, extent, kind, and POLAR.

Referenced by PCB_GRID_ITEM::GetCoverageArea(), and TakesPrecedenceOver().

◆ Contains()

bool GRID_GEOMETRY::Contains ( const VECTOR2D & aPoint,
double aTolerance = 0.0 ) const
Returns
true if aPoint is within aTolerance of the grid's coverage.

Definition at line 93 of file grid_geometry.cpp.

References std::abs(), CARTESIAN, extent, GetRotated(), kind, M_PI, orientation, origin, POLAR, RADIANS_T, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_GRID_ITEM::HitTest(), and PCB_GRID_ITEM::HitTestArea().

◆ Snap()

VECTOR2D GRID_GEOMETRY::Snap ( const VECTOR2D & aPoint) const

Snap a point to the nearest on-grid position.

Returns
aPoint unchanged for degenerate geometry (non-positive pitch).

Definition at line 29 of file grid_geometry.cpp.

References CARTESIAN, extent, GetRotated(), kind, M_PI, orientation, origin, pitch, POLAR, RADIANS_T, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ TakesPrecedenceOver()

bool GRID_GEOMETRY::TakesPrecedenceOver ( const GRID_GEOMETRY & aOther) const
inline
Returns
true if this grid owns a point that both grids cover: higher priority first, then the smaller (more specific) area.

The Compare for std::stable_sort - the winner sorts FIRST, ties keep document order. The background grid is the only one at priority 0, so it always sorts last.

Definition at line 72 of file grid_geometry.h.

References Area(), and priority.

Referenced by FindActiveGridAt().

Member Data Documentation

◆ extent

◆ kind

◆ orientation

◆ origin

◆ pitch

◆ priority

unsigned GRID_GEOMETRY::priority = 0

Higher wins where grids overlap.

0 is reserved for the background grid; see TakesPrecedenceOver.

Definition at line 44 of file grid_geometry.h.

Referenced by PCB_GRID_ITEM::AsGridGeometry(), KIGFX::CAIRO_GAL_BASE::DrawGrid(), KIGFX::OPENGL_GAL::DrawGrid(), and TakesPrecedenceOver().


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