void testNatural(const Spline &sp, const double *x, const double *y) { // test the common properties of splines testCommon(sp, x, y); static double eps = 1e-5; size_t n = sp.numSamples(); // make sure the second derivatives at both end points are 0 double d0 = sp.evalDerivative(x[0]); double d1 = sp.evalDerivative(x[0] + eps); double d2 = sp.evalDerivative(x[n-1] - eps); double d3 = sp.evalDerivative(x[n-1]); if (std::abs(d1 - d0)/eps > 1000*eps) OPM_THROW(std::runtime_error, "Invalid second derivative at beginning of interval: is " << (d1 - d0)/eps << " ought to be 0"); if (std::abs(d3 - d2)/eps > 1000*eps) OPM_THROW(std::runtime_error, "Invalid second derivative at end of interval: is " << (d3 - d2)/eps << " ought to be 0"); }
static void test(const SkPath& path, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) { SkTArray<SimplifyFindTopTest::Contour> contours; SimplifyFindTopTest::EdgeBuilder builder(path, contours); int index, end; const SimplifyFindTopTest::Segment* topSegment = testCommon(contours, index, end); SkPoint pts[2]; double firstT = topSegment->t(index); pts[0] = topSegment->xyAtT(&topSegment->span(index)); int direction = index < end ? 1 : -1; do { index += direction; double nextT = topSegment->t(index); if (nextT == firstT) { continue; } pts[1] = topSegment->xyAtT(&topSegment->span(index)); if (pts[0] != pts[1]) { break; } } while (true); SkASSERT(pts[0].fX == x1); SkASSERT(pts[0].fY == y1); SkASSERT(pts[1].fX == x2); SkASSERT(pts[1].fY == y2); }
static void test(const SkPath& path) { SkTArray<SimplifyFindTopTest::Contour> contours; SimplifyFindTopTest::EdgeBuilder builder(path, contours); int index, end; testCommon(contours, index, end); SkASSERT(index + 1 == end); }
static void test(const SkPath& path, int start, int end) { SkTArray<SimplifyFindNextTest::Contour> contours; SimplifyFindNextTest::EdgeBuilder builder(path, contours); int contourWinding = 0; int spanWinding = 1; testCommon(contourWinding, spanWinding, start, end, contours); }
void testMonotonic(const Spline &sp, const double *x, const double *y) { // test the common properties of splines testCommon(sp, x, y); size_t n = sp.numSamples(); for (size_t i = 0; i < n - 1; ++ i) { // make sure that the spline is monotonic for each interval // between sampling points if (!sp.monotonic(x[i], x[i + 1])) OPM_THROW(std::runtime_error, "Spline says it is not monotonic in interval " << i << " where it should be"); // test the intersection methods double d = (y[i] + y[i+1])/2; double interX = sp.template intersectInterval<double>(x[i], x[i+1], /*a=*/0, /*b=*/0, /*c=*/0, d); double interY = sp.eval(interX); if (std::abs(interY - d) > 1e-5) OPM_THROW(std::runtime_error, "Spline::intersectInterval() seems to be broken: " << sp.eval(interX) << " - " << d << " = " << sp.eval(interX) - d << "!"); } // make sure the spline says to be monotonic on the (extrapolated) // left and right sides if (!sp.monotonic(x[0] - 1.0, (x[0] + x[1])/2, /*extrapolate=*/true)) OPM_THROW(std::runtime_error, "Spline says it is not monotonic on left side where it should be"); if (!sp.monotonic((x[n - 2]+ x[n - 1])/2, x[n-1] + 1.0, /*extrapolate=*/true)) OPM_THROW(std::runtime_error, "Spline says it is not monotonic on right side where it should be"); for (size_t i = 0; i < n - 2; ++ i) { // make sure that the spline says that it is non-monotonic for // if extrema are within the queried interval if (sp.monotonic((x[i] + x[i + 1])/2, (x[i + 1] + x[i + 2])/2)) OPM_THROW(std::runtime_error, "Spline says it is monotonic in interval " << i << " where it should not be"); } }
void testFull(const Spline &sp, const double *x, const double *y, double m0, double m1) { // test the common properties of splines testCommon(sp, x, y); static double eps = 1e-5; size_t n = sp.numSamples(); // make sure the derivative at both end points is correct double d0 = sp.evalDerivative(x[0]); double d1 = sp.evalDerivative(x[n-1]); if (std::abs(d0 - m0) > eps) OPM_THROW(std::runtime_error, "Invalid derivative at beginning of interval: is " << d0 << " ought to be " << m0); if (std::abs(d1 - m1) > eps) OPM_THROW(std::runtime_error, "Invalid derivative at end of interval: is " << d1 << " ought to be " << m1); }
void occQt::createActions( void ) { mExitAction = new QAction(tr("Exit"), this); mExitAction->setShortcut(tr("Ctrl+Q")); mExitAction->setIcon(QIcon(":/Resources/close.png")); mExitAction->setStatusTip(tr("Exit the application")); connect(mExitAction, SIGNAL(triggered()), this, SLOT(close())); mViewZoomAction = new QAction(tr("Zoom"), this); mViewZoomAction->setIcon(QIcon(":/Resources/Zoom.png")); mViewZoomAction->setStatusTip(tr("Zoom the view")); connect(mViewZoomAction, SIGNAL(triggered()), mOccView, SLOT(zoom())); mViewPanAction = new QAction(tr("Pan"), this); mViewPanAction->setIcon(QIcon(":/Resources/Pan.png")); mViewPanAction->setStatusTip(tr("Pan the view")); connect(mViewPanAction, SIGNAL(triggered()), mOccView, SLOT(pan())); mViewRotateAction = new QAction(tr("Rotate"), this); mViewRotateAction->setIcon(QIcon(":/Resources/Rotate.png")); mViewRotateAction->setStatusTip(tr("Rotate the view")); connect(mViewRotateAction, SIGNAL(triggered()), mOccView, SLOT(rotate())); mViewResetAction = new QAction(tr("Reset"), this); mViewResetAction->setIcon(QIcon(":/Resources/Home.png")); mViewResetAction->setStatusTip(tr("Reset the view")); connect(mViewResetAction, SIGNAL(triggered()), mOccView, SLOT(reset())); mViewFitallAction = new QAction(tr("Fit All"), this); mViewFitallAction->setIcon(QIcon(":/Resources/FitAll.png")); mViewFitallAction->setStatusTip(tr("Fit all ")); connect(mViewFitallAction, SIGNAL(triggered()), mOccView, SLOT(fitAll())); mMakeBoxAction = new QAction(tr("Box"), this); mMakeBoxAction->setIcon(QIcon(":/Resources/box.png")); mMakeBoxAction->setStatusTip(tr("Make a box")); connect(mMakeBoxAction, SIGNAL(triggered()), this, SLOT(makeBox())); mMakeConeAction = new QAction(tr("Cone"), this); mMakeConeAction->setIcon(QIcon(":/Resources/cone.png")); mMakeConeAction->setStatusTip(tr("Make a cone")); connect(mMakeConeAction, SIGNAL(triggered()), this, SLOT(makeCone())); mMakeSphereAction = new QAction(tr("Sphere"), this); mMakeSphereAction->setStatusTip(tr("Make a sphere")); mMakeSphereAction->setIcon(QIcon(":/Resources/sphere.png")); connect(mMakeSphereAction, SIGNAL(triggered()), this, SLOT(makeSphere())); mMakeCylinderAction = new QAction(tr("Cylinder"), this); mMakeCylinderAction->setStatusTip(tr("Make a cylinder")); mMakeCylinderAction->setIcon(QIcon(":/Resources/cylinder.png")); connect(mMakeCylinderAction, SIGNAL(triggered()), this, SLOT(makeCylinder())); mMakeTorusAction = new QAction(tr("Torus"), this); mMakeTorusAction->setStatusTip(tr("Make a torus")); mMakeTorusAction->setIcon(QIcon(":/Resources/torus.png")); connect(mMakeTorusAction, SIGNAL(triggered()), this, SLOT(makeTorus())); mFilletAction = new QAction(tr("Fillet"), this); mFilletAction->setIcon(QIcon(":/Resources/fillet.png")); mFilletAction->setStatusTip(tr("Test Fillet algorithm")); connect(mFilletAction, SIGNAL(triggered()), this, SLOT(makeFillet())); mChamferAction = new QAction(tr("Chamfer"), this); mChamferAction->setIcon(QIcon(":/Resources/chamfer.png")); mChamferAction->setStatusTip(tr("Test chamfer algorithm")); connect(mChamferAction, SIGNAL(triggered()), this, SLOT(makeChamfer())); mExtrudeAction = new QAction(tr("Extrude"), this); mExtrudeAction->setIcon(QIcon(":/Resources/extrude.png")); mExtrudeAction->setStatusTip(tr("Test extrude algorithm")); connect(mExtrudeAction, SIGNAL(triggered()), this, SLOT(makeExtrude())); mRevolveAction = new QAction(tr("Revolve"), this); mRevolveAction->setIcon(QIcon(":/Resources/revolve.png")); mRevolveAction->setStatusTip(tr("Test revol algorithm")); connect(mRevolveAction, SIGNAL(triggered()), this, SLOT(makeRevol())); mLoftAction = new QAction(tr("Loft"), this); mLoftAction->setIcon(QIcon(":/Resources/loft.png")); mLoftAction->setStatusTip(tr("Test loft algorithm")); connect(mLoftAction, SIGNAL(triggered()), this, SLOT(makeLoft())); mCutAction = new QAction(tr("Cut"), this); mCutAction->setIcon(QIcon(":/Resources/cut.png")); mCutAction->setStatusTip(tr("Boolean operation cut")); connect(mCutAction, SIGNAL(triggered()), this, SLOT(testCut())); mFuseAction = new QAction(tr("Fuse"), this); mFuseAction->setIcon(QIcon(":/Resources/fuse.png")); mFuseAction->setStatusTip(tr("Boolean operation fuse")); connect(mFuseAction, SIGNAL(triggered()), this, SLOT(testFuse())); mCommonAction = new QAction(tr("Common"), this); mCommonAction->setIcon(QIcon(":/Resources/common.png")); mCommonAction->setStatusTip(tr("Boolean operation common")); connect(mCommonAction, SIGNAL(triggered()), this, SLOT(testCommon())); mAboutAction = new QAction(tr("About"), this); mAboutAction->setStatusTip(tr("About the application")); mAboutAction->setIcon(QIcon(":/Resources/lamp.png")); connect(mAboutAction, SIGNAL(triggered()), this, SLOT(about())); }