Wed, 16 Oct 2013 16:04:56 +0300
ring finder integrated! it lives!
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/gldraw.h | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/misc.h | file | annotate | diff | comparison | revisions |
--- a/src/gldraw.cpp Wed Oct 16 15:32:38 2013 +0300 +++ b/src/gldraw.cpp Wed Oct 16 16:04:56 2013 +0300 @@ -1324,6 +1324,21 @@ // ============================================================================= // ----------------------------------------------------------------------------- +matrix GLRenderer::getCircleDrawMatrix (double scale) +{ matrix transform = g_circleDrawTransforms[camera() % 3]; + + for (int i = 0; i < 9; ++i) + { if (transform[i] == 2) + transform[i] = scale; + elif (transform[i] == 1 && camera() >= 3) + transform[i] = -1; + } + + return transform; +} + +// ============================================================================= +// ----------------------------------------------------------------------------- void GLRenderer::endDraw (bool accept) { (void) accept; @@ -1383,32 +1398,39 @@ { const int segs = lores, divs = lores; // TODO: make customizable double dist0 = circleDrawDist (0), dist1 = circleDrawDist (1); - enum {Circle, Ring, Disc, CustomRing} type = Ring; - int num = 0; - double scale; + LDFile* refFile = null; + matrix transform; + bool circleOrDisc = false; if (dist1 < dist0) std::swap<double> (dist0, dist1); if (dist0 == dist1) - { scale = dist0; - type = Circle; - } elif (dist0 == 0 || dist1 == 0) - { scale = (dist0 != 0) ? dist0 : dist1; - type = Disc; - } else - { /* scale = |r1 - r0| - number = r0 / scale */ - scale = abs (dist1 - dist0); - assert (scale != 0); + { refFile = getFile ("4-4edge.dat"); + transform = getCircleDrawMatrix (dist0); + circleOrDisc = true; + } + elif (dist0 == 0 || dist1 == 0) + { refFile = getFile ("4-4disc.dat"); + transform = getCircleDrawMatrix ((dist0 != 0) ? dist0 : dist1); + circleOrDisc = true; + } + elif (g_RingFinder (dist0, dist1) /* && g_RingFinder.solution().size() <= 3 */) + { for (const RingFinder::SolutionComponent& cmp : g_RingFinder.solution()) + { if ((refFile = getFile (radialFileName (::Ring, lores, lores, cmp.num))) == null) + { refFile = generatePrimitive (::Ring, lores, lores, cmp.num); + refFile->setImplicit (false); + } - if (!isInteger (dist0) || !isInteger (scale) || (((int) dist0) % ((int) scale)) != 0) - type = CustomRing; // Non-integer ring number - make a custom ring - else - num = ((int) dist0) / ((int) scale); + LDSubfile* ref = new LDSubfile; + ref->setFileInfo (refFile); + ref->setTransform (getCircleDrawMatrix (cmp.scale)); + ref->setPosition (m_drawedVerts[0]); + ref->setColor (maincolor); + objs << ref; + } } - - if (type == CustomRing) + else { // Last resort: draw the ring with quads List<QLineF> c0, c1; @@ -1419,42 +1441,14 @@ { } } - else - { matrix transform = g_circleDrawTransforms[camera() % 3]; - LDFile* refFile = null; - for (int i = 0; i < 9; ++i) - { if (transform[i] == 2) - transform[i] = scale; - elif (transform[i] == 1 && camera() >= 3) - transform[i] = -1; - } - - switch (type) - { case Circle: - { refFile = getFile ("4-4edge.dat"); - } break; - - case Disc: - { refFile = getFile ("4-4disc.dat"); - } break; - - case Ring: - { if ((refFile = getFile (radialFileName (::Ring, lores, lores, num))) == null) - { refFile = generatePrimitive (::Ring, lores, lores, num); - refFile->setImplicit (false); - } - } break; - } - - if (refFile) - { LDSubfile* ref = new LDSubfile; - ref->setFileInfo (refFile); - ref->setTransform (transform); - ref->setPosition (m_drawedVerts[0]); - ref->setColor (maincolor); - objs << ref; - } + if (circleOrDisc) + { LDSubfile* ref = new LDSubfile; + ref->setFileInfo (refFile); + ref->setTransform (transform); + ref->setPosition (m_drawedVerts[0]); + ref->setColor (maincolor); + objs << ref; } } break;
--- a/src/gldraw.h Wed Oct 16 15:32:38 2013 +0300 +++ b/src/gldraw.h Wed Oct 16 16:04:56 2013 +0300 @@ -182,6 +182,7 @@ void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list QColor getTextPen() const; // Determine which color to draw text with void getRelativeAxes (Axis& relX, Axis& relY) const; + matrix getCircleDrawMatrix (double scale); void drawBlip (QPainter& paint, QPoint pos) const; double circleDrawDist(int pos) const;
--- a/src/misc.cpp Wed Oct 16 15:32:38 2013 +0300 +++ b/src/misc.cpp Wed Oct 16 16:04:56 2013 +0300 @@ -316,9 +316,15 @@ // as it would fall into an infinite recursion. // ----------------------------------------------------------------------------- bool RingFinder::findRings (double r0, double r1) +{ m_solution.clear(); + return findRingsRecursor (r0, r1); +} + +bool RingFinder::findRingsRecursor (double r0, double r1) { // Find the scale and number of a ring between r1 and r0. double scale = r1 - r0; double num = r0 / scale; + print ("r0: %1, r1: %2, scale: %3, num: %4\n", r0, r1, scale, num); // If the ring number is integral, we have found a fitting ring to r0 -> r1! if (isInteger (num)) @@ -330,16 +336,19 @@ else { // If not, find an intermediate <r> between the radii double r = ceil (num) * scale; + print ("\tr: %1\n", r); // If r is the same as r0 or r1, we simply cannot find any rings between // r0 and r1. Stop and return failure. if (isZero (r0 - r) || isZero (r1 - r)) + { print ("failure!\n"); return false; + } // Split this ring into r0 -> r and r -> r1. Recurse to possibly find // the rings for these. If either recurse fails, the entire algorithm // fails as well. - if (!findRings (r0, r) || !findRings (r, r1)) + if (!findRingsRecursor (r0, r) || !findRingsRecursor (r, r1)) return false; }