2011-10-12 03:02:50 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Anti-Grain Geometry - Version 2.4
|
|
|
|
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
|
|
|
|
//
|
2018-02-14 15:49:31 +00:00
|
|
|
// Permission to copy, use, modify, sell and distribute this software
|
|
|
|
// is granted provided this copyright notice appears in all copies.
|
2011-10-12 03:02:50 +00:00
|
|
|
// This software is provided "as is" without express or implied
|
|
|
|
// warranty, and with no claim as to its suitability for any purpose.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Contact: mcseem@antigrain.com
|
|
|
|
// mcseemagg@yahoo.com
|
|
|
|
// http://www.antigrain.com
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
#ifndef AGG_LINE_AA_BASICS_INCLUDED
|
|
|
|
#define AGG_LINE_AA_BASICS_INCLUDED
|
|
|
|
|
2013-02-28 19:41:08 +00:00
|
|
|
#include <cstdlib>
|
2011-10-12 03:02:50 +00:00
|
|
|
#include "agg_basics.h"
|
|
|
|
|
|
|
|
namespace agg
|
|
|
|
{
|
|
|
|
|
2018-02-14 15:49:31 +00:00
|
|
|
// See Implementation agg_line_aa_basics.cpp
|
2011-10-12 03:02:50 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
enum line_subpixel_scale_e
|
|
|
|
{
|
|
|
|
line_subpixel_shift = 8, //----line_subpixel_shift
|
|
|
|
line_subpixel_scale = 1 << line_subpixel_shift, //----line_subpixel_scale
|
|
|
|
line_subpixel_mask = line_subpixel_scale - 1, //----line_subpixel_mask
|
|
|
|
line_max_coord = (1 << 28) - 1, //----line_max_coord
|
|
|
|
line_max_length = 1 << (line_subpixel_shift + 10) //----line_max_length
|
|
|
|
};
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
enum line_mr_subpixel_scale_e
|
|
|
|
{
|
|
|
|
line_mr_subpixel_shift = 4, //----line_mr_subpixel_shift
|
2018-02-14 15:49:31 +00:00
|
|
|
line_mr_subpixel_scale = 1 << line_mr_subpixel_shift, //----line_mr_subpixel_scale
|
|
|
|
line_mr_subpixel_mask = line_mr_subpixel_scale - 1 //----line_mr_subpixel_mask
|
2011-10-12 03:02:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------line_mr
|
2018-02-14 15:49:31 +00:00
|
|
|
AGG_INLINE int line_mr(int x)
|
|
|
|
{
|
2022-08-04 10:25:35 +00:00
|
|
|
return x >> (line_subpixel_shift - static_cast<line_subpixel_scale_e>(line_mr_subpixel_shift));
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------line_hr
|
2018-02-14 15:49:31 +00:00
|
|
|
AGG_INLINE int line_hr(int x)
|
|
|
|
{
|
2022-08-04 10:25:35 +00:00
|
|
|
return x << (line_subpixel_shift - static_cast<line_subpixel_scale_e>(line_mr_subpixel_shift));
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------line_dbl_hr
|
2018-02-14 15:49:31 +00:00
|
|
|
AGG_INLINE int line_dbl_hr(int x)
|
|
|
|
{
|
|
|
|
return x * line_subpixel_scale;
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------line_coord
|
|
|
|
struct line_coord
|
|
|
|
{
|
|
|
|
AGG_INLINE static int conv(double x)
|
|
|
|
{
|
2022-08-04 10:25:35 +00:00
|
|
|
return iround(x * static_cast<double>(line_subpixel_scale));
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------line_coord_sat
|
|
|
|
struct line_coord_sat
|
|
|
|
{
|
|
|
|
AGG_INLINE static int conv(double x)
|
|
|
|
{
|
2022-08-04 10:25:35 +00:00
|
|
|
return saturation<line_max_coord>::iround(x * static_cast<double>(line_subpixel_scale));
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================line_parameters
|
|
|
|
struct line_parameters
|
|
|
|
{
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
line_parameters() {}
|
|
|
|
line_parameters(int x1_, int y1_, int x2_, int y2_, int len_) :
|
2018-02-14 15:49:31 +00:00
|
|
|
x1(x1_), y1(y1_), x2(x2_), y2(y2_),
|
2014-08-30 22:13:26 +00:00
|
|
|
dx(std::abs(x2_ - x1_)),
|
|
|
|
dy(std::abs(y2_ - y1_)),
|
2011-10-12 03:02:50 +00:00
|
|
|
sx((x2_ > x1_) ? 1 : -1),
|
|
|
|
sy((y2_ > y1_) ? 1 : -1),
|
|
|
|
vertical(dy >= dx),
|
|
|
|
inc(vertical ? sy : sx),
|
|
|
|
len(len_),
|
|
|
|
octant((sy & 4) | (sx & 2) | int(vertical))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
unsigned orthogonal_quadrant() const { return s_orthogonal_quadrant[octant]; }
|
|
|
|
unsigned diagonal_quadrant() const { return s_diagonal_quadrant[octant]; }
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
bool same_orthogonal_quadrant(const line_parameters& lp) const
|
|
|
|
{
|
|
|
|
return s_orthogonal_quadrant[octant] == s_orthogonal_quadrant[lp.octant];
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
bool same_diagonal_quadrant(const line_parameters& lp) const
|
|
|
|
{
|
|
|
|
return s_diagonal_quadrant[octant] == s_diagonal_quadrant[lp.octant];
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
void divide(line_parameters& lp1, line_parameters& lp2) const
|
|
|
|
{
|
|
|
|
int xmid = (x1 + x2) >> 1;
|
|
|
|
int ymid = (y1 + y2) >> 1;
|
|
|
|
int len2 = len >> 1;
|
|
|
|
|
|
|
|
lp1 = *this;
|
|
|
|
lp2 = *this;
|
|
|
|
|
|
|
|
lp1.x2 = xmid;
|
|
|
|
lp1.y2 = ymid;
|
|
|
|
lp1.len = len2;
|
2014-08-30 22:13:26 +00:00
|
|
|
lp1.dx = std::abs(lp1.x2 - lp1.x1);
|
|
|
|
lp1.dy = std::abs(lp1.y2 - lp1.y1);
|
2011-10-12 03:02:50 +00:00
|
|
|
|
|
|
|
lp2.x1 = xmid;
|
|
|
|
lp2.y1 = ymid;
|
|
|
|
lp2.len = len2;
|
2014-08-30 22:13:26 +00:00
|
|
|
lp2.dx = std::abs(lp2.x2 - lp2.x1);
|
|
|
|
lp2.dy = std::abs(lp2.y2 - lp2.y1);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2018-02-14 15:49:31 +00:00
|
|
|
|
2011-10-12 03:02:50 +00:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
int x1, y1, x2, y2, dx, dy, sx, sy;
|
|
|
|
bool vertical;
|
|
|
|
int inc;
|
|
|
|
int len;
|
|
|
|
int octant;
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
static const int8u s_orthogonal_quadrant[8];
|
|
|
|
static const int8u s_diagonal_quadrant[8];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-14 15:49:31 +00:00
|
|
|
// See Implementation agg_line_aa_basics.cpp
|
2011-10-12 03:02:50 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------bisectrix
|
2018-02-14 15:49:31 +00:00
|
|
|
void bisectrix(const line_parameters& l1,
|
|
|
|
const line_parameters& l2,
|
2011-10-12 03:02:50 +00:00
|
|
|
int* x, int* y);
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------fix_degenerate_bisectrix_start
|
2018-02-14 15:49:31 +00:00
|
|
|
void inline fix_degenerate_bisectrix_start(const line_parameters& lp,
|
2011-10-12 03:02:50 +00:00
|
|
|
int* x, int* y)
|
|
|
|
{
|
2018-02-14 15:49:31 +00:00
|
|
|
int d = iround((double(*x - lp.x2) * double(lp.y2 - lp.y1) -
|
2011-10-12 03:02:50 +00:00
|
|
|
double(*y - lp.y2) * double(lp.x2 - lp.x1)) / lp.len);
|
|
|
|
if(d < line_subpixel_scale/2)
|
|
|
|
{
|
|
|
|
*x = lp.x1 + (lp.y2 - lp.y1);
|
|
|
|
*y = lp.y1 - (lp.x2 - lp.x1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------fix_degenerate_bisectrix_end
|
2018-02-14 15:49:31 +00:00
|
|
|
void inline fix_degenerate_bisectrix_end(const line_parameters& lp,
|
2011-10-12 03:02:50 +00:00
|
|
|
int* x, int* y)
|
|
|
|
{
|
2018-02-14 15:49:31 +00:00
|
|
|
int d = iround((double(*x - lp.x2) * double(lp.y2 - lp.y1) -
|
2011-10-12 03:02:50 +00:00
|
|
|
double(*y - lp.y2) * double(lp.x2 - lp.x1)) / lp.len);
|
|
|
|
if(d < line_subpixel_scale/2)
|
|
|
|
{
|
|
|
|
*x = lp.x2 + (lp.y2 - lp.y1);
|
|
|
|
*y = lp.y2 - (lp.x2 - lp.x1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|