/* diversity-utils.h - * * Copyright 2007 OpenMoko, Inc. * Authored by Chia-I Wu * * 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. * */ #ifndef _DIVERSITY_UTILS_H_ #define _DIVERSITY_UTILS_H_ #ifndef M_EARTH #define M_EARTH_RADIUS (6371.0 * 1000.0) #endif #ifndef M_PI #define M_PI (3.14159265358979323846) #endif #define DIVERSITY_UNITS(l) ((180.0 * (l) / M_EARTH_RADIUS) / M_PI) #define DIVERSITY_RECTANGLE_HAVE(rect, px, py) \ ((rect)->x <= (px) && (rect)->x + (rect)->width > (px) && \ (rect)->y <= (py) && (rect)->y + (rect)->height > (py)) #define DIVERSITY_RECTANGLE_CONTAIN(rect1, rect2) \ (!((rect2)->x < (rect1)->x || (rect2)->y < (rect1)->y || \ (rect2)->x + (rect2)->width > (rect1)->x + (rect1)->width || \ (rect2)->y + (rect2)->height > (rect1)->y + (rect1)->height)) #define DIVERSITY_RECTANGLE_INTERSECT(rect1, rect2) \ (DIVERSITY_RECTANGLE_HAVE((rect1), (rect2)->x, (rect2)->y) || \ DIVERSITY_RECTANGLE_HAVE((rect1), (rect2)->x + (rect2)->width, (rect2)->y) || \ DIVERSITY_RECTANGLE_HAVE((rect1), (rect2)->x, (rect2)->y + (rect2)->height) || \ DIVERSITY_RECTANGLE_HAVE((rect1), (rect2)->x + (rect2)->width, (rect2)->y + (rect2)->height)) typedef struct _DiversityRectangle DiversityRectangle; struct _DiversityRectangle { gdouble x, y; gdouble width, height; }; #endif /* _DIVERSITY_UTILS_H_ */