Esempio n. 1
0
	static std::pair<Float2, Float2> GetNodeInCell(const TerrainCell& cell, unsigned nodeIndex)
	{
		const auto& sourceNode = *cell._nodes[nodeIndex];
		auto nodeMinInCell = Truncate(TransformPoint(sourceNode._localToCell, Float3(0.f, 0.f, 0.f)));
		auto nodeMaxInCell = Truncate(TransformPoint(sourceNode._localToCell, Float3(1.f, 1.f, 1.f)));
		return std::make_pair(nodeMinInCell, nodeMaxInCell);
	}
Esempio n. 2
0
BitoneRangeFit::BitoneRangeFit(BitoneSet const* bitones, int flags)
  : BitoneFit(bitones, flags)
{
  // initialize the best error
  m_besterror = Scr3(FLT_MAX);

  // cache some values
  int const count = m_bitones->GetCount();
  Vec3 const* values = m_bitones->GetPoints();
  Scr3 const* weights = m_bitones->GetWeights();

  Sym3x3 covariance;
  Vec3 centroid;
  Vec3 principle;

  // get the covariance matrix
  if (m_bitones->IsUnweighted())
    ComputeWeightedCovariance3(covariance, centroid, count, values, Vec3(1.0f));
  else
    ComputeWeightedCovariance3(covariance, centroid, count, values, Vec3(1.0f), weights);

  // compute the principle component
  GetPrincipleComponent(covariance, principle);

  // get the min and max range as the codebook endpoints
  Vec3 start(0.0f);
  Vec3 end(0.0f);

  if (count > 0) {
#ifdef	FEATURE_RANGEFIT_PROJECT
    // compute the projection
    GetPrincipleProjection(start, end, principle, centroid, count, values);
#else
    Scr3 min, max;

    // compute the range
    start = end = values[0];
    min = max = Dot(values[0], principle);

    for (int i = 1; i < count; ++i) {
      Scr3 val = Dot(values[i], principle);

      if (val < min) {
	start = values[i];
	min = val;
      }
      else if (val > max) {
	end = values[i];
	max = val;
      }
    }
#endif
  }

  // snap floating-point-values to the integer-lattice and save
  m_start = Truncate(start * 255.0f + Vec3(0.5f)) * (1.0f / 255.0f);
  m_end   = Truncate(end   * 255.0f + Vec3(0.5f)) * (1.0f / 255.0f);
}
Esempio n. 3
0
void CSteeringManager::Update(bool reverse, float scale)
{
	XMFLOAT3 worldUp = XMFLOAT3(0, 1, 0);
	XMVECTOR newX, newY, newZ, globalY;
	globalY = XMLoadFloat3(&worldUp);

	Truncate(m_vSteering, MAX_FORCE);
	XMVECTOR steering = XMLoadFloat3(&m_vSteering);
	XMVECTOR velocity = XMLoadFloat3(m_pBoid->GetZAxis());
	steering *= (1 / m_pBoid->GetMass()); 

	velocity += steering;
	XMFLOAT3 newVelocity;
	XMStoreFloat3(&newVelocity, velocity);

	Truncate(newVelocity, m_pBoid->GetMaxVelocity());

	newZ = XMLoadFloat3(&newVelocity);
	newZ = XMVector3Normalize(newZ);

	newX = XMVector3Cross(globalY, newZ);
	newY = XMVector3Cross(newZ, newX);

	newX = XMVector3Normalize(newX);
	newY = XMVector3Normalize(newY);
	newZ = XMVector3Normalize(newZ);

	XMFLOAT3 xAxis, yAxis, zAxis;
	XMStoreFloat3(&xAxis, newX);
	XMStoreFloat3(&yAxis, newY);
	XMStoreFloat3(&zAxis, newZ);

	xAxis.y = 0.0f;
	yAxis.x = 0.0f;
	yAxis.z = 0.0f;
	zAxis.y = 0.0f;

	m_pBoid->SetXAxis(xAxis);
	m_pBoid->SetYAxis(yAxis);
	m_pBoid->SetZAxis(zAxis);
	m_pBoid->Scale(scale, scale, scale);
	if (reverse)
	{
		newVelocity.x = -newVelocity.x;
		newVelocity.x = -newVelocity.x;
		newVelocity.x = -newVelocity.x;
	}

	m_pBoid->SetWorldVelocity(newVelocity); 
	Reset();

	

}
Esempio n. 4
0
void ScheduleViewEx::OnDraw(CDC* pDC)
{
	Periods& periods = static_cast<CScheduleApp*>(AfxGetApp())->m_periods;
	Period& period = periods.GetCurrentPeriod();

	CTime startDay = period.m_dateRange.GetStartDate();
	startDay = startDay + CTimeSpan(xDelta*GetXOffset(),0,0,0);
	CTime stopDay = startDay + CTimeSpan(xDelta,0,0,0);

	Truncate(startDay,period.m_dateRange.GetStartDate(),
		period.m_dateRange.GetEndDate());
	Truncate(stopDay,period.m_dateRange.GetStartDate(),
		period.m_dateRange.GetEndDate());
	
	
	int startNurse = yDelta * GetYOffset();
	int stopNurse = startNurse + yDelta;
	
	CString outputText = ViewOutput(startDay,stopDay,
		startNurse,stopNurse);

	CFont tmpcourierFont;
	if (pDC->m_bPrinting)
		tmpcourierFont.CreatePointFont(printFontSize,_T("Lucida Console"));
	else
		tmpcourierFont.CreatePointFont(viewFontSize,_T("Lucida Console"));
	LOGFONT logFont;
	tmpcourierFont.GetLogFont(&logFont);
	logFont.lfUnderline = 1;
	
	CFont courierFont;
	courierFont.CreateFontIndirect(&logFont);
	
	CFont * oldFont;
	oldFont = pDC->SelectObject(&courierFont);

	pDC->DrawText(outputText,CRect(250,-250,250,-250),DT_NOCLIP);
	if (!pDC->m_bPrinting)
	{
		CRect rcOut(0,0,0,0);
		VERIFY(pDC->DrawText(outputText,&rcOut,DT_NOCLIP | DT_CALCRECT));
		CSize newSize(rcOut.right*1.1,(rcOut.bottom*-1)*1.1);
		if (newSize != m_oldSize)
		{
			SetScrollSizes(MM_HIENGLISH,newSize);
			m_oldSize = newSize;
		}
	}

	CFont * tmpFont = pDC->SelectObject(oldFont);
	ASSERT(tmpFont = &courierFont);

}
Esempio n. 5
0
/// Compresses the list and truncates
void SHVDynArrayBase::Compress()
{
	Truncate();

	for (size_t i=0; i<Items; i++)
	{
		if (!Array[i])
		{
			Array[i] = Array[Items-1];
			Array[Items-1] = NULL;
			Truncate();
		}
	}
}
Esempio n. 6
0
	void Alien::Update(float deltaTime)
	{
		if (!DoneMoving)
		{
			Position = Owner.Transform.Position.ToVec2();

			Steering = PathFollowing();
			Truncate(Steering, MAX_FORCE);
			Steering *= 1 / Mass;

			Velocity += Steering;
			Truncate(Velocity, MAX_VELOCITY);
			Owner.Transform.Position += vec3(Velocity.x, Velocity.y, 0);
		}
	}
