Example #1
0
File: arena.cpp Project: QingYun/kj
Arena::Arena(ArrayPtr<byte> scratch)
    : nextChunkSize(kj::max(sizeof(ChunkHeader), scratch.size())) {
  if (scratch.size() > sizeof(ChunkHeader)) {
    ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(scratch.begin());
    chunk->end = scratch.end();
    chunk->pos = reinterpret_cast<byte*>(chunk + 1);
    chunk->next = nullptr;  // Never actually observed.

    // Don't place the chunk in the chunk list because it's not ours to delete.  Just make it the
    // current chunk so that we'll allocate from it until it is empty.
    currentChunk = chunk;
  }
}
Example #2
0
/* ------------------------------------------------------- */
void SphereVolume::computeFromData(const Ptr<VertexData>& vdata)
{
	m_radius = 0.0f;
	m_center = Vector3(0.0f, 0.0f, 0.0f);
	float curDistance = 0.0f;
	
	ArrayPtr<GeometryVertex> vertices = vdata->getGeometryData();

	for (int i = 0; i < vertices.size(); i++)
	{
		m_center += vertices[i].position;
	}
	m_center /= vertices.size();

	for (int i = 0; i < vertices.size(); i++)
	{
		curDistance = (vertices[i].position-m_center).squaredLength();
		if (curDistance > m_radius)
		{
			m_radius = curDistance;
		}
	}
	m_radius = Math<float>::Sqrt(m_radius);
}