Exemple #1
0
void bazier(float xb,float yb,float xc,float yc,float xd,float yd,int n)
{
float xab,yab,xbc,ybc,xcd,ycd;
float xabc,yabc,xbcd,ybcd;
float xabcd,yabcd;
//sprintf(s,"(%d%d)",xb yb);
outtextxy(xb,yb,s);

if(n==0)
{
line1(xb,yb);
line1(xc,yc);
line1(xd,yd);
}
else
{
xab=(xxx[0][0]+xb)/2;
yab=(xxx[0][1]+yb)/2;
xbc=(xb+xc)/2;
ybc=(yb+yc)/2;
xcd=(xc+xd)/2;
ycd=(yc+yd)/2;
xabc=(xab+xbc)/2;
yabc=(yab+ybc)/2;
xbcd=(xbc+xcd)/2;
ybcd=(ybc+ycd)/2;
xabcd=(xabc+xbcd)/2;
yabcd=(yabc+ybcd)/2;
n=n-1;
bazier(xab,yab,xabc,yabc,xabcd,yabcd,n);
bazier(xbcd,ybcd,xcd,ycd,xd,yd,n);
}
}
bezier(float xb,float yb,float xc,float yc,float xd,float yd,int n)
{
 float xab,yab,xbc,ybc,xcd,ycd;
 float xabc,yabc,xbcd,ybcd;
 float xabcd,yabcd;
 if (n==0)
 {
  line1(xb,yb);
  line1(xc,yc);
  line1(xd,yd);
 }
 else
 {
  xab = (xxx[0][0]+xb)/2;
  yab = (xxx[0][1]+yb)/2;
  xbc = (xb+xc)/2;
  ybc = (yb+yc)/2;
  xcd = (xc+xd)/2;
  ycd = (yc+yd)/2;
  xabc = (xab+xbc)/2;
  yabc = (yab+ybc)/2;
  xbcd = (xbc+xcd)/2;
  ybcd = (ybc+ycd)/2;
  xabcd = (xabc+xbcd)/2;
  yabcd = (yabc+ybcd)/2;
  n=n-1;
  bezier(xab,yab,xabc,yabc,xabcd,yabcd,n);
  bezier(xbcd,ybcd,xcd,ycd,xd,yd,n);
 }
 return (0);
}
Exemple #3
0
  void dump_grid_range_highlight(const Grid & grid,
				 ssize_t ix0, ssize_t iy0,
				 ssize_t ix1, ssize_t iy1,
				 ssize_t ixhigh, ssize_t iyhigh,
				 FILE * stream)
  {
    PVDEBUG("%zu   %zu   %zu   %zu   %zu   %zu\n",
	    ix0, iy0, ix1, iy1, ixhigh, iyhigh);
    fprintf(stream, " ");
    for(ssize_t ix(ix0); ix <= ix1; ++ix)
      if(ix == ixhigh) fprintf(stream, " ***********");
      else             fprintf(stream, "            ");
    fprintf(stream, " \n");
    ssize_t iy(iy1);
    for(/**/; iy != iy0; --iy){
      const char * high(iy == iyhigh ? "*" : " ");
      linesep(grid, stream, ix0, ix1, 0, " ");
      line1(grid, stream, iy, ix0, ix1, 0, high);
      line2(grid, stream, iy, ix0, ix1, 0, high);
      line3(grid, stream, iy, ix0, ix1, 0, high);
      line4(grid, stream, iy, ix0, ix1, 0, high);
    }
    const char * high(iy == iyhigh ? "*" : " ");
    linesep(grid, stream, ix0, ix1, 0, " ");
    line1(grid, stream, iy, ix0, ix1, 0, high);
    line2(grid, stream, iy, ix0, ix1, 0, high);
    line3(grid, stream, iy, ix0, ix1, 0, high);
    line4(grid, stream, iy, ix0, ix1, 0, high);
    linesep(grid, stream, ix0, ix1, 0, " ");
    fprintf(stream, " ");
    for(ssize_t ix(ix0); ix <= ix1; ++ix)
      if(ix == ixhigh) fprintf(stream, " ***********");
      else             fprintf(stream, "            ");
    fprintf(stream, " \n");
  }
Exemple #4
0
  void dump_grid_range(const Grid & grid,
		       ssize_t ix0, ssize_t iy0, ssize_t ix1, ssize_t iy1,
		       FILE * stream)
  {
    PVDEBUG("%zu   %zu   %zu   %zu\n", ix0, iy0, ix1, iy1);
    const char * even("");
    const char * oddsep;
    const char * oddpre;
    if (grid.GetNeighborhood() == Grid::SIX) {
      oddsep = "+-----";
      oddpre = "      ";
    }
    else {
      oddsep = even;
      oddpre = even;
    }
    ssize_t iy(iy1);
    const char * prefix;
    for(/**/; iy != iy0; --iy){
      if(iy % 2){
	linesep(grid, stream, ix0, ix1, oddsep, 0);
	prefix = oddpre;
      }
      else{
	linesep(grid, stream, ix0, ix1, even, 0);
	prefix = even;
      }
      line1(grid, stream, iy, ix0, ix1, prefix, 0);
      line2(grid, stream, iy, ix0, ix1, prefix, 0);
      line3(grid, stream, iy, ix0, ix1, prefix, 0);
      line4(grid, stream, iy, ix0, ix1, prefix, 0);
    }
    if(iy % 2){
      linesep(grid, stream, ix0, ix1, oddsep, 0);
      prefix = oddpre;
    }
    else{
      linesep(grid, stream, ix0, ix1, even, 0);
      prefix = even;
    }
    line1(grid, stream, iy, ix0, ix1, prefix, 0);
    line2(grid, stream, iy, ix0, ix1, prefix, 0);
    line3(grid, stream, iy, ix0, ix1, prefix, 0);
    line4(grid, stream, iy, ix0, ix1, prefix, 0);
    if(iy % 2)
      linesep(grid, stream, ix0, ix1, even, 0);
    else
      linesep(grid, stream, ix0, ix1, oddsep, 0);
  }