Esempio n. 7
0
		/**
		 * @brief TruncateLines
		 * @param source
		 * @param requested_length
		 */
		void TruncateLines( std::string & source, size_t requested_length )
		{
			std::string::size_type line_break = 0;
			std::string::size_type line_start = 0;
			std::string::size_type line_length = 0;
			std::string::size_type remove_char_count = 0;
			std::string::size_type center_char = requested_length/2;

			line_break = source.find_first_of("\n", line_start);

			if ( std::string::npos == line_break )
			{
				Truncate( source, requested_length );
			}
			else
			{
				while ( std::string::npos != line_break )
				{
					line_length = line_break - line_start;
					remove_char_count = line_length - requested_length;

					if ( line_length > requested_length )
					{
						source.replace( center_char - (remove_char_count/2), remove_char_count, "..." ); // …
					}

					line_start = line_break;

					line_break = source.find_first_of("\n", line_start+1);
				}
			}
		}
Esempio n. 8
0
void FString::Remove(size_t index, size_t remlen)
{
	if (index < Len())
	{
		if (index + remlen >= Len())
		{
			Truncate((long)index);
		}
		else
		{
			remlen = Len() - remlen < remlen ? Len() - remlen : remlen;
			if (Data()->RefCount == 1)
			{ // Can do this in place
				memmove(Chars + index, Chars + index + remlen, Len() - index - remlen);
				memset(Chars + Len() - remlen, 0, remlen);
				Data()->Len -= (unsigned)remlen;
			}
			else
			{ // Must do it in a copy
				FStringData *old = Data();
				AllocBuffer(old->Len - remlen);
				StrCopy(Chars, old->Chars(), index);
				StrCopy(Chars + index, old->Chars() + index + remlen, old->Len - index - remlen);
				old->Release();
			}
		}
	}
}
Esempio n. 9
0
void CRdbTable::DestroyObject()
{
	if(m_nThis)
	{
		m_pTabDef->SetStorageAddr(0);
		Truncate();
		uint32 nIndexCount = m_nIndexCount;
		if(nIndexCount)
		{
			for(uint32 i=0; i<nIndexCount; ++i)
			{
				if(m_pIndexTable[i])
				{
					CIndexDefine * pIndex = m_pTabDef->m_pIndexDefineSet[i];
					m_pIndexTable[i]->DestroyObject();
					pIndex->SetStorageAddr(0);
				}
			}
		}
		m_pRowIndex->DestroyObject();
		m_pTableSpace->DestroyObject();
		Distruction();
		vfree(m_nThis);
		m_nThis = 0;
	}
}
Esempio n. 10
0
BString&
BString::SetToFormat(const char* format, ...)
{
	int32 bufferSize = 1024;
	char buffer[bufferSize];

	va_list arg;
	va_start(arg, format);
	int32 bytes = vsnprintf(buffer, bufferSize, format, arg);
	va_end(arg);

	if (bytes < 0)
		return Truncate(0);

	if (bytes < bufferSize) {
		SetTo(buffer);
		return *this;
	}

	va_list arg2;
	va_start(arg2, format);
	bytes = vsnprintf(LockBuffer(bytes), bytes + 1, format, arg2);
	va_end(arg2);

	if (bytes < 0)
		bytes = 0;

	UnlockBuffer(bytes);
	return *this;
}
Esempio n. 11
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QTextCodec *utfcodec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForTr(utfcodec);
    QTextCodec::setCodecForCStrings(utfcodec);

    base = QSqlDatabase::addDatabase("QSQLITE"); //указываем тип базы

    ui->statusBar->addWidget(&stBar);

    connect(ui->tableView, SIGNAL(clicked(QModelIndex)), SLOT(TableRead(QModelIndex)));
    connect(ui->ButtonSave, SIGNAL(clicked()), SLOT(SaveBaseAll()));
    connect(ui->ButtonDelete, SIGNAL(clicked()), SLOT(DeleteRecord()));
    connect(ui->ButtonSearch, SIGNAL(clicked()), SLOT(Search()));
    connect(ui->ButtonDeleteFilter, SIGNAL(clicked()), SLOT(NoSearch()));
    connect(ui->ActionTruncate, SIGNAL(triggered()), SLOT(Truncate()));
    connect(ui->ButtonAddRecord, SIGNAL(clicked()), SLOT(AddRecord()));
    connect(ui->ActionNewBackup, SIGNAL(triggered()), SLOT(SaveBackup()));
    connect(ui->ActionLoadBackup, SIGNAL(triggered()), SLOT(LoadBackup()));
    connect(ui->AboutBase, SIGNAL(triggered()), SLOT(AboutBase()));
    connect(ui->ActionConvert, SIGNAL(triggered()), SLOT(ConvertFromOperaNotes()));
    connect(ui->ActionOpenBase, SIGNAL(triggered()), SLOT(OpenBase()));

    setAcceptDrops(true);
}
Esempio n. 12
0
void Mouse_SDL::NewPt(Uint32 ms, int x, int y) {
	/*
				x = pEvt->motion.xrel;
				y = pEvt->motion.yrel;
				if ( ! ((s_xLim0==0) && (s_xLim1==0) && (s_yLim0==0) && (s_yLim1==0)) ) { // limits are set
					x = (pEvt->motion.xrel <= s_xLim0) * s_xLim0 + 
						((pEvt->motion.xrel > s_xLim0) && (pEvt->motion.xrel < s_xLim1)) * pEvt->motion.xrel +
						(pEvt->motion.xrel >= s_xLim1) * s_xLim1;
					y = (pEvt->motion.yrel<=s_yLim0) * s_yLim0 + 
						((pEvt->motion.yrel>s_yLim0) && (pEvt->motion.yrel<s_yLim1)) * pEvt->motion.yrel +
						(pEvt->motion.yrel>=s_yLim1) * s_yLim1;				
				} else {} // limits unset
	*/

  static int old_x = 0;
  static int old_y = 0;

  if (m_bFirst) {
    if (m_bDraw) {
      old_x = m_xLast; old_y = m_yLast;
      m_xLast += x; 
			m_yLast += y;
			m_xLast = Truncate(m_xLast, s_xLim0, s_xLim1);
			m_yLast = Truncate(m_yLast, s_yLim0, s_yLim1);
      m_vPts.push_back(MousePoint(ms, m_xLast, m_yLast));
      m_pCursor->m_CurX.Set(m_xLast);
      m_pCursor->m_CurY.Set(m_yLast);
      //m_pTemplate->Redraw();
      DrawCursor(old_x, old_y);
    } else {
      m_xLast = Truncate(Mouse_SDL::s_x0 + x, s_xLim0, s_xLim1);
      m_yLast = Truncate(Mouse_SDL::s_y0 + y, s_yLim0, s_yLim1);
      m_vPts.push_back(MousePoint(ms, m_xLast, m_yLast));
    }
  } else {
    if (!m_bDraw) {
      Mouse_SDL::s_x0 = x;
      Mouse_SDL::s_y0 = y;
      m_xLast = x;
      m_yLast = y;
    } else {}
    // throw out the first sample
    //m_vPts.push_back(MousePoint(ms, m_x0 + x, m_y0 + y));
    m_bFirst = 1;
  }
}
Esempio n. 13
0
csStringBase& csStringBase::Replace (const csStringBase& Str, size_t Count)
{
  if (this != &Str)
    Replace(Str.GetData(), Count);
  else if (Count != (size_t)-1 && Count < Length())
    Truncate(Count);
  return *this;
}
Esempio n. 14
0
bool CPackage::CopyPackage( CPackage* pPackage )
{
	AllocMax();
	if(pPackage->Length() > m_pPackageBuf->Length())
		return false;
	memcpy(Address(),pPackage->Address(),pPackage->Length());
	Truncate(pPackage->Length());
	return true;
}
Esempio n. 15
0
void File::Prealloc(Int64 Size)
{
#ifdef _WIN_32
    if (RawSeek(Size,SEEK_SET))
    {
        Truncate();
        Seek(0,SEEK_SET);
    }
#endif
}
Esempio n. 16
0
void
nsTSubstring_CharT::SetIsVoid( bool val )
  {
    if (val)
      {
        Truncate();
        mFlags |= F_VOIDED;
      }
    else
      {
        mFlags &= ~F_VOIDED;
      }
  }
