From 253599a20bc1bb7080eb04d0d495fbbc965a0a4b Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 12 May 2007 16:19:24 +0000 Subject: [PATCH] Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21118 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Rect.h | 46 ++++++------ src/kits/interface/Rect.cpp | 139 +++++++++++++++++------------------- 2 files changed, 86 insertions(+), 99 deletions(-) diff --git a/headers/os/interface/Rect.h b/headers/os/interface/Rect.h index c0e4cae52d..9ee2bc74c0 100644 --- a/headers/os/interface/Rect.h +++ b/headers/os/interface/Rect.h @@ -1,28 +1,10 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// 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. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Frans van Nispen + */ #ifndef _RECT_H #define _RECT_H @@ -109,24 +91,28 @@ BRect::LeftTop() const return *(const BPoint *)&left; } + inline BPoint BRect::RightBottom() const { return *(const BPoint *)&right; } + inline BPoint BRect::LeftBottom() const { return BPoint(left, bottom); } + inline BPoint BRect::RightTop() const { return BPoint(right, top); } + inline BRect::BRect() { @@ -134,6 +120,7 @@ BRect::BRect() bottom = right = -1; } + inline 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; } + inline BRect::BRect(const BRect &r) { @@ -152,6 +140,7 @@ BRect::BRect(const BRect &r) bottom = r.bottom; } + inline BRect::BRect(BPoint leftTop, BPoint rightBottom) { @@ -161,6 +150,7 @@ BRect::BRect(BPoint leftTop, BPoint rightBottom) bottom = rightBottom.y; } + inline BRect & BRect::operator=(const BRect& from) { @@ -171,6 +161,7 @@ BRect::operator=(const BRect& from) return *this; } + inline void 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; } + inline bool BRect::IsValid() const { return left <= right && top <= bottom; } + inline int32 BRect::IntegerWidth() const { return (int32)ceil(right - left); } + inline float BRect::Width() const { return right - left; } + inline int32 BRect::IntegerHeight() const { return (int32)ceil(bottom - top); } + inline float BRect::Height() const { diff --git a/src/kits/interface/Rect.cpp b/src/kits/interface/Rect.cpp index cc17a9a70e..c56d51d5bb 100644 --- a/src/kits/interface/Rect.cpp +++ b/src/kits/interface/Rect.cpp @@ -1,43 +1,15 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2004, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// 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. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Frans van Nispen + */ -// Standard Includes ----------------------------------------------------------- #include -// System Includes ------------------------------------------------------------- #include -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - void BRect::SetLeftTop(const BPoint p) @@ -45,28 +17,32 @@ BRect::SetLeftTop(const BPoint p) left = p.x; top = p.y; } -//------------------------------------------------------------------------------ + + void BRect::SetRightBottom(const BPoint p) { right = p.x; bottom = p.y; } -//------------------------------------------------------------------------------ + + void BRect::SetLeftBottom(const BPoint p) { left = p.x; bottom = p.y; } -//------------------------------------------------------------------------------ + + void BRect::SetRightTop(const BPoint p) { right = p.x; top = p.y; } -//------------------------------------------------------------------------------ + + void BRect::InsetBy(BPoint point) { @@ -75,7 +51,8 @@ BRect::InsetBy(BPoint point) top += point.y; bottom -= point.y; } -//------------------------------------------------------------------------------ + + void BRect::InsetBy(float dx, float dy) { @@ -84,21 +61,24 @@ BRect::InsetBy(float dx, float dy) top += dy; bottom -= dy; } -//------------------------------------------------------------------------------ + + BRect& BRect::InsetBySelf(BPoint point) { InsetBy(point); return *this; } -//------------------------------------------------------------------------------ + + BRect& BRect::InsetBySelf(float dx, float dy) { InsetBy(dx, dy); return *this; } -//------------------------------------------------------------------------------ + + BRect BRect::InsetByCopy(BPoint point) { @@ -106,7 +86,8 @@ BRect::InsetByCopy(BPoint point) copy.InsetBy(point); return copy; } -//------------------------------------------------------------------------------ + + BRect BRect::InsetByCopy(float dx, float dy) { @@ -114,7 +95,8 @@ BRect::InsetByCopy(float dx, float dy) copy.InsetBy(dx, dy); return copy; } -//------------------------------------------------------------------------------ + + void BRect::OffsetBy(BPoint point) { @@ -123,7 +105,8 @@ BRect::OffsetBy(BPoint point) top += point.y; bottom += point.y; } -//------------------------------------------------------------------------------ + + void BRect::OffsetBy(float dx, float dy) { @@ -132,21 +115,24 @@ BRect::OffsetBy(float dx, float dy) top += dy; bottom += dy; } -//------------------------------------------------------------------------------ + + BRect& BRect::OffsetBySelf(BPoint point) { OffsetBy(point); return *this; } -//------------------------------------------------------------------------------ + + BRect& BRect::OffsetBySelf(float dx, float dy) { OffsetBy(dx, dy); return *this; } -//------------------------------------------------------------------------------ + + BRect BRect::OffsetByCopy(BPoint point) { @@ -154,7 +140,8 @@ BRect::OffsetByCopy(BPoint point) copy.OffsetBy(point); return copy; } -//------------------------------------------------------------------------------ + + BRect BRect::OffsetByCopy(float dx, float dy) { @@ -162,7 +149,8 @@ BRect::OffsetByCopy(float dx, float dy) copy.OffsetBy(dx, dy); return copy; } -//------------------------------------------------------------------------------ + + void BRect::OffsetTo(BPoint point) { @@ -171,7 +159,8 @@ BRect::OffsetTo(BPoint point) bottom = (bottom - top) + point.y; top = point.y; } -//------------------------------------------------------------------------------ + + void BRect::OffsetTo(float x, float y) { @@ -180,21 +169,24 @@ BRect::OffsetTo(float x, float y) bottom = (bottom - top) + y; top=y; } -//------------------------------------------------------------------------------ + + BRect& BRect::OffsetToSelf(BPoint point) { OffsetTo(point); return *this; } -//------------------------------------------------------------------------------ + + BRect& BRect::OffsetToSelf(float dx, float dy) { OffsetTo(dx, dy); return *this; } -//------------------------------------------------------------------------------ + + BRect BRect::OffsetToCopy(BPoint point) { @@ -202,7 +194,8 @@ BRect::OffsetToCopy(BPoint point) copy.OffsetTo(point); return copy; } -//------------------------------------------------------------------------------ + + BRect BRect::OffsetToCopy(float dx, float dy) { @@ -210,40 +203,46 @@ BRect::OffsetToCopy(float dx, float dy) copy.OffsetTo(dx, dy); return copy; } -//------------------------------------------------------------------------------ + + void BRect::PrintToStream() const { printf("BRect(l:%.1f, t:%.1f, r:%.1f, b:%.1f)\n", left, top, right, bottom); } -//------------------------------------------------------------------------------ + + bool BRect::operator==(BRect rect) const { return left == rect.left && right == rect.right && top == rect.top && bottom == rect.bottom; } -//------------------------------------------------------------------------------ + + bool BRect::operator!=(BRect rect) const { return !(*this == rect); } -//------------------------------------------------------------------------------ + + BRect BRect::operator&(BRect rect) const { return BRect(max_c(left, rect.left), max_c(top, rect.top), min_c(right, rect.right), min_c(bottom, rect.bottom)); } -//------------------------------------------------------------------------------ + + BRect BRect::operator|(BRect rect) const { return BRect(min_c(left, rect.left), min_c(top, rect.top), max_c(right, rect.right), max_c(bottom, rect.bottom)); } -//------------------------------------------------------------------------------ + + bool BRect::Intersects(BRect rect) const { @@ -253,27 +252,19 @@ BRect::Intersects(BRect rect) const return !(rect.left > right || rect.right < left || rect.top > bottom || rect.bottom < top); } -//------------------------------------------------------------------------------ + + bool BRect::Contains(BPoint point) const { return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom; } -//------------------------------------------------------------------------------ + + bool BRect::Contains(BRect rect) const { return rect.left >= left && rect.right <= right && rect.top >= top && rect.bottom <= bottom; } -//------------------------------------------------------------------------------ - - -/* - * $Log $ - * - * $Id $ - * - */ -