Skip to content

Commit

Permalink
Rename c_pi to math::PI
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Mar 21, 2021
1 parent 71554fc commit c0fd3da
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 71 deletions.
2 changes: 1 addition & 1 deletion libs/math/Vector3.h
Expand Up @@ -382,7 +382,7 @@ class BasicVector3
bool isParallel(const BasicVector3<OtherT>& other) const
{
return float_equal_epsilon(angle(other), 0.0, 0.001) ||
float_equal_epsilon(angle(other), c_pi, 0.001);
float_equal_epsilon(angle(other), math::PI, 0.001);
}

// Swaps all components with the other vector
Expand Down
14 changes: 9 additions & 5 deletions libs/math/pi.h
Expand Up @@ -21,12 +21,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#pragma once

const double c_pi = 3.1415926535897932384626433832795;
const double c_half_pi = c_pi / 2;
const double c_2pi = 2 * c_pi;
namespace math
{
const double PI = 3.1415926535897932384626433832795;
}

const double c_half_pi = math::PI / 2;
const double c_2pi = 2 * math::PI;

const double c_DEG2RADMULT = c_pi / 180.0;
const double c_RAD2DEGMULT = 180.0 / c_pi;
const double c_DEG2RADMULT = math::PI / 180.0;
const double c_RAD2DEGMULT = 180.0 / math::PI;

inline double radians_to_degrees(double radians)
{
Expand Down
6 changes: 3 additions & 3 deletions libs/render.h
Expand Up @@ -212,7 +212,7 @@ class RenderablePointVector :
if (_vector.empty()) return;

// Enable point colours if required
bool enablePointColours = info.checkFlag(RENDER_VERTEX_COLOUR) ||
bool enablePointColours = info.checkFlag(RENDER_VERTEX_COLOUR) ||
(info.checkFlag(RENDER_POINT_COLOUR) && _mode == GL_POINTS);

if (enablePointColours)
Expand Down Expand Up @@ -297,7 +297,7 @@ class RenderableVertexBuffer : public OpenGLRenderable
{
bool enableColours = info.checkFlag(RENDER_VERTEX_COLOUR)
|| (info.checkFlag(RENDER_POINT_COLOUR) && _mode == GL_POINTS);

if (enableColours)
{
glEnableClientState(GL_COLOR_ARRAY);
Expand Down Expand Up @@ -373,7 +373,7 @@ class RemapZXY {

template<typename remap_policy>
inline void draw_circle(const std::size_t segments, const float radius, VertexCb* vertices, remap_policy remap) {
const double increment = c_pi / double(segments << 2);
const double increment = math::PI / double(segments << 2);

std::size_t count = 0;
float x = radius;
Expand Down
20 changes: 10 additions & 10 deletions radiant/xyview/XYWnd.cpp
Expand Up @@ -107,7 +107,7 @@ XYWnd::XYWnd(int id, wxWindow* parent) :

_wxGLWidget->Connect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(XYWnd::onGLWindowScroll), NULL, this);
_wxGLWidget->Connect(wxEVT_MOTION, wxMouseEventHandler(XYWnd::onGLMouseMove), NULL, this);

_wxGLWidget->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XYWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(XYWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XYWnd::onGLMouseButtonRelease), NULL, this);
Expand Down Expand Up @@ -309,7 +309,7 @@ bool XYWnd::isActive() const {
return _isActive;
};

const Vector3& XYWnd::getOrigin() const
const Vector3& XYWnd::getOrigin() const
{
return _origin;
}
Expand Down Expand Up @@ -391,7 +391,7 @@ bool XYWnd::checkChaseMouse(unsigned int state)
{
_chasemouseDeltaY = std::max(y - epsilon, -GlobalXYWnd().chaseMouseCap());
}
else if (y > _height - epsilon)
else if (y > _height - epsilon)
{
_chasemouseDeltaY = std::min(y - _height + epsilon, GlobalXYWnd().chaseMouseCap());
}
Expand Down Expand Up @@ -605,7 +605,7 @@ void XYWnd::snapToGrid(Vector3& point)
point[1] = float_snapped(point[1], GlobalGrid().getGridSize());
point[2] = float_snapped(point[2], GlobalGrid().getGridSize());
}
else
else
{
point[0] = float_snapped(point[0], GlobalGrid().getGridSize());
point[2] = float_snapped(point[2], GlobalGrid().getGridSize());
Expand Down Expand Up @@ -1072,9 +1072,9 @@ void XYWnd::drawCameraIcon()
glEnd();

glBegin(GL_LINE_STRIP);
glVertex3f(x + static_cast<float>(fov * cos(a + c_pi / 4)), y + static_cast<float>(fov * sin(a + c_pi / 4)), 0);
glVertex3f(x + static_cast<float>(fov * cos(a + math::PI / 4)), y + static_cast<float>(fov * sin(a + math::PI / 4)), 0);
glVertex3f(x, y, 0);
glVertex3f(x + static_cast<float>(fov * cos(a - c_pi / 4)), y + static_cast<float>(fov * sin(a - c_pi / 4)), 0);
glVertex3f(x + static_cast<float>(fov * cos(a - math::PI / 4)), y + static_cast<float>(fov * sin(a - math::PI / 4)), 0);
glEnd();
}
catch (const std::runtime_error&)
Expand Down Expand Up @@ -1467,7 +1467,7 @@ void XYWnd::draw()
i.second->renderOverlay();
}
}

