KiCad PCB EDA Suite
alg Namespace Reference

Functions

template<typename _Type , typename _Function >
void run_on_pair (std::pair< _Type, _Type > &__pair, _Function __f)
 Apply a function to the first and second element of a std::pair. More...
 
template<typename _InputIterator , typename _Function >
void adjacent_pairs (_InputIterator __first, _InputIterator __last, _Function __f)
 Apply a function to every sequential pair of elements of a sequence. More...
 
template<typename _InputIterator , typename _Function >
void for_all_pairs (_InputIterator __first, _InputIterator __last, _Function __f)
 Apply a function to every possible pair of elements of a sequence. More...
 
template<class _Container , typename _Value >
bool contains (const _Container &__container, _Value __value)
 Returns true if the container contains the given value. More...
 
template<typename _Type , typename _Value >
bool pair_contains (const std::pair< _Type, _Type > __pair, _Value __value)
 Returns true if either of the elements in an std::pair contains the given value. More...
 
template<class T >
bool within_wrapped_range (T __val, T __minval, T __maxval, T __wrap)
 Test if __val lies within __minval and __maxval in a wrapped range. More...
 

Function Documentation

◆ adjacent_pairs()

template<typename _InputIterator , typename _Function >
void alg::adjacent_pairs ( _InputIterator  __first,
_InputIterator  __last,
_Function  __f 
)

Apply a function to every sequential pair of elements of a sequence.

Parameters
__firstAn input iterator.
__lastAn input iterator.
__fA unary function object.

Applies the function object __f to each sequential pair of elements in the range [first,last). __f must not modify the order of the sequence. If __f has a return value it is ignored.

Definition at line 61 of file kicad_algo.h.

62 {
63  if( __first != __last )
64  {
65  _InputIterator __follow = __first;
66  ++__first;
67  for( ; __first != __last; ++__first, ++__follow )
68  __f( *__follow, *__first );
69  }
70 }

◆ contains()

◆ for_all_pairs()

template<typename _InputIterator , typename _Function >
void alg::for_all_pairs ( _InputIterator  __first,
_InputIterator  __last,
_Function  __f 
)

Apply a function to every possible pair of elements of a sequence.

Parameters
__firstAn input iterator.
__lastAn input iterator.
__fA unary function object.

Applies the function object __f to every possible pair of elements in the range [first,last). __f must not modify the order of the sequence. If __f has a return value it is ignored.

Definition at line 83 of file kicad_algo.h.

84 {
85  if( __first != __last )
86  {
87  _InputIterator __follow = __first;
88  ++__first;
89  for( ; __first != __last; ++__first, ++__follow )
90  for( _InputIterator __it = __first; __it != __last; ++__it )
91  __f( *__follow, *__it );
92  }
93 }

Referenced by SCH_EDIT_FRAME::DeleteJunction(), and SCH_EDIT_FRAME::SchematicCleanUp().

◆ pair_contains()

template<typename _Type , typename _Value >
bool alg::pair_contains ( const std::pair< _Type, _Type >  __pair,
_Value  __value 
)

Returns true if either of the elements in an std::pair contains the given value.

Parameters
__pairA pair of elements (both elements must be the same type).
__valueA value to test
Returns
true if __value is contained in __pair

Definition at line 112 of file kicad_algo.h.

113 {
114  return __pair.first == static_cast<_Type>( __value )
115  || __pair.second == static_cast<_Type>( __value );
116 }

Referenced by SHAPE_LINE_CHAIN::NextShape().

◆ run_on_pair()

template<typename _Type , typename _Function >
void alg::run_on_pair ( std::pair< _Type, _Type > &  __pair,
_Function  __f 
)

Apply a function to the first and second element of a std::pair.

Parameters
__pairA pair of elements (both elements must be the same type).
__fA unary function object.

Applies the function object __f to __pair.first and __pair.second If __f has a return value it is ignored.

Definition at line 44 of file kicad_algo.h.

45 {
46  __f( __pair.first );
47  __f( __pair.second );
48 }

Referenced by SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::convertArc(), SHAPE_LINE_CHAIN::Insert(), SHAPE_LINE_CHAIN::Remove(), SHAPE_LINE_CHAIN::Replace(), SHAPE_LINE_CHAIN::Reverse(), SHAPE_LINE_CHAIN::SetPoint(), and SHAPE_LINE_CHAIN::splitArc().

◆ within_wrapped_range()

template<class T >
bool alg::within_wrapped_range ( __val,
__minval,
__maxval,
__wrap 
)

Test if __val lies within __minval and __maxval in a wrapped range.

Parameters
__valA value to test
__minvalLowest permissible value within the wrapped range
__maxvalHighest permissible value within the wrapped range
__wrapValue at which the range wraps around itself (must be positive)
Returns
true if __val lies in the wrapped range

Definition at line 128 of file kicad_algo.h.

129 {
130  wxCHECK_MSG( __wrap > 0, false, "Wrap must be positive!" );
131 
132  while( __maxval >= __wrap )
133  __maxval -= __wrap;
134 
135  while( __maxval < 0 )
136  __maxval += __wrap;
137 
138  while( __minval >= __wrap )
139  __minval -= __wrap;
140 
141  while( __minval < 0 )
142  __minval += __wrap;
143 
144  while( __val < 0 )
145  __val += __wrap;
146 
147  while( __val >= __wrap )
148  __val -= __wrap;
149 
150  if( __maxval > __minval )
151  return __val >= __minval && __val <= __maxval;
152  else
153  return __val >= __minval || __val <= __maxval;
154 }

Referenced by SHAPE_ARC::sliceContainsPoint().