Exemple #5
0
void test_circuit_rc()
{
	ngdc dc("dc1", 5);
	ngresistor r("r1", 5);
	ngcapacitor c("c1", 0.2);
	ngground gnd;

	ngline line1(dc[0], r[0]);
	ngline line2(r[1], c[0]);
	ngline line3(c[1], dc[1]);
	ngline line4(dc[0], gnd[0]);

	schema sch("design1");
	sch.AddDevice(&dc);
	sch.AddDevice(&r);
	sch.AddDevice(&c);
	sch.AddDevice(&gnd);

	sch.AddLine(&line1);
	sch.AddLine(&line2);
	sch.AddLine(&line3);
	sch.AddLine(&line4);

	circuit cir(&sch);
	cir.Tran("1s");
	
	do 
	{
		Sleep(200);
	} while (cir.IsRunning());
}
vector<Pixel> Rectangle::getPixels() const{

	Point p1(mPositionX,mPositionY);
	Point p2(mPositionX+mWidth,mPositionY);
	Point p3(mPositionX,mPositionY+mHeight);
	Point p4(mPositionX+mWidth,mPositionY+mHeight);

	Line line1(p1,p2,mColor);
	Line line2(p2,p4,mColor);
	Line line3(p3,p4,mColor);
	Line line4(p1,p3,mColor);

	vector<Pixel> linePixels1 = line1.getPixels();
	vector<Pixel> linePixels2 = line2.getPixels();
	vector<Pixel> linePixels3 = line3.getPixels();
	vector<Pixel> linePixels4 = line4.getPixels();

	vector<Pixel> pixels;

	pixels.insert(pixels.end(),linePixels1.begin(),linePixels1.end());
	pixels.insert(pixels.end(),linePixels2.begin(),linePixels2.end());
	pixels.insert(pixels.end(),linePixels3.begin(),linePixels3.end());
	pixels.insert(pixels.end(),linePixels4.begin(),linePixels4.end());

	return pixels;
}
TEST_F(TestDrawing, TestGetCenterNonOrigin2) {
    //LineSegment {(3.35231, 0.518918) <-> (1.35231, 0.518918)}
    //Arc {r1 @(3.35231, 1.51892), \270 /90s (3.35231, 0.518918), e (3.35231, 2.51892)}
    //LineSegment {(1.35231, 2.51892) <-> (3.35231, 2.51892)}
    //Arc {r1 @(1.35231, 1.51892), \90 /270s (1.35231, 2.51892), e (1.35231, 0.518918)}
    std::shared_ptr<Drawing> drawing = std::make_shared<Drawing>();
    drawing->AddComponent(std::make_shared<LineSegment>(3.35231L,0.518918L,1.35231,0.518918));
    drawing->AddComponent(std::make_shared<Arc>(1.0L,270,90,pt(3.35231,1.51892)));
    drawing->AddComponent(std::make_shared<LineSegment>(1.35231L,2.51892L,3.35231L,2.51892L));
    drawing->AddComponent(std::make_shared<Arc>(1.0L,90,270,pt(1.35231L,1.51892L)));

    drawing->Print(std::cout);
    std::cout << std::endl;

    double yCenter = (2.51892L-0.518918L)/2+0.518918L;
    double xCenter = (3.35231L-1.35231L)/2+1.35231L;
    std::list<double> collissions;
    Line line1(xCenter, 0, xCenter, 10);
    drawing->GetCollissions(line1, collissions);
    collissions.sort();
    ASSERT_EQ(2u, collissions.size());

    pt center = drawing->GetCenter();
    EXPECT_DOUBLE_EQ(yCenter, center.y);
    EXPECT_TRUE(center.x<=(xCenter*1.02));
    EXPECT_TRUE(center.x>=(xCenter*0.98));
}
Label TemplatePrinter::templateFiller(const char * templateFilePath)
{
    /* THIS IMPLEMENTATION IS TEMPORARY
     * In the future, TemplatePrinter will have a container of fields and columns
     * just like the label. The templateFiller will loop through the fields and columns to
     * A) format the label object with enough columns and fields and B) fill in the data from
     * the text fields of the gui. DO NOT rely on this implementation in the future!
     */
    Label tempLabel;
    QFile xmlFile(templateFilePath);
    LabelParser parser(xmlFile, tempLabel);
    parser.start();
    QString line1(ui->lineEdit->displayText());
    QString line2(ui->lineEdit_2->displayText());
    QString line3(ui->lineEdit_3->displayText());

    Column* column = &((tempLabel.getColumns())->at(0));
    Field* field1 = &(column->fields.at(0));
    field1->value = line1;
    Field* field2 = &(column->fields.at(1));
    field2->value = line2;
    Column* column2 = &((tempLabel.getColumns())->at(1));
    Field* field3 = &(column2->fields.at(1));
    field3->value = line3;

    return tempLabel;
}
Exemple #9
0
dFloat dPolygonRayCast (const dVector& l0, const dVector& l1, int indexCount, const dFloat* const vertex, int strideInBytes, const int* const indices)
{
	int stride = strideInBytes / sizeof (dFloat);

	dBigVector line0 (l0);
	dBigVector line1(l1);
	dBigVector segment (line1 - line0);
	dBigVector normal (dPolygonNormal (indexCount, vertex, strideInBytes, indices));
	double den = normal % segment;
	if (dAbs(den) < 1.0e-6) {
		return 1.2f;
	}
	
	double sign = (den < 0.0f) ? 1.0f : -1.0f;

	int index = indices[indexCount - 1] * stride;
	dBigVector v0 (vertex[index], vertex[index + 1], vertex[index + 2], 0.0f);
	dBigVector p0v0 (v0 - line0);
	for (int i = 0; i < indexCount; i ++) {
		index = indices[i] * stride;
		dBigVector v1 (vertex[index], vertex[index + 1], vertex[index + 2], 0.0f);
		dBigVector p0v1 (v1 - line0);
		double alpha = sign * ((p0v1 * p0v0) % segment);
		if (alpha < 1.0e-3f) {
			return 1.2f;
		}
		p0v0 = p0v1;
	}

	double t = - ((line0 - v0) % normal) / den;
	if ((t < 0.0f) || (t > 1.0f)) {
		return 1.2f;
	}
	return dFloat (t);
}
Exemple #10
0
/**
 * \brief Apply the angle of the slope to a colliding item.
 * \param that The other item in the collision.
 * \param info Informations on the collision.
 */