if (xyWndManager.showOutline()) {
if (isActive()) {
glMatrixMode (GL_PROJECTION);
Expand Down Expand Up @@ -1584,7 +1584,7 @@ bool XYWnd::onRender()

return true;
}


return false; // nothing rendered
}
Expand Down Expand Up @@ -1681,7 +1681,7 @@ void XYWnd::startCapture(const MouseToolPtr& tool)

unsigned int pointerMode = tool->getPointerMode();

_freezePointer.startCapture(_wxGLWidget,
_freezePointer.startCapture(_wxGLWidget,
[&, tool](int x, int y, unsigned int state) { handleGLCapturedMouseMotion(tool, x, y, state); }, // Motion Functor
[&, tool]() { MouseToolHandler::handleCaptureLost(tool); }, // called when the capture is lost.
(pointerMode & MouseTool::PointerMode::Freeze) != 0,
Expand Down Expand Up @@ -1709,4 +1709,4 @@ IInteractiveView& XYWnd::getInteractiveView()
ShaderPtr XYWnd::_selectedShader;
ShaderPtr XYWnd::_selectedShaderGroup;

} // namespace
} // namespace
40 changes: 20 additions & 20 deletions radiantcore/brush/Brush.cpp
Expand Up @@ -145,7 +145,7 @@ void Brush::forEachVisibleFace(const std::function<void(Face&)>& functor) const
void Brush::connectUndoSystem(IMapFileChangeTracker& changeTracker)
{
assert(_undoStateSaver == nullptr);

// Keep a reference around, we need it when faces are changing
_mapFileChangeTracker = &changeTracker;

Expand All @@ -158,7 +158,7 @@ void Brush::connectUndoSystem(IMapFileChangeTracker& changeTracker)
void Brush::disconnectUndoSystem(IMapFileChangeTracker& changeTracker)
{
assert(_undoStateSaver != nullptr);

// Notify each face
forEachFace([&](Face& face) { face.disconnectUndoSystem(changeTracker); });

Expand Down Expand Up @@ -268,10 +268,10 @@ const AABB& Brush::localAABB() const {
return m_aabb_local;
}

void Brush::renderComponents(SelectionSystem::EComponentMode mode, RenderableCollector& collector,
const VolumeTest& volume, const Matrix4& localToWorld) const
void Brush::renderComponents(SelectionSystem::EComponentMode mode, RenderableCollector& collector,
const VolumeTest& volume, const Matrix4& localToWorld) const
{
switch (mode)
switch (mode)
{
case SelectionSystem::eVertex:
collector.addRenderable(*m_state_point, _uniqueVertexPoints, localToWorld);
Expand Down Expand Up @@ -398,7 +398,7 @@ void Brush::setRenderSystem(const RenderSystemPtr& renderSystem)
m_state_point.reset();
}

for (Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i)
for (Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i)
{
(*i)->setRenderSystem(renderSystem);
}
Expand Down Expand Up @@ -499,7 +499,7 @@ void Brush::onFaceEvaluateTransform()
evaluateTransform();
}

void Brush::clear()
void Brush::clear()
{
undoSave();
if (_undoStateSaver)
Expand Down Expand Up @@ -730,8 +730,8 @@ void Brush::constructPrism(const AABB& bounds, std::size_t sides, int axis, cons

for (std::size_t i = 0 ; i < sides ; ++i)
{
float sv = sin(i*static_cast<float>(c_pi)*2/sides);
float cv = cos(i*static_cast<float>(c_pi)*2/sides);
float sv = sin(i*static_cast<float>(math::PI)*2/sides);
float cv = cos(i*static_cast<float>(math::PI)*2/sides);

planepts[0][(axis+1)%3] = floor(mid[(axis+1) % 3] + radius*cv + 0.5f);
planepts[0][(axis+2)%3] = floor(mid[(axis+2) % 3] + radius*sv + 0.5f);
Expand Down Expand Up @@ -789,8 +789,8 @@ void Brush::constructCone(const AABB& bounds, std::size_t sides, const std::stri

for (std::size_t i = 0 ; i < sides ; ++i)
{
float sv = sin (i*static_cast<float>(c_pi)*2/sides);
float cv = cos (i*static_cast<float>(c_pi)*2/sides);
float sv = sin (i*static_cast<float>(math::PI)*2/sides);
float cv = cos (i*static_cast<float>(math::PI)*2/sides);

planepts[0][0] = floor(mid[0] + radius*cv + 0.5f);
planepts[0][1] = floor(mid[1] + radius*sv + 0.5f);
Expand Down Expand Up @@ -836,15 +836,15 @@ void Brush::constructSphere(const AABB& bounds, std::size_t sides, const std::st
const Vector3& mid = bounds.origin;
Vector3 planepts[3];

float dt = 2 * static_cast<float>(c_pi) / sides;
float dp = static_cast<float>(c_pi) / sides;
float dt = 2 * static_cast<float>(math::PI) / sides;
float dp = static_cast<float>(math::PI) / sides;

for (std::size_t i = 0; i < sides; i++)
{
for (std::size_t j = 0; j < sides - 1; j++)
{
float t = i * dt;
float p = static_cast<float>(j * dp - c_pi / 2);
float p = static_cast<float>(j * dp - math::PI / 2);

planepts[0] = mid + Vector3::createForSpherical(t, p)*radius;
planepts[1] = mid + Vector3::createForSpherical(t, p + dp)*radius;
Expand All @@ -855,7 +855,7 @@ void Brush::constructSphere(const AABB& bounds, std::size_t sides, const std::st
}

{
float p = (sides - 1) * dp - static_cast<float>(c_pi) / 2;
float p = (sides - 1) * dp - static_cast<float>(math::PI) / 2;

for (std::size_t i = 0; i < sides; i++)
{
Expand Down Expand Up @@ -892,22 +892,22 @@ bool Brush::getIntersection(const Ray& ray, Vector3& intersection)

auto n = -(ray.origin - face.getWinding().front().vertex).dot(face.getPlane3().normal());
auto d = direction.dot(face.getPlane3().normal());

if (d == 0) // is the ray parallel to the face?
{
if (n < 0)
{
return false; // since the ray cannot intersect the brush;
}
else
else
{
// the ray cannot enter or leave the brush across this face
continue;
}
}

auto t = n / d;

if (d < 0)
{
// ray is entering the brush across this face
Expand All @@ -929,10 +929,10 @@ bool Brush::getIntersection(const Ray& ray, Vector3& intersection)
}
}
}

assert(tEnter <= tLeave);
intersection = ray.origin + direction * tEnter;

return true;
}

Expand Down
18 changes: 9 additions & 9 deletions radiantcore/entity/speaker/SpeakerRenderables.cpp
Expand Up @@ -8,15 +8,15 @@ void sphereDrawFill(const Vector3& origin, float radius, int sides)
return;

const double dt = c_2pi / static_cast<float>(sides);
const double dp = c_pi / static_cast<float>(sides);
const double dp = math::PI / static_cast<float>(sides);

glBegin(GL_TRIANGLES);
for (int i = 0; i <= sides - 1; ++i)
{
for (int j = 0; j <= sides - 2; ++j)
{
const double t = i * dt;
const double p = (j * dp) - (c_pi / 2.0);
const double p = (j * dp) - (math::PI / 2.0);

{
Vector3 v(origin + Vector3::createForSpherical(t, p) * radius);
Expand Down Expand Up @@ -51,7 +51,7 @@ void sphereDrawFill(const Vector3& origin, float radius, int sides)
}

{
const double p = (sides - 1) * dp - (static_cast<float>(c_pi) / 2.0f);
const double p = (sides - 1) * dp - (static_cast<float>(math::PI) / 2.0f);
for (int i = 0; i <= sides - 1; ++i)
{
const double t = i * dt;
Expand Down Expand Up @@ -82,8 +82,8 @@ void sphereDrawWire(const Vector3& origin, float radius, int sides)

for (int i = 0; i <= sides; i++)
{
float ds = sin((i * 2 * static_cast<float>(c_pi)) / sides);
float dc = cos((i * 2 * static_cast<float>(c_pi)) / sides);
float ds = sin((i * 2 * static_cast<float>(math::PI)) / sides);
float dc = cos((i * 2 * static_cast<float>(math::PI)) / sides);

glVertex3d(
origin[0] + radius * dc,
Expand All @@ -100,8 +100,8 @@ void sphereDrawWire(const Vector3& origin, float radius, int sides)

for (int i = 0; i <= sides; i++)
{
float ds = sin((i * 2 * static_cast<float>(c_pi)) / sides);
float dc = cos((i * 2 * static_cast<float>(c_pi)) / sides);
float ds = sin((i * 2 * static_cast<float>(math::PI)) / sides);
float dc = cos((i * 2 * static_cast<float>(math::PI)) / sides);

glVertex3d(
origin[0] + radius * dc,
Expand All @@ -118,8 +118,8 @@ void sphereDrawWire(const Vector3& origin, float radius, int sides)

for (int i = 0; i <= sides; i++)
{
float ds = sin((i * 2 * static_cast<float>(c_pi)) / sides);
float dc = cos((i * 2 * static_cast<float>(c_pi)) / sides);
float ds = sin((i * 2 * static_cast<float>(math::PI)) / sides);
float dc = cos((i * 2 * static_cast<float>(math::PI)) / sides);

glVertex3d(
origin[0],
Expand Down

0 comments on commit c0fd3da

Please sign in to comment.