2008-08-13 15:00:17 -07:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 2008 Freddie Witherden
|
|
|
|
Copyright (C) 2008 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 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.
|
|
|
|
|
|
|
|
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
#ifndef GEOM_H_
|
|
|
|
#define GEOM_H_
|
|
|
|
|
|
|
|
// TODO: Make this cross platform (MSVC)
|
|
|
|
#include <stdbool.h>
|
2008-08-15 02:59:11 -07:00
|
|
|
#include <math.h>
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-08-15 12:29:57 -07:00
|
|
|
/*
|
|
|
|
* Alignment schemes
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
LEFT,
|
|
|
|
CENTRE,
|
|
|
|
RIGHT
|
|
|
|
} hAlign;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TOP,
|
|
|
|
MIDDLE,
|
|
|
|
BOTTOM
|
|
|
|
} vAlign;
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* A point
|
|
|
|
*/
|
|
|
|
typedef struct _point point;
|
2008-06-21 10:23:00 -07:00
|
|
|
typedef point size;
|
2008-04-24 11:07:47 -07:00
|
|
|
|
|
|
|
struct _point
|
|
|
|
{
|
2008-08-02 07:47:12 -07:00
|
|
|
float x;
|
|
|
|
float y;
|
2008-04-24 11:07:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A rectangle
|
|
|
|
*/
|
|
|
|
typedef struct _rect rect;
|
|
|
|
|
|
|
|
struct _rect
|
|
|
|
{
|
|
|
|
point topLeft;
|
|
|
|
point bottomRight;
|
|
|
|
};
|
|
|
|
|
2008-07-02 16:18:32 -07:00
|
|
|
/*
|
|
|
|
* Helper macros
|
|
|
|
*/
|
|
|
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* Method signatures
|
|
|
|
*/
|
|
|
|
|
2008-06-21 10:23:00 -07:00
|
|
|
/**
|
|
|
|
* Creates a rect from an absolute point and a size.
|
|
|
|
*
|
|
|
|
* @param p
|
|
|
|
* @param s
|
|
|
|
* @return A rect.
|
|
|
|
*/
|
|
|
|
rect rectFromPointAndSize(point p, size s);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/**
|
|
|
|
* Checks to see if the point p is inside of the rectangle r.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-04-27 08:14:42 -07:00
|
|
|
* @param p
|
|
|
|
* @param r
|
|
|
|
* @return If the point is in the rectangle.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
bool pointInRect(point p, rect r);
|
|
|
|
|
2008-04-27 08:14:42 -07:00
|
|
|
/**
|
|
|
|
* Adds point p to point q.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-04-27 08:14:42 -07:00
|
|
|
* @param p
|
|
|
|
* @param q
|
|
|
|
* @return p + q.
|
|
|
|
*/
|
|
|
|
point pointAdd(point p, point q);
|
|
|
|
|
2008-07-07 12:10:23 -07:00
|
|
|
/**
|
|
|
|
* Subtracts point q from point p.
|
|
|
|
*
|
|
|
|
* @param p
|
|
|
|
* @param q
|
|
|
|
* @return p - q.
|
|
|
|
*/
|
|
|
|
point pointSub(point p, point q);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
|
|
|
|
#endif /*GEOM_H_*/
|