示例#1
0
//--------------------------------------------------------------------------------------
void Bline::getPoint(Real t, Point& point, Point& tangent) const
{
	assert(t >= (Real)0.0 && t <= (Real)1.0);

	if (t <= (Real)0.0) {
		point = m_keyPoints[0];
		tangent.x = -2 * point.x + 2 * m_keyPoints[1].x;
		tangent.y = -2 * point.y + 2 * m_keyPoints[1].y;
		tangent.z = -2 * point.z + 2 * m_keyPoints[1].z;
		_normalize(tangent);
		return;
	}

	size_t partIndex = m_partCounts;
	for (size_t i = 0; i < m_partCounts; i++) {
		if (m_parts[i].percentAddup >= t) {
			partIndex = i;
			break;
		}
	}

	if (partIndex >= m_partCounts) {
		point = m_keyPoints[m_keyCounts - 1];
		tangent.x = -2 * m_keyPoints[m_keyCounts - 2].x + 2 * point.x;
		tangent.y = -2 * m_keyPoints[m_keyCounts - 2].y + 2 * point.y;
		tangent.z = -2 * m_keyPoints[m_keyCounts - 2].z + 2 * point.z;
		_normalize(tangent);
		return;
	}

	const LinePart& lp = m_parts[partIndex];
	Real start_percent = (partIndex == 0) ? (Real)0.0 : m_parts[partIndex - 1].percentAddup;

	Real percent = (t - start_percent) / lp.percent;
	Real length = percent*lp.length;
	t = _getInvertLength(lp, percent, length);

	point.x = (1 - t)*(1 - t)*lp.pt0.x + 2 * (1 - t)*t*lp.pt1.x + t*t*lp.pt2.x;
	point.y = (1 - t)*(1 - t)*lp.pt0.y + 2 * (1 - t)*t*lp.pt1.y + t*t*lp.pt2.y;
	point.z = (1 - t)*(1 - t)*lp.pt0.z + 2 * (1 - t)*t*lp.pt1.z + t*t*lp.pt2.z;

	tangent.x = 2 * (t - 1)*lp.pt0.x + (2 - 4 * t)*lp.pt1.x + 2 * t*lp.pt2.x;
	tangent.y = 2 * (t - 1)*lp.pt0.y + (2 - 4 * t)*lp.pt1.y + 2 * t*lp.pt2.y;
	tangent.z = 2 * (t - 1)*lp.pt0.z + (2 - 4 * t)*lp.pt1.z + 2 * t*lp.pt2.z;
	_normalize(tangent);

	return;
}
示例#2
0
文件: color.cpp 项目: chenbk85/QOR
//------------------------------------------------------------------------------
__QOR_INTERFACE( QURSES_QOR ) int init_pair( short pair, short fg, short bg )
{
    __QCS_FCONTEXT( "init_pair" );

    if( !pdc_color_started || pair < 1 || pair >= COLOR_PAIRS || fg < first_col || fg >= COLORS || bg < first_col || bg >= COLORS )
	{
        return ERR;
	}

    _normalize( &fg, &bg );

    // To allow the PDC_PRESERVE_SCREEN option to work, we only reset curscr if this call to init_pair() alters a color pair created by the user.

    if( pair_set[ pair ] )
    {
        short oldfg, oldbg;

        PDC_pair_content( pair, &oldfg, &oldbg );

        if( oldfg != fg || oldbg != bg )
		{
            curscr->_clear = TRUE;
		}
    }

    PDC_init_pair( pair, fg, bg );

    pair_set[ pair ] = TRUE;

    return 0;
}
示例#3
0
文件: RGB.cpp 项目: Ruhm42/DOGLE
RGB::RGB(u_char r, u_char g , u_char b, u_char a) : r(r),
													g(g),
													b(b),
													a(a)
{
	_normalize();
}
示例#4
0
 constexpr friend diffmax_t operator^(diffmax_t a, diffmax_t b) noexcept
 {
     return _normalize(
         bool(a.neg_ ^ b.neg_),
         compl_if(bool(a.neg_ ^ b.neg_),
                  compl_if(a.neg_, a.val_) ^ compl_if(b.neg_, b.val_)));
 }
示例#5
0
文件: color.cpp 项目: chenbk85/QOR
__QCMP_ENDLINKAGE_C