Esempio n. 17
0
		/**
		 * @brief TruncateLines
		 * @param source
		 * @param requested_length
		 */
		void TruncateLines( std::string & source, size_t requested_length )
		{


			std::string::size_type line_break = 0;
			std::string::size_type line_start = 0;
			std::string::size_type line_length = 0;
			std::string::size_type remove_char_count = 0;
			std::string::size_type center_char = requested_length/2;

			line_break = source.find_first_of('\n', line_start);

			if ( std::string::npos == line_break )
			{
				Truncate( source, requested_length );
			}
			else
			{
				std::string::size_type string_length = source.length();

				while ( string_length >= line_break ) {

					line_length = line_break - line_start;
					remove_char_count = line_length - requested_length;

					if ( line_length > requested_length )
					{
						source.replace( line_start + (requested_length/2), remove_char_count, "…" );
					}


					if ( string_length > line_break )
					{
						line_start = line_break+1;
						line_break = source.find_first_of('\n', line_start);

						// We still want to Truncate the last line
						if ( std::string::npos == line_break )
						{
							line_break = source.length();
						}
					}
					else
					{
						line_break = std::string::npos;
					}

				}
			}
		}
Esempio n. 18
0
vcFloatValue::vcFloatValue(vcFloatType* t, string big_endian_value, string format):vcValue((vcType*)t)
{
  // number of bits must be exactly as expected..

  if(format == "binary")
    {
      assert((t)->Size() == big_endian_value.size());
      assert(big_endian_value.size() == t->Size());
      this->_value = Reverse(big_endian_value);
    }
  else 
    {
      this->_value = Reverse(Truncate(t->Size(),Hex_To_Binary(Reverse(big_endian_value))));
    }
}
Esempio n. 19
0
// -----------------------------------------------------------------------------
// Override of Archive::renameEntry to update namespaces if needed and rename
// the entry if necessary to be grp-friendly (twelve characters max)
// -----------------------------------------------------------------------------
bool GrpArchive::renameEntry(ArchiveEntry* entry, const string& name)
{
	// Check entry
	if (!checkEntry(entry))
		return false;

	// Process name (must be 12 characters max)
	auto new_name = name;
	new_name.Truncate(12);
	if (wad_force_uppercase)
		new_name.MakeUpper();

	// Do default rename
	return Archive::renameEntry(entry, new_name);
}
Esempio n. 20
0
csStringBase& csStringBase::Replace (const char* Str, size_t Count)
{
  char* p = GetDataMutable();
  if (Str == 0 || Count == 0)
    Free();
  else if (p != 0 && Str >= p && Str < p + Size) // Pathalogical cases
  {
    if (Count == (size_t)-1) Count = Size - (Str - p);
    if (Str == p && Count < Size)	// i.e. `s.Replace(s.GetData(), n)'
      Truncate(Count);
    else if (Str > p)			// i.e. `s.Replace(s.GetData() + n)'
    {
      memmove(p, Str, Count);
      p[Count] = '\0';
      Size = Count;
    }
  }
  else
  {
    Truncate(0);
    Append (Str, Count);
  }
  return *this;
}
Esempio n. 21
0
// Note: isalpha(int c),  toupper(int c), tolower(int c), isspace(int c)
// If c is not an unsigned char value, or EOF, the behaviour of these functions
// is undefined.
csStringBase &csStringBase::RTrim()
{
  if (Size > 0)
  {
    char const* const p = GetData();
    CS_ASSERT(p != 0);
    const char* c;
    for (c = p + Size - 1; c != p; c--)
      if (!isspace ((unsigned char)*c))
        break;
    size_t i = c - p;
    if (i < Size - 1)
      Truncate(i + 1);
  }
  return *this;
}
void
nsTString_CharT::AssignWithConversion( const incompatible_char_type* aData, int32_t aLength )
  {
      // for compatibility with the old string implementation, we need to allow
      // for a nullptr input buffer :-(
    if (!aData)
      {
        Truncate();
      }
    else
      {
        if (aLength < 0)
          aLength = nsCharTraits<incompatible_char_type>::length(aData);

        AssignWithConversion(Substring(aData, aLength));
      }
  }