void bear::bridge::apply_angle_to
( engine::base_item& that, const universe::collision_info& info) const
{
  universe::position_type left_pos(that.get_bottom_left());
  universe::position_type right_pos(that.get_bottom_right());
  universe::position_type previous_pos;
  universe::position_type next_pos;
  
  compute_neighboor
    (that.get_bottom_left(),previous_pos,next_pos);
  claw::math::line_2d<universe::coordinate_type> line1
    ( previous_pos, next_pos - previous_pos );
  left_pos.y = line1.y_value(that.get_left());

  compute_neighboor
    (that.get_bottom_right(),previous_pos,next_pos);
  claw::math::line_2d<universe::coordinate_type> line2
    ( previous_pos, next_pos - previous_pos );
  right_pos.y = line2.y_value(that.get_right());
  
  claw::math::line_2d<universe::coordinate_type> line
    ( left_pos, right_pos - left_pos );
  double angle = std::atan(line.direction.y / line.direction.x);
  
  that.set_contact_angle(angle);

  info.get_collision_repair().set_contact_normal
    (that, that.get_x_axis().get_orthonormal_anticlockwise());
} // bridge::apply_angle_to()
Exemple #11
0
void main() {
  int gdriver = DETECT, gmode, errorcode;
  initgraph(&gdriver, &gmode, "c:\\PROGRAMS\\bc\\bgi");
  TLine line1(0, 8);
  line1.show();
  line1.move(100);
  line1.show();
  line1.move(100);
  line1.povorot(0.4);
  line1.show();
  TLuch luch1(0.7, 2, 50, 50);
  luch1.show();
  luch1.move(200, 200);
  luch1.show();
  luch1.move(100, 100);
  luch1.povorot(0.3);
  luch1.show();
  TOtr otr1(0.0, 900, 100, 100, 200);
  otr1.show();
  otr1.move(100, 50);
  otr1.show();
  otr1.move(50, 50);
  otr1.show();
  otr1.povorot(1.57);
  otr1.show();
  getch();
  cleardevice();
  closegraph();
};
Exemple #12
0
 bool AppController::_loadFile(const QString& path)
 {
   if ( !path.endsWith(".dat") )
     return false;
   
   QFile file(path);
   file.open(QFile::ReadOnly);
   QDataStream stream(&file);
   
   while(m_LineController.count() > 0)
     model_removeLastLine();
   
   int count;
   stream >> count;
   
   qreal x1, y1, x2, y2;
   for(int i=0; i<count; ++i)
   {
     stream >> x1 >> y1 >> x2 >> y2;
     QLineF line0(x1, y1, x2, y2);
     stream >> x1 >> y1 >> x2 >> y2;
     QLineF line1(x1, y1, x2, y2);
     model_addLine(line0, line1);
   }
   
   stream >> m_Img0 >> m_Img1;
   m_Scene0->setPixmap(m_Img0);
   m_Scene1->setPixmap(m_Img1);
   
   return true;
 }
