nr-rect.h revision 8d10164b2636a9ee8b6ab5c5182143c0e50de3d4
#ifndef LIBNR_NR_RECT_H_SEEN
#define LIBNR_NR_RECT_H_SEEN
/** \file
* Definitions of NRRect and NR::Rect types, and some associated functions \& macros.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Nathan Hurst <njh@mail.csse.monash.edu.au>
* MenTaLguY <mental@rydia.net>
*
* This code is in public domain
*/
#include <stdexcept>
#include <limits>
#include "libnr/nr-values.h"
#include <libnr/nr-coord.h>
#include <libnr/nr-i-coord.h>
#include <libnr/nr-point.h>
#include <libnr/nr-maybe.h>
#include <libnr/nr-point-matrix-ops.h>
struct Matrix;
/** A rectangle is always aligned to the X and Y axis. This means it
* can be defined using only 4 coordinates, and determining
* intersection is very efficient. The points inside a rectangle are
* min[dim] <= _pt[dim] <= max[dim]. Emptiness, however, is defined
* as having zero area, meaning an empty rectangle may still contain
* points. Infinities are also permitted. */
/** returns the four corners of the rectangle in order
* (clockwise if +Y is up, anticlockwise if +Y is down) */
/** returns a vector from min to max. */
Point dimensions() const;
/** returns the midpoint of this rect. */
/** does this rectangle have zero area? */
bool isEmpty() const {
}
bool intersects(Rect const &r) const {
return intersects<X>(r) && intersects<Y>(r);
}
}
}
double area() const {
}
double maxExtent() const {
}
switch (axis) {
case X: return extent<X>();
case Y: return extent<Y>();
};
}
switch (i) {
case 0: return extent<X>();
case 1: return extent<Y>();
};
}
/**
\brief Remove some precision from the Rect
\param places The number of decimal places left in the end
This function just calls round on the \c _min and \c _max points.
*/
return;
}
/** Translates the rectangle by p. */
/** Makes this rectangle large enough to include the point p. */
/** Makes this rectangle large enough to include the rectangle r. */
}
}
}
}
/** Returns the set of points shared by both rectangles. */
/** Returns the smallest rectangle that encloses both rectangles. */
{
if (!a) {
return b;
} else if (!b) {
return a;
} else {
return union_bounds(*a, *b);
}
}
if (a) {
return union_bounds(*a, b);
} else {
return b;
}
}
if (b) {
return union_bounds(a, *b);
} else {
return a;
}
}
/** Scales the rect by s, with origin at 0, 0 */
}
/** Transforms the rect by m. Note that it gives correct results only for scales and translates */
}
}
static double _inf() {
}
double extent() const {
}
bool isEmpty() const {
}
bool intersects(Rect const &r) const {
}
}
}
/* evil, but temporary */
};
/** A function to print out the rectange if sent to an output
stream. */
{
out_file << "Rectangle:\n";
return out_file;
}
} /* namespace NR */
/* legacy rect stuff */
struct NRMatrix;
/* NULL rect is infinite */
struct NRRect {
NRRect() {}
{}
};
#define nr_rect_d_set_empty(r) (*(r) = NR_RECT_EMPTY)
#define nr_rect_l_set_empty(r) (*(r) = NR_RECT_L_EMPTY)
#define nr_rect_d_test_empty(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r))
#define nr_rect_l_test_empty(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r))
#define nr_rect_d_point_d_test_inside(r,p) ((p) && (!(r) || (!NR_RECT_DF_TEST_EMPTY(r) && NR_RECT_DF_POINT_DF_TEST_INSIDE(r,p))))
#define nr_rect_l_point_l_test_inside(r,p) ((p) && (!(r) || (!NR_RECT_DFLS_TEST_EMPTY(r) && NR_RECT_LS_POINT_LS_TEST_INSIDE(r,p))))
#define nr_rect_l_test_inside(r,x,y) ((!(r) || (!NR_RECT_DFLS_TEST_EMPTY(r) && NR_RECT_LS_TEST_INSIDE(r,x,y))))
// returns minimal rect which covers all of r0 not covered by r1
// returns the area of r
/* NULL values are OK for r0 and r1, but not for d */
#endif /* !LIBNR_NR_RECT_H_SEEN */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :