BOOL CArcView::IntersectsWithRect(const Rect& rectangle) { Point topLeft(rectangle.GetLeft(), rectangle.GetTop()); Point topRight(rectangle.GetRight(), rectangle.GetTop()); Point bottomLeft(rectangle.GetLeft(), rectangle.GetBottom()); Point bottomRight(rectangle.GetRight(), rectangle.GetBottom()); Point currentPoint(*pathPoints.begin()); for(auto it=pathPoints.begin() + 1; it != pathPoints.end(); ++it) { if(rectangle.Contains(currentPoint)) return TRUE; if(Geometry::LinesIntersect(topLeft, topRight, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(topLeft, bottomLeft, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(bottomLeft, bottomRight, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(topRight, bottomRight, currentPoint, *it)) return TRUE; currentPoint = *it; } return FALSE; }
bool Rect::Intersects(Rect box) { if(right < box.GetLeft() || left > box.GetRight() || top > box.GetBottom() || bottom < box.GetTop()) return false; else return true; }
BOOL CCircleView::IntersectsWithRect(const Rect& rectangle) { Point center(position); double edgeCenterDistance = INT_MAX; std::vector<Point> rectCorners; Point topLeft(rectangle.GetLeft(), rectangle.GetTop()); Point topRight(rectangle.GetRight(), rectangle.GetTop()); Point bottomLeft(rectangle.GetLeft(), rectangle.GetBottom()); Point bottomRight(rectangle.GetRight(), rectangle.GetBottom()); rectCorners.push_back(topLeft); rectCorners.push_back(topRight); rectCorners.push_back(bottomLeft); rectCorners.push_back(bottomRight); //Le centre du cercle est-il dans le rectangle ? if(rectangle.Contains(center)) return TRUE; //Un coin du rectangle est-il dans le cercle ? for(auto it=rectCorners.begin(); it!=rectCorners.end(); ++it) if(Geometry::Distance(*it, center) < radius) return TRUE; //Un côté du rectangle coupe-t-il dans le cercle ? if(topLeft.X < center.X && center.X < topRight.X && Geometry::LinePointDistance(topLeft, topRight, center) < radius) return TRUE; if(topLeft.Y < center.Y && center.Y < bottomLeft.Y && Geometry::LinePointDistance(topLeft, bottomLeft, center) < radius) return TRUE; if(bottomLeft.X < center.X && center.X < bottomRight.X && Geometry::LinePointDistance(bottomLeft, bottomRight, center) < radius) return TRUE; if(topRight.Y < center.Y && center.Y < bottomRight.Y && Geometry::LinePointDistance(topRight, bottomRight, center) < radius) return TRUE; return FALSE; }
virtual void UpdateLayoutPost(Graphics& g, const Rect& layout) { FlowLayout l(layout, g_theme->sz_margin); l.Add(el_text, FlowLayout::Left) .LineBreak(); Rect r = l.GetInsertRect(); LayoutOutlineChildren(g, r); l.InsertRect(r); r = l.GetBounds(); extents.Width = r.GetRight(); extents.Height = r.GetBottom(); }
/* ** Draws a bevel inside the given area */ void Meter::DrawBevel(Graphics& graphics, const Rect& rect, const Pen& light, const Pen& dark) { int l = rect.GetLeft(); int r = rect.GetRight() - 1; int t = rect.GetTop(); int b = rect.GetBottom() - 1; graphics.DrawLine(&light, l, t, l, b); graphics.DrawLine(&light, l, t, r, t); graphics.DrawLine(&light, l + 1, t + 1, l + 1, b - 1); graphics.DrawLine(&light, l + 1, t + 1, r - 1, t + 1); graphics.DrawLine(&dark, l, b, r, b); graphics.DrawLine(&dark, r, t, r, b); graphics.DrawLine(&dark, l + 1, b - 1, r - 1, b - 1); graphics.DrawLine(&dark, r - 1, t + 1, r - 1, b - 1); }