void TestCanvas::test(GiCanvas* canvas, int bits, int n, bool randStyle) { s_randStyle = randStyle; if ((bits & 0x400) == 0 || !s_inited) { initRand(); } if (bits & 0x01) testRect(canvas, n); if (bits & 0x02) testLine(canvas, n); if (bits & 0x04) testTextAt(canvas, n); if (bits & 0x08) testEllipse(canvas, n); if (bits & 0x10) testQuadBezier(canvas, n); if (bits & 0x20) testCubicBezier(canvas, n); if (bits & 0x40) testPolygon(canvas, n); if (bits & 0x80) canvas->clearRect(100, 100, 200, 200); if (bits & 0x100) testClipPath(canvas, n); if (bits & 0x200) testHandle(canvas, n); if (bits & 0x400) testDynCurves(canvas); }
TEST_F(TestDrawing, TestIntersections) { std::list<double> collissions; Line testLine(0,0, 0,1); m_drawing->GetCollissions(testLine, collissions); EXPECT_EQ(2u, collissions.size()); collissions.sort(); EXPECT_DOUBLE_EQ(-1.0L, collissions.front()); collissions.pop_front(); EXPECT_DOUBLE_EQ(1.0L, collissions.front()); Line testLine2(1.5,0, 1.5,1); collissions.clear(); m_drawing->GetCollissions(testLine2, collissions); ASSERT_EQ(2u, collissions.size()); collissions.sort(); EXPECT_DOUBLE_EQ(-sqrt(0.75), collissions.front()); collissions.pop_front(); EXPECT_DOUBLE_EQ(sqrt(0.75), collissions.front()); }
/* load * Reads the opened file, checks it for errors and stores it if none * are found. If no file is opened, returns false. * Params: none * Returns: bool - true if the file was read and stored succesfully * Modifies: lineNum, memory in memory.c * */ bool load() { if (file == NULL) return FALSE; char line[128]; lineNum = 1; while (fgets(line, 128, file) != NULL) { int result = testLine(line); if (result >= 0) // we want to count good lines and comments lineNum++; if (result == 0) // comment line, just ignore and move on continue; if (result < 0) { // found an error, stop parsing printf("Error on line %d\n%s\n", lineNum, line); return FALSE; } else // good line, store it storeData(line); } // because we aren't barbarians fclose(file); return TRUE; }
void TestCanvas::test(GiCanvas* canvas, int bits, int n, bool randStyle) { s_randStyle = randStyle; if ((bits & kDynCurves) == 0 || !s_inited) { initRand(); } if (bits & kRect) testRect(canvas, n * 2); if (bits & kLine) testLine(canvas, n * 2); if (bits & kTextAt) testTextAt(canvas, n); if (bits & kEllipse) testEllipse(canvas, n * 2); if (bits & kQuadBezier) testQuadBezier(canvas, n); if (bits & kCubicBezier) testCubicBezier(canvas, n); if (bits & kPolygon) testPolygon(canvas, n); if (bits & kClearRect) canvas->clearRect(100, 100, 200, 200); if (bits & kClipPath) testClipPath(canvas, n); if (bits & kHandle) testHandle(canvas, n); if (bits & kDynCurves) testDynCurves(canvas); }
bool Image::isPointInPolygon(const Polygon &polygon, const Common::Point &point) const { if (polygon.size() <= 1) { return false; // Empty polygon } // A ray cast from the point Math::Segment2d testLine(Math::Vector2d(point.x, point.y), Math::Vector2d(-100, -100)); // Special case the line created between the last point and the first Math::Vector2d prevPoint = Math::Vector2d(polygon.back().x, polygon.back().y); // Count the intersections of the ray with the polygon's edges int intersectCount = 0; for (uint32 j = 0; j < polygon.size(); j++) { Math::Vector2d curPoint = Math::Vector2d(polygon[j].x, polygon[j].y); if (Math::Segment2d(prevPoint, curPoint).intersectsSegment(testLine, nullptr)) { intersectCount++; } prevPoint = curPoint; } // If the ray crosses the polygon an odd number of times, the point is inside the polygon return intersectCount % 2 != 0; }
void startTest() { TCHAR logFileName[1024]; getLogFilename(logFileName); testLogFile = _tfopen(logFileName, _T("w")); if (!testLogFile) return; int pointTestErr = testPoint(); logHLine(); int vectorTestErr = testVector(); logHLine(); int lineTestErr = testLine(); logHLine(); int planeTestErr = testPlane(); logHLine(); int triangleTestErr = testTriangle(); logHLine(); int basisTestErr = testBasis(); logHLine(); int matrixTestErr = testMatrix(); fclose(testLogFile); testLogFile = NULL; }
void ArrowItem::updatePath(const QPointF &endPoint) { const double arrowWidth = 15.0; const double headWidth = 40.0; const double headLength = headWidth / pow(2, 0.5); // aka headWidth / sqrt (2) but this produces a compile error with MSVC++ const double phi = 15; if (!startItem) return; QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2)); QLineF line(startPoint, endPoint); qreal lineLength = line.length(); prepareGeometryChange(); if (lineLength < 30) path = QPainterPath(); else { QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength); QPainterPath centerLine; centerLine.moveTo(0, 0); centerLine.quadTo(c, QPointF(lineLength, 0)); double percentage = 1 - headLength / lineLength; QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage); QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001)); qreal alpha = testLine.angle() - 90; QPointF endPoint1 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180)); QPointF endPoint2 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180)); QPointF point1 = endPoint1 + (headWidth - arrowWidth) / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180)); QPointF point2 = endPoint2 + (headWidth - arrowWidth) / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180)); path = QPainterPath(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180))); path.quadTo(c, endPoint1); path.lineTo(point1); path.lineTo(QPointF(lineLength, 0)); path.lineTo(point2); path.lineTo(endPoint2); path.quadTo(c, arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180))); path.lineTo(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180))); } setPos(startPoint); setTransform(QTransform().rotate(-line.angle())); }
int my_test_gpu_draw_line(void) { // Init the system. // printf("gcAppInit\n"); gcAppInit(); // Virtualize target buffer. #if gcENABLEVIRTUAL gcVirtualizeSurface(&target); #endif // Switch to 2D pipe. // printf("Switch to 2D pipe\n"); gcSelect2DPipe(); printf("Entering: Line Test...\n"); testLine(&gcDisplaySurface); printf("Line Test End\n"); return 0; }
void TestCanvas::testClipPath(GiCanvas* canvas, int n) { for (int i = 0; i < 2; i++) { canvas->saveClip(); if (canvas->clipRect(randFloat(100.f, 500.f), randFloat(100.f, 500.f), randFloat(50.f, 200.f), randFloat(50.f, 200.f))) { testLine(canvas, n); } canvas->restoreClip(); } canvas->saveClip(); canvas->beginPath(); for (int j = 0; j < 5; j++) { float x1 = randFloat(100.f, 400.f); float y1 = randFloat(100.f, 400.f); canvas->moveTo(x1, y1); for (int k = randInt(2, 4); k > 0; k--) { float x2 = x1 + randFloat(-150.f, 150.f); float y2 = y1 + randFloat(-150.f, 150.f); float x3 = x2 + randFloat(-150.f, 150.f); float y3 = y2 + randFloat(-150.f, 150.f); x1 = x3 + randFloat(-150.f, 150.f); y1 = y3 + randFloat(-150.f, 150.f); canvas->bezierTo(x2, y2, x3, y3, x1, y1); } canvas->closePath(); } if (canvas->clipPath()) { if (s_randStyle) { canvas->setPen(0x41000000 | randInt(0, 0xFFFFFF), -1.f, -1, 0); canvas->setBrush(0x41000000 | randInt(0, 0xFFFFFF), 0); } canvas->drawRect(0, 0, 1000, 1000, true, true); testCubicBezier(canvas, n); } canvas->restoreClip(); }
void ParametricCurveTests::runTests(int &numTestsRun, int &numTestsPassed) { setup(); if (testGradientWrapper()) { numTestsPassed++; } numTestsRun++; teardown(); setup(); if (testTransfiniteInterpolant()) { numTestsPassed++; } numTestsRun++; teardown(); setup(); if (testCircularArc()) { numTestsPassed++; } numTestsRun++; teardown(); setup(); if (testLine()) { numTestsPassed++; } numTestsRun++; teardown(); setup(); if (testBubble()) { numTestsPassed++; } numTestsRun++; teardown(); setup(); if (testProjectionBasedInterpolation()) { numTestsPassed++; } numTestsRun++; teardown(); setup(); if (testPolygon()) { numTestsPassed++; } numTestsRun++; teardown(); setup(); if (testParametricCurveRefinement()) { numTestsPassed++; } numTestsRun++; teardown(); }
void GCodeExport::doShapes(FILE *fl, Mode mode, GShape *shapes, double diameter, double zsafe, double depth, double speed, double filamentMMPerHeadMM, double laserEnergy) { // mark all shapes as unused GShape *nshape = shapes; while(nshape) { nshape->used = false; nshape = nshape->next; } while(true) { double closetShapeDistance = FLT_MAX; GShape *closestShape = 0; ShapeClosestpointPlace closestPos = SCP_P1_FROM; GShape *nextShape = shapes; while(nextShape) { // looking for the closest shape if(!nextShape->used) { double tmpdst; switch(nextShape->type()) { case GSHAPE_CIRCLE: { GCircle *circle = (GCircle*)nextShape; if(circle->spanAngle>=2*M_PI) { if( (tmpdst=fabs(circle->center.distance(headPosition)-circle->radius))<closetShapeDistance ) { closestShape = nextShape; closetShapeDistance = tmpdst; closestPos = SCP_WHOLECIRCLE; if(tmpdst == 0.0L) goto foundClosest; } } else { if( (tmpdst=circle->fromPoint().distance(headPosition))<closetShapeDistance) { closestShape = nextShape; closetShapeDistance = tmpdst; closestPos = SCP_P1_FROM; if(tmpdst == 0.0L) goto foundClosest; } if( (tmpdst=circle->toPoint().distance(headPosition))<closetShapeDistance) { closestShape = nextShape; closetShapeDistance = tmpdst; closestPos = SCP_P2_TO; if(tmpdst == 0.0L) goto foundClosest; } } } break; case GSHAPE_LINE: { GLine *line = (GLine*)nextShape; if( (tmpdst=line->p1.distance(headPosition))<closetShapeDistance) { closestShape = nextShape; closetShapeDistance = tmpdst; closestPos = SCP_P1_FROM; if(tmpdst == 0.0L) goto foundClosest; } if( (tmpdst=line->p2.distance(headPosition))<closetShapeDistance) { closestShape = nextShape; closetShapeDistance = tmpdst; closestPos = SCP_P2_TO; if(tmpdst == 0.0L) goto foundClosest; } } break; case GSHAPE_RECT: assert("Rect in contur while export!"); break; } } nextShape = nextShape->next; } foundClosest: if(closestShape) { // put shape in gcode file GPoint st; GPoint en; bool isCCW = false; switch(closestShape->type()){ case GSHAPE_CIRCLE: { GCircle *circle = (GCircle*)closestShape; if(closestPos == SCP_P1_FROM) { st = circle->fromPoint(); en = circle->toPoint(); isCCW = true; } else if(closestPos == SCP_P2_TO) { st = circle->toPoint(); en = circle->fromPoint(); isCCW = false; } else if(closestPos == SCP_WHOLECIRCLE) { isCCW = false; GLine testLine(circle->center, headPosition); GPoint p1, p2; int intersectCount = GIntersects::lineWithCircle(testLine,*circle, &p1, &p2, false); if(intersectCount==0){ st = circle->center+GPoint(circle->radius, 0.0L); en = st; } else { if(intersectCount==1 || p1.distance(headPosition)<p2.distance(headPosition)){ st = p1; en = p1; } else { st = p2; en = p2; } } } } break; case GSHAPE_LINE: { GLine *line = (GLine*)closestShape; if(closestPos == SCP_P1_FROM) { st = line->p1; en = line->p2; } else if(closestPos == SCP_P2_TO) { st = line->p2; en = line->p1; } else { assert("Rect in contur while export2!"); } } break; case GSHAPE_RECT: assert("Rect in contur while export3!"); break; } if(st.distance(headPosition)>diameter) { moveHeadTo(fl, mode, st, zsafe); } else if (st.distance(headPosition)!=0.0L) { millingLineTo(fl, mode, st, depth, speed, filamentMMPerHeadMM, laserEnergy, diameter); } if(closestShape->type()==GSHAPE_LINE) { millingLineTo(fl, mode, en, depth, speed, filamentMMPerHeadMM, laserEnergy, diameter); } else if(closestShape->type()==GSHAPE_CIRCLE) { GCircle* circle = (GCircle*)closestShape; millingCircle(fl, mode, ((GCircle*)closestShape)->center,en,depth,speed,isCCW, circle->spanAngle*circle->radius, filamentMMPerHeadMM, laserEnergy*(circle->outer?1.0L:1.5L), diameter); } closestShape->used = true; } else break; // from while(true) } if(headZPosition!=zsafe) { char lineBuffer[256]; // raise head sprintf(lineBuffer, "G00Z%f\n", zsafe); // for the same style numeric fputs(lineBuffer, fl); totalTime += timeForMovement(SPEED_ON_IDLE, zsafe-headZPosition); headZPosition = zsafe; } }