1532{
1533 uint32_t split = it_first;
1534 if ((it_first - it_last) < 2)
1535 return it_first;
1536
1539
1541 {
1542
1543 for (uint32_t itk = it_first + 1; itk < it_last; itk++)
1544 {
1547 if (distance_sqr > max_distance_sqr)
1548 {
1549 split = itk;
1550 max_distance_sqr = distance_sqr;
1551 }
1552 }
1553 return split;
1554 }
1555
1556
1557 double ba_x = (B->
x - A->
x);
1558 double ba_y = (B->
y - A->
y);
1559 double ab_length_sqr = (ba_x * ba_x + ba_y * ba_y);
1560
1561
1562 max_distance_sqr *= ab_length_sqr;
1563 for (uint32_t itk = it_first + 1; itk < it_last; itk++)
1564 {
1566 double distance_sqr;
1567 double ca_x = (C->
x - A->
x);
1568 double ca_y = (C->
y - A->
y);
1569 double dot_ac_ab = (ca_x * ba_x + ca_y * ba_y);
1570
1571 if (dot_ac_ab <= 0.0)
1572 {
1574 }
1575 else if (dot_ac_ab >= ab_length_sqr)
1576 {
1578 }
1579 else
1580 {
1581 double s_numerator = ca_x * ba_y - ca_y * ba_x;
1582 distance_sqr = s_numerator * s_numerator;
1583 }
1584
1585 if (distance_sqr > max_distance_sqr)
1586 {
1587 split = itk;
1588 max_distance_sqr = distance_sqr;
1589 }
1590 }
1591 return split;
1592}
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.