void ScreenBase::GtoP(m2::RectD const & glbRect, m2::RectD & pxRect) const { pxRect = m2::RectD(GtoP(glbRect.LeftTop()), GtoP(glbRect.RightBottom())); }
void ScreenBase::PtoG(m2::RectD const & pxRect, m2::RectD & glbRect) const { glbRect = m2::RectD(PtoG(pxRect.LeftTop()), PtoG(pxRect.RightBottom())); }
void ClipTriangleByRect(m2::RectD const & rect, m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3, ClipTriangleByRectResultIt const & resultIterator) { if (resultIterator == nullptr) return; if (rect.IsPointInside(p1) && rect.IsPointInside(p2) && rect.IsPointInside(p3)) { resultIterator(p1, p2, p3); return; } const double kEps = 1e-8; vector<m2::PointD> poligon; auto const addPoligonPoint = [&poligon, kEps](m2::PointD const & pt) { if (poligon.empty() || !poligon.back().EqualDxDy(pt, kEps)) poligon.push_back(pt); }; vector<m2::PointD> const corners = { rect.LeftTop(), rect.RightTop(), rect.RightBottom(), rect.LeftBottom() }; int firstClipCode[3]; int lastClipCode[3]; bool intersected[3]; intersected[0] = IntersectEdge(rect, corners, p1, p2, p3, addPoligonPoint, 0, 0, firstClipCode[0], lastClipCode[0]); intersected[1] = IntersectEdge(rect, corners, p2, p3, p1, addPoligonPoint, lastClipCode[0], 0, firstClipCode[1], lastClipCode[1]); intersected[2] = IntersectEdge(rect, corners, p3, p1, p2, addPoligonPoint, lastClipCode[1] != 0 ? lastClipCode[1] : lastClipCode[0], firstClipCode[0] != 0 ? firstClipCode[0] : firstClipCode[1], firstClipCode[2], lastClipCode[2]); int const intersectCount = intersected[0] + intersected[1] + intersected[2]; if (intersectCount == 0) { if (IsPointInsideTriangle(rect.Center(), p1, p2, p3)) { resultIterator(rect.LeftTop(), rect.RightTop(), rect.RightBottom()); resultIterator(rect.RightBottom(), rect.LeftBottom(), rect.LeftTop()); } return; } if (intersectCount == 1 && intersected[2]) InsertCorners(corners, p1, p2, p3, addPoligonPoint, lastClipCode[2], firstClipCode[2]); if (!poligon.empty() && poligon.back().EqualDxDy(poligon[0], kEps)) poligon.pop_back(); if (poligon.size() < 3) return; for (size_t i = 0; i < poligon.size() - 2; ++i) resultIterator(poligon[0], poligon[i + 1], poligon[i + 2]); }