DiaGeometry

DiaGeometry — Stuff with points and rectangles.

Synopsis




struct      DiaPoint;
struct      DiaSPoint;
struct      DiaRectangle;
typedef     DiaColor;
gdouble     dia_distance_point_point        (DiaPoint *p1,
                                             DiaPoint *p2);
gdouble     dia_distance_point_point_manhattan
                                            (DiaPoint *p1,
                                             DiaPoint *p2);
gdouble     dia_distance_line_point         (DiaPoint *line_start,
                                             DiaPoint *line_end,
                                             DiaPoint *point,
                                             gdouble line_width,
                                             DiaCapStyle style,
                                             DiaPoint *point_on_line);
gdouble     dia_distance_rectangle_point    (DiaRectangle *rect,
                                             DiaPoint *point);
gboolean    dia_intersection_line_line      (DiaPoint *start1,
                                             DiaPoint *end1,
                                             DiaPoint *start2,
                                             DiaPoint *end2,
                                             DiaPoint *intersect);
gint        dia_intersection_line_rectangle (DiaPoint *start,
                                             DiaPoint *end,
                                             DiaRectangle *rect,
                                             DiaPoint intersect[2]);
gboolean    dia_intersection_rectangle_rectangle
                                            (DiaRectangle *r1,
                                             DiaRectangle *r2);
void        dia_rectangle_add_point         (DiaRectangle *rect,
                                             DiaPoint *p);
#define     DIA_COLOR                       (r, g, b)
#define     DIA_COLOR_A                     (r, g, b, a)
#define     DIA_COLOR_RED                   (c)
#define     DIA_COLOR_GREEN                 (c)
#define     DIA_COLOR_BLUE                  (c)
#define     DIA_COLOR_ALPHA                 (c)

Description

This is not really a class, but rather a bunch of function used to manipulate and do calculations with points and rectangles.

Details

struct DiaPoint

struct DiaPoint {

	gdouble x, y;
};


struct DiaSPoint

struct DiaSPoint {

	DiaVariable *x;
	DiaVariable *y;
};


struct DiaRectangle

struct DiaRectangle {

	gdouble left, top, right, bottom;
};


DiaColor

typedef guint32 DiaColor;


dia_distance_point_point ()

gdouble     dia_distance_point_point        (DiaPoint *p1,
                                             DiaPoint *p2);

Distance from one point to another point.

p1 :
p2 :
Returns : Distance.

dia_distance_point_point_manhattan ()

gdouble     dia_distance_point_point_manhattan
                                            (DiaPoint *p1,
                                             DiaPoint *p2);

Fast distance calculation (but less accurate).

p1 :
p2 :
Returns : Distance.

dia_distance_line_point ()

gdouble     dia_distance_line_point         (DiaPoint *line_start,
                                             DiaPoint *line_end,
                                             DiaPoint *point,
                                             gdouble line_width,
                                             DiaCapStyle style,
                                             DiaPoint *point_on_line);

This function estimates the distance from a point to a line segment specified by two endpoints. If the point is on the line, 0.0 is returned. Otherwise the distance in the R^2 metric from the point to the nearest point on the line segment is returned. Does one sqrt per call.

If point can not be projected on the line, the distance from the start or end point is taken. If style is DIA_CAP_ROUND or DIA_CAP_SQUARE the distance is decreased by line_width/2.

line_start :
line_end :
point :
line_width :
style :
point_on_line : OUT point on the line, closest to point. May be NULL.
Returns : Distance from the point to the line (this is equal to the distance from point to point_on_line - line_width/2).

dia_distance_rectangle_point ()

gdouble     dia_distance_rectangle_point    (DiaRectangle *rect,
                                             DiaPoint *point);

This function estimates the distance from a point to a rectangle. If the point is in the rectangle, 0.0 is returned. Otherwise the distance in a manhattan metric from the point to the nearest point on the rectangle is returned.

rect :
point :
Returns : Distance from the rectangle to the point, 0.0 if the point is inside the rectangle.

dia_intersection_line_line ()

gboolean    dia_intersection_line_line      (DiaPoint *start1,
                                             DiaPoint *end1,
                                             DiaPoint *start2,
                                             DiaPoint *end2,
                                             DiaPoint *intersect);

Find the intersection point of two lines, if any.

start1 : Starting point of line 1.
end1 : End of line 1.
start2 : Start of line 2.
end2 : End of line 2.
intersect : If TRUE is returned, intersect contains the point of intersection.
Returns : TRUE if an intersection point is found, FALSE otherwise.

dia_intersection_line_rectangle ()

gint        dia_intersection_line_rectangle (DiaPoint *start,
                                             DiaPoint *end,
                                             DiaRectangle *rect,
                                             DiaPoint intersect[2]);

Find the intersection points of a line and a rectangle by comparing each border line of the rectangle with the line's intersection.

start :
end :
rect :
intersect : A list of intersections.
Returns : Number of intersections: 0, 1 or 2.

dia_intersection_rectangle_rectangle ()

gboolean    dia_intersection_rectangle_rectangle
                                            (DiaRectangle *r1,
                                             DiaRectangle *r2);

Determine if two rectangles intersect with each other.

r1 :
r2 :
Returns : TRUE if an intersection is found, FALSE otherwise.

dia_rectangle_add_point ()

void        dia_rectangle_add_point         (DiaRectangle *rect,
                                             DiaPoint *p);

Extent rect so point p is also in the rectangle.

rect :
p :

DIA_COLOR()

#define     DIA_COLOR(r, g, b)

r :
g :
b :

DIA_COLOR_A()

#define     DIA_COLOR_A(r, g, b, a)

r :
g :
b :
a :

DIA_COLOR_RED()

#define DIA_COLOR_RED(c)	((int) (((DiaColor) (c)) >> 24) & 0xFF)

c :

DIA_COLOR_GREEN()

#define DIA_COLOR_GREEN(c)	((int) (((DiaColor) (c)) >> 16) & 0xFF)

c :

DIA_COLOR_BLUE()

#define DIA_COLOR_BLUE(c)	((int) (((DiaColor) (c)) >> 8) & 0xFF)

c :

DIA_COLOR_ALPHA()

#define DIA_COLOR_ALPHA(c)	((int) ((DiaColor) (c)) & 0xFF)

c :