Rectangle.

You will find a general example for the use of rect here.

Rectangle. The module defines a rectangle object and some basic rectangle functions.

static Rect rect::alloc()

Create a new rectangle object. Without any parameters, the empty rectangle (0.0, 0.0, 0.0, 0.0) is created.

Name Type Default Description
Return Rect   new created Rect
Square
s float - Square size, result is (0.0, 0.0, s, s)
Rectangle at (0.0, 0.0)
w, h float, float - Size of rectangle, result is (0.0, 0.0, w, h)
Rectangle
left, top, right, bottom float, float, float, float - Co-ordinates of rectangle. The data are not normalized!
int wrect (Rect r, char * trailer)
{
    if (strlen (trailer))	wlog ("", "%s	", trailer);
wlog ("", "%f, %f, %f, %f\n",   rect::left (r),   rect::top (r),   rect::right (r),   rect::bottom (r));
return 0; }
int main () { Rect r1 = rect::alloc (0.0, 0.0, 100.0, 200.0); Rect r2 = rect::alloc (80.0, 90.0, 110.0, 210.0); Rect intersect = rect::alloc (); Rect union_ = rect::alloc ();
rect::intersection (intersect, r1, r2); rect::union_ (union_, r1, r2);
wrect (r1, "R1"); wrect (r2, "R2"); wrect (intersect, "(-)"); wrect (union_, "(+)");
return 0; }

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.rect.create
comet.rect.createSquare

static Rect rect::clone(Rect org)

Clone an existing rectangle.

Name Type Default Description
Return Rect   new created Rect
org Rect - rectangle to clone

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

static int rect::release(Rect r)

Release a rectangle object from the stack.

Name Type Default Description
Return int   always 0
r Rect - rectangle to clone

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

static float rect::left(Rect rect)

Get the rectangle's left component.

Name Type Default Description
Return float   left component of rectangle
rect Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getLeft
comet.CRect.getValues

static float rect::top(Rect rect)

Get the rectangle's left component.

Name Type Default Description
Return float   top component of rectangle
rect Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getTop
comet.CRect.getValues

static float rect::right(Rect rect)

Get the rectangle's right component.

Name Type Default Description
Return float   right component of rectangle
rect Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getRight
comet.CRect.getValues

static float rect::bottom(Rect rect)

Get the rectangle's bottom component.

Name Type Default Description
Return float   bottom component of rectangle
rect Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getBottom
comet.CRect.getValues

static float rect::width(Rect rect)

Get the rectangle's width.

Name Type Default Description
Return float   width of rectangle
rect Rect - rectangle

v4.0.5 R18210, 19. May 2017

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getWidth

static float rect::height(Rect rect)

Get the rectangle's height.

Name Type Default Description
Return float   height of rectangle
rect Rect - rectangle

v4.0.5 R18210, 19. May 2017

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getHeight

static float rect::xcenter(Rect rect)

Get the rectangle's center on the X axis.

Name Type Default Description
Return float   rectangle's center on the X axis.
rect Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getCenter

static float rect::ycenter(Rect rect)

Get the rectangle's center on the Y axis.

Name Type Default Description
Return float   rectangle's center on the Y axis.
rect Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

static int rect::set_left(Rect rect, float l)

The rectangle's new left component.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
l float - The rectangle's new left component

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.setLeft

static int rect::set_top(Rect rect, float t)

The rectangle's new top component.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
t float - The rectangle's new top component

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.setTop

static int rect::set_right(Rect rect, float r)

The rectangle's new right component.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
r float - The rectangle's new right component

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.setRight

static int rect::set_bottom(Rect rect, float b)

The rectangle's new bottom component.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
b float - The rectangle's new bottom component

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.setBottom

static int rect::set_width(Rect rect, float w)

Set the rectangle's width.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
w float - The rectangle's new width

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.setWidth

static int rect::set_height(Rect rect, float h)

Set the rectangle's height.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
h float - The rectangle's new height

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.setHeight

static int rect::move_rel(
  Rect rect,
  float x,
  float y)

Move a rectangle relativ to its current position.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
x, y float, float - Values for move

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.moveBy

static int rect::move_to(
  Rect rect,
  float x,
  float y)

Move a rectangle relativ to a new position.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
x, y float, float - new position

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.moveTo

static int rect::center_on(
  Rect rect,
  float x,
  float y)

Center a rectangle at a given position.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
x, y float, float - new center position

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.moveTo

static int rect::inset(
  Rect rect,
  float dx,
  float dy)

Contracts the rectangle by (dx, dy) on all sides. Positive values contract the rectangle, negative values enlarge it.

Name Type Default Description
Return int   0 or ErrorCode
rect Rect - rectangle
dx, dy float, float - Contracts the rectangle by (dx, dy) on all sides. Positive values contract the rectangle, negative values enlarge it.

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.adjust

static int rect::intersect(Rect r1, Rect r2)