Exemple #13
0
void GraphicMoteur::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    qreal x = _dp.x();
    qreal y = _dp.y();

    QPolygonF polygone1, polygone2;

    QLineF line1(x+9, y+32, x+15, y+32);
    QLineF line2(x+31, y+32, x+25, y+32);

    polygone1 << QPointF(x, y) << QPointF(x+40, y) << QPointF(x+40, y+13) << QPointF(x, y+13);

    polygone2 << QPointF(x+6, y+13) << QPointF(x+34, y+13) << QPointF(x+34, y+25) << QPointF(x+28, y+48)
              << QPointF(x+12, y+48) << QPointF(x+6, y+25);

    painter->setPen(pen);

    painter->drawText(x+14, y+11, _nom);

    QPainterPath path;
    path.addPolygon(polygone2);

    painter->fillPath(path, brushDefault);

    painter->drawPolygon(polygone1);
    painter->drawPolygon(polygone2);
    painter->drawLine(line1);
    painter->drawLine(line2);
}
Exemple #14
0
TEST_F(TestDrawing, TestFromParsedDrawing) {
    ParseDXF parser;
    DL_Dxf dxf;
    dxf.in("test_shape.dxf", &parser);

    Drawing const& drawing(parser.GetDrawing());

    drawing.Print(std::cout);
    std::cout << std::endl;

    double yCenter = (2.51892L-0.518918L)/2+0.518918L;
    double xCenter = (3.35231L-1.35231L)/2+1.35231L;
    std::list<double> collissions;
    Line line1(xCenter, 0, xCenter, 10);
    drawing.GetCollissions(line1, collissions);

    collissions.sort();
    ASSERT_EQ(2u, collissions.size());


    pt center = drawing.GetCenter();

    EXPECT_TRUE(center.y<=(yCenter+0.001)) << "Expected=" << yCenter << " Actual =" << center.y;
    EXPECT_TRUE(center.y>=(yCenter-0.001)) << "Expected=" << yCenter << " Actual =" << center.y;

    EXPECT_TRUE(center.x<=(xCenter+0.001)) << "Expected=" << xCenter << " Actual =" << center.x;
    EXPECT_TRUE(center.x>=(xCenter-0.001)) << "Expected=" << xCenter << " Actual =" << center.x;
}
Exemple #15
0
bool Knob::sceneEvent(QEvent *event)
{
    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);

        if (touchEvent->touchPoints().count() == 2) {
            const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first();
            const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last();

            QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos());
            QLineF line2(touchPoint1.scenePos(), touchPoint2.scenePos());

            rotate(line2.angleTo(line1));
        }

        break;
    }

    default:
        return QGraphicsItem::sceneEvent(event);
    }

    return true;
}
Exemple #16
0
bool LineSegConeIntersect(const LineSegment * line, const Cone * cone)
{
	Circle circle(cone->GetVertex(), cone->GetHeight());
	if (Intersect(line, &circle) == true)
	{
		if ((cone->ContainsPoint(line->GetPoint1()) == true) || (cone->ContainsPoint(line->GetPoint2()) == true) || (line->ContainsPoint(cone->GetVertex()) == true))
		{
			return true;
		}

		Vector3D direction(cone->GetVertex(), cone->GetVertex() + cone->GetDirection());
		Float angle = direction.GetZeroAngleD();

		Float angle1 = angle + cone->GetAngle();
		Float angle2 = angle - cone->GetAngle();

		Float height = cone->GetHeight();
		Point3D vertex = cone->GetVertex();

		LineSegment line1(vertex, Point3D(vertex.GetX() + (CosD(angle1) * height), vertex.GetY() + (SinD(angle1) * height), 0));
		LineSegment line2(vertex, Point3D(vertex.GetX() + (CosD(angle2) * height), vertex.GetY() + (SinD(angle2) * height), 0));

		return ((Intersect(line, &line1) == true) || (Intersect(line, &line2) == true));
	}
	return false;
}
Exemple #17
0
bool CircleConeIntersect(const Circle * c, const Cone * cone)
{
	Circle circle(cone->GetVertex(), cone->GetHeight());
	if (Intersect(c, &circle) == true)
	{
		if ((c->ContainsPoint(cone->GetVertex()) == true) || (cone->ContainsPoint(c->GetCenter()) == true))
		{
			return true;
		}


		Vector3D direction(cone->GetVertex(), cone->GetVertex() + cone->GetDirection());
		Vector3D centerDirection(cone->GetVertex(), c->GetCenter());
		Float angle = direction.GetZeroAngleD();
		Float angleDif = centerDirection.GetZeroAngleD() - angle;

		if (AbsVal(angleDif) < cone->GetAngle())
		{
			return true;
		}

		Float angle1 = angle + cone->GetAngle();
		Float angle2 = angle - cone->GetAngle();

		Float height = cone->GetHeight();
		Point3D vertex = cone->GetVertex();

		LineSegment line1(vertex, Point3D(vertex.GetX() + (CosD(angle1) * height), vertex.GetY() + (SinD(angle1) * height), 0));
		LineSegment line2(vertex, Point3D(vertex.GetX() + (CosD(angle2) * height), vertex.GetY() + (SinD(angle2) * height), 0));

		return ((Intersect(c, &line1) == true) || (Intersect(c, &line2) == true));
	}
	return false;
}
Exemple #18
0
void Rectangle::draw(Frame* fr) {
    /* 
     * x1y2-------x2y2
     * |             |
     * |             |
     * |             |
     * x1y1-------x2y1
     */
    if(x1 > x2 && y1 > y2) {
        std::swap(x1, x2);
        std::swap(y1, y2);
    }
    if(is_valid(fr)) {
        // Create 4 lines
        Line line1(x1, y1, x1, y2);
        Line line2(x1, y2, x2, y2);
        Line line3(x2, y2, x2, y1);
        Line line4(x2, y1, x1, y1);
        // Draw them
        line1.draw(fr);
        line2.draw(fr);
        line3.draw(fr);
        line4.draw(fr);
    } else {
        throw std::runtime_error("Rechteck nicht korrekt!");
    }
}
Exemple #19
0
void main()
{
	ifstream inStream;
	int cases;

	inStream.open("input.txt");
	if(inStream.fail())
	{
		cerr<<"Input file opening failed\n";
		exit(1);
	}

	inStream>>cases;

	for(int i=0;i<cases;i++)
	{
		int p1x, p2x, p3x, p4x, p1y, p2y, p3y, p4y;

		inStream>>p1x>>p1y>>p2x>>p2y>>p3x>>p3y>>p4x>>p4y;

		point p1(p1x, p1y), p2(p2x, p2y), p3(p3x, p3y), p4(p4x, p4y);
		linesegment line1(p1, p2);
		linesegment line2(p3, p4);

		if(line1.properintersection(line2) || line2.properintersection(line1))
			cout<<"1"<<endl;
		else if(line1.improperintersection(line2) || line2.improperintersection(line1))
			cout<<"2"<<endl;
		else
			cout<<"0"<<endl;
	}
	inStream.close();
}
Exemple #20
0
void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc,
                                               Inkscape::SnapCandidatePoint const &p,
                                               Geom::OptRect const &/*bbox_to_snap*/,
                                               ConstraintLine const &c,
                                               std::vector<SPItem const *> const */*it*/) const

