Next: Rational Points ( rat_point Up: Basic Data Types for Previous: Triangles ( triangle )   Contents   Index

# Iso-oriented Rectangles ( rectangle )

Definition

An instance r of the data type rectangle is an iso-oriented rectangle in the two-dimensional plane.

#include < LEDA/geo/rectangle.h >

Creation

 rectangle r(const point& p, const point& q) introduces a variable r of type rectangle. r is initialized to the rectangle with diagonal corners p and q rectangle r(const point& p, double w, double h) introduces a variable r of type rectangle. r is initialized to the rectangle with lower left corner p, width w and height h. rectangle r(double x1, double y1, double x2, double y2) introduces a variable r of type rectangle. r is initialized to the rectangle with diagonal corners (x1,y1) and (x2,y2).

Operations

 point r.upper_left() returns the upper left corner. point r.upper_right() returns the upper right corner. point r.lower_left() returns the lower left corner. point r.lower_right() returns the lower right corner. point r.center() returns the center of r. list r.vertices() returns the vertices of r in counter-clockwise order starting from the lower left point. double r.xmin() returns the minimal x-coordinate of r. double r.xmax() returns the maximal x-coordinate of r. double r.ymin() returns the minimal y-coordinate of r. double r.ymax() returns the maximal y-coordinate of r. double r.width() returns the width of r. double r.height() returns the height of r. bool r.is_degenerate() returns true, if r degenerates to a segment or point (the 4 corners are collinear), false otherwise. bool r.is_point() returns true, if r degenerates to a point. bool r.is_segment() returns true, if r degenerates to a segment. int r.cs_code(const point& p) returns the code for Cohen-Sutherland algorithm. bool r.inside(const point& p) returns true, if p is inside of r, false otherwise. bool r.outside(const point& p) returns true, if p is outside of r, false otherwise. bool r.inside_or_contains(const point& p) returns true, if p is inside of r or on the border, false otherwise. bool r.contains(const point& p) returns true, if p is on the border of r, false otherwise. region_kind r.region_of(const point& p) returns BOUNDED_REGION if p lies in the bounded region of r, returns ON_REGION if p lies on r, and returns UNBOUNDED_REGION if p lies in the unbounded region. rectangle r.include(const point& p) returns a new rectangle that includes the points of r and p. rectangle r.include(const rectangle& r2) returns a new rectangle that includes the points of r and r2. rectangle r.translate(double dx, double dy) returns a new rectangle that is the translation of r by (dx,dy). rectangle r.translate(const vector& v) returns a new rectangle that is the translation of r by v. rectangle r + const vector& v returns r translated by v. rectangle r - const vector& v returns r translated by -v. point r[int i] returns the i-th vertex of r. Precondition: (0 0 the rotation is counter-clockwise otherwise it is clockwise. rectangle r.rotate90(int i=1) returns r rotated by an angle of i x 90 degrees about the origin. rectangle r.reflect(const point& p) returns r reflected across p . list r.intersection(const segment& s) returns r s . bool r.clip(const segment& t, segment& inter) clips t on r and returns the result in inter. bool r.clip(const line& l, segment& inter) clips l on r and returns the result in inter. bool r.clip(const ray& ry, segment& inter) clips ry on r and returns the result in inter. bool r.difference(const rectangle& q, list& L) returns true iff the difference of r and q is not empty, and false otherwise. The difference L is returned as a partition into rectangles. list r.intersection(const line& l) returns r l. list r.intersection(const rectangle& s) returns r s. bool r.do_intersect(const rectangle& b) returns true iff r and b intersect, false otherwise. double r.area() returns the area of r.

Next: Rational Points ( rat_point Up: Basic Data Types for Previous: Triangles ( triangle )   Contents   Index