git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21118 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-05-12 16:19:24 +00:00
parent f2d34b2994
commit 253599a20b
2 changed files with 86 additions and 99 deletions

View File

@ -1,28 +1,10 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2005, Haiku * Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * Frans van Nispen
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Rect.h
// Author: Frans van Nispen (xlr8@tref.nl)
// Description: BRect represents a rectangular area.
//------------------------------------------------------------------------------
#ifndef _RECT_H #ifndef _RECT_H
#define _RECT_H #define _RECT_H
@ -109,24 +91,28 @@ BRect::LeftTop() const
return *(const BPoint *)&left; return *(const BPoint *)&left;
} }
inline BPoint inline BPoint
BRect::RightBottom() const BRect::RightBottom() const
{ {
return *(const BPoint *)&right; return *(const BPoint *)&right;
} }
inline BPoint inline BPoint
BRect::LeftBottom() const BRect::LeftBottom() const
{ {
return BPoint(left, bottom); return BPoint(left, bottom);
} }
inline BPoint inline BPoint
BRect::RightTop() const BRect::RightTop() const
{ {
return BPoint(right, top); return BPoint(right, top);
} }
inline inline
BRect::BRect() BRect::BRect()
{ {
@ -134,6 +120,7 @@ BRect::BRect()
bottom = right = -1; bottom = right = -1;
} }
inline inline
BRect::BRect(float l, float t, float r, float b) BRect::BRect(float l, float t, float r, float b)
{ {
@ -143,6 +130,7 @@ BRect::BRect(float l, float t, float r, float b)
bottom = b; bottom = b;
} }
inline inline
BRect::BRect(const BRect &r) BRect::BRect(const BRect &r)
{ {
@ -152,6 +140,7 @@ BRect::BRect(const BRect &r)
bottom = r.bottom; bottom = r.bottom;
} }
inline inline
BRect::BRect(BPoint leftTop, BPoint rightBottom) BRect::BRect(BPoint leftTop, BPoint rightBottom)
{ {
@ -161,6 +150,7 @@ BRect::BRect(BPoint leftTop, BPoint rightBottom)
bottom = rightBottom.y; bottom = rightBottom.y;
} }
inline BRect & inline BRect &
BRect::operator=(const BRect& from) BRect::operator=(const BRect& from)
{ {
@ -171,6 +161,7 @@ BRect::operator=(const BRect& from)
return *this; return *this;
} }
inline void inline void
BRect::Set(float l, float t, float r, float b) BRect::Set(float l, float t, float r, float b)
{ {
@ -180,30 +171,35 @@ BRect::Set(float l, float t, float r, float b)
bottom = b; bottom = b;
} }
inline bool inline bool
BRect::IsValid() const BRect::IsValid() const
{ {
return left <= right && top <= bottom; return left <= right && top <= bottom;
} }
inline int32 inline int32
BRect::IntegerWidth() const BRect::IntegerWidth() const
{ {
return (int32)ceil(right - left); return (int32)ceil(right - left);
} }
inline float inline float
BRect::Width() const BRect::Width() const
{ {
return right - left; return right - left;
} }
inline int32 inline int32
BRect::IntegerHeight() const BRect::IntegerHeight() const
{ {
return (int32)ceil(bottom - top); return (int32)ceil(bottom - top);
} }
inline float inline float
BRect::Height() const BRect::Height() const
{ {

View File

@ -1,43 +1,15 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2004, Haiku, Inc. * Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * Frans van Nispen
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Rect.cpp
// Author: Frans van Nispen (xlr8@tref.nl)
// Description: BRect represents a rectangular area.
//------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
#include <stdio.h> #include <stdio.h>
// System Includes -------------------------------------------------------------
#include <Rect.h> #include <Rect.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
void void
BRect::SetLeftTop(const BPoint p) BRect::SetLeftTop(const BPoint p)
@ -45,28 +17,32 @@ BRect::SetLeftTop(const BPoint p)
left = p.x; left = p.x;
top = p.y; top = p.y;
} }
//------------------------------------------------------------------------------
void void
BRect::SetRightBottom(const BPoint p) BRect::SetRightBottom(const BPoint p)
{ {
right = p.x; right = p.x;
bottom = p.y; bottom = p.y;
} }
//------------------------------------------------------------------------------
void void
BRect::SetLeftBottom(const BPoint p) BRect::SetLeftBottom(const BPoint p)
{ {
left = p.x; left = p.x;
bottom = p.y; bottom = p.y;
} }
//------------------------------------------------------------------------------
void void
BRect::SetRightTop(const BPoint p) BRect::SetRightTop(const BPoint p)
{ {
right = p.x; right = p.x;
top = p.y; top = p.y;
} }
//------------------------------------------------------------------------------
void void
BRect::InsetBy(BPoint point) BRect::InsetBy(BPoint point)
{ {
@ -75,7 +51,8 @@ BRect::InsetBy(BPoint point)
top += point.y; top += point.y;
bottom -= point.y; bottom -= point.y;
} }
//------------------------------------------------------------------------------
void void
BRect::InsetBy(float dx, float dy) BRect::InsetBy(float dx, float dy)
{ {
@ -84,21 +61,24 @@ BRect::InsetBy(float dx, float dy)
top += dy; top += dy;
bottom -= dy; bottom -= dy;
} }
//------------------------------------------------------------------------------
BRect& BRect&
BRect::InsetBySelf(BPoint point) BRect::InsetBySelf(BPoint point)
{ {
InsetBy(point); InsetBy(point);
return *this; return *this;
} }
//------------------------------------------------------------------------------
BRect& BRect&
BRect::InsetBySelf(float dx, float dy) BRect::InsetBySelf(float dx, float dy)
{ {
InsetBy(dx, dy); InsetBy(dx, dy);
return *this; return *this;
} }
//------------------------------------------------------------------------------
BRect BRect
BRect::InsetByCopy(BPoint point) BRect::InsetByCopy(BPoint point)
{ {
@ -106,7 +86,8 @@ BRect::InsetByCopy(BPoint point)
copy.InsetBy(point); copy.InsetBy(point);
return copy; return copy;
} }
//------------------------------------------------------------------------------
BRect BRect
BRect::InsetByCopy(float dx, float dy) BRect::InsetByCopy(float dx, float dy)
{ {
@ -114,7 +95,8 @@ BRect::InsetByCopy(float dx, float dy)
copy.InsetBy(dx, dy); copy.InsetBy(dx, dy);
return copy; return copy;
} }
//------------------------------------------------------------------------------
void void
BRect::OffsetBy(BPoint point) BRect::OffsetBy(BPoint point)
{ {
@ -123,7 +105,8 @@ BRect::OffsetBy(BPoint point)
top += point.y; top += point.y;
bottom += point.y; bottom += point.y;
} }
//------------------------------------------------------------------------------
void void
BRect::OffsetBy(float dx, float dy) BRect::OffsetBy(float dx, float dy)
{ {
@ -132,21 +115,24 @@ BRect::OffsetBy(float dx, float dy)
top += dy; top += dy;
bottom += dy; bottom += dy;
} }
//------------------------------------------------------------------------------
BRect& BRect&
BRect::OffsetBySelf(BPoint point) BRect::OffsetBySelf(BPoint point)
{ {
OffsetBy(point); OffsetBy(point);
return *this; return *this;
} }
//------------------------------------------------------------------------------
BRect& BRect&
BRect::OffsetBySelf(float dx, float dy) BRect::OffsetBySelf(float dx, float dy)
{ {
OffsetBy(dx, dy); OffsetBy(dx, dy);
return *this; return *this;
} }
//------------------------------------------------------------------------------
BRect BRect
BRect::OffsetByCopy(BPoint point) BRect::OffsetByCopy(BPoint point)
{ {
@ -154,7 +140,8 @@ BRect::OffsetByCopy(BPoint point)
copy.OffsetBy(point); copy.OffsetBy(point);
return copy; return copy;
} }
//------------------------------------------------------------------------------
BRect BRect
BRect::OffsetByCopy(float dx, float dy) BRect::OffsetByCopy(float dx, float dy)
{ {
@ -162,7 +149,8 @@ BRect::OffsetByCopy(float dx, float dy)
copy.OffsetBy(dx, dy); copy.OffsetBy(dx, dy);
return copy; return copy;
} }
//------------------------------------------------------------------------------
void void
BRect::OffsetTo(BPoint point) BRect::OffsetTo(BPoint point)
{ {
@ -171,7 +159,8 @@ BRect::OffsetTo(BPoint point)
bottom = (bottom - top) + point.y; bottom = (bottom - top) + point.y;
top = point.y; top = point.y;
} }
//------------------------------------------------------------------------------
void void
BRect::OffsetTo(float x, float y) BRect::OffsetTo(float x, float y)
{ {
@ -180,21 +169,24 @@ BRect::OffsetTo(float x, float y)
bottom = (bottom - top) + y; bottom = (bottom - top) + y;
top=y; top=y;
} }
//------------------------------------------------------------------------------
BRect& BRect&
BRect::OffsetToSelf(BPoint point) BRect::OffsetToSelf(BPoint point)
{ {
OffsetTo(point); OffsetTo(point);
return *this; return *this;
} }
//------------------------------------------------------------------------------
BRect& BRect&
BRect::OffsetToSelf(float dx, float dy) BRect::OffsetToSelf(float dx, float dy)
{ {
OffsetTo(dx, dy); OffsetTo(dx, dy);
return *this; return *this;
} }
//------------------------------------------------------------------------------
BRect BRect
BRect::OffsetToCopy(BPoint point) BRect::OffsetToCopy(BPoint point)
{ {
@ -202,7 +194,8 @@ BRect::OffsetToCopy(BPoint point)
copy.OffsetTo(point); copy.OffsetTo(point);
return copy; return copy;
} }
//------------------------------------------------------------------------------
BRect BRect
BRect::OffsetToCopy(float dx, float dy) BRect::OffsetToCopy(float dx, float dy)
{ {
@ -210,40 +203,46 @@ BRect::OffsetToCopy(float dx, float dy)
copy.OffsetTo(dx, dy); copy.OffsetTo(dx, dy);
return copy; return copy;
} }
//------------------------------------------------------------------------------
void void
BRect::PrintToStream() const BRect::PrintToStream() const
{ {
printf("BRect(l:%.1f, t:%.1f, r:%.1f, b:%.1f)\n", left, top, right, bottom); printf("BRect(l:%.1f, t:%.1f, r:%.1f, b:%.1f)\n", left, top, right, bottom);
} }
//------------------------------------------------------------------------------
bool bool
BRect::operator==(BRect rect) const BRect::operator==(BRect rect) const
{ {
return left == rect.left && right == rect.right && return left == rect.left && right == rect.right &&
top == rect.top && bottom == rect.bottom; top == rect.top && bottom == rect.bottom;
} }
//------------------------------------------------------------------------------
bool bool
BRect::operator!=(BRect rect) const BRect::operator!=(BRect rect) const
{ {
return !(*this == rect); return !(*this == rect);
} }
//------------------------------------------------------------------------------
BRect BRect
BRect::operator&(BRect rect) const BRect::operator&(BRect rect) const
{ {
return BRect(max_c(left, rect.left), max_c(top, rect.top), return BRect(max_c(left, rect.left), max_c(top, rect.top),
min_c(right, rect.right), min_c(bottom, rect.bottom)); min_c(right, rect.right), min_c(bottom, rect.bottom));
} }
//------------------------------------------------------------------------------
BRect BRect
BRect::operator|(BRect rect) const BRect::operator|(BRect rect) const
{ {
return BRect(min_c(left, rect.left), min_c(top, rect.top), return BRect(min_c(left, rect.left), min_c(top, rect.top),
max_c(right, rect.right), max_c(bottom, rect.bottom)); max_c(right, rect.right), max_c(bottom, rect.bottom));
} }
//------------------------------------------------------------------------------
bool bool
BRect::Intersects(BRect rect) const BRect::Intersects(BRect rect) const
{ {
@ -253,27 +252,19 @@ BRect::Intersects(BRect rect) const
return !(rect.left > right || rect.right < left return !(rect.left > right || rect.right < left
|| rect.top > bottom || rect.bottom < top); || rect.top > bottom || rect.bottom < top);
} }
//------------------------------------------------------------------------------
bool bool
BRect::Contains(BPoint point) const BRect::Contains(BPoint point) const
{ {
return point.x >= left && point.x <= right return point.x >= left && point.x <= right
&& point.y >= top && point.y <= bottom; && point.y >= top && point.y <= bottom;
} }
//------------------------------------------------------------------------------
bool bool
BRect::Contains(BRect rect) const BRect::Contains(BRect rect) const
{ {
return rect.left >= left && rect.right <= right return rect.left >= left && rect.right <= right
&& rect.top >= top && rect.bottom <= bottom; && rect.top >= top && rect.bottom <= bottom;
} }
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/