//------------------------------------------------------------------------------
void PDC_init_atrtab( void )
{
	__QCS_FCONTEXT( "PDC_init_atrtab" );

    int i;
    short fg, bg;

    if( pdc_color_started && !default_colors )
    {
        fg = COLOR_WHITE;
        bg = COLOR_BLACK;
    }
    else
	{
        fg = bg = -1;
	}

    _normalize( &fg, &bg );

    for( i = 0; i < PDC_COLOR_PAIRS; i++ )
	{
        PDC_init_pair( (short)i, fg, bg );
	}
}
示例#6
0
文件: color.c 项目: ryoon/eCos
int init_pair(short pair, short fg, short bg)
{
    PDC_LOG(("init_pair() - called: pair %d fg %d bg %d\n", pair, fg, bg));

    if (!pdc_color_started || pair < 1 || pair >= COLOR_PAIRS ||
        fg < first_col || fg >= COLORS || bg < first_col || bg >= COLORS)
        return ERR;

    _normalize(&fg, &bg);

    /* To allow the PDC_PRESERVE_SCREEN option to work, we only reset 
       curscr if this call to init_pair() alters a color pair created by 
       the user. */

    if (pair_set[pair])
    {
        short oldfg, oldbg;

        PDC_pair_content(pair, &oldfg, &oldbg);

        if (oldfg != fg || oldbg != bg)
            curscr->_clear = TRUE;
    }

    PDC_init_pair(pair, fg, bg);

    pair_set[pair] = TRUE;

    return OK;
}
示例#7
0
CSymbol::operator CString()
{
	CString result;
	for(int i=0;i<m_nDirection;i++)
	{
		_normalize(m_Direction[i].x);
		_normalize(m_Direction[i].y);
		int x=m_Direction[i].x+50;
		int y=m_Direction[i].y+50;
		result+=(CString)((char)((x/10)+48));
		result+=(CString)((char)((x%10)+48));
		result+=(CString)((char)((y/10)+48));
		result+=(CString)((char)((y%10)+48));
	}
	return result;
}
示例#8
0
文件: color.c 项目: ryoon/eCos
int assume_default_colors(int f, int b)
{
    PDC_LOG(("assume_default_colors() - called: f %d b %d\n", f, b));

    if (f < -1 || f >= COLORS || b < -1 || b >= COLORS)
        return ERR;

    if (pdc_color_started)
    {
        short fg, bg, oldfg, oldbg;

        fg = f;
        bg = b;

        _normalize(&fg, &bg);

        PDC_pair_content(0, &oldfg, &oldbg);

        if (oldfg != fg || oldbg != bg)
            curscr->_clear = TRUE;

        PDC_init_pair(0, fg, bg);
    }

    return OK;
}
示例#9
0
extern "C" SEXP normalize(SEXP texts, SEXP type, SEXP ctype) {
  const int n = LENGTH(texts);
  const char* encoding = CHAR(STRING_ELT(ctype, 0));
  SEXP ret;
  PROTECT(ret = allocVector(STRSXP, n));

  UNormalizationMode unmode;
  switch(INTEGER(type)[0]) {
  case 0:
    unmode = UNORM_NFD;
    break;
  case 1:
    unmode = UNORM_NFKD;
    break;
  case 2:
    unmode = UNORM_NFC;
    break;
  case 3:
    unmode = UNORM_NFKC;
    break;
  default:
    error("Invalid Unicode form");
  }

  for (int i = 0; i < n; ++i) {
    char *buf;
    _normalize(CHAR(STRING_ELT(texts, i)), &buf, encoding, unmode);
    SET_STRING_ELT(ret, i, mkChar(buf));
    free(buf);
  }

  UNPROTECT(1);
  return(ret);
}
示例#10
0
文件: color.cpp 项目: chenbk85/QOR
//------------------------------------------------------------------------------
__QOR_INTERFACE( QURSES_QOR ) int assume_default_colors( int f, int b )
{
    __QCS_FCONTEXT( "assume_default_colors" );

    if( f < -1 || f >= COLORS || b < -1 || b >= COLORS )
	{
        return ERR;
	}

    if( pdc_color_started )
    {
        short fg, bg, oldfg, oldbg;

        fg = (short)f;
        bg = (short)b;

        _normalize( &fg, &bg );

        PDC_pair_content( 0, &oldfg, &oldbg );

        if( oldfg != fg || oldbg != bg )
		{
            curscr->_clear = TRUE;
		}

        PDC_init_pair( 0, fg, bg );
    }

    return 0;
}
示例#11
0
 constexpr friend diffmax_t operator|(diffmax_t a, diffmax_t b) noexcept
 {
     return _normalize(
         a.neg_ || b.neg_,
         compl_if(a.neg_ || b.neg_,
                  compl_if(a.neg_, a.val_) | compl_if(b.neg_, b.val_)));
 }
