1746{
1747 uint32_t split = it_first;
1748 if ((it_first - it_last) < 2)
1749 return it_first;
1750
1753
1755 {
1756
1757 for (uint32_t itk = it_first + 1; itk < it_last; itk++)
1758 {
1761 if (distance_sqr > max_distance_sqr)
1762 {
1763 split = itk;
1764 max_distance_sqr = distance_sqr;
1765 }
1766 }
1767 return split;
1768 }
1769
1770
1771 double ba_x = (B->
x - A->
x);
1772 double ba_y = (B->
y - A->
y);
1773 double ab_length_sqr = (ba_x * ba_x + ba_y * ba_y);
1774
1775
1776 max_distance_sqr *= ab_length_sqr;
1777 for (uint32_t itk = it_first + 1; itk < it_last; itk++)
1778 {
1780 double distance_sqr;
1781 double ca_x = (C->
x - A->
x);
1782 double ca_y = (C->
y - A->
y);
1783 double dot_ac_ab = (ca_x * ba_x + ca_y * ba_y);
1784
1785 if (dot_ac_ab <= 0.0)
1786 {
1788 }
1789 else if (dot_ac_ab >= ab_length_sqr)
1790 {
1792 }
1793 else
1794 {
1795 double s_numerator = ca_x * ba_y - ca_y * ba_x;
1796 distance_sqr = s_numerator * s_numerator;
1797 }
1798
1799 if (distance_sqr > max_distance_sqr)
1800 {
1801 split = itk;
1802 max_distance_sqr = distance_sqr;
1803 }
1804 }
1805 return split;
1806}
static double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.