Esempio n. 23
0
/**
this is not needed for bulk_extractor
*/
void File::Prealloc(int64 Size)
{ 
#ifdef _WIN_ALL
  if (RawSeek(Size,SEEK_SET))
  {
    Truncate();
    Seek(0,SEEK_SET);
  }
#endif

#if defined(_UNIX) && defined(USE_FALLOCATE)
  // fallocate is rather new call. Only latest kernels support it.
  // So we are not using it by default yet.
  int fd = fileno(hFile);
  if (fd >= 0)
    fallocate(fd, 0, 0, Size);
#endif
}
Esempio n. 24
0
csStringBase& csStringBase::AppendFmtV (const char* format, va_list args)
{
  csStringFmtWriter writer (*this);
  csFmtDefaultReader<utf8_char> reader ((utf8_char*)format, strlen (format));
  csPrintfFormatter<csStringFmtWriter, csFmtDefaultReader<utf8_char> >
    formatter (&reader, args);
  formatter.Format (writer);

  // csStringBase is capable of storing any binary data, including null bytes.
  // csPrintfFormatter() always appends a null terminator for the convenience
  // of raw string buffers (char[]), but csStringBase already maintains its own
  // null terminator one position beyond the string length. We discard the
  // final null added by csPrintfFormatter() because we do not want it to be
  // considered by Length() as actual string data. csStringBase's own final
  // null suffices as a suitable string terminator.
  if (!IsEmpty())
    Truncate(Length() - 1);

  return *this;
}
Esempio n. 25
0
void LLDBPlugin::HookPopupMenu(wxMenu* menu, MenuType type)
{
    wxUnusedVar(type);

    if(!m_connector.IsRunning()) { return; }

    const auto editor = m_mgr->GetActiveEditor();
    if(!editor) { return; }

    size_t numberOfMenuItems = 0;

    if(m_connector.IsCanInteract()) {
        menu->Prepend(lldbJumpToCursorContextMenuId, wxT("Jump to Caret Line"));
        ++numberOfMenuItems;

        menu->Prepend(lldbRunToCursorContextMenuId, wxT("Run to Caret Line"));
        ++numberOfMenuItems;
    }

    auto word = GetWatchWord(*editor);
    if(word.Contains("\n")) {
        // Don't create massive context menu
        word.Clear();
    }

    // Truncate the word
    if(word.length() > 20) {
        word.Truncate(20);
        word << "...";
    }

    if(!word.IsEmpty()) {
        const auto menuItemText = wxString(wxT("Add Watch")) << wxT(" '") << word << wxT("'");
        menu->Prepend(lldbAddWatchContextMenuId, menuItemText);
        ++numberOfMenuItems;
    }

    if(numberOfMenuItems > 0) { menu->InsertSeparator(numberOfMenuItems); }
}
Esempio n. 26
0
void
nsTSubstring_CharT::Assign( const char_type* data, size_type length )
  {
      // unfortunately, some callers pass null :-(
    if (!data)
      {
        Truncate();
        return;
      }

    if (length == size_type(-1))
      length = char_traits::length(data);

    if (IsDependentOn(data, data + length))
      {
        // take advantage of sharing here...
        Assign(string_type(data, length));
        return;
      }

    if (ReplacePrep(0, mLength, length))
      char_traits::copy(mData, data, length);
  }