示例#12
0
  void MimicGa::_updateScores()
  {
    GeneticAlgorithm::_updateScores();

    // sort in descending order
    sort(_population.begin(), _population.end(), CompareGenomes());

    WeightMap oldWeights = _weights;
    _weights.clear();

    // @todo test this
//     // if we're stagnating, start bringing the weights back together. This should help broaden
//     // the search a bit.
//     if (_lastBest == _population[0]->getScore())
//     {
//       _stagnation++;
//       for (WeightMap::iterator it = oldWeights.begin(); it != oldWeights.end(); ++it)
//       {
//         it->second = pow(it->second, 1.0 / (double)_stagnation);
//       }
//       _normalize(oldWeights);
//     }

    boost::shared_ptr<CalculatorGenome> cg = boost::dynamic_pointer_cast<CalculatorGenome>(_population[0]);

    const CalculatorGenome::AvailableNodeMap& anm = cg->getAvailableNodes();
    for (CalculatorGenome::AvailableNodeMap::const_iterator it = anm.begin(); it != anm.end(); 
      ++it)
    {
      _weights[it->first] = 1e-5;
    }

    for (unsigned int i = 0; i < _population.size() * _thetaPercentile; i++)
    {
      cg = boost::dynamic_pointer_cast<CalculatorGenome>(_population[i]);
      assert(cg);
      _populateWeights(cg->getRoot());
    }

    // normalize the weights so they sum to 1
    _normalize(_weights);

    if (oldWeights.size() > 0)
    {
      for (WeightMap::iterator it = _weights.begin(); it != _weights.end(); ++it)
      {
        it->second = it->second * _learningRate + oldWeights[it->first] * (1 - _learningRate);
        //cout << it->first << "\t" << it->second << endl;
      }
    }

//     for (WeightMap::iterator it = _weights.begin(); it != _weights.end(); ++it)
//     {
//       cout << it->first << "\t" << it->second << endl;
//     }
  }
示例#13
0
		::std::string to_string(const char* method, const char* url_no_param, const char* params)
		{
			_normalize();
			
			_string s = "Authorization: OAuth ";
			//s.resize(1024);
			
			MAP_T_ITERATOR it = m_auth_map.begin();
			for(; it != m_auth_map.end(); it++ )
			{
				_to_string_vk_append(s, it->first.c_str(), it->second.c_str());
			}
			return s;
		}
示例#14
0
/*!
 * \internal
 */
