double CQIllustratorShape:: distance(const CPoint2D &p) const { const CBBox2D &bbox = getFlatBBox(); const CPoint2D &p1 = bbox.getLL(); const CPoint2D &p2 = bbox.getUR(); if (p.x < p1.x) { if (p.y < p1.y) return pointDist(p, CPoint2D(p1.x, p1.y)); else if (p.y > p2.y) return pointDist(p, CPoint2D(p1.x, p2.y)); else return (p1.x - p.x); } else if (p.x > p2.x) { if (p.y < p1.y) return pointDist(p, CPoint2D(p2.x, p1.y)); else if (p.y > p2.y) return pointDist(p, CPoint2D(p2.x, p2.y)); else return (p.x - p2.x); } else { if (p.y < p1.y) return (p1.y - p.y); else if (p.y > p2.y) return (p.y - p2.y); else return 0; } }
QWidget * CQPropertySizeFEditor:: createEdit(QWidget *parent) { CQPoint2DEdit *edit = new CQPoint2DEdit(parent); edit->setSpin(true); edit->setMinimum(CPoint2D(0, 0)); edit->setMaximum(CPoint2D(max_, max_)); edit->setStep(CPoint2D(step_, step_)); return edit; }
void CPinhole::Render_Stereo(CWorld* _world, double _x, int _offset) { CRGBColor pixel_color; CRay ray; CPoint2D pt; double x, y; int nSample = _world->vp.nSamples; double hres = _world->vp.hres; double vres = _world->vp.vres; double size = _world->vp.size / m_zoom; /* * Clean before rendering */ ray.o = m_eye; for (int c = 0; c < hres; c++) { for (int r = 0; r < vres; r++) { pixel_color = CRGBColor(0, 0, 0); for (int p = 0; p < nSample; p++) { pt = _world->vp.sampler->Sample_unit_square(); x = size * (c - hres / 2 + pt.x) + _x; y = size * (r - vres / 2 + pt.y); ray.d = Ray_Direction(CPoint2D(x, y)); pixel_color += _world->tracer_ptr->Trace_Ray(ray); } pixel_color /= nSample; _world->m_screen->SetPixel(c+_offset, r, pixel_color); } } }
void SimpleNavigation::go() { //interface that will be used by the reactive nav to sense the environment and make the robot move //initial position mrpt::poses::CPose2D pose = CPoint2D(); float v = 0; float w = 0; interface->getCurrentPoseAndSpeeds(pose, v,w); double lat = pose.x(); double lon = pose.y(); // solves the tsp problem, in autonomous challenge we need to add some code here to make it work. TSPNavigation nav = TSPNavigation(lat,lon); nav.loadPoints(fileName, !inMeters); //waypoints in the order we want to visit them points = nav.solve(false); gotoNextPoint(); }
QPointF CQGnuPlotColorBox:: origin() const { CPoint3D p = CGnuPlotColorBox::origin().point(); return CQUtil::toQPoint(CPoint2D(p.x, p.y)); }
CPoint2D CGnuPlotStyleRadar:: radarPoint(const CPoint2D &o, double r, double a) const { double x = o.x + r*cos(CAngle::Deg2Rad(a)); double y = o.y + r*sin(CAngle::Deg2Rad(a)); return CPoint2D(x, y); }
bool CNPC::PlanBuilding(void) { int i,j,w,h; CPoint2D cur; memset(&my_plan,0,sizeof(my_plan)); memset(&cur_change,0,sizeof(cur_change)); //FIXME: single char only, ugly hardcoded shack, for testing only! w = 5; h = 4; for (i = 0; i < w; i++) for (j = 0; j < h; j++) { if ((i==0) || (i==4)) { my_plan.map[i][j] = CT_HH_Wall; continue; } switch (j) { case 0: my_plan.map[i][j] = CT_HH_Wall; break; case 3: my_plan.map[i][j] = CT_HH_Door; break; default: my_plan.map[i][j] = CT_HH_Empty; } } my_plan.map[1][1] = CT_HH_Bed; my_plan.map[2][1] = CT_HH_Bowl; //try to find a place for that my_plan.ul = my_coord; for (i = -1; i <= w; i++) { for (j = -1; j <= h; j++) { cur = my_plan.ul + CPoint2D(i,j); if (!ispointin(&cur,0,0,WRLD_SIZE_X,WRLD_SIZE_Y)) return false; if ((memory[cur.X][cur.Y].owned != signature) || (!memory[cur.X][cur.Y].routable)) return false; } } my_plan.sz = CPoint2D(w,h); return true; }
void CSVGBuffer:: windowToPixel(double xi, double yi, int *xo, int *yo) { CPoint2D p; renderer_->windowToPixel(CPoint2D(xi, yi), p); *xo = p.x; *yo = p.y; }
double CGnuPlotCoordValue:: getYValue(CGnuPlotRenderer *renderer, double y) const { CPoint2D w(0, y); if (system_ == CGnuPlotTypes::CoordSys::SECOND) { renderer->secondToWindow(CPoint2D(0.0, y), w); } else if (system_ == CGnuPlotTypes::CoordSys::GRAPH) { renderer->graphToWindow(CPoint2D(0.0, y), w); } else if (system_ == CGnuPlotTypes::CoordSys::SCREEN) { renderer->screenToWindow(CPoint2D(0.0, y), w); } else if (system_ == CGnuPlotTypes::CoordSys::CHARACTER) { renderer->charToWindow(CPoint2D(0.0, y), w); } return w.y; }
CMetaSixEdge::CMetaSixEdge() { m_point[0] = CPoint2D(-SQRT3*0.5f, -0.5f); m_point[1] = CPoint2D(-SQRT3*0.5f, 0.5f); m_point[2] = CPoint2D(0.0f, 1.0f); m_point[3] = CPoint2D(SQRT3*0.5f, 0.5f); m_point[4] = CPoint2D(SQRT3*0.5f, -0.5f); m_point[5] = CPoint2D(0.0f, -1.0f); }
void CQIllustratorShape:: moveBy(const CPoint2D &d) { assert(! getFixed()); checkoutShape(CQIllustratorData::ChangeType::GEOMETRY); CMatrix2D m; m.setTranslation(d.x, d.y); transform(CPoint2D(0, 0), m); checkinShape(CQIllustratorData::ChangeType::GEOMETRY); }
void CNPC::PutVision(CPoint2D ul, NPCVisualIn* arr) { CPoint2D rp; int x,y,lin; for (x = 0, lin = 0; x < WRLD_CHR_VIEW; x++) { for (y = 0; y < WRLD_CHR_VIEW; y++, lin++) { view[x][y] = arr[lin]; rp = CPoint2D(x,y) + ul; if (ispointin(&rp,0,0,WRLD_SIZE_X,WRLD_SIZE_Y)) { if (arr[lin].b.typ != CT_Empty) memory[rp.X][rp.Y] = arr[lin].b; } } } my_view_ul = ul; }
void CSVGBuffer:: pathText(const string &text, CFontPtr font, CHAlignType align) { renderer_->setFont(font); CBBox2D box; renderer_->textBounds(text, box); int dx; if (align == CHALIGN_TYPE_LEFT) dx = 0; else if (align == CHALIGN_TYPE_CENTER) dx = -box.getWidth()/2; else if (align == CHALIGN_TYPE_RIGHT) dx = -box.getWidth(); renderer_->pathRMoveTo(CPoint2D(dx, 0)); renderer_->pathText(text); }
CQAlignAnchorPoint:: CQAlignAnchorPoint(QWidget *parent) : QWidget(parent) { QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(0); layout->setSpacing(2); pointEdit_ = new CQPointEdit(CPoint2D(0,0)); pointEdit_->setFocusPolicy(Qt::ClickFocus); layout->addWidget(pointEdit_); selButton_ = new QToolButton; selButton_->setCheckable(true); selButton_->setAutoRaise(true); selButton_->setIcon(CQPixmapCacheInst->getIcon("ALIGN_SELECT")); connect(selButton_, SIGNAL(clicked(bool)), this, SLOT(selectSlot(bool))); layout->addWidget(selButton_); }
void CGnuPlotStyleBivariate:: draw2D(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotBivariateStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotBivariateStyleValue>(plot); if (! value) { value = plot->app()->device()->createBivariateStyleValue(plot); //value->init(plot->bivariateStyleValue()); CGnuPlotStyleValueMgrInst->setValue<CGnuPlotBivariateStyleValue>(plot, value); } //--- CGnuPlotStroke stroke(plot); //------ typedef std::vector<CGnuPlotPointData> PointDatas; PointDatas pointDatas; for (const auto &point : plot->getPoints2D()) { std::vector<double> reals; (void) point.getReals(reals); if (reals.size() != 3) continue; double x = reals[0]; double y1 = reals[1]; double y2 = reals[2]; CRGBA c1 = stroke.color(); CGnuPlotPointData data; data.setPoint (CPoint2D(x, y1)); data.setSize (y2 - y1); data.setPointType(CGnuPlotTypes::SymbolType::BIVARIATE); data.setLineWidth(stroke.width()); data.setColor (c1); pointDatas.push_back(data); } //---- if (! renderer->isPseudo()) plot->updatePointCacheSize(pointDatas.size()); int pointNum = 0; for (const auto &data : pointDatas) { if (! renderer->isPseudo()) { CGnuPlotPointObject *point = plot->pointObjects()[pointNum]; if (! point->testAndSetUsed()) { point->setData(data); } else { point->setPoint(data.point()); } } else { renderer->drawPoint(data.point(), data.color()); renderer->drawPoint(data.point() + CPoint2D(0, data.size().getValue(0)), data.color()); } ++pointNum; } if (! renderer->isPseudo()) { for (const auto &point : plot->pointObjects()) point->draw(renderer); } }
void CGnuPlotStyleCandlesticks:: draw2D(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotCandlesticksStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotCandlesticksStyleValue>(plot); if (! value) { value = plot->app()->device()->createCandlesticksStyleValue(plot); value->init(); CGnuPlotStyleValueMgrInst->setValue<CGnuPlotCandlesticksStyleValue>(plot, value); } //--- CGnuPlotGroup *group = plot->group(); const CGnuPlotLineStyle &lineStyle = plot->lineStyle(); CGnuPlotFill fill (plot); CGnuPlotStroke stroke(plot); bool isCalcColor = lineStyle.isCalcColor(); double bw = value->getSpacing(); //--- if (! renderer->isPseudo()) plot->updateBoxBarCacheSize(plot->getPoints2D().size()); int i = 0; for (const auto &point : plot->getPoints2D()) { std::vector<double> reals; (void) point.getReals(reals); uint minN = (isCalcColor ? 6 : 5); while (reals.size() < minN) reals.push_back(0); double x = reals[0]; double bmin = reals[1]; double wmin = reals[2]; double wmax = reals[3]; double bmax = reals[4]; if (renderer->isPseudo() && ! renderer->isInside(CPoint2D(x, bmin))) continue; double bw1 = bw; int ind = 5; if ((! isCalcColor && reals.size() > 5) || (isCalcColor && reals.size() > 6)) bw1 = reals[++ind]; CRGBA lc1 = stroke.color(); CRGBA fc1 = fill .color(); if (isCalcColor) { double z = reals[ind]; if (renderer->isPseudo()) renderer->setCBValue(z); else { lc1 = lineStyle.calcColor(plot, z); fc1 = lineStyle.calcColor(plot, z); } } //--- CPoint2D p1(x, wmin); CPoint2D p2(x, bmin); CPoint2D p3(x, bmax); CPoint2D p4(x, wmax); p1 = group->mapLogPoint(plot->xind(), plot->yind(), 1, p1); p2 = group->mapLogPoint(plot->xind(), plot->yind(), 1, p2); p3 = group->mapLogPoint(plot->xind(), plot->yind(), 1, p3); p4 = group->mapLogPoint(plot->xind(), plot->yind(), 1, p4); double x1 = p1.x - bw1/2; double x2 = p1.x + bw1/2; CBBox2D bbox(x1, p2.y, x2, p3.y); CGnuPlotTypes::FillType fillType = fill.type(); if (fillType == CGnuPlotTypes::FillType::EMPTY) { if (bmin > bmax) fillType = CGnuPlotTypes::FillType::SOLID; } if (! renderer->isPseudo()) { CGnuPlotBoxBarObject *bar = plot->boxBarObjects()[i]; bar->setBBox(bbox); bar->setValues(p1.x, bmin); bar->setVertical(true); if (! bar->testAndSetUsed()) { CGnuPlotFillP fill (bar->fill ()->dup()); CGnuPlotStrokeP stroke(bar->stroke()->dup()); fill ->setType (fillType); fill ->setColor(fc1); stroke->setColor(lc1); bar->setFill (fill ); bar->setStroke(stroke); //--- bar->clearEndBars(); CGnuPlotEndBarP endBar1 = bar->addEndBar(p1, p2); CGnuPlotEndBarP endBar2 = bar->addEndBar(p3, p4); bool hasBars = plot->whiskerBars().isValid(); endBar1->setStartLine(hasBars); endBar1->setEndLine(false ); endBar2->setStartLine(false ); endBar2->setEndLine(hasBars); if (hasBars) { endBar1->setEndWidth(bw1*plot->whiskerBars().getValue()); endBar2->setEndWidth(bw1*plot->whiskerBars().getValue()); } CGnuPlotStrokeP endStroke1(bar->stroke()->dup()); CGnuPlotStrokeP endStroke2(bar->stroke()->dup()); endBar1->setStroke(endStroke1); endBar2->setStroke(endStroke2); } } else { renderer->drawClipLine(p1, p2, lc1, stroke.width()); renderer->drawClipLine(p3, p4, lc1, stroke.width()); if (plot->whiskerBars() > 0) { renderer->drawClipLine(CPoint2D(x1, p1.y), CPoint2D(x2, p1.y), lc1, stroke.width()); renderer->drawClipLine(CPoint2D(x1, p4.y), CPoint2D(x2, p4.y), lc1, stroke.width()); } if (fillType != CGnuPlotTypes::FillType::EMPTY) { CGnuPlotFill fill1 = fill; fill1.setType (fillType); fill1.setColor(fc1); renderer->fillClippedRect(bbox, fill1); } renderer->drawClippedRect(bbox, lc1, 1); } ++i; } if (! renderer->isPseudo()) { for (const auto &bar : plot->boxBarObjects()) bar->draw(renderer); } }
void CGnuPlotStyleBoxErrorBars:: draw2D(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotBoxErrorBarsStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotBoxErrorBarsStyleValue>(plot); if (! value) { value = plot->app()->device()->createBoxErrorBarsStyleValue(plot); value->init(); CGnuPlotStyleValueMgrInst->setValue<CGnuPlotBoxErrorBarsStyleValue>(plot, value); } //--- const CGnuPlotLineStyle &lineStyle = plot->lineStyle(); CGnuPlotFill fill (plot); CGnuPlotStroke stroke(plot); bool isCalcColor = lineStyle.isCalcColor(); CBBox2D bbox = plot->bbox2D(); double ymin = bbox.getYMin(); double y2 = std::max(0.0, ymin); double bw = value->getSpacing(); //--- if (! renderer->isPseudo()) plot->updateBoxBarCacheSize(plot->getPoints2D().size()); //--- int i = 0; for (const auto &point : plot->getPoints2D()) { std::vector<double> reals; (void) point.getReals(reals); COptReal colorVal; if (isCalcColor && ! reals.empty()) { colorVal = reals.back(); reals.pop_back(); } while (reals.size() < 3) reals.push_back(0.0); double x = reals[0]; double y = reals[1]; double dx = bw; double dy = 0.0; double yl = y; double yh = y; // x y ydelta if (reals.size() == 3) { dy = reals[2]; yl = y - dy; yh = y + dy; } else if (reals.size() == 4) { // x y ydelta xdelta if (! value->isAutoWidth()) { dx = reals[2]; dy = reals[3]; yl = y - dy; yh = y + dy; } // x y ylow yhigh else { yl = reals[2]; yh = reals[3]; } } // x y ylow yhigh xdelta else if (reals.size() >= 5) { yl = reals[2]; yh = reals[3]; dx = reals[4]; } //--- COptRGBA lc; if (colorVal.isValid()) { if (renderer->isPseudo()) renderer->setCBValue(colorVal.getValue()); else lc = lineStyle.calcColor(plot, colorVal.getValue()); } //--- CBBox2D bbox(x - dx/2, y2, x + dx/2, y); CPoint2D p1(x, yl); CPoint2D p2(x, yh); if (! renderer->isPseudo()) { CGnuPlotBoxBarObject *bar = plot->boxBarObjects()[i]; bar->setBBox(bbox); bar->setValues(x, y); bar->setVertical(true); if (! bar->testAndSetUsed()) { CGnuPlotFillP fill (bar->fill ()->dup()); CGnuPlotStrokeP stroke(bar->stroke()->dup()); bar->setFill (fill ); bar->setStroke(stroke); //--- bar->clearEndBars(); CGnuPlotEndBarP endBar = bar->addEndBar(p1, p2); endBar->setStartLine(true); endBar->setEndLine (true); endBar->setEndWidth (dx/2); CGnuPlotStrokeP endStroke(bar->stroke()->dup()); endBar->setStroke(endStroke); } } else { CGnuPlotStroke stroke; stroke.setEnabled(true); renderer->strokeRect(bbox, stroke); renderer->strokeClipLine(p1, p2, stroke); double w = dx/2; renderer->strokeClipLine(p1 - CPoint2D(w/2, 0), p1 + CPoint2D(w/2, 0), stroke); renderer->strokeClipLine(p2 - CPoint2D(w/2, 0), p2 + CPoint2D(w/2, 0), stroke); } ++i; } if (! renderer->isPseudo()) { for (const auto &bar : plot->boxBarObjects()) bar->draw(renderer); } }
void CNPC::Quantum(void) { if (dead) return; if (++tick >= chrom[CHR_LIFESP]) { dead = true; //stop talking if you're dead :) if (my_state == NPC_Talking) if (my_stats.talk_to) my_stats.talk_to->StopTalkTo(this); my_state = NPC_Idle; return; } //do something to reach our goal (if it exists, of course) // if ((my_stats.aimed) && (my_stats.aim != my_coord)) { // //check correctness of currently selected direction // if (my_stats.last_dist <= distance(my_stats.aim,my_coord)) { // if (!my_stats.stuck) SetDirectionTo(); //we resolve it below // } // //remember the distance! :) // my_stats.last_dist = distance(my_stats.aim,my_coord); // //and switch to walking if we're near // if ((my_stats.last_dist < 3) && (my_state == NPC_Running)) // my_state = NPC_Walking; // } else // my_stats.last_dist = 0; //-------------------NPC' state machine------------------- switch (my_state) { case NPC_Idle: my_stats.direction = -1; if (my_stats.idle_count++ > rnd->RangedNumber(chrom[CHR_LAZINS])) { my_stats.idle_count = 0; my_state = (my_stats.building)? NPC_Building:NPC_Browsing; } break; case NPC_Running: my_stats.stamina--; //no break case NPC_Walking: my_stats.idle_count = 0; if (--my_stats.stamina <= 0) { my_state = NPC_Sleeping; return; } if (my_coord == my_stats.aim) { my_state = (my_stats.building)? NPC_Building:NPC_Browsing; return; } if (my_stats.stuck) { my_stats.stuck = false; if (my_stats.aimed) { //right-hand rule // if (++my_stats.direction > 7) my_stats.direction = 0; my_stats.direction = -1; //reset direction if (!AimTo()) my_state = NPC_Browsing; } else my_state = NPC_Idle; } //TODO: move along routed path break; case NPC_Sleeping: my_stats.aimed = false; my_stats.talk_to = NULL; if (my_stats.on_bed) my_stats.stamina += 3; else my_stats.stamina++; if (my_stats.stamina >= chrom[CHR_STRGTH]) my_state = NPC_Idle; my_stats.idle_count = 0; break; case NPC_Browsing: my_stats.aimed = false; if (my_stats.direction >= 0) { //already have some visual information if (PlanTalking()) return; } if (++my_stats.direction >= 8) { //it's time to make a decision my_stats.direction = rnd->RangedNumber(8); if ((!my_stats.own_home) && (!my_stats.building) && (PlanBuilding())) my_state = NPC_Building; else my_state = NPC_Walking; } break; case NPC_Talking: my_stats.aimed = false; if (my_stats.idle_count++ > my_stats.stamina) { if (my_stats.talk_to) my_stats.talk_to->StopTalkTo(this); my_state = NPC_Idle; return; } if (my_stats.talk_to) //just in case SetDisposition(my_stats.talk_to->GetSign(), GetDisposition(my_stats.talk_to->GetSign() + my_stats.talk_to->TalkAbout(chrom[rnd->RangedNumber(CHR_TRAITD-CHR_TRAITA+1)+CHR_TRAITA]))); else my_state = NPC_Idle; //failsafe break; case NPC_Building: my_plan.cur = CPoint2D(my_plan.done/(my_plan.sz.X-1),my_plan.done%(my_plan.sz.X-1)); // my_stats.aim = my_plan.cur + my_plan.ul; // my_stats.aimed = true; if (!AimTo(my_plan.cur + my_plan.ul)) { //unable to reach destination cell // my_stats.building = false; my_state = NPC_Idle; //let's wait return; } if (!my_stats.building) //well, let's do it my_stats.building = true; if (my_coord != my_stats.aim) { // SetDirectionTo(); // AimTo(); my_state = NPC_Walking; return; } if (cur_change.changed) { //continue cur_change.want_change = cur_change.changed = false; if (++my_plan.done >= my_plan.sz.X*my_plan.sz.Y) { //done my_stats.building = false; my_stats.aimed = false; my_stats.direction = 4; my_stats.own_home = true; my_stats.stamina = 1; my_state = NPC_Walking; return; } } else if (!cur_change.want_change) { cur_change.want_change = true; cur_change.change_to = my_plan.map[my_plan.cur.X][my_plan.cur.Y]; if (cur_change.change_to == CT_Empty) abort(); } else { if (++my_stats.idle_count > chrom[CHR_STRGTH]) { //abandon all hope my_stats.building = false; my_state = NPC_Idle; } } break; default: ; } }
void CSVGBuffer:: pathRBezier3To(double x1, double y1, double x2, double y2, double x3, double y3) { renderer_->pathRCurveTo(CPoint2D(x1, y1), CPoint2D(x2, y2), CPoint2D(x3, y3)); }
void CSVGBuffer:: pathBezier2To(double x1, double y1, double x2, double y2) { renderer_->pathCurveTo(CPoint2D(x1, y1), CPoint2D(x2, y2)); }
void CSVGBuffer:: pathArcTo(double cx, double cy, double rx, double ry, double theta1, double theta2) { renderer_->pathArcTo(CPoint2D(cx, cy), rx, ry, theta1, theta2); }
CPoint2D CPoint2D::rotate_about(CPoint2D& o, double rad) { return CPoint2D((m_x-o.x()) * cos(rad) - (m_y - o.y()) * sin(rad) + o.x(), (m_y-o.y()) * cos(rad) + (m_x - o.x()) * sin(rad) + o.y()); }
NodePoint(Type type1=NONE, int i1=0, int id1=0, const CPoint2D &p1=CPoint2D()) : type(type1), i(i1), id(id1), p(p1), ip(NULL), used(false) { }
void CSVGBuffer:: drawImage(double x, double y, CImagePtr image) { renderer_->drawImage(CPoint2D(x, y), image); }
void CGnuPlotStylePieChart:: drawKey(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotPieChartStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotPieChartStyleValue>(plot); if (! value) return; //--- CGnuPlotGroup *group = plot->group(); const CGnuPlotKeyP &key = group->key(); //const CGnuPlotAxisData &xaxis = group->xaxis(1); if (! key->isDisplayed()) return; if (key->getFont().isValid()) renderer->setFont(key->getFont()); CGnuPlotFill fill(plot); //--- CBBox2D rbbox = (key->isOutside() ? group->getRegionBBox() : renderer->range()); //--- CFontPtr font = renderer->getFont(); double font_size = font->getCharAscent() + font->getCharDescent(); double pw = renderer->pixelWidthToWindowWidth (1); double ph = renderer->pixelHeightToWindowHeight(1); double bx = 8*pw; double by = 8*ph; double bw = font_size - 2; CSize2D size; double textWidth = 0.0, textHeight = 0.0; std::string header; if (key->hasTitle()) { header = key->title(); if (header != "") textHeight += font_size*ph; } NameValueColors values = nameValueColors(plot, value->palette(), value->alpha()); for (const auto &v : values) { std::string label = v.first; textWidth = std::max(textWidth, font->getStringWidth(label)*pw); textHeight += font_size*ph; } size = CSize2D(textWidth + bw*pw + 3*bx, textHeight + 2*by); CHAlignType halign = key->getHAlign(); CVAlignType valign = key->getVAlign(); double x1 = 0, y1 = 0; if (halign == CHALIGN_TYPE_LEFT) x1 = rbbox.getLeft () + bx; else if (halign == CHALIGN_TYPE_RIGHT) x1 = rbbox.getRight() - bx - size.getWidth(); else if (halign == CHALIGN_TYPE_CENTER) x1 = rbbox.getXMid() - size.getWidth()/2; if (valign == CVALIGN_TYPE_TOP) y1 = rbbox.getTop () - by - size.getHeight(); else if (valign == CVALIGN_TYPE_BOTTOM) y1 = rbbox.getBottom() + by; else if (valign == CVALIGN_TYPE_CENTER) y1 = rbbox.getYMid() - size.getHeight()/2; double x2 = x1 + size.getWidth (); double y2 = y1 + size.getHeight(); CBBox2D bbox(x1, y1, x2, y2); if (key->getFillBox()) { renderer->fillRect(bbox, fill.background()); } if (key->getDrawBox()) { CRGBA c(0, 0, 0); if (key->hasLineType()) c = CGnuPlotStyleInst->indexColor(key->getLineType()); renderer->drawRect(bbox, c, 1); } double y = y2 - by; if (header != "") { renderer->drawHAlignedText(CPoint2D((x1 + x2)/2, y), HAlignPos(CHALIGN_TYPE_CENTER, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), header, CRGBA(0,0,0)); y -= font_size*ph; } if (! renderer->isPseudo()) plot->updatePieCacheSize(values.size()); int pi = 0; for (const auto &v : values) { CGnuPlotPieObject *pieObject = 0; if (! renderer->isPseudo()) pieObject = plot->pieObjects()[pi]; //--- const std::string &name = v .first; const ValueColor &vc = v .second; const LineFillColor &lfc = vc.second; double xx = (key->isReverse() ? x1 + bx : x2 - bw*pw - bx); double yy = y - font_size*ph/2; CPoint2D p1(xx, yy - bw*ph/2), p2(xx + bw*pw, yy + bw*ph/2); CBBox2D bbox(p1, p2); renderer->fillEllipse(bbox, lfc.second); renderer->drawEllipse(bbox, lfc.first, 1); //double lw = font->getStringWidth(name); CRGBA tc = CRGBA(0,0,0); if (key->isReverse()) renderer->drawHAlignedText(CPoint2D(xx + bw*pw + bx, y), HAlignPos(CHALIGN_TYPE_LEFT, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), name, tc); else renderer->drawHAlignedText(CPoint2D(xx - bx, y), HAlignPos(CHALIGN_TYPE_RIGHT, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), name, tc); if (pieObject) { CBBox2D keyRect(x1, y - font_size*ph, x2, y); pieObject->setKeyRect(keyRect); //renderer->drawRect(keyRect, lfc.second, 1); } y -= font_size*ph; ++pi; } }
void CGnuPlotStyleRadar:: drawKey(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer) { CGnuPlotRadarStyleValue *value = CGnuPlotStyleValueMgrInst->getValue<CGnuPlotRadarStyleValue>(plot); if (! value) return; //--- CGnuPlotGroup *group = plot->group(); const CGnuPlotKeyP &key = group->key(); const CGnuPlotAxisData &xaxis = group->xaxis(1); if (! key->isDisplayed()) return; if (key->getFont().isValid()) renderer->setFont(key->getFont()); CGnuPlotFill fill(plot); //--- CBBox2D rbbox = (key->isOutside() ? group->getRegionBBox() : renderer->range()); //--- CFontPtr font = renderer->getFont(); double font_size = font->getCharAscent() + font->getCharDescent(); double pw = renderer->pixelWidthToWindowWidth (1); double ph = renderer->pixelHeightToWindowHeight(1); double bx = 8*pw; double by = 8*ph; double bw = font_size - 2; CSize2D size; double textWidth = 0.0, textHeight = 0.0; std::string header; if (key->hasTitle()) { header = key->title(); if (header != "") textHeight += font_size*ph; } int i = 0; for (const auto &point : plot->getPoints2D()) { assert(! point.isDiscontinuity()); std::string label = xaxis.iticLabel(i); //std::string label = point.label(); textWidth = std::max(textWidth, font->getStringWidth(label)*pw); textHeight += font_size*ph; ++i; } size = CSize2D(textWidth + bw*pw + 3*bx, textHeight + 2*by); CHAlignType halign = key->getHAlign(); CVAlignType valign = key->getVAlign(); double x1 = 0, y1 = 0; if (halign == CHALIGN_TYPE_LEFT) x1 = rbbox.getLeft () + bx; else if (halign == CHALIGN_TYPE_RIGHT) x1 = rbbox.getRight() - bx - size.getWidth(); else if (halign == CHALIGN_TYPE_CENTER) x1 = rbbox.getXMid() - size.getWidth()/2; if (valign == CVALIGN_TYPE_TOP) y1 = rbbox.getTop () - by - size.getHeight(); else if (valign == CVALIGN_TYPE_BOTTOM) y1 = rbbox.getBottom() + by; else if (valign == CVALIGN_TYPE_CENTER) y1 = rbbox.getYMid() - size.getHeight()/2; double x2 = x1 + size.getWidth (); double y2 = y1 + size.getHeight(); CBBox2D bbox(x1, y1, x2, y2); if (key->getFillBox()) { renderer->fillRect(bbox, fill.background()); } if (key->getDrawBox()) { CRGBA c(0, 0, 0); if (key->hasLineType()) c = CGnuPlotStyleInst->indexColor(value->palette(), key->getLineType()); renderer->drawRect(bbox, c, 1); } double y = y2 - by; if (header != "") { CRGBA tc = CRGBA(0,0,0); renderer->drawHAlignedText(CPoint2D((x1 + x2)/2, y), HAlignPos(CHALIGN_TYPE_CENTER, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), header, tc); y -= font_size*ph; } int pi = 0; for (const auto &point : plot->getPoints2D()) { assert(! point.isDiscontinuity()); double xx = (key->isReverse() ? x1 + bx : x2 - bw*pw - bx); double yy = y - font_size*ph/2; CPoint2D p1(xx, yy - bw*ph/2), p2(xx + bw*pw, yy + bw*ph/2); CRGBA lc, fc; getPointsColor(value, pi + 1, lc, fc); CBBox2D bbox(p1, p2); renderer->fillRect(bbox, fc); renderer->drawRect(bbox, lc, 1); std::string label = xaxis.iticLabel(pi); //std::string label = point.label(); //double lw = font->getStringWidth(label); CRGBA tc = CRGBA(0,0,0); if (key->isReverse()) renderer->drawHAlignedText(CPoint2D(xx + bw*pw + bx, y), HAlignPos(CHALIGN_TYPE_LEFT, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), label, tc); else renderer->drawHAlignedText(CPoint2D(xx - bx, y), HAlignPos(CHALIGN_TYPE_RIGHT, 0), VAlignPos(CVALIGN_TYPE_TOP, 0), label, tc); y -= font_size*ph; ++pi; } }
void CQIllustratorAlignMode:: align(CQIllustrator::AlignSide side, bool commit) { CQIllustratorSelectedShapes *selection = illustrator_->getSelection(); if (selection->empty()) return; //------ if (illustrator_->getFlipY()) { if (side == CQIllustrator::ALIGN_BOTTOM) side = CQIllustrator::ALIGN_TOP; else if (side == CQIllustrator::ALIGN_TOP ) side = CQIllustrator::ALIGN_BOTTOM; } //------ CQIllustratorShape *ashape = 0; CBBox2D abbox; CBBox2D bbbox; bool afixed = false; CQIllustratorAlignToolbar::AnchorMode anchorMode = toolbar_->getAnchorMode(); if (anchorMode == CQIllustratorAlignToolbar::AnchorMode::SELECTION) { // get anchor shape for side CQIllustratorSelectedShapes::iterator ps1, ps2; ps1 = selection->begin(); ps2 = selection->end(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); bbbox += shape->getFlatBBox(); } ps1 = selection->begin(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); const CBBox2D &bbox = shape->getFlatBBox(); if (! abbox.isSet() || (! afixed && shape->getFixed())) { ashape = shape; abbox = bbox; afixed = ashape->getFixed(); continue; } if (afixed && ! shape->getFixed()) continue; if ((side == CQIllustrator::ALIGN_LEFT && bbox.getXMin() < abbox.getXMin()) || (side == CQIllustrator::ALIGN_BOTTOM && bbox.getYMin() < abbox.getYMin()) || (side == CQIllustrator::ALIGN_RIGHT && bbox.getXMax() > abbox.getXMax()) || (side == CQIllustrator::ALIGN_TOP && bbox.getYMax() > abbox.getYMax()) || (side == CQIllustrator::ALIGN_HORIZONTAL && bbox.getYMid() < abbox.getYMid()) || (side == CQIllustrator::ALIGN_VERTICAL && bbox.getXMid() < abbox.getXMid())) { ashape = shape; abbox = bbox; afixed = ashape->getFixed(); } } } else if (anchorMode == CQIllustratorAlignToolbar::AnchorMode::OBJECT) { CQIllustratorShape *shape = illustrator_->getShape(toolbar_->getAnchorObject().toStdString()); if (shape == 0) return; CQIllustratorAlignToolbar::ObjectEdgeType edgeType = toolbar_->getAnchorObjectEdgeType(); abbox = shape->getFlatBBox(); if (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::LEFT_BOTTOM) abbox = CBBox2D(abbox.getLL(), abbox.getLR()); else if (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::RIGHT_TOP) abbox = CBBox2D(abbox.getUR(), abbox.getUR()); else if (edgeType == CQIllustratorAlignToolbar::ObjectEdgeType::MIDDLE) abbox = CBBox2D(abbox.getCenter(), abbox.getCenter()); bbbox = abbox; } else if (anchorMode == CQIllustratorAlignToolbar::AnchorMode::POSITION) { QPointF pos = toolbar_->getAnchorPosition(); abbox = CBBox2D(CQUtil::fromQPoint(pos), CQUtil::fromQPoint(pos)); CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); const CBBox2D &bbox = shape->getFlatBBox(); bbbox += bbox; } } else return; // align double offset = toolbar_->getOffset(); if (commit) { illustrator_->startUndoGroup("Align"); CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); if (shape->getFixed()) continue; const CBBox2D &bbox = shape->getFlatBBox(); double dx = 0.0, dy = 0.0; if (shape != ashape) { if (side == CQIllustrator::ALIGN_LEFT ) dx = abbox.getXMin() - bbox.getXMin(); else if (side == CQIllustrator::ALIGN_BOTTOM ) dy = abbox.getYMin() - bbox.getYMin(); else if (side == CQIllustrator::ALIGN_RIGHT ) dx = abbox.getXMax() - bbox.getXMax(); else if (side == CQIllustrator::ALIGN_TOP ) dy = abbox.getYMax() - bbox.getYMax(); else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy = abbox.getYMid() - bbox.getYMid(); else if (side == CQIllustrator::ALIGN_VERTICAL ) dx = abbox.getXMid() - bbox.getXMid(); } if (side == CQIllustrator::ALIGN_LEFT ) dx += offset; else if (side == CQIllustrator::ALIGN_BOTTOM ) dy += offset; else if (side == CQIllustrator::ALIGN_RIGHT ) dx -= offset; else if (side == CQIllustrator::ALIGN_TOP ) dy -= offset; else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy += offset; else if (side == CQIllustrator::ALIGN_VERTICAL ) dx += offset; shape->moveBy(CPoint2D(dx, dy)); } illustrator_->endUndoGroup(); illustrator_->setDimmed(false); illustrator_->clearPreviewObjects(); illustrator_->redraw(); } else { illustrator_->clearPreviewObjects(); CQIllustratorSelectedShapes::iterator ps1 = selection->begin(), ps2 = selection->end(); for ( ; ps1 != ps2; ++ps1) { CQIllustratorShape *shape = (*ps1).getShape(); if (shape->getFixed()) continue; const CBBox2D &bbox = shape->getFlatBBox(); double dx = 0.0, dy = 0.0; if (shape != ashape) { if (side == CQIllustrator::ALIGN_LEFT ) dx = abbox.getXMin() - bbox.getXMin(); else if (side == CQIllustrator::ALIGN_BOTTOM ) dy = abbox.getYMin() - bbox.getYMin(); else if (side == CQIllustrator::ALIGN_RIGHT ) dx = abbox.getXMax() - bbox.getXMax(); else if (side == CQIllustrator::ALIGN_TOP ) dy = abbox.getYMax() - bbox.getYMax(); else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy = abbox.getYMid() - bbox.getYMid(); else if (side == CQIllustrator::ALIGN_VERTICAL ) dx = abbox.getXMid() - bbox.getXMid(); } if (side == CQIllustrator::ALIGN_LEFT ) dx += offset; else if (side == CQIllustrator::ALIGN_BOTTOM ) dy += offset; else if (side == CQIllustrator::ALIGN_RIGHT ) dx -= offset; else if (side == CQIllustrator::ALIGN_TOP ) dy -= offset; else if (side == CQIllustrator::ALIGN_HORIZONTAL) dy += offset; else if (side == CQIllustrator::ALIGN_VERTICAL ) dx += offset; illustrator_->addPreviewObject(new CQIllustrator::PreviewShape(shape, CPoint2D(dx, dy))); } double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0; if (side == CQIllustrator::ALIGN_LEFT || side == CQIllustrator::ALIGN_RIGHT) { x1 = abbox.getXMin(); x2 = abbox.getXMax(); y1 = bbbox.getYMin(); y2 = bbbox.getYMax(); } else if (side == CQIllustrator::ALIGN_BOTTOM || side == CQIllustrator::ALIGN_TOP) { y1 = abbox.getYMin(); y2 = abbox.getYMax(); x1 = bbbox.getXMin(); x2 = bbbox.getXMax(); } else if (side == CQIllustrator::ALIGN_HORIZONTAL) { x1 = bbbox.getXMin(); x2 = bbbox.getXMax(); y1 = abbox.getYMid(); y2 = y2; } else if (side == CQIllustrator::ALIGN_VERTICAL) { y1 = bbbox.getYMin(); y2 = bbbox.getYMax(); x1 = abbox.getXMid(); x2 = x1; } double dx = (x2 - x1)/8; double dy = (y2 - y1)/8; if (side == CQIllustrator::ALIGN_LEFT ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1, y1 - dy), CPoint2D(x1, y2 + dy))); else if (side == CQIllustrator::ALIGN_BOTTOM ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y1), CPoint2D(x2 + dx, y1))); else if (side == CQIllustrator::ALIGN_RIGHT ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x2, y1 - dy), CPoint2D(x2, y2 + dy))); else if (side == CQIllustrator::ALIGN_TOP ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y2), CPoint2D(x2 + dx, y2))); else if (side == CQIllustrator::ALIGN_HORIZONTAL) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1 - dx, y1), CPoint2D(x2 + dx, y1))); else if (side == CQIllustrator::ALIGN_VERTICAL ) illustrator_->addPreviewObject( new CQIllustrator::PreviewLine(CPoint2D(x1, y1 - dy), CPoint2D(x1, y2 + dy))); illustrator_->redrawOverlay(); } }
void CSVGBuffer:: pathLineTo(double x, double y) { renderer_->pathLineTo(CPoint2D(x, y)); }
CPoint2D CGWIC_Cell::GetCoord() { return CPoint2D(this->posX,this->posY); }
void CSVGBuffer:: pathRLineTo(double dx, double dy) { renderer_->pathRLineTo(CPoint2D(dx, dy)); }