Back to index

texmacs  1.0.7.15
Defines | Functions
rectangles.cpp File Reference
#include "rectangles.hpp"

Go to the source code of this file.

Defines

#define min(x, y)   ((x)<=(y)?(x):(y))
#define max(x, y)   ((x)<=(y)?(y):(x))

Functions

tm_ostreamoperator<< (tm_ostream &out, rectangle r)
rectangle copy (rectangle r)
bool operator== (rectangle r1, rectangle r2)
bool operator!= (rectangle r1, rectangle r2)
bool operator<= (rectangle r1, rectangle r2)
bool intersect (rectangle r1, rectangle r2)
rectangle translate (rectangle r, SI x, SI y)
double area (rectangle r)
void complement (rectangle r1, rectangle r2, rectangles &l)
void complement (rectangles l1, rectangle r2, rectangles &l)
void intersection (rectangle r1, rectangle r2, rectangles &l)
rectangle operator* (rectangle r, int d)
rectangle operator/ (rectangle r, int d)
rectangles operator- (rectangles l1, rectangles l2)
rectangles operator& (rectangles l1, rectangles l2)
bool adjacent (rectangle r1, rectangle r2)
rectangles disjoint_union (rectangles l, rectangle r)
rectangles operator| (rectangles l1, rectangles l2)
rectangles translate (rectangles l, SI x, SI y)
rectangles thicken (rectangles l, SI width, SI height)
rectangles outline (rectangles rs, SI pixel)
rectangles operator* (rectangles l, int d)
rectangles operator/ (rectangles l, int d)
rectangles correct (rectangles l)
rectangles simplify (rectangles l)
rectangle least_upper_bound (rectangles l)
double area (rectangles r)

Define Documentation

#define max (   x,
  y 
)    ((x)<=(y)?(y):(x))

Definition at line 90 of file rectangles.cpp.

#define min (   x,
  y 
)    ((x)<=(y)?(x):(y))

Definition at line 89 of file rectangles.cpp.


Function Documentation

bool adjacent ( rectangle  r1,
rectangle  r2 
)

Definition at line 151 of file rectangles.cpp.

                                      {
  return
    (((r1->x2==r2->x1) || (r1->x1==r2->x2)) &&
     ((r1->y1==r2->y1) && (r1->y2==r2->y2))) ||
    (((r1->y2==r2->y1) || (r1->y1==r2->y2)) &&
     ((r1->x1==r2->x1) && (r1->x2==r2->x2)));
}

Here is the caller graph for this function:

double area ( rectangle  r)

Definition at line 78 of file rectangles.cpp.

                   {
  double w= max (r->x2 - r->x1, 0);
  double h= max (r->y2 - r->y1, 0);
  return w*h;
}

Here is the caller graph for this function:

double area ( rectangles  r)

Definition at line 243 of file rectangles.cpp.

                    {
  double sum= 0.0;
  while (!is_nil (r)) {
    sum += area (r->item);
    r= r->next;
  }
  return sum;
}

Here is the call graph for this function:

void complement ( rectangle  r1,
rectangle  r2,
rectangles l 
)

