src/geometry.cpp

changeset 201
5d201ee4a9c3
parent 200
ca23936b455b
child 206
654661eab7f3
--- a/src/geometry.cpp	Mon Jun 06 22:01:22 2022 +0300
+++ b/src/geometry.cpp	Tue Jun 07 01:37:26 2022 +0300
@@ -9,9 +9,9 @@
  * @param plane
  * @return point of intersection. Does not return a value if the line is in parallel to the plane.
  */
-std::optional<glm::vec3> geom::linePlaneIntersection(
-	const geom::Line<3>& line,
-	const geom::Plane& plane,
+std::optional<glm::vec3> linePlaneIntersection(
+	const Line<3>& line,
+	const Plane& plane,
 	const float epsilon)
 {
 	const float denominator = glm::dot(line.direction, plane.normal);
@@ -31,9 +31,9 @@
  * @param triangle
  * @return plane
  */
-geom::Plane geom::planeFromTriangle(const geom::Triangle& triangle)
+Plane planeFromTriangle(const Triangle& triangle)
 {
-	return geom::Plane{normalVector(triangle), triangle.p1};
+	return Plane{normalVector(triangle), triangle.p1};
 }
 
 /**
@@ -41,7 +41,7 @@
  * @param triangle
  * @return normal vector
  */
-glm::vec3 geom::normalVector(const geom::Triangle& triangle)
+glm::vec3 normalVector(const Triangle& triangle)
 {
 	return glm::normalize(
 		glm::cross(
@@ -55,10 +55,10 @@
  * @param matrix Matrix to compute
  * @return scaling vector and unscaled matrix
  */
-geom::ScalingExtract geom::extractScaling(const glm::mat4& matrix)
+ScalingExtract extractScaling(const glm::mat4& matrix)
 {
-	geom::ScalingExtract result;
-	result.scaling = geom::scalingVector(matrix);
+	ScalingExtract result;
+	result.scaling = scalingVector(matrix);
 	result.unscaled = glm::scale(matrix, 1.0f / result.scaling);
 	return result;
 }
@@ -68,7 +68,7 @@
  * @param matrix
  * @return scaling vector
  */
-glm::vec3 geom::scalingVector(const glm::mat4 matrix)
+glm::vec3 scalingVector(const glm::mat4 matrix)
 {
 	auto component = [](const glm::mat4& matrix, const int i) -> float
 	{
@@ -77,7 +77,7 @@
 	return glm::vec3{component(matrix, 0), component(matrix, 1), component(matrix, 2)};
 }
 
-std::optional<glm::vec2> geom::lineLineIntersection(const Line<2>& line_1, const Line<2>& line_2)
+std::optional<glm::vec2> lineLineIntersection(const Line<2>& line_1, const Line<2>& line_2)
 {
 	const float denominator = (line_1.direction.x * line_2.direction.y) - (line_1.direction.y * line_2.direction.x);
 	constexpr float epsilon = 1e-6f;
@@ -103,7 +103,7 @@
 	}
 }
 
-std::optional<glm::vec2> geom::rayLineSegmentIntersection(const Ray<2>& ray, const LineSegment2D& line)
+std::optional<glm::vec2> rayLineSegmentIntersection(const Ray<2>& ray, const LineSegment2D& line)
 {
 	std::optional<glm::vec2> result = lineLineIntersection(
 		rayToLine(ray),
@@ -127,7 +127,7 @@
 	return result;
 }
 
-std::optional<geom::PointOnRectagle> geom::rayRectangleIntersection(const Ray<2>& ray, const QRectF& rectangle)
+std::optional<PointOnRectagle> rayRectangleIntersection(const Ray<2>& ray, const QRectF& rectangle)
 {
 	std::optional<glm::vec2> position;
 	std::optional<PointOnRectagle> result;
@@ -167,7 +167,7 @@
 	return result;
 }
 
-geom::LineSegment2D geom::top(const QRectF& rectangle)
+LineSegment2D top(const QRectF& rectangle)
 {
 	return {
 		glm::vec2{rectangle.left(), rectangle.top()},
@@ -175,7 +175,7 @@
 	};
 }
 
-geom::LineSegment2D geom::bottom(const QRectF& rectangle)
+LineSegment2D bottom(const QRectF& rectangle)
 {
 	return {
 		glm::vec2{rectangle.left(), rectangle.bottom()},
@@ -183,7 +183,7 @@
 	};
 }
 
-geom::LineSegment2D geom::left(const QRectF& rectangle)
+LineSegment2D left(const QRectF& rectangle)
 {
 	return {
 		glm::vec2{rectangle.left(), rectangle.top()},
@@ -191,7 +191,7 @@
 	};
 }
 
-geom::LineSegment2D geom::right(const QRectF& rectangle)
+LineSegment2D right(const QRectF& rectangle)
 {
 	return {
 		glm::vec2{rectangle.right(), rectangle.top()},
@@ -199,7 +199,7 @@
 	};
 }
 
-bool geom::isConvex(const std::vector<glm::vec3>& polygon)
+bool isConvex(const std::vector<glm::vec3>& polygon)
 {
 	const int n = polygon.size();
 	auto polygonRing = iter::ring(polygon, n);
@@ -223,7 +223,7 @@
  * @param polygon
  * @return winding
  */
-Winding geom::winding(const QPolygonF &polygon)
+Winding winding(const QPolygonF &polygon)
 {
 	// based on https://stackoverflow.com/a/1165943
 	double sum = 0.0;
@@ -242,7 +242,7 @@
  * @param t scalar between 0 and 1, with t=0 being P0 and t=1 being P3
  * @return point on curve
  */
-glm::vec3 geom::pointOnCurve(const BezierCurve &curve, float t)
+glm::vec3 pointOnCurve(const BezierCurve &curve, float t)
 {
 	// clamp t as rounding errors might make it slightly out of bounds
 	t = std::clamp(t, 0.0f, 1.0f);
@@ -262,7 +262,7 @@
  * @param t scalar between 0 and 1, with t=0 being P0 and t=1 being P3
  * @return point on curve
  */
-glm::vec3 geom::derivativeOnCurve(const BezierCurve &curve, float t)
+glm::vec3 derivativeOnCurve(const BezierCurve &curve, float t)
 {
 	// clamp t as rounding errors might make it slightly out of bounds
 	t = std::clamp(t, 0.0f, 1.0f);

mercurial