Esempio n. 27
0
bool
nsTSubstring_CharT::Assign( const char_type* data, size_type length, const fallible_t& )
  {
    if (!data)
      {
        Truncate();
        return true;
      }

    if (length == size_type(-1))
      length = char_traits::length(data);

    if (IsDependentOn(data, data + length))
      {
        return Assign(string_type(data, length), fallible_t());
      }

    if (!ReplacePrep(0, mLength, length))
      return false;

    char_traits::copy(mData, data, length);
    return true;
  }
Esempio n. 28
0
bool
nsTSubstring_CharT::Assign( const self_type& str, const fallible_t& )
  {
    // |str| could be sharable.  we need to check its flags to know how to
    // deal with it.

    if (&str == this)
      return true;

    if (!str.mLength)
      {
        Truncate();
        mFlags |= str.mFlags & F_VOIDED;
        return true;
      }

    if (str.mFlags & F_SHARED)
      {
        // nice! we can avoid a string copy :-)

        // |str| should be null-terminated
        NS_ASSERTION(str.mFlags & F_TERMINATED, "shared, but not terminated");

        ::ReleaseData(mData, mFlags);

        mData = str.mData;
        mLength = str.mLength;
        SetDataFlags(F_TERMINATED | F_SHARED);

        // get an owning reference to the mData
        nsStringBuffer::FromData(mData)->AddRef();
        return true;
      }

    // else, treat this like an ordinary assignment.
    return Assign(str.Data(), str.Length(), fallible_t());
  }
