Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// CallCircle.cpp: implementation of the CCallCircle class.
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <math.h></math.h>
Toshihiro Shimizu 890ddd
#include <stdlib.h></stdlib.h>
Toshihiro Shimizu 890ddd
#include <search.h></search.h>
Toshihiro Shimizu 890ddd
//#include "myetc.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "CallCircle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
// Construction/Destruction
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Campbell Barton b3bd84
static int callcircle_xydwCompare(const void *a, const void *b) {
Shinya Kitaoka 120a6e
  SXYDW *aa = (SXYDW *)a;
Shinya Kitaoka 120a6e
  SXYDW *bb = (SXYDW *)b;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (aa->w < bb->w) return -1;
Shinya Kitaoka 120a6e
  if (aa->w > bb->w) return 1;
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
CCallCircle::CCallCircle(const double r) : m_r(r), m_nb(0) {
Shinya Kitaoka 120a6e
  int rr = (int)r + 1;
Shinya Kitaoka 120a6e
  rr *= 2;
Shinya Kitaoka 120a6e
  int dd  = rr * 2 + 1;
Shinya Kitaoka 120a6e
  int dd2 = dd * dd;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (dd2 == 0) {
Shinya Kitaoka 120a6e
    null();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_c.reset(new SXYDW[dd2]);
Shinya Kitaoka 120a6e
  if (!m_c) throw SMemAllocError("in callCircle");
Shinya Kitaoka 120a6e
  for (int y = -rr; y <= rr; y++)
Shinya Kitaoka 120a6e
    for (int x = -rr; x <= rr; x++) {
Shinya Kitaoka 120a6e
      double d = sqrt((double)(x * x + y * y));
Shinya Kitaoka 120a6e
      if (d <= r && m_nb < dd2) {
Shinya Kitaoka 120a6e
        m_c[m_nb].x = x;
Shinya Kitaoka 120a6e
        m_c[m_nb].y = y;
Shinya Kitaoka 120a6e
        m_c[m_nb].w = d;
Shinya Kitaoka 120a6e
        m_nb++;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  qsort(m_c.get(), m_nb, sizeof(SXYDW), callcircle_xydwCompare);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CCallCircle::null() {
Shinya Kitaoka 120a6e
  m_nb = 0;
Shinya Kitaoka 120a6e
  m_r  = 0.0;
Shinya Kitaoka 120a6e
  m_c.reset();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
CCallCircle::~CCallCircle() { null(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CCallCircle::print() {
Shinya Kitaoka 120a6e
  /*smsg_info(" --- CCallCircle ---");
Shinya Kitaoka 120a6e
  smsg_info(" m_nb=%d", m_nb);
Shinya Kitaoka 120a6e
  smsg_info(" m_r=%f", m_r);
Shinya Kitaoka 120a6e
  for( int i=0; i
Shinya Kitaoka 120a6e
          smsg_info(" %d. = (%d,%d,%f)", i, m_c[i].x,m_c[i].y,m_c[i].w);
Shinya Kitaoka 120a6e
  smsg_info(" --- ----------- ---\n");
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CCallCircle::draw(UCHAR *drawB, const int lX, const int lY, const int xx,
Shinya Kitaoka 120a6e
                       const int yy, const double r) {
Shinya Kitaoka 120a6e
  double aa = 2.0 * r / 3.0;  // Size of antialising
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int i = 0; i < m_nb && m_c[i].w <= r; i++) {
Shinya Kitaoka 120a6e
    double w = m_c[i].w;
Shinya Kitaoka 120a6e
    int x    = xx + m_c[i].x;
Shinya Kitaoka 120a6e
    int y    = yy + m_c[i].y;
Shinya Kitaoka 120a6e
    if (x >= 0 && y >= 0 && x < lX && y < lY) {
Shinya Kitaoka 120a6e
      UCHAR *pDB = drawB + y * lX + x;
Shinya Kitaoka 120a6e
      if (w <= aa) {
Shinya Kitaoka 120a6e
        *pDB = (UCHAR)255;
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        double q  = 255.0 * (r - w) / (r - aa);
Shinya Kitaoka 120a6e
        q         = D_CUT_0_255(q);
Shinya Kitaoka 120a6e
        UCHAR ucq = UC_ROUND(q);
Shinya Kitaoka 120a6e
        (*pDB)    = (*pDB) < ucq ? ucq : (*pDB);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}