float PointList::ComputeSegmentLens (float heightFactor, float widthFactor ) const { if (QueueSize () < 1) return 0.0f; float totalLen = 0.0f; const_iterator idx; idx = begin (); PointPtr lastPoint = *idx; ++idx; while (idx != end ()) { PointPtr nextPoint = *idx; ++idx; float deltaHeight = (float)(nextPoint->Row () - lastPoint->Row ()) * heightFactor; float deltaWidth = (float)(nextPoint->Col () - lastPoint->Col ()) * widthFactor; float segmentLen = sqrt (deltaHeight * deltaHeight + deltaWidth * deltaWidth); totalLen += segmentLen; lastPoint = nextPoint; } return totalLen; } /* ComputeSegmentLens */
void PointList::BoxCoordinites (kkint32& minRow, kkint32& minCol, kkint32& maxRow, kkint32& maxCol ) { minRow = minCol = 999999; maxRow = maxCol = -1; for (iterator x = begin (); x != end (); x++) { PointPtr p = *x; if (p->Row () < minRow) minRow = p->Row (); if (p->Row () > maxRow) maxRow = p->Row (); if (p->Col () < minCol) minCol = p->Col (); if (p->Col () > maxCol) maxCol = p->Col (); } }
Point PointList::CalculateCenterPoint () { kkint32 totalRow = 0; kkint32 totalCol = 0; for (iterator x = begin (); x != end (); x++) { PointPtr p = *x; totalRow += p->Row (); totalCol += p->Col (); } kkint32 centerRow = (kkint32)((double)totalRow / (double)size () + 0.5); kkint32 centerCol = (kkint32)((double)totalCol / (double)size () + 0.5); return Point (centerRow, centerCol); }
KKStr PointList::ToDelStr (char del) const { if (QueueSize () < 1) return "[]"; KKStr result (QueueSize () * 10); int count = 0; PointList::const_iterator idx; for (idx = begin (); idx != end (); ++idx, ++count) { PointPtr p = *idx; if (count > 0) result << del; result << p->Row () << del << p->Col (); } return result; } /* ToDelStr */