Пример #1
0
bool
EdgeStrip::has_break(int i) const
{
   // Returns true if the line strip is broken at vert i
   // (or if it's the first or last vert):

   // For bogus input say it's not broken:
   if (empty() || (i < 0) || (i > _verts.num()))
      return false;

   // For the first or last vertex say it is broken:
   // Note: last vert is the one *after* _verts.last()
   if ((i == 0) || (i == _verts.num()))
      return true;

   // Just check the vertex:
   return (_verts[i] != next_vert(i-1));
}
Пример #2
0
/**********************************************************************
 * EdgeStrip:
 **********************************************************************/
void
EdgeStrip::draw(StripCB* cb)
{
   // Draw the strip -- e.g. by making calls to OpenGL or some
   // other graphics API, or by writing a description of the
   // strip to a text file. Which of these is done depends on the
   // implementation of the StripCB.

   // Stop now if nothing is going on
   if (empty())
      return;

   // Iterate over the strip. Keep in mind _verts[i] is the
   // leading vertex (with respect to this strip) of _edges[i].
   // Whenever _edges[i]->other_vertex(_verts[i]) is different
   // from _verts[i+1], the line strip is broken at that point.
   // So a single EdgeStrip encodes 1 or more GL_LINE_STRIPs.
   // The following loop checks for these breaks.

   bool started = 0;
   for (int i=0; i<_verts.num(); i++) {

      // start new line strip if needed:
      if (!started) {
         cb->begin_edges(this);
         cb->edgeCB(_verts[i], _edges[i]);
         started = 1;
      }

      // Get next vert:
      Bvert* next = next_vert(i);  // _edges[i]->other_vertex(_verts[i])

      // Continue line strip ("finish" this edge):
      cb->edgeCB(next, _edges[i]);

      // If we got to the end of the array or if _verts[i+1]
      // isn't part of current edge, then break the strip here.
      if ((i == _verts.num()-1) || (_verts[i+1] != next)) {
         cb->end_edges(this);
         started = 0;
      }
   }
}
Пример #3
0
bool
EdgeStrip::get_chain(int& k, Bvert_list& chain) const
{
   // Return the chain starting at index k,
   // and advance k to the start of the next chain.

   chain.clear();               // get set...

   if (k < 0 || k >= num())     // if out of range, reject
      return false;

   if (!has_break(k))           // if k is not a chain endpoint, reject
      return false;             

   chain += vert(k);            // add leading vertex
   do {
      chain.add(next_vert(k));  // add subsequent vertex
   } while (!has_break(++k));   // advance k, break at chain end

   return true;
}
Пример #4
0
 void Element::calc_diameter()
 {
   double max, l;
   if (is_triangle())
   {
     max = 0.0;
     for (int i = 0; i < 3; i++)
     {
       int j = next_vert(i);
       l = sqr(vn[i]->x - vn[j]->x) + sqr(vn[i]->y - vn[j]->y);
       if (l > max)
         max = l;
     }
   }
   else
   {
     max = sqr(vn[0]->x - vn[2]->x) + sqr(vn[0]->y - vn[2]->y);
     l = sqr(vn[1]->x - vn[3]->x) + sqr(vn[1]->y - vn[3]->y);
     if (l > max)
       max = l;
   }
   this->diameter = sqrt(max);
 }
Пример #5
0
 Bvert* last()           const { return next_vert(num()-1); }