dPoint Conv::units_bck(dPoint p) const{ dPoint p1 = p + dPoint(1,0); dPoint p2 = p + dPoint(0,1); bck(p), bck(p1), bck(p2); return dPoint(pdist(p1-p), pdist(p2-p)); }
double Conv::ang_bck(dPoint p, double a, double dx) const{ dPoint p1 = p + dPoint(dx*cos(a), dx*sin(a)); dPoint p2 = p - dPoint(dx*cos(a), dx*sin(a)); bck(p1); bck(p2); p1-=p2; return atan2(p1.y, p1.x); }
void PageBox::ch_page() { if (no_ch) return; dPoint p = page->get_active_id(); if (p.x==0) { signal_changed_.emit(); return; } double d = dpi->get_value(); // convert margins to mm double m = marg->get_value() * u2mm(m_units->get_active_id(),d); p-=2*dPoint(m,m); if (p.x<0) p.x=0; if (p.y<0) p.y=0; // convert p to interface units: p/=u2mm(units->get_active_id(),d); bool sw = landsc->get_active(); no_ch=true; x->set_value(sw? p.y:p.x); y->set_value(sw? p.x:p.y); no_ch=false; signal_changed_.emit(); }
vector<cv::Point> ImageTransformation::getPointsRandomTransformation(vector<cv::Point> iP, Mat_<float> mx, Mat_<float> my) { vector<Point> iiP; for(int i = 0; i < iP.size(); ++i) { int x = mx(iP[i].x,iP[i].y); int y = my(iP[i].x,iP[i].y); // qDebug()<< "x:" << iP[i].x << "to" << x; // qDebug()<< "y:" << iP[i].y << "to" << y; Point dPoint(x,y); iiP.push_back(dPoint); } return iiP; }
QPointF KisCoordinatesConverter::centeringCorrection() const { KisConfig cfg; QSize documentSize = imageRectInWidgetPixels().toAlignedRect().size(); QPointF dPoint(documentSize.width(), documentSize.height()); QPointF wPoint(m_d->canvasWidgetSize.width(), m_d->canvasWidgetSize.height()); QPointF minOffset = -cfg.vastScrolling() * wPoint; QPointF maxOffset = dPoint - wPoint + cfg.vastScrolling() * wPoint; QPointF range = maxOffset - minOffset; range.rx() = qMin(range.x(), (qreal)0.0); range.ry() = qMin(range.y(), (qreal)0.0); range /= 2; return -range; }
bool Cube::intersect(Vertex p, Vect d, vector<Shape *> * intersects){ Vertex dPoint(d.x, d.y, d.z); translate(-trans[0], -trans[1], -trans[2], &p); rotate(-rot[2], 0, 0 , 1, &p); rotate(-rot[1], 0, 1 , 0, &p); rotate(-rot[0], 1, 0 , 0, &p); rotate(-rot[2], 0, 0 , 1, &dPoint); rotate(-rot[1], 0, 1 , 0, &dPoint); rotate(-rot[0], 1, 0 , 0, &dPoint); scale(1/scal[0], 1/scal[1], 1/scal[2], &p); scale(1/scal[0], 1/scal[1], 1/scal[2], &dPoint); d.x = dPoint.x; d.y = dPoint.y; d.z = dPoint.z; //Vect * newD = Vect::unitVector(d); return intersectUnit(p,d, intersects); }
dLine Conv::line_frw(const dLine & l, double acc, int max) const { dLine ret; if (l.size()==0) return ret; dPoint P1 = l[0], P1a =P1; frw(P1a); ret.push_back(P1a); // add first point dPoint P2, P2a; for (int i=1; i<l.size(); i++){ P1 = l[i-1]; P2 = l[i]; double d = pdist(P1-P2)/(max+1)*1.5; do { P1a = P1; frw(P1a); P2a = P2; frw(P2a); // C1 - is a center of (P1-P2) // C2-C1 is a perpendicular to (P1-P2) with acc length dPoint C1 = (P1+P2)/2.; dPoint C2 = C1 + acc*pnorm(dPoint(P1.y-P2.y, -P1.x+P2.x)); dPoint C1a = C1; frw(C1a); dPoint C2a = C2; frw(C2a); if ((pdist(C1a, (P1a+P2a)/2.) < pdist(C1a,C2a)) || (pdist(P1-P2) < d)){ // go to the rest of line (P2-l[i]) ret.push_back(P2a); P1 = P2; P2 = l[i]; } else { // go to the first half (P1-C1) of current line P2 = C1; } } while (P1!=P2); } return ret; }
bool KisZoomAndPanTest::checkRotation(ZoomAndPanTester &t, qreal angle) { // save old values QPoint oldOffset = t.coordinatesConverter()->documentOffset(); QPointF oldCenteringCorrection = t.coordinatesConverter()->centeringCorrection(); QPointF oldPreferredCenter = t.canvasController()->preferredCenter(); QPointF oldRealCenterPoint = t.coordinatesConverter()->widgetToImage(t.coordinatesConverter()->widgetCenterPoint()); QSize oldDocumentSize = t.canvasController()->documentSize(); qreal baseAngle = t.coordinatesConverter()->rotationAngle(); t.canvasController()->rotateCanvas(angle); // save result values QPoint newOffset = t.coordinatesConverter()->documentOffset(); QPointF newCenteringCorrection = t.coordinatesConverter()->centeringCorrection(); QPointF newPreferredCenter = t.canvasController()->preferredCenter(); QPointF newRealCenterPoint = t.coordinatesConverter()->widgetToImage(t.coordinatesConverter()->widgetCenterPoint()); QSize newDocumentSize = t.canvasController()->documentSize(); // calculate theoretical preferred center QTransform rot; rot.rotate(angle); QSizeF dSize = t.coordinatesConverter()->imageSizeInFlakePixels(); QPointF dPoint(dSize.width(), dSize.height()); QPointF expectedPreferredCenter = (oldPreferredCenter - dPoint * correctionMatrix(baseAngle)) * rot + dPoint * correctionMatrix(baseAngle + angle); // calculate theoretical offset based on the real preferred center QPointF wPoint(t.canvasWidget()->size().width(), t.canvasWidget()->size().height()); QPointF expectedOldOffset = oldPreferredCenter - 0.5 * wPoint; QPointF expectedNewOffset = newPreferredCenter - 0.5 * wPoint; bool preferredCenterAsExpected = compareWithRounding(expectedPreferredCenter, newPreferredCenter, 2); bool oldOffsetAsExpected = compareWithRounding(expectedOldOffset + oldCenteringCorrection, QPointF(oldOffset), 2); bool newOffsetAsExpected = compareWithRounding(expectedNewOffset + newCenteringCorrection, QPointF(newOffset), 3); qreal zoom = t.zoomController()->zoomAction()->effectiveZoom(); bool realCenterPointAsExpected = compareWithRounding(oldRealCenterPoint, newRealCenterPoint, 2/zoom); if (!oldOffsetAsExpected || !newOffsetAsExpected || !preferredCenterAsExpected || !realCenterPointAsExpected) { qDebug() << "***** ROTATE **************"; if(!oldOffsetAsExpected) { qDebug() << " ### Old offset invariant broken"; } if(!newOffsetAsExpected) { qDebug() << " ### New offset invariant broken"; } if(!preferredCenterAsExpected) { qDebug() << " ### Preferred center invariant broken"; } if(!realCenterPointAsExpected) { qDebug() << " ### *Real* center invariant broken"; } qDebug() << ppVar(expectedOldOffset); qDebug() << ppVar(expectedNewOffset); qDebug() << ppVar(expectedPreferredCenter); qDebug() << ppVar(oldOffset) << ppVar(newOffset); qDebug() << ppVar(oldCenteringCorrection) << ppVar(newCenteringCorrection); qDebug() << ppVar(oldPreferredCenter) << ppVar(newPreferredCenter); qDebug() << ppVar(oldRealCenterPoint) << ppVar(newRealCenterPoint); qDebug() << ppVar(oldDocumentSize) << ppVar(newDocumentSize); qDebug() << ppVar(baseAngle) << "deg"; qDebug() << ppVar(angle) << "deg"; qDebug() << "***************************"; } return preferredCenterAsExpected && oldOffsetAsExpected && newOffsetAsExpected && realCenterPointAsExpected; }
dPoint PageBox::get_px() { double f = u2px(units->get_active_id(), dpi->get_value()); return dPoint(x->get_value(), y->get_value()) * f; }
int GObjGridPulk::draw(iImage & image, const iPoint & origin){ /* find wgs coordinate range and 6 degree zones */ const g_map m = *get_ref(); dPoint dorg(origin); dRect rng = image.range() + dorg; dRect rng_wgs = cnv.bb_frw(rng); // screen -> wgs int lon0a = convs::lon2lon0(rng_wgs.TLC().x); int lon0b = convs::lon2lon0(rng_wgs.BRC().x); /* for all zones */ for (int lon0=lon0a; lon0<=lon0b; lon0+=6){ /* build screen -> pulkovo conversion or get it from the cache */ if (!convs.contains(lon0)){ Options o; o.put("lon0", lon0); convs.add(lon0, convs::map2pt(m, Datum("pulk"), Proj("tmerc"), o)); } convs::map2pt cnv1(convs.get(lon0)); dRect rng_pulk = cnv1.bb_frw(rng); // screen -> pulkovo if (std::isinf(rng_pulk.w) || std::isinf(rng_pulk.w)) continue; double step = 1000; while (rng_pulk.w> step*10 || rng_pulk.h> step*10) step*=10.0; while (rng_pulk.w< step/10 || rng_pulk.h< step/10) step/=10.0; dPoint tlc = rng_pulk.TLC(), brc= rng_pulk.BRC(); double xmin = floor(tlc.x/step)*step; double xmax = ceil(brc.x/step)*step; double ymin = floor(tlc.y/step)*step; double ymax = ceil(brc.y/step)*step; CairoWrapper cr(image); cr->set_source_rgba(1,0,0,1); cr->set_line_width(2); if (lon0a!=lon0b){ /* clip the zone */ dRect rng_clip(lon0-3.0, rng_wgs.y, 6.0, rng_wgs.h); rng_wgs.y-=rng_wgs.h*0.2; rng_wgs.h+=rng_wgs.h*0.4; cr->mkpath(cnv.line_bck(rect2line(rng_clip,1)) - dorg); cr->clip_preserve(); cr->stroke(); } for (double x=xmin; x<=xmax; x+=step){ dPoint p1(x, tlc.y), p2(x, brc.y); cnv1.bck(p1), cnv1.bck(p2); cr->move_to(p1-dorg); cr->line_to(p2-dorg); } for (double y=ymin; y<=ymax; y+=step){ dPoint p1(tlc.x, y), p2(brc.x, y); cnv1.bck(p1), cnv1.bck(p2); cr->move_to(p1-dorg); cr->line_to(p2-dorg); } cr->stroke(); /* step for labels */ step*=2; xmin = floor(tlc.x/step)*step; xmax = ceil(brc.x/step)*step; ymin = floor(tlc.y/step)*step; ymax = ceil(brc.y/step)*step; /* labels */ cr->set_fig_font(18, 15, 100); for (double x=xmin; x<=xmax; x+=step){ for (double y=ymin; y<=ymax; y+=step){ stringstream sx, sy; sx << int(x/1000), sy << int(y/1000); dPoint p1(x,y); cnv1.bck(p1); cr->move_to(p1-dorg + dPoint(5, -5)); cr->show_text(sy.str()); cr->move_to(p1-dorg + dPoint(20, -25)); cr->save(); cr->rotate(-M_PI/2.0); cr->show_text(sx.str()); cr->restore(); } } } return GObj::FILL_PART; }