Shinya Kitaoka 120a6e
#include <cmath>  // sqrt() sin() cos()</cmath>
Shinya Kitaoka 120a6e
#ifndef M_PI      /* only Microsoft C++ */
Toshihiro Shimizu 890ddd
#define M_PI 3.14159265358979323846
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
#include <iostream>  // std::cout</iostream>
Toshihiro Shimizu 890ddd
#include "igs_maxmin_lens_matrix.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
/*
Shinya Kitaoka 120a6e
                        y
Shinya Kitaoka 120a6e
                        ^
Shinya Kitaoka 120a6e
                        |   <-
Shinya Kitaoka 120a6e
                        |      \
Shinya Kitaoka 120a6e
                        |	|
Shinya Kitaoka 120a6e
        <---------------+----------------> x
Shinya Kitaoka 120a6e
                        |
Shinya Kitaoka 120a6e
                        |
Shinya Kitaoka 120a6e
                        |
Shinya Kitaoka 120a6e
                        v
Toshihiro Shimizu 890ddd
 */
Shinya Kitaoka 120a6e
bool inside_polygon_(double radius, int odd_diameter, double xp, double yp,
Shinya Kitaoka 120a6e
                     int polygon_number, double roll_degree) {
Shinya Kitaoka 120a6e
  if (polygon_number < 3) { /* equal less than 2  is circle */
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  double radian     = roll_degree * (M_PI / 180),
Shinya Kitaoka 120a6e
         add_radian = 2.0 * M_PI / polygon_number;
Shinya Kitaoka 120a6e
  double x1 = radius * cos(radian), y1 = radius * sin(radian), x2 = 0, y2 = 0,
Shinya Kitaoka 120a6e
         xa = odd_diameter, xb = odd_diameter;
Shinya Kitaoka 120a6e
  radian += add_radian;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /* 線分の回数loop回す */
Shinya Kitaoka 120a6e
  for (int ii = 0; ii < polygon_number;
Shinya Kitaoka 120a6e
       ++ii, radian += add_radian, x1 = x2, y1 = y2) {
Shinya Kitaoka 120a6e
    /* (0,0)を原点とした正多角形の各頂点
Shinya Kitaoka 120a6e
    数学的開始点(右)及び回転方向(CCW)とするため、
Shinya Kitaoka 120a6e
    内部では上下左右反転する。
Shinya Kitaoka 120a6e
    これをしないと左からCW回転となる
Shinya Kitaoka 120a6e
    計算の考えを単純にするため反転しない2013-12-10
Shinya Kitaoka 120a6e
    */
Shinya Kitaoka 120a6e
    x2 = radius * cos(radian);
Shinya Kitaoka 120a6e
    y2 = radius * sin(radian);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    /* scanline方向でy1とy2の間で区切った領域外なら次へ
Shinya Kitaoka 120a6e
    ((y2==y1==yp)の場合も)しない線分なら次へ */
Shinya Kitaoka 120a6e
    if (!(((y1 <= yp) && (yp <= y2)) || ((y2 <= yp) && (yp <= y1)))) {
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    /* scanline方向でy1とy2の間で区切った領域 */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    /* 水平線分 */
Shinya Kitaoka 120a6e
    if (y2 == y1) {
Shinya Kitaoka 120a6e
      if (((x1 <= xp) && (xp <= x2)) || ((x2 <= xp) && (xp <= x1))) {
Shinya Kitaoka 120a6e
        return true;
Shinya Kitaoka 120a6e
      } /* 水平線分上 */
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        return false;
Shinya Kitaoka 120a6e
      } /* 水平範囲外 */
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    /* 水平方向の初めの交差位置(xa) */
Shinya Kitaoka 120a6e
    if (xa == odd_diameter) {
Shinya Kitaoka 120a6e
      /* (x2 - x1)/(y2 - y1)=(xa - x1)/(yp - y1);
Shinya Kitaoka 120a6e
(xa - x1)=(yp - y1)*(x2 - x1)/(y2 - y1); */
Shinya Kitaoka 120a6e
      xa = (yp - y1) * (x2 - x1) / (y2 - y1) + x1;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
        /* 2番目の交差位置(xb) */
Shinya Kitaoka 120a6e
        if (xb == odd_diameter) {
Shinya Kitaoka 120a6e
      xb = (yp - y1) * (x2 - x1) / (y2 - y1) + x1;
Shinya Kitaoka 120a6e
      if (((xa <= xp) && (xp <= xb)) || ((xb <= xp) && (xp <= xa))) {
Shinya Kitaoka 120a6e
        return true;
Shinya Kitaoka 120a6e
      } /* 水平範囲内 */
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        return false;
Shinya Kitaoka 120a6e
      } /* 水平範囲外 */
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*
Shinya Kitaoka 120a6e
        二点(x1,y1),(x2,y2)を通る直線
Shinya Kitaoka 120a6e
         x - x1    y - y1
Shinya Kitaoka 120a6e
        ------- = -------
Shinya Kitaoka 120a6e
        x2 - x1   y2 - y1
Toshihiro Shimizu 890ddd
    -->	(x - x1) * (y2 - y1) = (y - y1) * (x2 - x1)
Toshihiro Shimizu 890ddd
    -->	x * (y2 - y1) - x1 * (y2 - y1) = y * (x2 - x1) - y1 * (x2 - x1)
Toshihiro Shimizu 890ddd
    --> y * (x2 - x1) - y1 * (x2 - x1) = x * (y2 - y1) - x1 * (y2 - y1)
Toshihiro Shimizu 890ddd
    -->	y * (x2 - x1) + x1 * (y2 - y1) = x * (y2 - y1) + y1 * (x2 - x1)
Toshihiro Shimizu 890ddd
    -->	(y1 - y2) * x + (x2 - x1) * y + x1 * (y2 - y1) - y1 * (x2 - x1) = 0
Toshihiro Shimizu 890ddd
    --> (y1 - y2) * x + (x2 - x1) * y + x1*y2 - x1*y1 - y1*x2 + y1*x1 = 0
Toshihiro Shimizu 890ddd
    --> (y1 - y2) * x + (x2 - x1) * y + x1*y2 - y1*x2 = 0
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        点(x0,y0)と直線との距離(垂線の長さ)(h)
Shinya Kitaoka 120a6e
        a * x + b * y + c = 0 ならば、
Shinya Kitaoka 120a6e
                | a * x0 + b * y0 + c |
Shinya Kitaoka 120a6e
        h =	-----------------------
Shinya Kitaoka 120a6e
                  sqrt(a * a + b * b)
Shinya Kitaoka 120a6e
                | (y1 - y2) * x0 + (x2 - x1) * y0 + x1*y2 - y1*x2 |
Shinya Kitaoka 120a6e
        h =	---------------------------------------------------
Shinya Kitaoka 120a6e
                sqrt((y1 - y2) * (y1 - y2) + (x2 - x1) * (x2 - x1))
Toshihiro Shimizu 890ddd
 */
Shinya Kitaoka 120a6e
double length_to_polygon_(double radius, double xp, double yp,
Shinya Kitaoka 120a6e
                          int polygon_number, double roll_degree) {
Shinya Kitaoka 120a6e
  /* 現在位置での角度 */
Shinya Kitaoka 120a6e
  double radian = atan2(yp, xp); /* 0 ... M_PI , -M_PI ... 0 */
Shinya Kitaoka 120a6e
  if (radian < 0) {
Shinya Kitaoka 120a6e
    radian += M_PI * 2.0;
Shinya Kitaoka 120a6e
  } /* 0 ... M_PI*2 */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /* 多角形の辺の2点 */
Shinya Kitaoka 120a6e
  double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
Shinya Kitaoka 120a6e
  const double add_radian = 2.0 * M_PI / polygon_number;
Shinya Kitaoka 120a6e
  double radian1          = roll_degree * (M_PI / 180);
Shinya Kitaoka 120a6e
  /* rad1だとMS-VC++_v10でエラー!!! */
Shinya Kitaoka 120a6e
  while (radian1 < 0.0) {
Shinya Kitaoka 120a6e
    radian1 += add_radian;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  double radian2 = radian1 + add_radian;
Shinya Kitaoka 120a6e
  /* rad2だとMS-VC++_v10でエラー!!! */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /* 開始角度より現在位置の角度が小さい場合360先に進める */
Shinya Kitaoka 120a6e
  if (radian < radian1) {
Shinya Kitaoka 120a6e
    radian += M_PI * 2.0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int ii = 0; ii < polygon_number;
Shinya Kitaoka 120a6e
       ++ii, radian1 = radian2, radian2 += add_radian) {
Shinya Kitaoka 120a6e
    if (radian1 <= radian && radian <= radian2) {
Shinya Kitaoka 120a6e
      x1 = radius * cos(radian1);
Shinya Kitaoka 120a6e
      y1 = radius * sin(radian1);
Shinya Kitaoka 120a6e
      x2 = radius * cos(radian2);
Shinya Kitaoka 120a6e
      y2 = radius * sin(radian2);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (x1 == 0.0) {
Shinya Kitaoka 120a6e
    /* エラー */
Shinya Kitaoka 120a6e
    return -1.0;  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return fabs((y1 - y2) * xp + (x2 - x1) * yp + x1 * y2 - y1 * x2) /
Shinya Kitaoka 120a6e
         sqrt((y1 - y2) * (y1 - y2) + (x2 - x1) * (x2 - x1));
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void alloc_lens_matrix_(const int odd_diameter, std::vector<int> &lens_offsets,</int>
Shinya Kitaoka 120a6e
                        std::vector<int> &lens_sizes,</int>
Shinya Kitaoka 120a6e
                        std::vector<std::vector<double>> &lens_ratio) {</std::vector<double>
Shinya Kitaoka 120a6e
  lens_offsets.resize(odd_diameter);
Shinya Kitaoka 120a6e
  lens_sizes.resize(odd_diameter);
Shinya Kitaoka 120a6e
  lens_ratio.resize(odd_diameter);
Shinya Kitaoka 120a6e
  for (int yy = 0; yy < odd_diameter; ++yy) {
Shinya Kitaoka 120a6e
    lens_ratio.at(yy).resize(odd_diameter);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void free_lens_matrix_(std::vector<int> &lens_offsets,</int>
Shinya Kitaoka 120a6e
                       std::vector<int> &lens_sizes,</int>
Shinya Kitaoka 120a6e
                       std::vector<std::vector<double>> &lens_ratio) {</std::vector<double>
Shinya Kitaoka 120a6e
  lens_ratio.clear();
Shinya Kitaoka 120a6e
  lens_sizes.clear();
Shinya Kitaoka 120a6e
  lens_offsets.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
const int igs::maxmin::diameter_from_outer_radius(const double outer_radius) {
Shinya Kitaoka 120a6e
  /* -------- 半径(radius)を含むピクセル直径 --------
Shinya Kitaoka 120a6e
  中心pixelが必要、奇数(1,3,5...)となる
Shinya Kitaoka 120a6e
           ---+---|---+---|---+---|---+---|---+---
Shinya Kitaoka 120a6e
outer_radius-->		    +---->
Shinya Kitaoka 120a6e
Pixelの半分幅足す(+0.5)	|-------->
Shinya Kitaoka 120a6e
全体が入るPixel数幅(ceil())	|--------------->
Shinya Kitaoka 120a6e
整数化時誤差防ぐ(+0.5)		|------------------->
Shinya Kitaoka 120a6e
整数化(static_cast<int>)	|-------|-------></int>
Shinya Kitaoka 120a6e
中心を除く半径Pixel幅(-1)		|------->
Shinya Kitaoka 120a6e
中心除く直径(*2)	<-------|	|------->
Shinya Kitaoka 120a6e
直径(+1)		<-------|-------|------->
Shinya Kitaoka 120a6e
-->odd_diameter
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  return (static_cast<int>(ceil(outer_radius + 0.5) + 0.5) - 1) * 2 + 1;</int>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
const double igs::maxmin::outer_radius_from_radius(
Shinya Kitaoka 120a6e
    const double radius, const double smooth_outer_range) {
Shinya Kitaoka 120a6e
  if (radius < 1.0) {
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
    半径ゼロでは処理しない絵となり、
Shinya Kitaoka 120a6e
    わずかな半径に変化したとき、
Shinya Kitaoka 120a6e
    いきなり大きなエッジ足(smooth_outer_range)が
Shinya Kitaoka 120a6e
    飛び出さないように
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    radiusがゼロなら足長さを1.0(影響のない最小値)に、
Shinya Kitaoka 120a6e
    radiusが1ならradius + smooth_outer_rangeになり、
Shinya Kitaoka 120a6e
    影響が反映される
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    smooth_outer_rangeは1以上でないとsmoothにならない。
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
    return 1.0 + radius * (radius + smooth_outer_range - 1.0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return radius + smooth_outer_range;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
const int igs::maxmin::alloc_and_shape_lens_matrix(
Shinya Kitaoka 120a6e
    const double radius  // 0<=
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    const double outer_radius, const int polygon_number  // =2
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    const double roll_degree  // 0<= ... <=360
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    std::vector<int> &lens_offsets, std::vector<int> &lens_sizes,</int></int>
Shinya Kitaoka 120a6e
    std::vector<std::vector<double>> &lens_ratio) {</std::vector<double>
Shinya Kitaoka 120a6e
  /*------ 大きさが無い指定のときMemory解放 ------*/
Shinya Kitaoka 120a6e
  if (radius <= 0.0) {
Shinya Kitaoka 120a6e
    free_lens_matrix_(lens_offsets, lens_sizes, lens_ratio);
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*------ 半径から必要なピクセル単位の直径を求める ------*/
Shinya Kitaoka 120a6e
  const int odd_diameter =
Shinya Kitaoka 120a6e
      igs::maxmin::diameter_from_outer_radius(outer_radius);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*------ Memory確保or再利用 ------*/
Shinya Kitaoka 120a6e
  alloc_lens_matrix_(odd_diameter, lens_offsets, lens_sizes, lens_ratio);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*------ lens matrix情報を書き込む ------*/
Shinya Kitaoka 120a6e
  igs::maxmin::reshape_lens_matrix(
Shinya Kitaoka 120a6e
      radius,
Shinya Kitaoka 120a6e
      igs::maxmin::outer_radius_from_radius(radius, outer_radius - radius),
Shinya Kitaoka 120a6e
      odd_diameter, polygon_number, roll_degree, lens_offsets, lens_sizes,
Shinya Kitaoka 120a6e
      lens_ratio);
Shinya Kitaoka 120a6e
  return odd_diameter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
const void igs::maxmin::reshape_lens_matrix(
Shinya Kitaoka 120a6e
    const double radius  // 0<=
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    const double outer_radius, const int odd_diameter /* 最大直径 */
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    const int polygon_number  // =2
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    const double roll_degree  // 0<= ... <=360
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    std::vector<int> &lens_offsets /* 最大直径分の配列 */</int>
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    std::vector<int> &lens_sizes /* 最大直径分の配列 */</int>
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    std::vector<std::vector<double>> &lens_ratio /* 最大直径分の配列 */</std::vector<double>
Shinya Kitaoka 120a6e
    ) {
Shinya Kitaoka 120a6e
  /***std::cout
Toshihiro Shimizu 890ddd
<< "ra=" << radius
Toshihiro Shimizu 890ddd
<< " outr=" << outer_radius
Toshihiro Shimizu 890ddd
<< " dia=" << odd_diameter
Toshihiro Shimizu 890ddd
<< " pol=" << polygon_number
Toshihiro Shimizu 890ddd
<< " deg=" << roll_degree
Toshihiro Shimizu 890ddd
<< " lens_offsets=" << lens_offsets.size()
Toshihiro Shimizu 890ddd
<< " lens_sizes=" << lens_sizes.size()
Toshihiro Shimizu 890ddd
<< " lens_ratio=" << lens_ratio.size()
Toshihiro Shimizu 890ddd
<< std::endl;***/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /* --- scanlineスタート位置とscanlineサイズ生成 --- */
Shinya Kitaoka 120a6e
  double yp = 0.5 - (odd_diameter / 2.0); /* matrix中心からのy距離 */
Shinya Kitaoka 120a6e
  for (int yy = 0; yy < odd_diameter; ++yy, yp += 1.0) {
Shinya Kitaoka 120a6e
    /* --- 開始位置とサイズを計算 ------------------- */
Shinya Kitaoka 120a6e
    lens_offsets.at(yy) = -1;               /* 初期化 */
Shinya Kitaoka 120a6e
    lens_sizes.at(yy)   = 0;                /* 初期化 */
Shinya Kitaoka 120a6e
    double xp = 0.5 - (odd_diameter / 2.0); /* matrix中心からのx距離 */
Shinya Kitaoka 120a6e
    for (int xx = 0; xx < odd_diameter; ++xx, xp += 1.0) {
Shinya Kitaoka 120a6e
      const double current_radius = sqrt(xp * xp + yp * yp);
Shinya Kitaoka 120a6e
      /* 外枠影響内 */
Shinya Kitaoka 120a6e
      if ((current_radius <= outer_radius) &&
Shinya Kitaoka 120a6e
          inside_polygon_(outer_radius, odd_diameter, xp, yp, polygon_number,
Shinya Kitaoka 120a6e
                          roll_degree)) {
Shinya Kitaoka 120a6e
        /* scanlineスタート位置(ポインタ)のセット */
Shinya Kitaoka 120a6e
        if (lens_offsets.at(yy) < 0) {
Shinya Kitaoka 120a6e
          /* 半径内に入った瞬間その位置を記録 */
Shinya Kitaoka 120a6e
          lens_offsets.at(yy) = xx;
Shinya Kitaoka 120a6e
        }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      } else { /* 影響外 */
Shinya Kitaoka 120a6e
        /* scalineサイズのセット */
Shinya Kitaoka 120a6e
        if ((0 <= lens_offsets.at(yy)) && (lens_sizes.at(yy) == 0)) {
Shinya Kitaoka 120a6e
          /* 半径内を出た瞬間そこまでのサイズを記録 */
Shinya Kitaoka 120a6e
          lens_sizes.at(yy) = xx - lens_offsets.at(yy);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    /* scanlineの最後までが半径内のとき */
Shinya Kitaoka 120a6e
    if ((0 <= lens_offsets.at(yy)) && (lens_sizes.at(yy) == 0)) {
Shinya Kitaoka 120a6e
      lens_sizes.at(yy) = odd_diameter - lens_offsets.at(yy);
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    /* --- 外枠から内枠へのリニア変化 --------------- */
Shinya Kitaoka 120a6e
    /* 円の外 */
Shinya Kitaoka 120a6e
    if (lens_sizes.at(yy) <= 0) {
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    /* ratio設定 */
Shinya Kitaoka 120a6e
    xp     = 0.5 - (odd_diameter / 2.0); /* matrix中心からのx距離 */
Shinya Kitaoka 120a6e
    int xr = 0;
Shinya Kitaoka 120a6e
    for (int xx = 0; xx < odd_diameter; ++xx, xp += 1.0) {
Shinya Kitaoka 120a6e
      const double current_radius = sqrt(xp * xp + yp * yp);
Shinya Kitaoka 120a6e
      /* 外枠内 */
Shinya Kitaoka 120a6e
      if ((current_radius <= outer_radius) &&
Shinya Kitaoka 120a6e
          inside_polygon_(outer_radius, odd_diameter, xp, yp, polygon_number,
Shinya Kitaoka 120a6e
                          roll_degree)) {
Shinya Kitaoka 120a6e
        /* 内枠内 */
Shinya Kitaoka 120a6e
        if ((current_radius <= radius) &&
Shinya Kitaoka 120a6e
            inside_polygon_(radius, odd_diameter, xp, yp, polygon_number,
Shinya Kitaoka 120a6e
                            roll_degree)) {
Shinya Kitaoka 120a6e
          lens_ratio.at(yy).at(xr++) = 1.0;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        /* 外枠と内枠の間 */
Shinya Kitaoka 120a6e
        else {
Shinya Kitaoka 120a6e
          if (polygon_number < 3) {
Shinya Kitaoka 120a6e
            lens_ratio.at(yy).at(xr++) =
Shinya Kitaoka 120a6e
                (outer_radius - current_radius) / (outer_radius - radius);
Shinya Kitaoka 120a6e
          } else {
Shinya Kitaoka 120a6e
            const double leninn =
Shinya Kitaoka 120a6e
                length_to_polygon_(radius, xp, yp, polygon_number, roll_degree);
Shinya Kitaoka 120a6e
            const double lenout = length_to_polygon_(
Shinya Kitaoka 120a6e
                outer_radius, xp, yp, polygon_number, roll_degree);
Shinya Kitaoka 120a6e
            lens_ratio.at(yy).at(xr++) = lenout / (leninn + lenout);
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}