THREEVector3 *THREEVector3::_transformDirection(THREEMatrix4 *threeMatrix4)
{
    // input: THREE.Matrix4 affine matrix
    // vector interpreted as a direction
    float x = m_x, y = m_y, z = m_z;

    float *e = threeMatrix4->elementsPtr();

    m_x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ]  * z;
    m_y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ]  * z;
    m_z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;

    _normalize();

    return this;
}
示例#15
0
文件: color.c 项目: ryoon/eCos
void PDC_init_atrtab(void)
{
    int i;
    short fg, bg;

    if (pdc_color_started && !default_colors)
    {
        fg = COLOR_WHITE;
        bg = COLOR_BLACK;
    }
    else
        fg = bg = -1;

    _normalize(&fg, &bg);

    for (i = 0; i < PDC_COLOR_PAIRS; i++)
        PDC_init_pair(i, fg, bg);
}
示例#16
0
static void
_normalize_data(struct compass_data *mdata)
{
    /* Data is normalized based on direction-vector min and max. Maybe,
     * it would be a good idea using the actual min and max present on readings.
     */
    mdata->accel.x = _normalize(mdata->accel.x, mdata->accel.min, mdata->accel.max);
    mdata->accel.y = _normalize(mdata->accel.y, mdata->accel.min, mdata->accel.max);
    mdata->accel.z = _normalize(mdata->accel.z, mdata->accel.min, mdata->accel.max);

    mdata->mag.x = _normalize(mdata->mag.x, mdata->mag.min, mdata->mag.max);
    mdata->mag.y = _normalize(mdata->mag.y, mdata->mag.min, mdata->mag.max);
    mdata->mag.z = _normalize(mdata->mag.z, mdata->mag.min, mdata->mag.max);
}
示例#17
0
void
md2_generateLightNormals (md2_model_t *model)
{
	int i;

	if (!model)
		return;


	for (i = 0; i < model->header.numFrames; i++)
	{
		int j;

		/* clear all normals */
		for (j = 0; j < model->header.numVertices; j++)
		{
			model->frames[i].vertices[j].normal[0] = 0.0f;
			model->frames[i].vertices[j].normal[1] = 0.0f;
			model->frames[i].vertices[j].normal[2] = 0.0f;
		}

		/* calc normals */
		for (j = 0; j < model->header.numTriangles; j++)
		{
			int k;
			float facetnormal[3];

			_makeFacetNormal (model, &model->triangles[j], i, facetnormal);

			for (k = 0; k < 3; k++)
			{
				model->frames[i].vertices[model->triangles[j].vertexIndices[k]].normal[0] -= facetnormal[0];
				model->frames[i].vertices[model->triangles[j].vertexIndices[k]].normal[1] += facetnormal[2];
				model->frames[i].vertices[model->triangles[j].vertexIndices[k]].normal[2] -= facetnormal[1];
			}
		}

		/* normalize normals */
		for (j = 0; j < model->header.numVertices; j++)
			_normalize (model->frames[i].vertices[j].normal);
	}
}
示例#18
0
__forceinline int ClusteredLightCuller::_sphereOverlapsFroxel(int x, int y, int z, float sphere_radius, const vec3& sphere_center, const FroxelInfo* froxel_infos)
{
   __m128* center_coord = (__m128*)&froxel_infos[_toFlatFroxelIndex(x, y, z)].center_coord;
   __m128 sse_sphere_center = _mm_set_ps(1.0, sphere_center.z, sphere_center.y, sphere_center.x);
   __m128 sse_plane_normal = _normalize(_mm_sub_ps(*center_coord, sse_sphere_center));

   __m128 plane_origin = _mm_add_ps(sse_sphere_center, _mm_mul_ps(_mm_set1_ps(sphere_radius), sse_plane_normal));
   __m128 sse_dot_plane = _mm_dp_ps(plane_origin, sse_plane_normal, 0x70 | 0xF);

   __m128* corner_a = (__m128*)&froxel_infos[_toFlatFroxelIndex(x + 0, y + 0, z + 0)].corner_coord;
   __m128* corner_b = (__m128*)&froxel_infos[_toFlatFroxelIndex(x + 1, y + 0, z + 0)].corner_coord;
   __m128* corner_c = (__m128*)&froxel_infos[_toFlatFroxelIndex(x + 1, y + 1, z + 0)].corner_coord;
   __m128* corner_d = (__m128*)&froxel_infos[_toFlatFroxelIndex(x + 0, y + 1, z + 0)].corner_coord;

   if (_overlap(sse_plane_normal, sse_dot_plane, corner_a, corner_b, corner_c, corner_d))
      return 1;

   corner_a = (__m128*)&froxel_infos[_toFlatFroxelIndex(x + 0, y + 0, z + 1)].corner_coord;
   corner_b = (__m128*)&froxel_infos[_toFlatFroxelIndex(x + 1, y + 0, z + 1)].corner_coord;
   corner_c = (__m128*)& froxel_infos[_toFlatFroxelIndex(x + 1, y + 1, z + 1)].corner_coord;
   corner_d = (__m128*)& froxel_infos[_toFlatFroxelIndex(x + 0, y + 1, z + 1)].corner_coord;

   return (_overlap(sse_plane_normal, sse_dot_plane, corner_a, corner_b, corner_c, corner_d));
}
示例#19
0
 constexpr friend diffmax_t operator-(diffmax_t a) noexcept
 {
     return _normalize(!a.neg_, a.val_);
 }
示例#20
0
 constexpr friend diffmax_t operator%(diffmax_t a, diffmax_t b) noexcept
 {
     return _normalize(a.neg_, a.val_ % b.val_);
 }
示例#21
0
QJSValue THREEVector3::normalize() {
    return m_engine->newQObject(_normalize());
}