/* Geometry convinience functions. Copyright (C) 2001 Johan Rydberg. All Rights Reserved. This file is part of Crust. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include "GFGeometry.h" #include "priv.h" /* ... */ GFPoint GFPointZero = { 0.0, 0.0 }; GFPoint GFPointMake (float x, float y) { GFPoint point; point.x = x; point.y = y; return point; } GFPoint GFPointSubtract (GFPoint a, GFPoint b) { a.x -= b.x; a.y -= b.x; return a; } GFSize GFSizeMake (float w, float h) { GFSize size; size.width = w; size.height = h; return size; } /* Determine whether rectangle is empty. Returns TRUE if SRC is an empty rectangle, FALSE otherwise. */ bool GFRectIsEmpty (GFRect src) { return (src.size.width == 0.0 || src.size.height == 0.0); } /* Find union of two rectangles. Returns result rectangle. SRC1 and SRC2 is the two source rectangles. */ GFRect GFRectUnion (GFRect src1, GFRect src2) { GFRect dst; if (GFRectIsEmpty (src1)) return src2; else if (GFRectIsEmpty (src2)) return src1; dst.origin.x = MIN (src1.origin.x, src2.origin.x); dst.origin.y = MIN (src1.origin.y, src2.origin.y); dst.size.width = MAX (src1.size.width, src2.size.width); dst.size.height = MAX (src1.size.height, src2.size.height); return dst; } /* Find intersection of two rectangles. Returns result rectangle. SRC1 and SRC2 is the two source rectangles. */ GFRect GFRectIntersect (GFRect src1, GFRect src2) { GFRect dst; dst.origin.x = MAX (src1.origin.x, src2.origin.x); dst.origin.y = MAX (src1.origin.y, src2.origin.y); dst.size.width = MIN (src1.size.width, src2.size.width); dst.size.height = MIN (src1.size.height, src2.size.height); return dst; } /* Construct a rectangle from (X, Y, W, H). The rectangle is returned. */ GFRect GFRectMake (float x, float y, float w, float h) { GFRect dst; dst.origin.x = x; dst.origin.y = y; dst.size.width = w; dst.size.height = h; return dst; }