From 1dd95f603c65853ae9ad0400267b8e5627eda0a0 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Fri, 14 Feb 2025 17:13:05 -0300 Subject: [PATCH 1/3] ofRectangle changes to avoid including ofVectorMath.h --- libs/openFrameworks/types/ofRectangle.cpp | 15 +++++++++------ scripts/apothecary | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/openFrameworks/types/ofRectangle.cpp b/libs/openFrameworks/types/ofRectangle.cpp index 8b142d420f9..5cb2bd5f270 100644 --- a/libs/openFrameworks/types/ofRectangle.cpp +++ b/libs/openFrameworks/types/ofRectangle.cpp @@ -1,6 +1,5 @@ #include "ofRectangle.h" #include "ofLog.h" -#include "ofVectorMath.h" #include "ofMath.h" using std::ostream; @@ -756,7 +755,7 @@ float ofRectangle::getHeight() const { //---------------------------------------------------------- glm::vec2 ofRectangle::map(const glm::vec2 & coeff) const { return glm::vec2( - ofMap(coeff.x, 0.0f, 1.0f, getMinX(), getMaxX(), false), + ofMap(coeff.x, 0.0f, 1.0f, getMinX(), getMaxX(), false), ofMap(coeff.y, 0.0f, 1.0f, getMinY(), getMaxY(), false) ); } @@ -772,7 +771,7 @@ ofRectangle ofRectangle::map(const ofRectangle & coeff) const { glm::vec2 ofRectangle::mapClamp(const glm::vec2 & coeff) const { return glm::vec2( - ofMap(coeff.x, 0.0f, 1.0f, getMinX(), getMaxX(), true), + ofMap(coeff.x, 0.0f, 1.0f, getMinX(), getMaxX(), true), ofMap(coeff.y, 0.0f, 1.0f, getMinY(), getMaxY(), true) ); } @@ -783,7 +782,7 @@ ofRectangle ofRectangle::mapClamp(const ofRectangle & coeff) const { mapClamp(glm::vec2(coeff.getMaxX(), coeff.getMaxY())) ); } - + //---------------------------------------------------------- ofRectangle& ofRectangle::operator = (const ofRectangle& rect) { @@ -829,13 +828,17 @@ bool ofRectangle::isZero() const{ //---------------------------------------------------------- ostream& operator<<(ostream& os, const ofRectangle& rect){ - os << rect.position << ", " << rect.width << ", " << rect.height; + os << rect.position.x << ", " << rect.position.y << ", " << rect.width << ", " << rect.height; return os; } //---------------------------------------------------------- istream& operator>>(istream& is, ofRectangle& rect){ - is >> rect.position; + is >> rect.position.x; + is.ignore(2); + is >> rect.position.y; + is.ignore(2); + is >> rect.position.z; is.ignore(2); is >> rect.width; is.ignore(2); diff --git a/scripts/apothecary b/scripts/apothecary index 5c0f7bab40d..2d2f7ad685a 160000 --- a/scripts/apothecary +++ b/scripts/apothecary @@ -1 +1 @@ -Subproject commit 5c0f7bab40da5a59ef354c7135535566d4fcc225 +Subproject commit 2d2f7ad685abb329363a82955779f26c4cd1d39b From 1e0d6e41d6d6392044111e6b9fff6eb7189d779a Mon Sep 17 00:00:00 2001 From: Dimitre Date: Fri, 14 Feb 2025 17:28:08 -0300 Subject: [PATCH 2/3] ofPolyline ofVectorMath.h removal --- libs/openFrameworks/graphics/ofPolyline.inl | 158 ++++++++++---------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/libs/openFrameworks/graphics/ofPolyline.inl b/libs/openFrameworks/graphics/ofPolyline.inl index a02ff15d6d2..a8b63db9ff0 100644 --- a/libs/openFrameworks/graphics/ofPolyline.inl +++ b/libs/openFrameworks/graphics/ofPolyline.inl @@ -4,11 +4,12 @@ #include "ofRectangle.h" #include "ofGraphicsBaseTypes.h" -#include "ofVectorMath.h" #include "ofAppRunner.h" #include "ofLog.h" #include "ofMath.h" +#include + //---------------------------------------------------------- template ofPolyline_::ofPolyline_(){ @@ -187,7 +188,7 @@ template void ofPolyline_::setCircleResolution(int res){ if (res > 1 && res != (int)circlePoints.size()){ circlePoints.resize(res); - + float angle = 0.0f; const float angleAdder = glm::two_pi() / (float)res; for (int i = 0; i < res; i++){ @@ -215,34 +216,34 @@ void ofPolyline_::bezierTo( const T & cp1, const T & cp2, const T & to, int c // if, and only if poly vertices has points, we can make a bezier // from the last point curveVertices.clear(); - + // the resolultion with which we computer this bezier // is arbitrary, can we possibly make it dynamic? - + if (size() > 0){ float x0 = points[size()-1].x; float y0 = points[size()-1].y; float z0 = points[size()-1].z; - + float ax, bx, cx; float ay, by, cy; float az, bz, cz; float t, t2, t3; float x, y, z; - + // polynomial coefficients cx = 3.0f * (cp1.x - x0); bx = 3.0f * (cp2.x - cp1.x) - cx; ax = to.x - x0 - cx - bx; - + cy = 3.0f * (cp1.y - y0); by = 3.0f * (cp2.y - cp1.y) - cy; ay = to.y - y0 - cy - by; - + cz = 3.0f * (cp1.z - z0); bz = 3.0f * (cp2.z - cp1.z) - cz; az = to.z - z0 - cz - bz; - + for (int i = 1; i <= curveResolution; i++){ t = (float)i / (float)(curveResolution); t2 = t * t; @@ -276,11 +277,11 @@ void ofPolyline_::quadBezierTo(float x1, float y1, float z1, float x2, float //---------------------------------------------------------- template void ofPolyline_::curveTo( const T & to, int curveResolution ){ - + curveVertices.push_back(to); - + if (curveVertices.size() == 4){ - + float x0 = curveVertices[0].x; float y0 = curveVertices[0].y; float z0 = curveVertices[0].z; @@ -293,31 +294,31 @@ void ofPolyline_::curveTo( const T & to, int curveResolution ){ float x3 = curveVertices[3].x; float y3 = curveVertices[3].y; float z3 = curveVertices[3].z; - + float t,t2,t3; float x,y,z; - + for (int i = 1; i <= curveResolution; i++){ - + t = (float)i / (float)(curveResolution); t2 = t * t; t3 = t2 * t; - + x = 0.5f * ( ( 2.0f * x1 ) + ( -x0 + x2 ) * t + ( 2.0f * x0 - 5.0f * x1 + 4 * x2 - x3 ) * t2 + ( -x0 + 3.0f * x1 - 3.0f * x2 + x3 ) * t3 ); - + y = 0.5f * ( ( 2.0f * y1 ) + ( -y0 + y2 ) * t + ( 2.0f * y0 - 5.0f * y1 + 4 * y2 - y3 ) * t2 + ( -y0 + 3.0f * y1 - 3.0f * y2 + y3 ) * t3 ); - + z = 0.5f * ( ( 2.0f * z1 ) + ( -z0 + z2 ) * t + ( 2.0f * z0 - 5.0f * z1 + 4 * z2 - z3 ) * t2 + ( -z0 + 3.0f * z1 - 3.0f * z2 + z3 ) * t3 ); - + points.emplace_back(x,y,z); } curveVertices.pop_front(); @@ -328,40 +329,40 @@ void ofPolyline_::curveTo( const T & to, int curveResolution ){ //---------------------------------------------------------- template void ofPolyline_::arc(const T & center, float radiusX, float radiusY, float angleBegin, float angleEnd, bool clockwise, int circleResolution){ - + if(circleResolution<=1) circleResolution=2; setCircleResolution(circleResolution); points.reserve(points.size()+circleResolution); const float epsilon = 0.0001f; - + const size_t nCirclePoints = circlePoints.size(); float segmentArcSize = glm::two_pi() / (float)nCirclePoints; - + // convert angles to radians and wrap them into the range 0 - glm::two_pi() and float angleBeginRad = wrapAngle(glm::radians(angleBegin)); float angleEndRad = wrapAngle(glm::radians(angleEnd)); - + while(angleBeginRad >= angleEndRad) angleEndRad += glm::two_pi(); - + // determine the directional angle delta float d = clockwise ? angleEndRad - angleBeginRad : angleBeginRad - angleEndRad; // find the shortest angle delta, clockwise delta direction yeilds POSITIVE values float deltaAngle = std::atan2(std::sin(d),std::cos(d)); - + // establish the remaining angle that we have to work through float remainingAngle = deltaAngle; - + // if the delta angle is in the CCW direction OR the start and stop angles are // effectively the same adjust the remaining angle to be a be a full rotation if(deltaAngle < 0 || std::abs(deltaAngle) < epsilon) remainingAngle += glm::two_pi(); - + T radii(radiusX, radiusY, 0.f); T point(0); - + int currentLUTIndex = 0; bool isFirstPoint = true; // special case for the first point - + while(remainingAngle > 0) { if(isFirstPoint) { // TODO: should this be the exact point on the circle or @@ -378,13 +379,13 @@ void ofPolyline_::arc(const T & center, float radiusX, float radiusY, float a // the angle between the beginning angle and the next angle in the LUT table float d = clockwise ? (lutAngleAtIndex - angleBeginRad) : (angleBeginRad - lutAngleAtIndex); float firstPointDelta = std::atan2(std::sin(d),std::cos(d)); // negative is in the clockwise direction - + // if the are "equal", get the next one CCW if(std::abs(firstPointDelta) < epsilon) { currentLUTIndex = clockwise ? (currentLUTIndex + 1) : (currentLUTIndex - 1); firstPointDelta = segmentArcSize; // we start at the next lut point } - + // start counting from the offset remainingAngle -= firstPointDelta; isFirstPoint = false; @@ -400,18 +401,18 @@ void ofPolyline_::arc(const T & center, float radiusX, float radiusY, float a // if the angle overshoots, then the while loop will fail next time } } - + // keep the current lut index in range if(clockwise) { currentLUTIndex = currentLUTIndex % nCirclePoints; } else { if(currentLUTIndex < 0) currentLUTIndex = nCirclePoints + currentLUTIndex; } - + // add the point to the poly line point = point * radii + center; points.push_back(point); - + // if the next LUT point moves us past the end angle then // add a a point a the exact end angle and call it finished if(remainingAngle < epsilon) { @@ -452,7 +453,7 @@ T ofPolyline_::getCentroid2D() const{ //---------------------------------------------------------- template ofRectangle ofPolyline_::getBoundingBox() const { - + ofRectangle box; for(size_t i = 0; i < size(); i++) { if(i == 0) { @@ -470,7 +471,7 @@ ofPolyline_ ofPolyline_::getSmoothed(int smoothingSize, float smoothingSha int n = size(); smoothingSize = ofClamp(smoothingSize, 0, n); smoothingShape = ofClamp(smoothingShape, 0, 1); - + // precompute weights and normalization std::vector weights; weights.resize(smoothingSize); @@ -479,10 +480,10 @@ ofPolyline_ ofPolyline_::getSmoothed(int smoothingSize, float smoothingSha float curWeight = ofMap(i, 0, smoothingSize, 1, smoothingShape); weights[i] = curWeight; } - + // make a copy of this polyline ofPolyline_ result = *this; - + for(int i = 0; i < n; i++) { float sum = 1; // center weight for(int j = 1; j < smoothingSize; j++) { @@ -507,7 +508,7 @@ ofPolyline_ ofPolyline_::getSmoothed(int smoothingSize, float smoothingSha } result[i] /= sum; } - + return result; } @@ -521,7 +522,7 @@ ofPolyline_ ofPolyline_::getResampledBySpacing(float spacing) const { for(f=0; f<=totalLength; f += spacing) { poly.lineTo(getPointAtLength(f)); } - + if(!isClosed()) { if( f != totalLength ){ poly.lineTo(points.back()); @@ -530,7 +531,7 @@ ofPolyline_ ofPolyline_::getResampledBySpacing(float spacing) const { } else { poly.setClosed(true); } - + return poly; } @@ -556,13 +557,13 @@ inline T getClosestPointUtil(const T& p1, const T& p2, const T& p3, float* norma } return p1; } - + float u = (p3.x - p1.x) * (p2.x - p1.x); u += (p3.y - p1.y) * (p2.y - p1.y); // perfect place for fast inverse sqrt... float len = glm::length(toGlm(p2 - p1)); u /= (len * len); - + // clamp u if(u > 1) { u = 1; @@ -581,14 +582,14 @@ template // which assumes vertices are evenly spaced T ofPolyline_::getClosestPoint(const T& target, unsigned int* nearestIndex) const { const ofPolyline_ & polyline = *this; - + if(polyline.size() < 2) { if(nearestIndex != nullptr) { nearestIndex = 0; } return target; } - + float distance = 0; T nearestPoint(0); unsigned int nearest = 0; @@ -599,10 +600,10 @@ T ofPolyline_::getClosestPoint(const T& target, unsigned int* nearestIndex) c } for(int i = 0; i < (int) lastPosition; i++) { bool repeatNext = i == (int) (polyline.size() - 1); - + const auto& cur = polyline[i]; const auto& next = repeatNext ? polyline[0] : polyline[i + 1]; - + float curNormalizedPosition = 0; auto curNearestPoint = getClosestPointUtil(cur, next, target, &curNormalizedPosition); float curDistance = glm::distance(toGlm(curNearestPoint), toGlm(target)); @@ -613,7 +614,7 @@ T ofPolyline_::getClosestPoint(const T& target, unsigned int* nearestIndex) c normalizedPosition = curNormalizedPosition; } } - + if(nearestIndex != nullptr) { if(normalizedPosition > .5) { nearest++; @@ -623,7 +624,7 @@ T ofPolyline_::getClosestPoint(const T& target, unsigned int* nearestIndex) c } *nearestIndex = nearest; } - + return nearestPoint; } @@ -640,9 +641,9 @@ bool ofPolyline_::inside(float x, float y, const ofPolyline_ & polyline){ int i; double xinters; T p1,p2; - + int N = polyline.size(); - + p1 = polyline[0]; for (i=1;i<=N;i++) { p2 = polyline[i % N]; @@ -659,7 +660,7 @@ bool ofPolyline_::inside(float x, float y, const ofPolyline_ & polyline){ } p1 = p2; } - + if (counter % 2 == 0) return false; else return true; } @@ -668,7 +669,7 @@ bool ofPolyline_::inside(float x, float y, const ofPolyline_ & polyline){ template bool ofPolyline_::inside(float x, float y) const { return ofPolyline_::inside(x, y, *this); - + } //-------------------------------------------------- @@ -754,50 +755,50 @@ namespace of{ template void ofPolyline_::simplify(float tol){ if(points.size() < 2) return; - + int n = size(); - + if(n == 0) { return; } std::vector sV; sV.resize(n); - + int i, k, m, pv; // misc counters float tol2 = tol * tol; // tolerance squared std::vector vt; std::vector mk; vt.resize(n); mk.resize(n,0); - - + + // STAGE 1. Vertex Reduction within tolerance of prior vertex cluster vt[0] = points[0]; // start at the beginning for (i=k=1, pv=0; i float ofPolyline_::getIndexAtLength(float length) const { if(points.size() < 2) return 0; updateCache(); - + float totalLength = getPerimeter(); length = ofClamp(length, 0, totalLength); - + int lastPointIndex = isClosed() ? points.size() : points.size()-1; - + int i1 = ofClamp(std::floor(length / totalLength * lastPointIndex), 0, lengths.size()-2); // start approximation here int leftLimit = 0; int rightLimit = lastPointIndex; - + float distAt1, distAt2; for(int iterations = 0; iterations < 32; iterations ++) { // limit iterations i1 = ofClamp(i1, 0, lengths.size()-1); @@ -1092,12 +1093,12 @@ void ofPolyline_::calcData(int index, T &tangent, float &angle, T &rotation, auto v1(p1 - p2); // vector to previous point auto v2(p3 - p2); // vector to next point - + v1 = glm::normalize(v1); v2 = glm::normalize(v2); - // If just one of p1, p2, or p3 was identical, further calculations - // are (almost literally) pointless, as v1 or v2 will then contain + // If just one of p1, p2, or p3 was identical, further calculations + // are (almost literally) pointless, as v1 or v2 will then contain // NaN values instead of floats. bool noSegmentHasZeroLength = (v1 == v1 && v2 == v2); @@ -1118,7 +1119,7 @@ void ofPolyline_::calcData(int index, T &tangent, float &angle, T &rotation, template int ofPolyline_::getWrappedIndex(int index) const { if(points.empty()) return 0; - + if(index < 0) return isClosed() ? (index + points.size()) % points.size() : 0; if(index > int(points.size())-1) return isClosed() ? index % points.size() : points.size() - 1; return index; @@ -1145,7 +1146,7 @@ void ofPolyline_::updateCache(bool bForceUpdate) const { area = 0; centroid2D = {0.f, 0.f, 0.f}; bCacheIsDirty = false; - + if(points.size() < 2) return; // area @@ -1154,7 +1155,7 @@ void ofPolyline_::updateCache(bool bForceUpdate) const { } area += points[points.size()-1].x * points[0].y - points[0].x * points[points.size()-1].y; area *= 0.5; - + if(fabsf(area) < std::numeric_limits::epsilon()) { centroid2D = getBoundingBox().getCenter(); } else { @@ -1166,19 +1167,19 @@ void ofPolyline_::updateCache(bool bForceUpdate) const { } centroid2D.x += (points[points.size()-1].x + points[0].x) * (points[points.size()-1].x*points[0].y - points[0].x*points[points.size()-1].y); centroid2D.y += (points[points.size()-1].y + points[0].y) * (points[points.size()-1].x*points[0].y - points[0].x*points[points.size()-1].y); - + centroid2D.x /= (6*area); centroid2D.y /= (6*area); } - + // per vertex cache lengths.resize(points.size()); tangents.resize(points.size()); angles.resize(points.size()); normals.resize(points.size()); rotations.resize(points.size()); - + float angle; T rotation; T normal; @@ -1193,10 +1194,10 @@ void ofPolyline_::updateCache(bool bForceUpdate) const { angles[i] = angle; rotations[i] = rotation; normals[i] = normal; - + length += glm::distance(toGlm(points[i]), toGlm(points[getWrappedIndex(i + 1)])); } - + if(isClosed()) lengths.push_back(length); } } @@ -1249,4 +1250,3 @@ template typename std::vector::const_reverse_iterator ofPolyline_::rend() const{ return points.rend(); } - From 14df4b8f514e6731a3cf255ccaa092b82ca35147 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Fri, 14 Feb 2025 18:16:28 -0300 Subject: [PATCH 3/3] more changes --- libs/openFrameworks/3d/of3dPrimitives.cpp | 7 ++++--- libs/openFrameworks/3d/ofMesh.inl | 3 +++ libs/openFrameworks/3d/ofNode.cpp | 1 + libs/openFrameworks/gl/ofVbo.cpp | 1 + libs/openFrameworks/graphics/ofPolyline.inl | 3 ++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/openFrameworks/3d/of3dPrimitives.cpp b/libs/openFrameworks/3d/of3dPrimitives.cpp index 7ae27839329..e4b8bdb8206 100644 --- a/libs/openFrameworks/3d/of3dPrimitives.cpp +++ b/libs/openFrameworks/3d/of3dPrimitives.cpp @@ -12,6 +12,7 @@ #include "ofVboMesh.h" #include "ofTexture.h" #include "of3dUtils.h" +#include "ofVectorMath.h" using std::vector; using std::shared_ptr; @@ -242,11 +243,11 @@ void of3dPrimitive::drawNormals(float length, bool bFaceNormals) const{ if(bFaceNormals) { for(size_t i = 0; i < normals.size(); i++ ) { if(i % 3 == 0) { - vert = (vertices[i]+vertices[i+1]+vertices[i+2]) / 3; + vert = (vertices[i]+vertices[i+1]+vertices[i+2]) / 3.0f; } else if(i % 3 == 1) { - vert = (vertices[i-1]+vertices[i]+vertices[i+1]) / 3; + vert = (vertices[i-1]+vertices[i]+vertices[i+1]) / 3.0f; } else if ( i % 3 == 2) { - vert = (vertices[i-2]+vertices[i-1]+vertices[i]) / 3; + vert = (vertices[i-2]+vertices[i-1]+vertices[i]) / 3.0f; } normalsMesh.setVertex(i*2, vert); normal = glm::normalize(toGlm(normals[i])); diff --git a/libs/openFrameworks/3d/ofMesh.inl b/libs/openFrameworks/3d/ofMesh.inl index f738ead0cc2..e9e5363b0fc 100644 --- a/libs/openFrameworks/3d/ofMesh.inl +++ b/libs/openFrameworks/3d/ofMesh.inl @@ -4,11 +4,14 @@ #include "ofAppRunner.h" #include "ofGraphicsBaseTypes.h" +// it can be removed if other PR is merged #8178 #include "ofVectorMath.h" #include "ofLog.h" #include "ofColor.h" #include "ofUtils.h" // ofTo +//#include + #include //-------------------------------------------------------------- diff --git a/libs/openFrameworks/3d/ofNode.cpp b/libs/openFrameworks/3d/ofNode.cpp index 13cc516a135..f727599472a 100644 --- a/libs/openFrameworks/3d/ofNode.cpp +++ b/libs/openFrameworks/3d/ofNode.cpp @@ -5,6 +5,7 @@ #define GLM_FORCE_CTOR_INIT #define GLM_ENABLE_EXPERIMENTAL #include +#include "ofVectorMath.h" //---------------------------------------- ofNode::ofNode() diff --git a/libs/openFrameworks/gl/ofVbo.cpp b/libs/openFrameworks/gl/ofVbo.cpp index 4770b505d26..b9743c13505 100644 --- a/libs/openFrameworks/gl/ofVbo.cpp +++ b/libs/openFrameworks/gl/ofVbo.cpp @@ -11,6 +11,7 @@ #include "ofGLUtils.h" #include "ofMesh.h" #include "ofGLBaseTypes.h" +#include "ofVec3f.h" #ifdef TARGET_ANDROID #include "ofAppAndroidWindow.h" diff --git a/libs/openFrameworks/graphics/ofPolyline.inl b/libs/openFrameworks/graphics/ofPolyline.inl index a8b63db9ff0..c976ef8a64a 100644 --- a/libs/openFrameworks/graphics/ofPolyline.inl +++ b/libs/openFrameworks/graphics/ofPolyline.inl @@ -8,7 +8,8 @@ #include "ofLog.h" #include "ofMath.h" -#include +#include // toGlm +//#include //---------------------------------------------------------- template