Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "drawutil.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tmathutil.h"
Toshihiro Shimizu 890ddd
//#include "tregion.h"
Toshihiro Shimizu 890ddd
#include "tcurveutil.h"
Toshihiro Shimizu 890ddd
#include "tcurves.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
void drawQuadraticCenterline(const TQuadratic &inQuad, double pixelSize,
Shinya Kitaoka 120a6e
                             double from, double to) {
Shinya Kitaoka 120a6e
  assert(0.0 <= from && from <= to && to <= 1.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  to   = (std::max)(0.0, (std::min)(to, 1.0));
Shinya Kitaoka 120a6e
  from = (std::max)(0.0, (std::min)(from, to));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TQuadratic tmp(inQuad), s1, s2;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TQuadratic *quad = &tmp;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double newFrom = from;
Shinya Kitaoka 120a6e
  if (to != 1.0) {
Shinya Kitaoka 120a6e
    tmp.split(to, s1, s2);
Shinya Kitaoka 120a6e
    quad    = &s1;
Shinya Kitaoka 120a6e
    newFrom = from / to;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (from != 0.0) {
Shinya Kitaoka 120a6e
    tmp = *quad;
Shinya Kitaoka 120a6e
    tmp.split(newFrom, s1, s2);
Shinya Kitaoka 120a6e
    quad = &s2;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // glColor( TPixel32::Black );
Shinya Kitaoka 120a6e
  double step = computeStep(*quad, pixelSize);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // It draws the curve as a linear piecewise approximation
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double invSqrtScale = 1.0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // First of all, it computes the control circles of the curve in screen
Shinya Kitaoka 120a6e
  // coordinates
Shinya Kitaoka 120a6e
  TPointD scP0 = quad->getP0();
Shinya Kitaoka 120a6e
  TPointD scP1 = quad->getP1();
Shinya Kitaoka 120a6e
  TPointD scP2 = quad->getP2();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointD A = scP0 - 2 * scP1 + scP2;
Shinya Kitaoka 120a6e
  TPointD B = scP0 - scP1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double h;
Shinya Kitaoka 120a6e
  h         = invSqrtScale * step;
Shinya Kitaoka 120a6e
  double h2 = h * h;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointD P = scP0, D2 = 2 * h2 * A, D1 = A * h2 - 2 * B * h;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (h < 0 || isAlmostZero(h)) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //    if ( h < from )
Shinya Kitaoka 120a6e
  //      h = from;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // It draws the whole curve, using forward differencing
Shinya Kitaoka 120a6e
  glBegin(GL_LINE_STRIP);  // The curve starts from scP0
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // scP0 = quad.getPoint(from);
Shinya Kitaoka 120a6e
  glVertex2d(scP0.x, scP0.y);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (double t = from + h; t < to; t = t + h) {
Shinya Kitaoka 120a6e
    P  = P + D1;
Shinya Kitaoka 120a6e
    D1 = D1 + D2;
Shinya Kitaoka 120a6e
    glVertex2d(P.x, P.y);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // scP2 = quad.getPoint(to);
Shinya Kitaoka 120a6e
  glVertex2d(scP2.x, scP2.y);  // The curve ends in scP2
Shinya Kitaoka 120a6e
  glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void stroke2polyline(std::vector<tpointd> &pnts, const TStroke &stroke,</tpointd>
Shinya Kitaoka 120a6e
                     double pixelSize, double w0, double w1,
Shinya Kitaoka 120a6e
                     bool lastRepeatable) {
Shinya Kitaoka 120a6e
  TPointD p;
Shinya Kitaoka 120a6e
  double step;
Shinya Kitaoka 120a6e
  int i, index0, index1;
Shinya Kitaoka 120a6e
  double t0, t1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (isAlmostZero(w0)) w0     = 0.0;
Shinya Kitaoka 120a6e
  if (isAlmostZero(w1)) w1     = 0.0;
Shinya Kitaoka 120a6e
  if (isAlmostZero(1 - w0)) w0 = 1.0;
Shinya Kitaoka 120a6e
  if (isAlmostZero(1 - w1)) w1 = 1.0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(w0 >= 0.0);
Shinya Kitaoka 120a6e
  assert(w0 <= 1.0);
Shinya Kitaoka 120a6e
  assert(w1 >= 0.0);
Shinya Kitaoka 120a6e
  assert(w1 <= 1.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  stroke.getChunkAndT(w0, index0, t0);
Shinya Kitaoka 120a6e
  stroke.getChunkAndT(w1, index1, t1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double t;
Shinya Kitaoka 120a6e
  double endT;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (index1 < index0 || (index1 == index0 && t1 < t0)) {
Shinya Kitaoka 120a6e
    for (i = index0; i >= index1; i--) {
Shinya Kitaoka 120a6e
      step = computeStep(*(stroke.getChunk(i)), pixelSize);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (step < TConsts::epsilon) step = TConsts::epsilon;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      p = stroke.getChunk(i)->getPoint(t0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (pnts.empty() || pnts.back() != p) pnts.push_back(p);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      endT = (i == index1) ? t1 : 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      pnts.reserve((UINT)((t0 - endT) / step) + 1 + pnts.size());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      for (t = t0 - step; t >= endT; t -= step)
Shinya Kitaoka 120a6e
        pnts.push_back(stroke.getChunk(i)->getPoint(t));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      t0 = 1;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    for (i = index0; i <= index1; i++) {
Shinya Kitaoka 120a6e
      step = computeStep(*(stroke.getChunk(i)), pixelSize);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      assert(step);
Shinya Kitaoka 120a6e
      if (!step) step = TConsts::epsilon;  // non dovrebbe accadere mai!!!
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      p = stroke.getChunk(i)->getPoint(t0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (pnts.empty() || pnts.back() != p) pnts.push_back(p);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      endT = (i == index1) ? t1 : 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      pnts.reserve((UINT)((endT - t0) / step) + 1 + pnts.size());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      for (t = t0 + step; t <= endT; t += step)
Shinya Kitaoka 120a6e
        pnts.push_back(stroke.getChunk(i)->getPoint(t));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      t0 = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  p = stroke.getPoint(w1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (pnts.empty() ||
Shinya Kitaoka 120a6e
      (p != pnts.back() && (p != pnts.front() || lastRepeatable)))
Shinya Kitaoka 120a6e
    pnts.push_back(p);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void  region2polyline(vector<t3dpointd>& pnts,</t3dpointd>
Shinya Kitaoka 120a6e
                      const TRegion* reg,
Toshihiro Shimizu 890ddd
                      double pixelSize )
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
assert( reg );
Toshihiro Shimizu 890ddd
if(!reg) return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const TStroke* stroke;
Toshihiro Shimizu 890ddd
double w0;
Toshihiro Shimizu 890ddd
double w1;
Toshihiro Shimizu 890ddd
TPointD lastPnt;
Toshihiro Shimizu 890ddd
for(UINT i=0; i<reg->getEdgeCount(); i++)</reg->
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  TRegion::edge* edge = reg->getEdge(i);
Toshihiro Shimizu 890ddd
  stroke = edge->m_stroke;
Toshihiro Shimizu 890ddd
  assert(stroke);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  if (edge->m_w0==-1)
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
    int index;
Toshihiro Shimizu 890ddd
    double t, dummy;
Toshihiro Shimizu 890ddd
    stroke->getNearestChunk(edge->m_p0, t, index, dummy);
Toshihiro Shimizu 890ddd
    edge->m_w0 = getWfromChunkAndT(stroke, index, t);
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
    stroke->getNearestChunk(edge->m_p1, t, index, dummy);
Toshihiro Shimizu 890ddd
    edge->m_w1 = getWfromChunkAndT(stroke, index, t);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  w0 = edge->m_w0;
Toshihiro Shimizu 890ddd
  w1 = edge->m_w1;
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  assert( 0 <= w0 && w0 <= 1.0 );
Toshihiro Shimizu 890ddd
  assert( 0 <= w1 && w1 <= 1.0 );
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  double step = computeStep( *stroke, pixelSize );
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
    // assert( step != 2 && step != 0.0 );
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if( isAlmostZero( step ) )
Toshihiro Shimizu 890ddd
    step = 1.0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  step/= stroke->getChunkCount();
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  double direction = 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if( w0 > w1 )
Toshihiro Shimizu 890ddd
    direction *=-1;
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  T3DPointD pnt;
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  double incr = direction*step;
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  pnt = T3DPointD( stroke->getPoint( w0 ), 0 );
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  if ( pnts.empty() || pnt != pnts.back() )
Toshihiro Shimizu 890ddd
    pnts.push_back( pnt );
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
  for( double w = w0 + incr; direction*w < direction*w1; w+= incr)
Toshihiro Shimizu 890ddd
    {
Shinya Kitaoka 120a6e
    pnt = T3DPointD( stroke->getPoint( w ), 0 );
Toshihiro Shimizu 890ddd
      if ( pnt != pnts.back() )
Toshihiro Shimizu 890ddd
        pnts.push_back( pnt );
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Shinya Kitaoka 120a6e
void lefttRotateBits(UCHAR *buf, int bufferSize) {
Shinya Kitaoka 120a6e
  UINT *buffer = (UINT *)buf;
Shinya Kitaoka 120a6e
  UINT app;
Shinya Kitaoka 120a6e
  for (int i = 0; i < bufferSize; i++, buffer++) {
Shinya Kitaoka 120a6e
    app     = *buffer;
Shinya Kitaoka 120a6e
    *buffer = app << 8 | app >> 24;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double computeStep(const TStroke &s, double pixelSize) {
Shinya Kitaoka 120a6e
  double minVal = (std::numeric_limits<double>::max)();</double>
Shinya Kitaoka 120a6e
  double tempVal;
Shinya Kitaoka 120a6e
  for (int i = 0; i < s.getChunkCount(); ++i)
Shinya Kitaoka 120a6e
    if ((tempVal = computeStep(*s.getChunk(i), pixelSize)) < minVal)
Shinya Kitaoka 120a6e
      minVal = tempVal;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return minVal;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
TRasterP prepareTexture(const TRasterP &ras, TextureInfoForGL &texinfo) {
Shinya Kitaoka 120a6e
  TDimension size = ras->getSize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  texinfo.width          = size.lx;
Shinya Kitaoka 120a6e
  texinfo.height         = size.ly;
Shinya Kitaoka 120a6e
  texinfo.internalformat = ras->getPixelSize();
Shinya Kitaoka 120a6e
  texinfo.format         = GL_UNSIGNED_BYTE;
Shinya Kitaoka 120a6e
  texinfo.pixels         = ras->getRawData();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (texinfo.internalformat) {
Shinya Kitaoka 120a6e
  case 1:
Shinya Kitaoka 120a6e
    texinfo.type = GL_LUMINANCE;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case 2:
Shinya Kitaoka 120a6e
    texinfo.type = GL_LUMINANCE_ALPHA;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (texinfo.internalformat > 2) {
Shinya Kitaoka 120a6e
    switch (texinfo.internalformat) {
Shinya Kitaoka 120a6e
    case 3:
Shinya Kitaoka 120a6e
      texinfo.type = GL_RGB;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case 4:
Shinya Kitaoka 120a6e
      texinfo.type = GL_RGBA;
Shinya Kitaoka 120a6e
      break;  // GL_RGBA;  break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#ifdef TNZ_MACHINE_CHANNEL_ORDER_BGRM  // under win32 pixel are in reverse order
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#ifdef GL_EXT_bgra  // if extension exists...
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // and it's  present at run time all okay
Shinya Kitaoka 120a6e
    // if(TGLArea::isBGRASupported())
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      switch (texinfo.internalformat) {
Shinya Kitaoka 120a6e
      case 3:
Shinya Kitaoka 120a6e
        texinfo.type = GL_BGR_EXT;
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      case 4:
Shinya Kitaoka 120a6e
        texinfo.type = GL_BGRA_EXT;
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      return ras;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    TDimension size = ras->getSize();
Shinya Kitaoka 120a6e
    TRasterP outRas = ras->clone();
Shinya Kitaoka 120a6e
    outRas->lock();
Shinya Kitaoka 120a6e
    int pixelSize  = ras->getPixelSize();
Shinya Kitaoka 120a6e
    texinfo.pixels = outRas->getRawData();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    UCHAR *p1, *p2;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (int i = 0; i < size.lx; ++i)
Shinya Kitaoka 120a6e
      for (int j = 0; j < size.ly; ++j) {
Shinya Kitaoka 120a6e
        p1 = outRas->getRawData(i, j);
Shinya Kitaoka 120a6e
        p2 = p1 + 2;
Shinya Kitaoka 120a6e
        std::swap(*p1, *p2);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    outRas->unlock();
Shinya Kitaoka 120a6e
    return outRas;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#elif defined(TNZ_MACHINE_CHANNEL_ORDER_MRGB)
Shinya Kitaoka 120a6e
// mrgb
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#warning "ottimizzare in qualche modo"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    TDimension size = ras->getSize();
Shinya Kitaoka 120a6e
    TRasterP outRas = ras->clone();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    texinfo.pixels = outRas->getRawData();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    lefttRotateBits((UCHAR *)texinfo.pixels, size.lx * size.ly);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    return outRas;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  texinfo.pixels = ras->getRawData();
Shinya Kitaoka 120a6e
  return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawStrokeCenterline(const TStroke &stroke, double pixelSize, double from,
Shinya Kitaoka 120a6e
                          double to) {
Shinya Kitaoka 120a6e
  int c1 = 0, c2 = 0;
Shinya Kitaoka 120a6e
  double t1 = 1.0, t2 = 0.0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (stroke.getChunkCount() == 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  stroke.getChunkAndT(from, c1, t1);
Shinya Kitaoka 120a6e
  stroke.getChunkAndT(to, c2, t2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (c1 == c2) {
Shinya Kitaoka 120a6e
    if (from == to) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    drawQuadraticCenterline(*stroke.getChunk(c1), pixelSize, t1, t2);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    // partial first chunk
Shinya Kitaoka 120a6e
    drawQuadraticCenterline(*stroke.getChunk(c1), pixelSize, t1, 1.0);
Shinya Kitaoka 120a6e
    // next chunk
Shinya Kitaoka 120a6e
    ++c1;
Shinya Kitaoka 120a6e
    if (c1 < c2) {
Shinya Kitaoka 120a6e
      for (int i = c1; i < c2; ++i)
Shinya Kitaoka 120a6e
        drawQuadraticCenterline(*stroke.getChunk(i), pixelSize, 0.0, 1.0);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // partial last chunk
Shinya Kitaoka 120a6e
    drawQuadraticCenterline(*stroke.getChunk(c2), pixelSize, 0.0, t2);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DVAPI TStroke *makeEllipticStroke(double thick, TPointD center, double radiusX,
Shinya Kitaoka 120a6e
                                  double radiusY) {
Shinya Kitaoka 120a6e
  std::vector<tthickpoint> points(17);</tthickpoint>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double xmin = center.x - radiusX;  // x coordinate of the upper left corner of
Shinya Kitaoka 120a6e
                                     // the bounding rectangle
Shinya Kitaoka 120a6e
  double ymin = center.y - radiusY;  // y coordinate of the upper left corner of
Shinya Kitaoka 120a6e
                                     // the bounding rectangle
Shinya Kitaoka 120a6e
  double xmax = center.x + radiusX;  // x coordinate of the bottom right corner
Shinya Kitaoka 120a6e
                                     // of the bounding rectangle
Shinya Kitaoka 120a6e
  double ymax = center.y + radiusY;  // y coordinate of the bottom right corner
Shinya Kitaoka 120a6e
                                     // of the bounding rectangle
Shinya Kitaoka 120a6e
  const double C1 = 0.1465;          // magic number for coefficient1
Shinya Kitaoka 120a6e
  const double C2 = 0.2070;          // magic number for coefficient2
Shinya Kitaoka 120a6e
  double dx       = xmax - xmin;     // dx is width diameter
Shinya Kitaoka 120a6e
  double dy       = ymax - ymin;     // dy is height diameter
Shinya Kitaoka 120a6e
  const double begin =
Shinya Kitaoka 120a6e
      0.8535;  // starting position to draw (bounding square is 1x1)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double c1dx = (double)(C1 * dx);
Shinya Kitaoka 120a6e
  double c1dy = (double)(C1 * dy);
Shinya Kitaoka 120a6e
  double c2dx = (double)(C2 * dx);
Shinya Kitaoka 120a6e
  double c2dy = (double)(C2 * dy);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  points[0] = TThickPoint(xmin + begin * dx, ymin + begin * dy, thick);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  points[1]  = points[0] + TThickPoint(-c1dx, c1dy, 0);   //
Shinya Kitaoka 120a6e
  points[2]  = points[1] + TThickPoint(-c2dx, 0, 0);      //
Shinya Kitaoka 120a6e
  points[3]  = points[2] + TThickPoint(-c2dx, 0, 0);      //
Shinya Kitaoka 120a6e
  points[4]  = points[3] + TThickPoint(-c1dx, -c1dy, 0);  //
Shinya Kitaoka 120a6e
  points[5]  = points[4] + TThickPoint(-c1dx, -c1dy, 0);  //
Shinya Kitaoka 120a6e
  points[6]  = points[5] + TThickPoint(0, -c2dy, 0);      //
Shinya Kitaoka 120a6e
  points[7]  = points[6] + TThickPoint(0, -c2dy, 0);      //
Shinya Kitaoka 120a6e
  points[8]  = points[7] + TThickPoint(c1dx, -c1dy, 0);   //
Shinya Kitaoka 120a6e
  points[9]  = points[8] + TThickPoint(c1dx, -c1dy, 0);   //
Shinya Kitaoka 120a6e
  points[10] = points[9] + TThickPoint(c2dx, 0, 0);       //
Shinya Kitaoka 120a6e
  points[11] = points[10] + TThickPoint(c2dx, 0, 0);      //
Shinya Kitaoka 120a6e
  points[12] = points[11] + TThickPoint(c1dx, c1dy, 0);   //
Shinya Kitaoka 120a6e
  points[13] = points[12] + TThickPoint(c1dx, c1dy, 0);   //
Shinya Kitaoka 120a6e
  points[14] = points[13] + TThickPoint(0, c2dy, 0);      //
Shinya Kitaoka 120a6e
  points[15] = points[14] + TThickPoint(0, c2dy, 0);      //
Shinya Kitaoka 120a6e
  points[16] = points[0];  // need to be closed!!!
Shinya Kitaoka 120a6e
                           // points[15]+TThickPoint(-c1dx,  c1dy,0);//
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TStroke *stroke = new TStroke(points);
Shinya Kitaoka 120a6e
  stroke->setSelfLoop();
Shinya Kitaoka 120a6e
  return stroke;
Toshihiro Shimizu 890ddd
}