Skip to content

Commit

Permalink
2041: adapt to changes in vecmath
Browse files Browse the repository at this point in the history
  • Loading branch information
kduske committed Oct 9, 2019
1 parent 0bc8b5c commit e2e3066
Show file tree
Hide file tree
Showing 91 changed files with 530 additions and 543 deletions.
10 changes: 5 additions & 5 deletions app/resources/shader/EntityLinkArrow.vertsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

/*
Copyright (C) 2010-2017 Kristian Duske

This file is part of TrenchBroom.

TrenchBroom is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

TrenchBroom is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -113,7 +113,7 @@ float measureAngle(vec3 vec, vec3 axis, vec3 up) {
return radians(180.0);
}
vec3 crossProd = cross(axis, vec);
if (dot(crossProd, up) > -almostZero) {
if (dot(crossProd, up) > -almost_zero) {
return acos(cosAngle);
}
return radians(360.0) - acos(cosAngle);
Expand Down
28 changes: 28 additions & 0 deletions cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,34 @@ MACRO(SET_XCODE_ATTRIBUTES TARGET)
set_target_properties(${TARGET} PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=RelWithDebInfo] NO)
ENDMACRO(SET_XCODE_ATTRIBUTES)

MACRO(SET_COMPILER_CONFIG TARGET)
if(COMPILER_IS_CLANG)
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Weverything -pedantic -Wno-format -Wno-variadic-macros -Wno-c99-extensions -Wno-padded -Wno-unused-parameter -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-weak-template-vtables -Wno-float-equal -Wno-used-but-marked-unused -Wno-format-nonliteral -Wno-missing-noreturn -Wno-unused-local-typedef -Wno-double-promotion -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-implicit-fallthrough -Wno-zero-as-null-pointer-constant -Wno-switch-enum -Wno-c++98-compat-bind-to-temporary-copy)
target_compile_options(${TARGET} PRIVATE "$<$<CONFIG:RELEASE>:-O3>")

# FIXME: Remove once we switch to Xcode 10
target_compile_options(${TARGET} PRIVATE -Wno-missing-braces)

# FIXME: Suppress warnings in moc generated files:
target_compile_options(${TARGET} PRIVATE -Wno-redundant-parens)
elseif(COMPILER_IS_GNU)
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -pedantic -Wno-format -Wno-variadic-macros -Wno-padded -Wno-unused-parameter -Wno-float-equal -Wno-format-nonliteral -Wno-missing-noreturn -Wno-zero-as-null-pointer-constant -Wno-error=maybe-uninitialized)
target_compile_options(${TARGET} PRIVATE "$<$<CONFIG:RELEASE>:-O3>")

# FIXME: enable -Wcpp once we found a workaround for glew / QOpenGLWindow problem, see RenderView.h
target_compile_options(${TARGET} PRIVATE -Wno-cpp)
elseif(COMPILER_IS_MSVC)
target_compile_definitions(${TARGET} PRIVATE _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE)
target_compile_options(${TARGET} PRIVATE /W3 /EHsc /MP)
target_compile_options(${TARGET} PRIVATE "$<$<CONFIG:RELEASE>:/Ox>")

# Generate debug symbols even for Release; we build a stripped pdb in Release mode, see TrenchBroomApp.cmake
target_compile_options(${TARGET} PRIVATE "$<$<CONFIG:RELEASE>:/Zi>")
else()
message(FATAL_ERROR "Cannot set compile options for target ${TARGET}")
endif()
ENDMACRO(SET_COMPILER_CONFIG)

MACRO(FIX_WIN32_PATH VARNAME)
IF (WIN32)
STRING(REPLACE "/" "\\" ${VARNAME} "${${VARNAME}}")
Expand Down
27 changes: 1 addition & 26 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1080,32 +1080,7 @@ if(APPLE)
target_compile_definitions(common PUBLIC GL_SILENCE_DEPRECATION)
endif()

if(COMPILER_IS_CLANG)
target_compile_options(common PRIVATE -Wall -Wextra -Weverything -pedantic -Wno-format -Wno-variadic-macros -Wno-c99-extensions -Wno-padded -Wno-unused-parameter -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-weak-template-vtables -Wno-float-equal -Wno-used-but-marked-unused -Wno-format-nonliteral -Wno-missing-noreturn -Wno-unused-local-typedef -Wno-double-promotion -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-implicit-fallthrough -Wno-zero-as-null-pointer-constant -Wno-switch-enum)
target_compile_options(common PRIVATE "$<$<CONFIG:RELEASE>:-O3>")

# FIXME: Remove once we switch to Xcode 10
target_compile_options(common PRIVATE -Wno-missing-braces)

# FIXME: Suppress warnings in moc generated files:
target_compile_options(common PRIVATE -Wno-redundant-parens)
elseif(COMPILER_IS_GNU)
target_compile_options(common PRIVATE -Wall -Wextra -pedantic -Wno-format -Wno-variadic-macros -Wno-padded -Wno-unused-parameter -Wno-float-equal -Wno-format-nonliteral -Wno-missing-noreturn -Wno-zero-as-null-pointer-constant -Wno-error=maybe-uninitialized)
target_compile_options(common PRIVATE "$<$<CONFIG:RELEASE>:-O3>")

# FIXME: enable -Wcpp once we found a workaround for glew / QOpenGLWindow problem, see RenderView.h
target_compile_options(common PRIVATE -Wno-cpp)
elseif(COMPILER_IS_MSVC)
target_compile_definitions(common PRIVATE _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE)
target_compile_options(common PRIVATE /W3 /EHsc /MP)
target_compile_options(common PRIVATE "$<$<CONFIG:RELEASE>:/Ox>")

# Generate debug symbols even for Release; we build a stripped pdb in Release mode, see TrenchBroomApp.cmake
target_compile_options(common PRIVATE "$<$<CONFIG:RELEASE>:/Zi>")
else()
message(FATAL_ERROR "Cannot set compile options for target common")
endif()

SET_COMPILER_CONFIG(common)

# Create the cmake script for generating the version information
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateVersion.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/GenerateVersion.cmake" @ONLY)
Expand Down
2 changes: 1 addition & 1 deletion common/src/AABBTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ class AABBTree {
* @return the bounds of all nodes in this tree, or a bounding box made up of NaN values if this tree is empty
*/
const Box& bounds() const {
static const auto EmptyBox = Box(vm::vec<T,S>::NaN, vm::vec<T,S>::NaN);
static constexpr auto EmptyBox = Box(vm::vec<T,S>::nan(), vm::vec<T,S>::nan());

assert(!empty());
if (empty()) {
Expand Down
2 changes: 1 addition & 1 deletion common/src/Assets/Quake3Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace TrenchBroom {
namespace Assets {
const String Quake3ShaderStage::BlendFunc::One = "GL_ONE";
const String Quake3ShaderStage::BlendFunc::zero() = "GL_ZERO";
const String Quake3ShaderStage::BlendFunc::Zero = "GL_ZERO";
const String Quake3ShaderStage::BlendFunc::SrcColor = "GL_SRC_COLOR";
const String Quake3ShaderStage::BlendFunc::DestColor = "GL_DST_COLOR";
const String Quake3ShaderStage::BlendFunc::OneMinusSrcColor = "GL_ONE_MINUS_SRC_COLOR";
Expand Down
2 changes: 1 addition & 1 deletion common/src/IO/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace TrenchBroom {
return token;
}

void expect(ParserStatus& status, const String& typeName, const Token& token) const {
void expect(ParserStatus& /* status */, const String& typeName, const Token& token) const {
const String msg = expectString(typeName, token);
throw ParserException(token.line(), token.column(), msg);
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/IO/Quake3ShaderParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ namespace TrenchBroom {
stage.blendFunc.destFactor = Assets::Quake3ShaderStage::BlendFunc::One;
} else if (StringUtils::caseInsensitiveEqual(param1, "filter")) {
stage.blendFunc.srcFactor = Assets::Quake3ShaderStage::BlendFunc::DestColor;
stage.blendFunc.destFactor = Assets::Quake3ShaderStage::BlendFunc::zero();
stage.blendFunc.destFactor = Assets::Quake3ShaderStage::BlendFunc::Zero;
} else if (StringUtils::caseInsensitiveEqual(param1, "blend")) {
stage.blendFunc.srcFactor = Assets::Quake3ShaderStage::BlendFunc::SrcAlpha;
stage.blendFunc.destFactor = Assets::Quake3ShaderStage::BlendFunc::OneMinusSrcAlpha;
Expand Down
24 changes: 12 additions & 12 deletions common/src/Model/Brush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "Model/TagVisitor.h"
#include "Model/World.h"

#include <vecmath/abstract_line.h>
#include <vecmath/intersection.h>
#include <vecmath/vec.h>
#include <vecmath/vec_ext.h>
Expand Down Expand Up @@ -361,7 +360,7 @@ namespace TrenchBroom {

BrushFace* Brush::findFace(const vm::vec3& normal) const {
for (auto* face : m_faces) {
if (vm::is_equal(face->boundary().normal, normal, vm::C::almostZero())) {
if (vm::is_equal(face->boundary().normal, normal, vm::C::almost_zero())) {
return face;
}
}
Expand All @@ -370,7 +369,7 @@ namespace TrenchBroom {

BrushFace* Brush::findFace(const vm::plane3& boundary) const {
for (auto* face : m_faces) {
if (vm::is_equal(face->boundary(), boundary, vm::C::almostZero())) {
if (vm::is_equal(face->boundary(), boundary, vm::C::almost_zero())) {
return face;
}
}
Expand Down Expand Up @@ -724,7 +723,7 @@ namespace TrenchBroom {
result.reserve(vertexPositions.size());

for (const auto& position : vertexPositions) {
const auto* newVertex = m_geometry->findClosestVertex(position + delta, vm::C::almostZero());
const auto* newVertex = m_geometry->findClosestVertex(position + delta, vm::C::almost_zero());
if (newVertex != nullptr) {
result.push_back(newVertex->position());
}
Expand All @@ -747,7 +746,7 @@ namespace TrenchBroom {
const PolyhedronMatcher<BrushGeometry> matcher(*m_geometry, newGeometry);
doSetNewGeometry(worldBounds, matcher, newGeometry);

auto* newVertex = m_geometry->findClosestVertex(position, vm::C::almostZero());
auto* newVertex = m_geometry->findClosestVertex(position, vm::C::almost_zero());
ensure(newVertex != nullptr, "vertex could not be added");
return newVertex;
}
Expand Down Expand Up @@ -861,7 +860,8 @@ namespace TrenchBroom {
result.reserve(edgePositions.size());

for (const auto& edgePosition : edgePositions) {
const auto* newEdge = m_geometry->findClosestEdge(edgePosition.start() + delta, edgePosition.end() + delta, vm::C::almostZero());
const auto* newEdge = m_geometry->findClosestEdge(edgePosition.start() + delta, edgePosition.end() + delta,
vm::C::almost_zero());
if (newEdge != nullptr) {
result.push_back(vm::segment3(newEdge->firstVertex()->position(), newEdge->secondVertex()->position()));
}
Expand All @@ -875,7 +875,7 @@ namespace TrenchBroom {
ensure(!facePositions.empty(), "no face positions");

std::vector<vm::vec3> vertexPositions;
vm::polygon3::getVertices(std::begin(facePositions), std::end(facePositions), std::back_inserter(vertexPositions));
vm::polygon3::get_vertices(std::begin(facePositions), std::end(facePositions), std::back_inserter(vertexPositions));
const auto result = doCanMoveVertices(worldBounds, vertexPositions, delta, false);

if (!result.success) {
Expand All @@ -895,14 +895,14 @@ namespace TrenchBroom {
assert(canMoveFaces(worldBounds, facePositions, delta));

std::vector<vm::vec3> vertexPositions;
vm::polygon3::getVertices(std::begin(facePositions), std::end(facePositions), std::back_inserter(vertexPositions));
vm::polygon3::get_vertices(std::begin(facePositions), std::end(facePositions), std::back_inserter(vertexPositions));
doMoveVertices(worldBounds, vertexPositions, delta, uvLock);

std::vector<vm::polygon3> result;
result.reserve(facePositions.size());

for (const auto& facePosition : facePositions) {
const auto* newFace = m_geometry->findClosestFace(facePosition.vertices() + delta, vm::C::almostZero());
const auto* newFace = m_geometry->findClosestFace(facePosition.vertices() + delta, vm::C::almost_zero());
if (newFace != nullptr) {
result.push_back(vm::polygon3(newFace->vertexPositions()));
}
Expand Down Expand Up @@ -951,7 +951,7 @@ namespace TrenchBroom {
*/
Brush::CanMoveVerticesResult Brush::doCanMoveVertices(const vm::bbox3& worldBounds, const std::vector<vm::vec3>& vertexPositions, vm::vec3 delta, const bool allowVertexRemoval) const {
// Should never occur, takes care of the first row.
if (vertexPositions.empty() || vm::is_zero(delta, vm::C::almostZero())) {
if (vertexPositions.empty() || vm::is_zero(delta, vm::C::almost_zero())) {
return CanMoveVerticesResult::rejectVertexMove();
}

Expand Down Expand Up @@ -1054,7 +1054,7 @@ namespace TrenchBroom {
const auto& oldPosition = oldVertex->position();
const auto moved = vertexSet.count(oldPosition);
const auto newPosition = moved ? oldPosition + delta : oldPosition;
const auto* newVertex = newGeometry.findClosestVertex(newPosition, vm::C::almostZero());
const auto* newVertex = newGeometry.findClosestVertex(newPosition, vm::C::almost_zero());
if (newVertex != nullptr) {
vertexMapping.insert(std::make_pair(oldPosition, newVertex->position()));
}
Expand All @@ -1072,7 +1072,7 @@ namespace TrenchBroom {
const auto leftPosition = leftVertex->position();
const auto rightPosition = rightVertex->position();

if (vm::is_equal(leftPosition, rightPosition, vm::constants<FloatType>::almostZero())) {
if (vm::is_equal(leftPosition, rightPosition, vm::constants<FloatType>::almost_zero())) {
unmovedVerts.push_back(leftPosition);
} else {
movedVerts.emplace_back(leftPosition, rightPosition);
Expand Down
5 changes: 2 additions & 3 deletions common/src/Model/BrushFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "Model/ParaxialTexCoordSystem.h"
#include "Model/TagVisitor.h"

#include <vecmath/abstract_line.h>
#include <vecmath/bbox.h>
#include <vecmath/intersection.h>
#include <vecmath/mat.h>
Expand Down Expand Up @@ -142,7 +141,7 @@ namespace TrenchBroom {
m_texCoordSystem->updateNormal(sourceFacePlane.normal, m_boundary.normal, m_attribs, wrapStyle);

// Adjust the offset on this face so that the texture coordinates at the refPoint stay the same
if (!vm::is_zero(seam.direction, vm::C::almostZero())) {
if (!vm::is_zero(seam.direction, vm::C::almost_zero())) {
const auto currentCoords = m_texCoordSystem->getTexCoords(refPoint, m_attribs) * m_attribs.textureSize();
const auto offsetChange = desriedCoords - currentCoords;
m_attribs.setOffset(correct(m_attribs.modOffset(m_attribs.offset() + offsetChange), 4));
Expand Down Expand Up @@ -523,7 +522,7 @@ namespace TrenchBroom {
// Get a line, and a reference point, that are on both the old plane
// (before moving the face) and after moving the face.
const auto seam = vm::intersect_plane_plane(oldPlane, m_boundary);
if (!vm::is_zero(seam.direction, vm::C::almostZero())) {
if (!vm::is_zero(seam.direction, vm::C::almost_zero())) {
const auto refPoint = project_point(seam, center());

// Get the texcoords at the refPoint using the old face's attribs and tex coord system
Expand Down
2 changes: 1 addition & 1 deletion common/src/Model/BrushFaceAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ namespace TrenchBroom {
}

bool BrushFaceAttributes::valid() const {
return !vm::is_zero(m_scale.x(), vm::Cf::almostZero()) && !vm::is_zero(m_scale.y(), vm::Cf::almostZero());
return !vm::is_zero(m_scale.x(), vm::Cf::almost_zero()) && !vm::is_zero(m_scale.y(), vm::Cf::almost_zero());
}

void BrushFaceAttributes::setOffset(const vm::vec2f& offset) {
Expand Down
1 change: 0 additions & 1 deletion common/src/Model/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "Model/PickResult.h"
#include "Model/TagVisitor.h"

#include <vecmath/abstract_line.h>
#include <vecmath/forward.h>
#include <vecmath/vec.h>
#include <vecmath/bbox.h>
Expand Down
2 changes: 1 addition & 1 deletion common/src/Model/HitQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace TrenchBroom {
containsOccluder = true;
}
++it;
} while (it != end && vm::is_equal(it->distance(), distance, vm::C::almostZero()));
} while (it != end && vm::is_equal(it->distance(), distance, vm::C::almost_zero()));
}

if (bestMatch != end && bestMatchError <= bestOccluderError)
Expand Down
9 changes: 5 additions & 4 deletions common/src/Model/ParaxialTexCoordSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace TrenchBroom {
const vm::vec3 offset = transformation * vm::vec3::zero();
const vm::vec3& oldNormal = oldBoundary.normal;
vm::vec3 newNormal = newBoundary.normal;
assert(vm::is_unit(newNormal, vm::C::almostZero()));
assert(vm::is_unit(newNormal, vm::C::almost_zero()));

// fix some rounding errors - if the old and new texture axes are almost the same, use the old axis
if (vm::is_equal(newNormal, oldNormal, 0.01)) {
Expand Down Expand Up @@ -220,8 +220,8 @@ namespace TrenchBroom {
assert(!vm::is_nan(newOffset));
assert(!vm::is_nan(newScale));
assert(!vm::is_nan(newRotation));
assert(!vm::is_zero(newScale.x(), vm::Cf::almostZero()));
assert(!vm::is_zero(newScale.y(), vm::Cf::almostZero()));
assert(!vm::is_zero(newScale.x(), vm::Cf::almost_zero()));
assert(!vm::is_zero(newScale.y(), vm::Cf::almost_zero()));

attribs.setOffset(newOffset);
attribs.setScale(newScale);
Expand All @@ -245,7 +245,8 @@ namespace TrenchBroom {
const auto rot = vm::quat3(vm::vec3::pos_z(), -vm::to_radians(currentAngle));
const auto vec = rot * vm::vec3(point - center);

const auto angleInRadians = vm::C::twoPi() - vm::measure_angle(vm::normalize(vec), vm::vec3::pos_x(), vm::vec3::pos_z());
const auto angleInRadians =
vm::C::two_pi() - vm::measure_angle(vm::normalize(vec), vm::vec3::pos_x(), vm::vec3::pos_z());
return float(vm::to_degrees(angleInRadians));
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/Model/TexCoordSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace TrenchBroom {

template <typename T>
T safeScale(const T value) const {
return vm::is_equal(value, T(0.0), vm::constants<T>::almostZero()) ? static_cast<T>(1.0) : value;
return vm::is_equal(value, T(0.0), vm::constants<T>::almost_zero()) ? static_cast<T>(1.0) : value;
}

template <typename T1, typename T2>
Expand Down
6 changes: 3 additions & 3 deletions common/src/Polyhedron.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Polyhedron {

HalfEdge* findConnectingEdge(const Vertex* vertex) const;
HalfEdge* findColinearEdge(const HalfEdge* arriving) const;
void correctPosition(const size_t decimals = 0, const T epsilon = vm::constants<T>::correctEpsilon());
void correctPosition(const size_t decimals = 0, const T epsilon = vm::constants<T>::correct_epsilon());
void setPosition(const V& position);
void setLeaving(HalfEdge* edge);
};
Expand Down Expand Up @@ -244,7 +244,7 @@ class Polyhedron {
V normal() const;
V center() const;
T intersectWithRay(const vm::ray<T,3>& ray, const vm::side side) const;
vm::plane_status pointStatus(const V& point, T epsilon = vm::constants<T>::pointStatusEpsilon()) const;
vm::plane_status pointStatus(const V& point, T epsilon = vm::constants<T>::point_status_epsilon()) const;

friend std::ostream& operator<<(std::ostream& stream, const Face& face) {
const auto* firstEdge = face.boundary().front();
Expand Down Expand Up @@ -419,7 +419,7 @@ class Polyhedron {

void updateBounds();
public: // Vertex correction and edge healing
void correctVertexPositions(const size_t decimals = 0, const T epsilon = vm::constants<T>::correctEpsilon());
void correctVertexPositions(const size_t decimals = 0, const T epsilon = vm::constants<T>::correct_epsilon());
bool healEdges(const T minLength = MinEdgeLength);
bool healEdges(Callback& callback, const T minLength = MinEdgeLength);
private:
Expand Down
Loading

0 comments on commit e2e3066

Please sign in to comment.