Definition at line 93 of file rectangles.cpp.

                                                       {
  if (!intersect (r1, r2)) { r1 >> l; return; }
  if (r1->x1 < r2->x1) rectangle (r1->x1, r1->y1, r2->x1, r1->y2) >> l;
  if (r1->x2 > r2->x2) rectangle (r2->x2, r1->y1, r1->x2, r1->y2) >> l;
  if (r1->y1 < r2->y1) rectangle (max (r1->x1, r2->x1), r1->y1,
                              min (r1->x2, r2->x2), r2->y1) >> l;
  if (r1->y2 > r2->y2) rectangle (max (r1->x1, r2->x1), r2->y2,
                              min (r1->x2, r2->x2), r1->y2) >> l;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void complement ( rectangles  l1,
rectangle  r2,
rectangles l 
)

Definition at line 104 of file rectangles.cpp.

                                                        {
  for (; !is_nil (l1); l1= l1->next)
    complement (l1->item, r2, l);
}

Here is the call graph for this function:

Definition at line 40 of file rectangles.cpp.

                   {
  return rectangle (r->x1, r->y1, r->x2, r->y2);
}

Definition at line 214 of file rectangles.cpp.

                       {
  if (is_nil (l)) return l;
  if ((l->item->x1 >= l->item->x2) || (l->item->y1 >= l->item->y2))
    return correct (l->next);
  return rectangles (l->item, correct (l->next));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 160 of file rectangles.cpp.

                                           {
  if (is_nil (l)) return r;
  if (adjacent (l->item, r))
    return disjoint_union (l->next,
                        least_upper_bound (rectangles (l->item, r)));
  return rectangles (l->item, disjoint_union (l->next, r));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool intersect ( rectangle  r1,
rectangle  r2 
)

Definition at line 66 of file rectangles.cpp.

                                       {
  return
    (r1->x1<r2->x2) && (r1->x2>r2->x1) &&
    (r1->y1<r2->y2) && (r1->y2>r2->y1);
}

Here is the caller graph for this function:

void intersection ( rectangle  r1,
rectangle  r2,
rectangles l 
)

Definition at line 110 of file rectangles.cpp.

                                                         {
  if (!intersect (r1, r2)) return;
  rectangle (max (r1->x1, r2->x1), max (r1->y1, r2->y1),
            min (r1->x2, r2->x2), min (r1->y2, r2->y2)) >> l;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 228 of file rectangles.cpp.

                                 {
  ASSERT (!is_nil (l), "no rectangles in list");
  rectangle r1= copy (l->item);
  while (!is_nil (l->next)) {
    l= l->next;
    rectangle r2= l->item;
    r1->x1= min (r1->x1, r2->x1);
    r1->y1= min (r1->y1, r2->y1);
    r1->x2= max (r1->x2, r2->x2);
    r1->y2= max (r1->y2, r2->y2);
  }
  return r1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool operator!= ( rectangle  r1,
rectangle  r2 
)

Definition at line 52 of file rectangles.cpp.

                                         {
  return
    (r1->x1!=r2->x1) || (r1->y1!=r2->y1) ||
    (r1->x2!=r2->x2) || (r1->y2!=r2->y2);
}
rectangles operator& ( rectangles  l1,
rectangles  l2 
)

Definition at line 142 of file rectangles.cpp.

                                          {
  rectangles l, lc1, lc2;
  for (lc1= l1; !is_nil (lc1); lc1= lc1->next)
    for (lc2= l2; !is_nil (lc2); lc2= lc2->next)
      intersection (lc1->item, lc2->item, l);
  return l;
}

Here is the call graph for this function:

rectangle operator* ( rectangle  r,
int  d 
)

Definition at line 117 of file rectangles.cpp.

                                {
  return rectangle (r->x1*d, r->y1*d, r->x2*d, r->y2*d);
}
rectangles operator* ( rectangles  l,
int  d 
)

Definition at line 202 of file rectangles.cpp.

                                 {
  if (is_nil (l)) return l;
  return rectangles (l->item*d, l->next*d);
}

Here is the call graph for this function:

rectangles operator- ( rectangles  l1,
rectangles  l2 
)

Definition at line 131 of file rectangles.cpp.

                                          {
  rectangles a=l1;
  for (; !is_nil (l2); l2= l2->next) {
    rectangles b;
    complement (a, l2->item, b);
    a=b;
  }
  return a;
}

Here is the call graph for this function:

rectangle operator/ ( rectangle  r,
int  d 
)

Definition at line 122 of file rectangles.cpp.

                                {
  return rectangle (r->x1/d, r->y1/d, r->x2/d, r->y2/d);
}
rectangles operator/ ( rectangles  l,
int  d 
)

Definition at line 208 of file rectangles.cpp.

                                 {
  if (is_nil (l)) return l;
  return rectangles (l->item/d, l->next/d);
}

Here is the call graph for this function:

tm_ostream& operator<< ( tm_ostream out,
rectangle  r 
)

Definition at line 32 of file rectangles.cpp.

                                           {
  out << "rectangle ("
      << r->x1 << ", " << r->y1 << ", "
      << r->x2 << ", " << r->y2 << ")";
  return out;
}
bool operator<= ( rectangle  r1,
rectangle  r2 
)

Definition at line 59 of file rectangles.cpp.

                                         {
  return
    (r1->x1>=r2->x1) && (r1->x2<=r2->x2) &&
    (r1->y1>=r2->y1) && (r1->y2<=r2->y2);
}
bool operator== ( rectangle  r1,
rectangle  r2 
)

Definition at line 45 of file rectangles.cpp.

                                         {
  return
    (r1->x1==r2->x1) && (r1->y1==r2->y1) &&
    (r1->x2==r2->x2) && (r1->y2==r2->y2);
}
rectangles operator| ( rectangles  l1,
rectangles  l2 
)

Definition at line 169 of file rectangles.cpp.

                                          {
  rectangles l (l1-l2);
  while (!is_nil (l2)) {
    l = disjoint_union (l, l2->item);
    l2= l2->next;
  }
  return l;
}

Here is the call graph for this function:

rectangles outline ( rectangles  rs,
SI  pixel 
)

Definition at line 196 of file rectangles.cpp.

                                  {
  return simplify (correct (thicken (rs, pixel, 3*pixel) -
                         thicken (rs, 0, 2*pixel)));
}

Here is the call graph for this function:

Definition at line 222 of file rectangles.cpp.

                        {
  if (is_nil (l) || is_atom (l)) return l;
  return simplify (l->next) | rectangles (l->item);
}

Here is the call graph for this function:

rectangles thicken ( rectangles  l,
SI  width,
SI  height 
)

Definition at line 187 of file rectangles.cpp.

                                            {
  if (is_nil (l)) return l;
  rectangle& r= l->item;
  return rectangles (rectangle (r->x1- width, r->y1- height,
                            r->x2+ width, r->y2+ height),
                   thicken (l->next, width, height));
}

Here is the call graph for this function:

Here is the caller graph for this function:

rectangle translate ( rectangle  r,
SI  x,
SI  y 
)

Definition at line 73 of file rectangles.cpp.

                                    {
  return rectangle (r->x1+x, r->y1+y, r->x2+x, r->y2+y);
}

Here is the caller graph for this function:

rectangles translate ( rectangles  l,
SI  x,
SI  y 
)

Definition at line 179 of file rectangles.cpp.

                                     {
  if (is_nil (l)) return l;
  rectangle& r= l->item;
  return rectangles (rectangle (r->x1+ x, r->y1+ y, r->x2+ x, r->y2+ y),
                   translate (l->next, x, y));
}

Here is the call graph for this function: