haiku/src/servers/app/IntRect.cpp
Stephan Aßmus 264fe59ded * introduced IntPoint and IntRect, which are just like BPoint and BRect,
but use integer coordinates. These are now used in ViewLayer for the
  coordinate system (layout, scrolling offset, view bitmap layout)
* modest performance improvements by inlining some very often used
  methods, and by preventing to go down the entire layer tree too often,
  for example InvalidateScreenClipping was always called in the deep
  mode, therefor it is save to assume that the tree does not have to
  be traversed as soon as the clipping is already invalid


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19390 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-11-29 03:20:07 +00:00

273 lines
3.7 KiB
C++

/*
* Copyright 2001-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Frans van Nispen
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "IntRect.h"
#include <stdio.h>
void
IntRect::SetLeftTop(const IntPoint& p)
{
left = p.x;
top = p.y;
}
void
IntRect::SetRightBottom(const IntPoint& p)
{
right = p.x;
bottom = p.y;
}
void
IntRect::SetLeftBottom(const IntPoint& p)
{
left = p.x;
bottom = p.y;
}
void
IntRect::SetRightTop(const IntPoint& p)
{
right = p.x;
top = p.y;
}
void
IntRect::InsetBy(const IntPoint& point)
{
left += point.x;
right -= point.x;
top += point.y;
bottom -= point.y;
}
void
IntRect::InsetBy(int32 dx, int32 dy)
{
left += dx;
right -= dx;
top += dy;
bottom -= dy;
}
IntRect&
IntRect::InsetBySelf(const IntPoint& point)
{
InsetBy(point);
return *this;
}
IntRect&
IntRect::InsetBySelf(int32 dx, int32 dy)
{
InsetBy(dx, dy);
return *this;
}
IntRect
IntRect::InsetByCopy(const IntPoint& point)
{
IntRect copy(*this);
copy.InsetBy(point);
return copy;
}
IntRect
IntRect::InsetByCopy(int32 dx, int32 dy)
{
IntRect copy(*this);
copy.InsetBy(dx, dy);
return copy;
}
void
IntRect::OffsetBy(const IntPoint& point)
{
left += point.x;
right += point.x;
top += point.y;
bottom += point.y;
}
void
IntRect::OffsetBy(int32 dx, int32 dy)
{
left += dx;
right += dx;
top += dy;
bottom += dy;
}
IntRect&
IntRect::OffsetBySelf(const IntPoint& point)
{
OffsetBy(point);
return *this;
}
IntRect&
IntRect::OffsetBySelf(int32 dx, int32 dy)
{
OffsetBy(dx, dy);
return *this;
}
IntRect
IntRect::OffsetByCopy(const IntPoint& point)
{
IntRect copy(*this);
copy.OffsetBy(point);
return copy;
}
IntRect
IntRect::OffsetByCopy(int32 dx, int32 dy)
{
IntRect copy(*this);
copy.OffsetBy(dx, dy);
return copy;
}
void
IntRect::OffsetTo(const IntPoint& point)
{
right = (right - left) + point.x;
left = point.x;
bottom = (bottom - top) + point.y;
top = point.y;
}
void
IntRect::OffsetTo(int32 x, int32 y)
{
right = (right - left) + x;
left = x;
bottom = (bottom - top) + y;
top=y;
}
IntRect&
IntRect::OffsetToSelf(const IntPoint& point)
{
OffsetTo(point);
return *this;
}
IntRect&
IntRect::OffsetToSelf(int32 dx, int32 dy)
{
OffsetTo(dx, dy);
return *this;
}
IntRect
IntRect::OffsetToCopy(const IntPoint& point)
{
IntRect copy(*this);
copy.OffsetTo(point);
return copy;
}
IntRect
IntRect::OffsetToCopy(int32 dx, int32 dy)
{
IntRect copy(*this);
copy.OffsetTo(dx, dy);
return copy;
}
void
IntRect::PrintToStream() const
{
printf("IntRect(l:%ld, t:%ld, r:%ld, b:%ld)\n", left, top, right, bottom);
}
bool
IntRect::operator==(const IntRect& rect) const
{
return left == rect.left && right == rect.right &&
top == rect.top && bottom == rect.bottom;
}
bool
IntRect::operator!=(const IntRect& rect) const
{
return !(*this == rect);
}
IntRect
IntRect::operator&(const IntRect& rect) const
{
return IntRect(max_c(left, rect.left), max_c(top, rect.top),
min_c(right, rect.right), min_c(bottom, rect.bottom));
}
IntRect
IntRect::operator|(const IntRect& rect) const
{
return IntRect(min_c(left, rect.left), min_c(top, rect.top),
max_c(right, rect.right), max_c(bottom, rect.bottom));
}
bool
IntRect::Intersects(const IntRect& rect) const
{
if (!IsValid() || !rect.IsValid())
return false;
return !(rect.left > right || rect.right < left
|| rect.top > bottom || rect.bottom < top);
}
bool
IntRect::Contains(const IntPoint& point) const
{
return point.x >= left && point.x <= right
&& point.y >= top && point.y <= bottom;
}
bool
IntRect::Contains(const IntRect& rect) const
{
return rect.left >= left && rect.right <= right
&& rect.top >= top && rect.bottom <= bottom;
}