{
    if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false) {
        return;
    }

    /* Get the lines that we will try to snap to */
    const LineList lines = _getSnapLines(p.getPoint());

    for (LineList::const_iterator i = lines.begin(); i != lines.end(); i++) {
        if (Geom::L2(c.getDirection()) > 0) { // Can't do a constrained snap without a constraint
            // constraint line
            Geom::Point const point_on_line = c.hasPoint() ? c.getPoint() : p.getPoint();
            Geom::Line line1(point_on_line, point_on_line + c.getDirection());

            // grid/guide line
            Geom::Point const p1 = i->second; // point at guide/grid line
            Geom::Point const p2 = p1 + Geom::rot90(i->first); // 2nd point at guide/grid line
            Geom::Line line2(p1, p2);

            Geom::OptCrossing inters = Geom::OptCrossing(); // empty by default
            try
            {
                inters = Geom::intersection(line1, line2);
            }
            catch (Geom::InfiniteSolutions e)
            {
                // We're probably dealing with parallel lines, so snapping doesn't make any sense here
                continue; // jump to the next iterator in the for-loop
            }

            if (inters) {
                Geom::Point t = line1.pointAt((*inters).ta);
                const Geom::Coord dist = Geom::L2(t - p.getPoint());
                if (dist < getSnapperTolerance()) {
                    // When doing a constrained snap, we're already at an intersection.
                    // This snappoint is therefore fully constrained, so there's no need
                    // to look for additional intersections; just return the snapped point
                    // and forget about the line
                    _addSnappedPoint(sc, t, dist, p.getSourceType(), p.getSourceNum(), true);
                    // For any line that's within range, we will also look at it's "point on line" p1. For guides
                    // this point coincides with its origin; for grids this is of no use, but we cannot
                    // discern between grids and guides here
                    Geom::Coord const dist_p1 = Geom::L2(p1 - p.getPoint());
                    if (dist_p1 < getSnapperTolerance()) {
                        _addSnappedLinesOrigin(sc, p1, dist_p1, p.getSourceType(), p.getSourceNum(), true);
                        // Only relevant for guides; grids don't have an origin per line
                        // Therefore _addSnappedLinesOrigin() will only be implemented for guides
                    }
                }
            }
        }
    }
}
Exemple #21
0
void Sonar2DUtils::DouglasPeucker(const Sonar2DUtils::tBottomLine& bottomLineFt, float epsilon, Sonar2DUtils::tBottomLine& returnResults)
{
    const unsigned int minPoints = 3;

    if(bottomLineFt.size() < minPoints)
    {
        returnResults = bottomLineFt;
    }
    else
    {
        Sonar2DUtils::tBottomLine lineSegment;
        lineSegment.push_back( *bottomLineFt.begin() );
        lineSegment.push_back( bottomLineFt.back() );
        
        float dMax = 0.0f;
        Sonar2DUtils::tBottomLine::const_iterator iterMax;
        Sonar2DUtils::tBottomLine::const_iterator iterEnd = bottomLineFt.begin() + (bottomLineFt.size() - 2);
        // Find the point with maximum distance, excluding the first and last point of the segment.
        for(Sonar2DUtils::tBottomLine::const_iterator iter=bottomLineFt.begin()+1; iter!=iterEnd; ++iter )
        {
            float d = ShortestDistanceToSegment( *iter, lineSegment );
            if( d > dMax )
            {
                dMax = d;
                iterMax = iter;
            }
        }

        // If max distance is greater than epsilon, recursively simplify
        if( dMax > epsilon)
        {
            // Split up new lines
            Sonar2DUtils::tBottomLine line1( bottomLineFt.begin(), (iterMax+1) );
            Sonar2DUtils::tBottomLine line2( iterMax, bottomLineFt.end() );

            Sonar2DUtils::tBottomLine results1;
            DouglasPeucker(line1, epsilon, results1 );

            Sonar2DUtils::tBottomLine results2;
            DouglasPeucker(line2, epsilon, results2 );

            if(results1.size() < minPoints)
            {
                returnResults.push_back( *results1.begin() );
            }
            else
            {
                returnResults = Sonar2DUtils::tBottomLine( results1.begin(), (results1.begin() + results1.size() - 2) );
            }

            returnResults.insert( returnResults.end(), results2.begin(), results2.end() );
        }
        else
        {
            returnResults.push_back( *bottomLineFt.begin() );
            returnResults.push_back( bottomLineFt.back() );
        }
    }
}
Exemple #22
0
LocationPtr ParserBase::getLocation() const {
    LocationPtr location(new Location());
    location->file  = file();
    location->line0 = line0();
    location->char0 = char0();
    location->line1 = line1();
    location->char1 = char1();
    return location;
}
//在指定列表中查找卡
bool CDlgAddCards::FindCardLine(CCardLine* pLine,vector<CCardLine*> vecLine)
{
	if ( !pLine || vecLine.empty())
		return false;

	switch (m_type)
	{
	case TYPE_BUS:
	case TYPE_GEN:
		{
			string name1 = pLine->m_card.FindValueByKeyname(_T("NAME"));
			double volt1 = std::stod(pLine->m_card.FindValueByKeyname(_T("VOLT")));
			CSimpleBus bus1(name1,volt1);
			for (vector<CCardLine*>::iterator it = vecLine.begin();
				it != vecLine.end();
				++it)
			{
				CCardLine* pLine2 = *it;
				if( !pLine2)
					continue;
				string name2 = pLine2->m_card.FindValueByKeyname(_T("NAME"));
				double volt2 = std::stod(pLine2->m_card.FindValueByKeyname(_T("VOLT")));
				CSimpleBus bus2(name2,volt2);
				if(bus1.IsSameAs(bus2))
					return true;
			}
		}
		break;
	case TYPE_LINE:
		{
			string name = pLine->m_card.FindValueByKeyname(_T("NAME"));
			double volt = std::stod(pLine->m_card.FindValueByKeyname(_T("VOLT")));
			string name1 = pLine->m_card.FindValueByKeyname(_T("NAME1"));
			double volt1 = std::stod(pLine->m_card.FindValueByKeyname(_T("VOLT1")));
			string circuit = pLine->m_card.FindValueByKeyname(_T("CIRCUIT"));
			CSimpleLine line1(name,volt,name1,volt1,circuit);
			for (vector<CCardLine*>::iterator it = vecLine.begin();
				it != vecLine.end();
				++it)
			{
				CCardLine* pLine2 = *it;
				if( !pLine2)
					continue;
				name = pLine2->m_card.FindValueByKeyname(_T("NAME"));
				volt = std::stod(pLine2->m_card.FindValueByKeyname(_T("VOLT")));
				name1 = pLine2->m_card.FindValueByKeyname(_T("NAME1"));
				volt1 = std::stod(pLine2->m_card.FindValueByKeyname(_T("VOLT1")));
				circuit = pLine2->m_card.FindValueByKeyname(_T("CIRCUIT"));
				CSimpleLine line2(name,volt,name1,volt1,circuit);
				if(line1.IsSameAs(line2))
					return true;
			}
		}
		break;
	}
	return false;
}
FlowOperator::FlowOperator(const int rows, const int cols) : _b(2 * rows * cols, true, 0), _rows(rows), _cols(cols), _cells(rows * cols), FMxD(rows, cols, OPTFLOW_TYPE), FMxd(rows, cols, OPTFLOW_TYPE), FMyD(rows, cols, OPTFLOW_TYPE), FMyd(rows, cols, OPTFLOW_TYPE){
	//construct consts
		//FMx/Fx const
	//FMx contains the FMxD mat on its main diagonal and FMxd on the -cols(in matlab its -rows) diagonal
	FArray zeros(_cols, true, 0);
	FArray ones(_cols, true, 1);
	FArray nones(_cols, true, -1);

	/*
	0  1  1  1       0  0  0  0
	0  1  1  1  ->   1  1  1  1
	0  1  1  1       1  1  1  1
	0  1  1  1       1  1  1  1
	*/
	//cv::Mat FMxD(_rows, _cols, OPTFLOW_TYPE);
	memcpy(FMxD.ptr<float>(0), zeros.ptr, _cols * sizeof(float));
	for(int i = 1; i < _rows; ++i)
		memcpy(FMxD.ptr<float>(i), ones.ptr, _cols * sizeof(float));
	/*
	-1 -1 -1  0      -1 -1 -1 -1
	-1 -1 -1  0  ->  -1 -1 -1 -1
	-1 -1 -1  0      -1 -1 -1 -1
	-1 -1 -1  0       0  0  0  0
	*/
	//cv::Mat FMxd(_rows, _cols, OPTFLOW_TYPE, cv::Scalar(-1)); increases quality
	//cv::Mat FMxd(_rows, _cols, OPTFLOW_TYPE);
	for(int i = 1; i < _rows; ++i)
		memcpy(FMxd.ptr<float>(i), nones.ptr, _cols * sizeof(float));
	memcpy(FMxd.ptr<float>(0), zeros.ptr, _cols * sizeof(float));


	//FMy/Fy const

	/*
	 0  0  0  0       0  1  1  1
	 1  1  1  1  ->   0  1  1  1
	 1  1  1  1       0  1  1  1
	 1  1  1  1       0  1  1  1
	*/
	FArray line1(_cols, true, 1);
	*(line1.ptr) = 0;	
	//cv::Mat FMyD(_rows, _cols, OPTFLOW_TYPE);
	for(int i = 0; i < _rows; ++i)
		memcpy(FMyD.ptr<float>(i), line1.ptr, _cols * sizeof(float));
	
	/*
	-1 -1 -1 -1       -1 -1 -1  0
	-1 -1 -1 -1   ->  -1 -1 -1  0
	-1 -1 -1 -1       -1 -1 -1  0
	 0  0  0  0       -1 -1 -1  0
	*/
	FArray line2(_cols, true, -1);
	*(line2.ptr + _cols - 1) = 0;
	//cv::Mat FMyd(_rows, _cols, OPTFLOW_TYPE);
	for(int i = 0; i < _rows; ++i)
		memcpy(FMyd.ptr<float>(i), line2.ptr, _cols * sizeof(float));
}
void SegmentsTests<dimension>::run()
{
  VecD origin1 = random_vec<VecD>();
  VecD direction1 = random_vec<VecD>();
  geom::Point<dimension> point1( new typename geom::Point<dimension>::EuclideanDriver( random_vec<HomogenousVecD>() ) );
  geom::Point<dimension> point2( new typename geom::Point<dimension>::EuclideanDriver( random_vec<HomogenousVecD>() ) );
  
  // Test based on line
  geom::Line<dimension> line1( new typename geom::Line<dimension>::EuclideanDriver( origin1, direction1));
  
  double firstIndex = random_float();
  double lastIndex = random_float();
  SegmentD seg1( new typename SegmentD::LineDriver( &line1, firstIndex, lastIndex ) );
  test_segment_validity( seg1 );
  GEOM_CHECK_VEC_EQUAL( seg1.firstPoint(), line1.pointAt(firstIndex) );
  GEOM_CHECK_VEC_EQUAL( seg1.lastPoint(), line1.pointAt(lastIndex) );
  GEOM_CHECK_NULL( geom::angle(seg1, line1 ) );
  test_segment( seg1 );
  JFR_CHECK( !seg1.isTransformable() );
  // Test constructor based on two points
  SegmentD seg2( new typename SegmentD::TwoPointsPointerDriver( &point1, &point2 ) );
  test_segment_validity( seg2 );
  GEOM_CHECK_VEC_EQUAL( seg2.firstPoint(), point1.homogenousCoordinates() );
  GEOM_CHECK_VEC_EQUAL( seg2.lastPoint(), point2.homogenousCoordinates() );
  test_segment( seg2 );
  JFR_CHECK( !seg2.isTransformable() );
  // Test constructor based on two points
  SegmentD seg3( new typename SegmentD::TwoPointsDriver( point1.homogenousCoordinates(), point2.homogenousCoordinates() ) );
  test_segment_validity( seg3 );
  GEOM_CHECK_VEC_EQUAL( seg3.firstPoint(), point1.homogenousCoordinates() );
  GEOM_CHECK_VEC_EQUAL( seg3.lastPoint(), point2.homogenousCoordinates() );
  test_segment( seg3 );
  JFR_CHECK( seg3.isTransformable() );
  // Test transformability
  HomogenousMatrixD m = random_inversible_mat<dimension>();
  HomogenousMatrixD mInv;
  jmath::ublasExtra::inv( m, mInv );
  SegmentD seg3bis = seg3;
  seg3bis.applyTransformation( m );
  GEOM_CHECK_VEC_EQUAL( seg3bis.firstPoint(), ublas::prod(m, seg3.firstPoint() ) );
  GEOM_CHECK_VEC_EQUAL( seg3bis.lastPoint(), ublas::prod(m, seg3.lastPoint() ) );
  seg3bis.applyTransformation( mInv );
  GEOM_CHECK_VEC_EQUAL( seg3bis.firstPoint(), seg3.firstPoint() );
  GEOM_CHECK_VEC_EQUAL( seg3bis.lastPoint(), seg3.lastPoint() );
  
  // Test distance
  test_distance(seg1, seg2);
  test_distance(seg2, seg3);
  test_distance(seg1, seg3);
  test_distance(seg1, seg2.support());
  test_distance(seg1, seg3.support());
  test_distance(seg2, seg1.support());
  test_distance(seg2, seg3.support());
  test_distance(seg3, seg2.support());
  test_distance(seg3, seg1.support());
}
Exemple #26
0
std::string Diagnostics::GetFrameOverlayString(const GPUStats& aStats) {
  TimeStamp now = TimeStamp::Now();
  unsigned fps = unsigned(mCompositeFps.AddFrameAndGetFps(now));
  unsigned txnFps = unsigned(mTransactionFps.GetFPS(now));

  float pixelFillRatio =
      aStats.mInvalidPixels
          ? float(aStats.mPixelsFilled) / float(aStats.mInvalidPixels)
          : 0.0f;
  float screenFillRatio = aStats.mScreenPixels ? float(aStats.mPixelsFilled) /
                                                     float(aStats.mScreenPixels)
                                               : 0.0f;

  if (aStats.mDrawTime) {
    mGPUDrawMs.Add(aStats.mDrawTime.value());
  }

  std::string gpuTimeString;
  if (mGPUDrawMs.Empty()) {
    gpuTimeString = "N/A";
  } else {
    gpuTimeString = nsPrintfCString("%0.1fms", mGPUDrawMs.Average()).get();
  }

  // DL  = nsDisplayListBuilder
  // FLB = FrameLayerBuilder
  // R   = ClientLayerManager::EndTransaction
  // CP  = ShadowLayerForwarder::EndTransaction (txn build)
  // TX  = LayerTransactionChild::SendUpdate (IPDL serialize+send)
  // UP  = LayerTransactionParent::RecvUpdate (IPDL deserialize, update, APZ
  //                                           update)
  // CC_BUILD = Container prepare/composite frame building
  // CC_EXEC  = Container render/composite drawing
  nsPrintfCString line1("FPS: %d (TXN: %d)", fps, txnFps);
  nsPrintfCString line2(
      "[CC] Build: %0.1fms Exec: %0.1fms GPU: %s Fill Ratio: %0.1f/%0.1f",
      mPrepareMs.Average(), mCompositeMs.Average(), gpuTimeString.c_str(),
      pixelFillRatio, screenFillRatio);
  nsCString line3;
  if (mDlb2Ms.Average() != 0.0f) {
    line3 += nsPrintfCString(
        "[Content] DL: %0.1f/%0.1fms FLB: %0.1fms Raster: %0.1fms",
        mDlb2Ms.Average(), mDlbMs.Average(), mFlbMs.Average(),
        mRasterMs.Average());
  } else {
    line3 += nsPrintfCString(
        "[Content] DL: %0.1fms FLB: %0.1fms Raster: %0.1fms", mDlbMs.Average(),
        mFlbMs.Average(), mRasterMs.Average());
  }
  nsPrintfCString line4("[IPDL] Build: %0.1fms Send: %0.1fms Update: %0.1fms",
                        mSerializeMs.Average(), mSendMs.Average(),
                        mUpdateMs.Average());

  return std::string(line1.get()) + "\n" + std::string(line2.get()) + "\n" +
         std::string(line3.get()) + "\n" + std::string(line4.get());
}
Exemple #27
0
LocationPtr ParserBase::getLocation() const {
  auto location = std::make_shared<Location>();
  location->file  = file();
  location->line0 = line0();
  location->char0 = char0();
  location->line1 = line1();
  location->char1 = char1();
  location->cursor = cursor();
  return location;
}
Exemple #28
0
void
MFD::setPage ( MfdPage page )
{
    std::string line1(page.getLine1());
    std::string line2(page.getLine2());
    std::string line3(page.getLine3());
    if(isUpdateEnabled) {
        MFD::setLine1(line1, true);
        MFD::setLine2(line2, true);
        MFD::setLine3(line3, true);
    }
}
//-----------------------------------------------------------------------
Shape RoundedCornerSpline2::realizeShape()
{
	assert(!mPoints.empty());

	Shape shape;
	unsigned int numPoints = mClosed ? mPoints.size() : (mPoints.size() - 2);
	if (!mClosed)
			shape.addPoint(mPoints[0]);
		
	for (unsigned int i = 0; i < numPoints; ++i)
	{
		const Vector2& p0 = safeGetPoint(i);
		const Vector2& p1 = safeGetPoint(i+1);
		const Vector2& p2 = safeGetPoint(i+2);

		Vector2 vBegin = p1-p0;
		Vector2 vEnd = p2-p1;
		
		// We're capping the radius if it's too big compared to segment length
		Real radius = mRadius;
		Real smallestSegLength = std::min(vBegin.length(), vEnd.length());
		if (smallestSegLength < 2 * mRadius)
			radius = smallestSegLength / 2.0f;
		
		Vector2 pBegin = p1 - vBegin.normalisedCopy() * radius;
		Vector2 pEnd = p1 + vEnd.normalisedCopy() * radius;
		Line2D line1(pBegin, vBegin.perpendicular());
		Line2D line2(pEnd, vEnd.perpendicular());
		Vector2 center;
		line1.findIntersect(line2, center);
		Vector2 vradBegin = pBegin - center;
		Vector2 vradEnd = pEnd - center;		
		Radian angleTotal = Utils::angleBetween(vradBegin, vradEnd);
		if (vradBegin.crossProduct(vradEnd)<0)
			angleTotal = -angleTotal;
				
		for (unsigned int j=0;j<=mNumSeg;j++)
		{
			Vector2 deltaVector = Utils::rotateVector2(vradBegin, (Real)j * angleTotal / (Real)mNumSeg);
			shape.addPoint(center + deltaVector);
		}
	}

	if (!mClosed)
		shape.addPoint(mPoints[mPoints.size()-1]);

	if (mClosed)
			shape.close();
		shape.setOutSide(mOutSide);

	return shape;
}
Exemple #30
0
void billing(struct product *pro,int *sel,int *selqty,int n)
 {
   if(n==0)
    {
     line1();
     printf("\n\n\n Total Payable Bill : %d",total);
     printf("\n\n\n Thanks Visit Again!!!");
     return;
    }
   total+=((pro+*(sel))->price)*(*(selqty));
   printf("\n\n %-15.15s %-15d %-15d %-15d",(pro+*(sel))->name,(pro+*(sel))->price,*(selqty),((pro+*(sel))->price)*(*(selqty)));
   billing(pro,sel+1,selqty+1,n-1);
 }