Esempio n. 29
0
Vec4 ClusterFit::SolveLeastSquares( Vec4& start, Vec4& end ) const
{
	// accumulate all the quantities we need
	int const count = m_colours->GetCount();
	Vec4 alpha2_sum = VEC4_CONST( 0.0f );
	Vec4 beta2_sum = VEC4_CONST( 0.0f );
	Vec4 alphabeta_sum = VEC4_CONST( 0.0f );
	Vec4 alphax_sum = VEC4_CONST( 0.0f );
	Vec4 betax_sum = VEC4_CONST( 0.0f );
	for( int i = 0; i < count; ++i )
	{
		Vec4 alpha = m_alpha[i];
		Vec4 beta = m_beta[i];
		Vec4 x = m_weighted[i];
	
		alpha2_sum = MultiplyAdd( alpha, alpha, alpha2_sum );
		beta2_sum = MultiplyAdd( beta, beta, beta2_sum );
		alphabeta_sum = MultiplyAdd( alpha, beta, alphabeta_sum );
		alphax_sum = MultiplyAdd( alpha, x, alphax_sum );
		betax_sum = MultiplyAdd( beta, x, betax_sum );	
	}

	// select the results
	Vec4 const zero = VEC4_CONST( 0.0f );
	Vec4 beta2_sum_zero = CompareEqual( beta2_sum, zero );
	Vec4 alpha2_sum_zero = CompareEqual( alpha2_sum, zero );
	
	Vec4 a1 = alphax_sum*Reciprocal( alpha2_sum );
	Vec4 b1 = betax_sum*Reciprocal( beta2_sum );
	
	Vec4 factor = Reciprocal( NegativeMultiplySubtract( 
		alphabeta_sum, alphabeta_sum, alpha2_sum*beta2_sum 
	) );
	Vec4 a2 = NegativeMultiplySubtract( 
		betax_sum, alphabeta_sum, alphax_sum*beta2_sum
	)*factor;
	Vec4 b2 = NegativeMultiplySubtract(
		alphax_sum, alphabeta_sum, betax_sum*alpha2_sum
	)*factor;
	
	Vec4 a = Select( Select( a2, a1, beta2_sum_zero ), zero, alpha2_sum_zero );
	Vec4 b = Select( Select( b2, b1, alpha2_sum_zero ), zero, beta2_sum_zero );

	// clamp the output to [0, 1]
	Vec4 const one = VEC4_CONST( 1.0f );
	Vec4 const half = VEC4_CONST( 0.5f );
	a = Min( one, Max( zero, a ) );
	b = Min( one, Max( zero, b ) );

	// clamp to the grid
	Vec4 const grid( 31.0f, 63.0f, 31.0f, 0.0f );
	Vec4 const gridrcp( 1.0f/31.0f, 1.0f/63.0f, 1.0f/31.0f, 0.0f );
	Vec4 const onethird = VEC4_CONST( 1.0f/3.0f );
	Vec4 const twothirds = VEC4_CONST( 2.0f/3.0f );
	a = Truncate( MultiplyAdd( grid, a, half ) )*gridrcp;
	b = Truncate( MultiplyAdd( grid, b, half ) )*gridrcp;

	// compute the error
	Vec4 const two = VEC4_CONST( 2.0 );
	Vec4 e1 = MultiplyAdd( b*b, beta2_sum, m_xxsum );
	Vec4 e2 = MultiplyAdd( a, alphax_sum, b*betax_sum );
	Vec4 e3 = MultiplyAdd( a*a, alpha2_sum, e1 );
	Vec4 e4 = MultiplyAdd( a*b*alphabeta_sum - e2, two, e3 );

	// apply the metric to the error term
	Vec4 e5 = e4*m_metricSqr;
	Vec4 error = e5.SplatX() + e5.SplatY() + e5.SplatZ();
	
	// save the start and end
	start = a;
	end = b;
	return error;
}
Esempio n. 30
0
bool MPEG_File::strip(int tags, bool freeMemory)
{
	if( ReadOnly() )
	{
		wxLogDebug(wxT("MPEG::File::strip() - Cannot strip tags from a read only file."));
		return false;
	}

	if((tags & MPEG_ID3v2) && m_hasId3v2)
	{
		if( !RemoveBlock(m_id3v2Location, m_id3v2OriginalSize) )
			return false;
		m_id3v2Location = -1;
		m_id3v2OriginalSize = 0;
		m_hasId3v2 = false;
		if(freeMemory)
		{
			delete m_id3v2Tag;
			m_id3v2Tag = NULL;
			m_combinedTag->setID3v2Tag(NULL);
		}

		// v1 tag location has changed, update if it exists
		if(m_id3v1Tag)
		{
			m_id3v1Location = findID3v1();
		}
	}

	if((tags & MPEG_ID3v1) && m_hasId3v1)
	{
		Truncate(m_id3v1Location);
		m_id3v1Location = -1;
		m_hasId3v1 = false;
		if(freeMemory)
		{
			delete m_id3v1Tag;
			m_id3v1Tag = NULL;
			m_combinedTag->setID3v1Tag(NULL);
		}
	}

	if((tags & MPEG_APE) && m_hasApe)
	{
		if( !RemoveBlock(m_apeLocation, m_apeOriginalSize) )
			return false;
		m_apeLocation = -1;
		m_hasApe = false;
		if(m_hasId3v1)
		{
			if (m_id3v1Location > m_apeLocation)
				m_id3v1Location -= m_apeOriginalSize;
		}
		if(freeMemory)
		{
			delete m_apeTag;
			m_apeTag = NULL;
			m_combinedTag->setAPETag(NULL);
		}
	}

	return true;
}