Determines if two rectangles intersect. True if rectangles intersect in both x and y directions, but false if only a side is shared (ie., rectangles must strictly intersect).

Name Type Default Description
Return int   0 : no intersection
1 : yes
r1 Rect - rectangle 1
r2 Rect - rectangle 2

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

intersection
union_
contains
comet.CRect.intersects

static int rect::intersection(
  Rect result,
  Rect r1,
  Rect r2)

Calculates the intersection of two rectangles. If the rectangles do not strictly intersect, the specified empty rectangle is returned.

Name Type Default Description
Return int   0 or ErrorCode
result Rect - intersection of r1 and r2 (empty, if r1 and r2 do not intersect strictly)
r1 Rect - rectangle 1
r2 Rect - rectangle 2
int wrect (Rect r, char * trailer)
{
    if (strlen (trailer))	wlog ("", "%s	", trailer);
wlog ("", "%f, %f, %f, %f\n",   rect::left (r),   rect::top (r),   rect::right (r),   rect::bottom (r));
return 0; }
int main () { Rect r1 = rect::alloc (0.0, 0.0, 100.0, 200.0); Rect r2 = rect::alloc (80.0, 90.0, 110.0, 210.0); Rect intersect = rect::alloc (); Rect union_ = rect::alloc ();
rect::intersection (intersect, r1, r2); rect::union_ (union_, r1, r2);
wrect (r1, "R1"); wrect (r2, "R2"); wrect (intersect, "(-)"); wrect (union_, "(+)");
return 0; }

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

intersect
union_
contains
comet.CRect.createIntersection

static int rect::union_(
  Rect result,
  Rect r1,
  Rect r2)

Unions a rectangle with another.

Name Type Default Description
Return int   0 or ErrorCode
result Rect - Bounding box of r1 and r2
r1 Rect - rectangle 1
r2 Rect - rectangle 2
int wrect (Rect r, char * trailer)
{
    if (strlen (trailer))	wlog ("", "%s	", trailer);
wlog ("", "%f, %f, %f, %f\n",   rect::left (r),   rect::top (r),   rect::right (r),   rect::bottom (r));
return 0; }
int main () { Rect r1 = rect::alloc (0.0, 0.0, 100.0, 200.0); Rect r2 = rect::alloc (80.0, 90.0, 110.0, 210.0); Rect intersect = rect::alloc (); Rect union_ = rect::alloc ();
rect::intersection (intersect, r1, r2); rect::union_ (union_, r1, r2);
wrect (r1, "R1"); wrect (r2, "R2"); wrect (intersect, "(-)"); wrect (union_, "(+)");
return 0; }

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

intersection
contains
comet.CRect.createUnion

static int rect::contains_point(
  Rect rect,
  float x,
  float y)

Determines whether the specified point falls within a rectangle.

Name Type Default Description
Return int   0 : No
1 : Yes, the point falls into rect.
rect Rect - rectangle
x, y float, float - point

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

intersection
contains
comet.CRect.containsPoint

static int rect::contains(Rect r1, Rect r2)

Determines whether the specified rectangle is contained with a rectangle.

Name Type Default Description
Return int   0 : No, r1 does not contain r1
1 : Yes, r1 contains r2
r1 Rect - rectangle
r2 Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

intersection
contains_point
comet.CRect.containsRect

static float rect::aspect_ratio(Rect rect)

Calculates the aspect ratio for the rectangle. The aspect ratio is calculated as the ratio of the rectangle's height to its width. If the rectangle is empty, zero is returned.

Name Type Default Description
Return float   aspcet ratio or 0.0 if the rectangle is empty
rect Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getAspectRatio

static float rect::area(Rect rect)

Area of a rectangle.

Name Type Default Description
Return float   size of the rectangle
rect Rect - rectangle

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

comet.CRect.getArea

static float rect::is_equal(Rect r1, Rect r2)

Check whether to rectangles are equal.

Name Type Default Description
Return int   0 : not equal
1 : equal
r1 Rect - rectangle 1
r2 Rect - rectangle 2

Version 3.1 R2210, 29.11.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator®

int wrect (Rect r, char * trailer)
{
    if (strlen (trailer))	wlog ("", "%s	", trailer);
wlog ("", "%f, %f, %f, %f\n",   rect::left (r),   rect::top (r),   rect::right (r),   rect::bottom (r));
return 0; }
int main () { Rect r1 = rect::alloc (0.0, 0.0, 100.0, 200.0); Rect r2 = rect::alloc (80.0, 90.0, 110.0, 210.0); Rect intersect = rect::alloc (); Rect union_ = rect::alloc ();
rect::intersection (intersect, r1, r2); rect::union_ (union_, r1, r2);
wrect (r1, "R1"); wrect (r2, "R2"); wrect (intersect, "(-)"); wrect (union_, "(+)");
return 0; }

Since
Version 3.1 R2210, 29.11.2010

Alphabetic index HTML hierarchy of classes or Java