mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Bresenham line mods
This commit is contained in:
parent
e114bce5f5
commit
62318783af
@ -46,9 +46,8 @@ namespace etl
|
||||
/// line algorithm.
|
||||
/// T is the type for the etl::coordinate_2d value type.
|
||||
/// TWork is the internal working variable type. Default is int16_t.
|
||||
/// TCoordinate is the coordinate type. Default is etl::coordinate_2d<TWork>
|
||||
//***************************************************************************
|
||||
template <typename T, typename TWork = int16_t, typename TCoordinate = etl::coordinate_2d<TWork> >
|
||||
template <typename T, typename TWork = int16_t>
|
||||
class bresenham_line
|
||||
{
|
||||
public:
|
||||
@ -56,14 +55,13 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Standard container types.
|
||||
//***************************************************
|
||||
typedef TCoordinate value_type;
|
||||
typedef TCoordinate coordinate_type;
|
||||
typedef typename TCoordinate::axis_type axis_type;
|
||||
typedef size_t size_type;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef etl::coordinate_2d<T> value_type;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
|
||||
//***************************************************
|
||||
/// Const Iterator
|
||||
@ -122,7 +120,7 @@ namespace etl
|
||||
//***************************************************
|
||||
/// De-reference operator
|
||||
//***************************************************
|
||||
TCoordinate operator *() const
|
||||
value_type operator *() const
|
||||
{
|
||||
return p_bresenham_line->get_coordinate();
|
||||
}
|
||||
@ -148,29 +146,27 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Constructor for use by bresenham_line
|
||||
//***************************************************
|
||||
const_iterator(bresenham_line<T, TWork, TCoordinate>* pb)
|
||||
const_iterator(bresenham_line<T>* pb)
|
||||
: p_bresenham_line(pb)
|
||||
{
|
||||
}
|
||||
|
||||
bresenham_line<T, TWork, TCoordinate>* p_bresenham_line;
|
||||
bresenham_line<T>* p_bresenham_line;
|
||||
};
|
||||
|
||||
friend class const_iterator;
|
||||
|
||||
//***************************************************
|
||||
/// Constructor.
|
||||
//***************************************************
|
||||
bresenham_line()
|
||||
{
|
||||
initialise(axis_type(0), axis_type(0), axis_type(0), axis_type(0));
|
||||
initialise(T(0), T(0), T(0), T(0));
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Constructor.
|
||||
/// Supplied first and last coordinates
|
||||
//***************************************************
|
||||
bresenham_line(coordinate_type first_, coordinate_type last_)
|
||||
bresenham_line(etl::coordinate_2d<T> first_, etl::coordinate_2d<T> last_)
|
||||
{
|
||||
initialise(first_.x, first_.y, last_.x, last_.y);
|
||||
}
|
||||
@ -179,7 +175,7 @@ namespace etl
|
||||
/// Constructor.
|
||||
/// Supplied first and last coordinates
|
||||
//***************************************************
|
||||
bresenham_line(axis_type first_x, axis_type first_y, axis_type last_x, axis_type last_y)
|
||||
bresenham_line(T first_x, T first_y, T last_x, T last_y)
|
||||
{
|
||||
initialise(first_x, first_y, last_x, last_y);
|
||||
}
|
||||
@ -188,7 +184,7 @@ namespace etl
|
||||
/// Resets the line.
|
||||
/// Supplied first and last coordinates
|
||||
//***************************************************
|
||||
void reset(coordinate_type first_, coordinate_type last_)
|
||||
void reset(etl::coordinate_2d<T> first_, etl::coordinate_2d<T> last_)
|
||||
{
|
||||
initialise(first_.x, first_.y, last_.x, last_.y);
|
||||
}
|
||||
@ -197,7 +193,7 @@ namespace etl
|
||||
/// Resets the line.
|
||||
/// Supplied first and last coordinates
|
||||
//***************************************************
|
||||
void reset(axis_type first_x, axis_type first_y, axis_type last_x, axis_type last_y)
|
||||
void reset(T first_x, T first_y, T last_x, T last_y)
|
||||
{
|
||||
initialise(first_x, first_y, last_x, last_y);
|
||||
}
|
||||
@ -273,10 +269,10 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Get the current number of generated points.
|
||||
//***************************************************
|
||||
void initialise(axis_type first_x, axis_type first_y, axis_type last_x, axis_type last_y)
|
||||
void initialise(T first_x, T first_y, T last_x, T last_y)
|
||||
{
|
||||
first = coordinate_type(first_x, first_y);
|
||||
last = coordinate_type(last_x, last_y);
|
||||
first = value_type(first_x, first_y);
|
||||
last = value_type(last_x, last_y);
|
||||
coordinate = first;
|
||||
x_increment = (last_x < first_x) ? -1 : 1;
|
||||
y_increment = (last_y < first_y) ? -1 : 1;
|
||||
@ -316,11 +312,11 @@ namespace etl
|
||||
// Y is major axis.
|
||||
if (do_minor_increment)
|
||||
{
|
||||
coordinate.x = coordinate.x + x_increment;
|
||||
coordinate.x = T(coordinate.x + x_increment);
|
||||
balance -= dy;
|
||||
}
|
||||
|
||||
coordinate.y = coordinate.y + y_increment;
|
||||
coordinate.y = T(coordinate.y + y_increment);
|
||||
balance += dx;
|
||||
}
|
||||
else
|
||||
@ -328,11 +324,11 @@ namespace etl
|
||||
// X is major axis.
|
||||
if (do_minor_increment)
|
||||
{
|
||||
coordinate.y = coordinate.y + y_increment;
|
||||
coordinate.y = T(coordinate.y + y_increment);
|
||||
balance -= dx;
|
||||
}
|
||||
|
||||
coordinate.x = coordinate.x + x_increment;
|
||||
coordinate.x = T(coordinate.x + x_increment);
|
||||
balance += dy;
|
||||
}
|
||||
|
||||
@ -342,16 +338,16 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Get the current coordinate.
|
||||
//***************************************************
|
||||
coordinate_type get_coordinate() const
|
||||
value_type get_coordinate() const
|
||||
{
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
typedef TWork work_t;
|
||||
|
||||
coordinate_type first;
|
||||
coordinate_type last;
|
||||
coordinate_type coordinate;
|
||||
value_type first;
|
||||
value_type last;
|
||||
value_type coordinate;
|
||||
work_t x_increment;
|
||||
work_t y_increment;
|
||||
work_t dx;
|
||||
|
||||
@ -3286,6 +3286,9 @@
|
||||
<ClInclude Include="..\..\include\etl\callback_timer_deferred_locked.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_timer_interrupt.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_timer_locked.h" />
|
||||
<ClInclude Include="..\..\include\etl\center_of_gravity_1d.h" />
|
||||
<ClInclude Include="..\..\include\etl\center_of_gravity_2d.h" />
|
||||
<ClInclude Include="..\..\include\etl\center_of_gravity_3d.h" />
|
||||
<ClInclude Include="..\..\include\etl\chrono.h" />
|
||||
<ClInclude Include="..\..\include\etl\circular_buffer.h" />
|
||||
<ClInclude Include="..\..\include\etl\circular_iterator.h" />
|
||||
@ -3297,6 +3300,7 @@
|
||||
<ClInclude Include="..\..\include\etl\const_multimap.h" />
|
||||
<ClInclude Include="..\..\include\etl\const_multiset.h" />
|
||||
<ClInclude Include="..\..\include\etl\const_set.h" />
|
||||
<ClInclude Include="..\..\include\etl\coordinate.h" />
|
||||
<ClInclude Include="..\..\include\etl\correlation.h" />
|
||||
<ClInclude Include="..\..\include\etl\covariance.h" />
|
||||
<ClInclude Include="..\..\include\etl\crc.h" />
|
||||
@ -9382,6 +9386,9 @@
|
||||
<ClCompile Include="..\test_callback_timer_deferred_locked.cpp" />
|
||||
<ClCompile Include="..\test_callback_timer_interrupt.cpp" />
|
||||
<ClCompile Include="..\test_callback_timer_locked.cpp" />
|
||||
<ClCompile Include="..\test_center_of_gravity_1d.cpp" />
|
||||
<ClCompile Include="..\test_center_of_gravity_2d.cpp" />
|
||||
<ClCompile Include="..\test_center_of_gravity_3d.cpp" />
|
||||
<ClCompile Include="..\test_char_traits.cpp" />
|
||||
<ClCompile Include="..\test_chrono_clocks.cpp" />
|
||||
<ClCompile Include="..\test_chrono_day.cpp" />
|
||||
@ -9424,6 +9431,7 @@
|
||||
<ClCompile Include="..\test_const_set_constexpr.cpp" />
|
||||
<ClCompile Include="..\test_const_set_ext.cpp" />
|
||||
<ClCompile Include="..\test_const_set_ext_constexpr.cpp" />
|
||||
<ClCompile Include="..\test_coordinate.cpp" />
|
||||
<ClCompile Include="..\test_correlation.cpp" />
|
||||
<ClCompile Include="..\test_covariance.cpp" />
|
||||
<ClCompile Include="..\test_crc1.cpp" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user