本文整理汇总了C++中QPointF::manhattanLength方法的典型用法代码示例。如果您正苦于以下问题:C++ QPointF::manhattanLength方法的具体用法?C++ QPointF::manhattanLength怎么用?C++ QPointF::manhattanLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPointF
的用法示例。
在下文中一共展示了QPointF::manhattanLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processFoundToken
void GuiModel::processFoundToken()
{
tokensFound++;
int itt = 0;
QPointF distance;
distance.setX(500);
distance.setY(500);
QString nearest = "ERROR";
int dist = 5000;
for (itt = 0 ; itt < 4 ; itt++){
if(initList.at(itt).second.x() >= 0){
distance = initList.at(itt).second - leadRoverPosition;
if(distance.manhattanLength() < dist){
nearest = initList.at(itt).first;
dist = distance.manhattanLength();
}
}
}
leadRunningTokenError += dist;
leadTokenErrorDivisor++;
runStats();
emit updateLeadRoverTokenStats(nearest, leadRoverPosition);
}
示例2: distanceFromLineEnds
// returns distance to nearest end of line
float ShaderConnectionUI::distanceFromLineEnds(const QPointF& point) const
{
// currently this is only designed to be used with fully-connected (at both ends)
// connections - no temporary ones
QPointF srcPoint;
QPointF dstPoint;
// these checks should be redundant as it should be done before this function gets called...
if (m_pSrcNode && m_srcNodePortIndex != -1)
{
srcPoint = m_pSrcNode->getOutputPortPosition(m_srcNodePortIndex);
}
if (m_pDstNode && m_dstNodePortIndex != -1)
{
dstPoint = m_pDstNode->getInputPortPosition(m_dstNodePortIndex);
}
QPointF v = srcPoint - point;
QPointF u = dstPoint - srcPoint;
// TODO: strictly-speaking, this isn't correct, and should be the real length, but...
float length = u.manhattanLength();
float det = (-v.x() * u.x()) + (-v.y() * u.y());
if (det < 0.0f || det > length)
{
u = dstPoint - point;
return sqrtf(std::min(v.manhattanLength(), u.manhattanLength()));
}
det = u.x() * v.y() - u.y() * v.x();
return sqrtf((det * det) / length);
}
示例3: mergeWith
bool SCgCommandSelectedObjectMove::mergeWith (const QUndoCommand* command)
{
if (command->id() != id() || childCount() || command->childCount())
return false;
const SCgCommandSelectedObjectMove* c = static_cast<const SCgCommandSelectedObjectMove*>(command);
if(mUndoInfo.keys() != c->mUndoInfo.keys())
return false;
qreal maxManhattanLength = 0;
SCgScene::ObjectUndoInfo::ConstIterator const_it = c->mUndoInfo.begin();
while(const_it != c->mUndoInfo.end())
{
QPointF offset = const_it.value().second.second - const_it.value().first.second;
if(offset.manhattanLength() > maxManhattanLength)
maxManhattanLength = offset.manhattanLength();
++const_it;
}
if(maxManhattanLength > 35)
return false;
SCgScene::ObjectUndoInfo::iterator it = mUndoInfo.begin();
while(it != mUndoInfo.end())
{
it.value().second = c->mUndoInfo.value(it.key()).second;
++it;
}
return true;
}
示例4: didHit
bool ShaderConnectionUI::didHit(const QPointF& pos, SelectionInfo& selInfo, float& closestDistance) const
{
if (boundingRect().contains(pos))
{
float distance = distanceFromLineEnds(pos);
// see if we're close to the line now
if (distance < closestDistance)
{
closestDistance = distance;
// nasty, but...
selInfo.pConnection = const_cast<ShaderConnectionUI*>(this);
// this is duplicate work done already in distanceFromLineEnds(), but...
QPointF srcDelta = m_pSrcNode->getOutputPortPosition(m_srcNodePortIndex) - pos;
QPointF dstDelta = m_pDstNode->getInputPortPosition(m_dstNodePortIndex) - pos;
float srcDistance = srcDelta.manhattanLength();
float dstDistance = dstDelta.manhattanLength();
if (srcDistance < dstDistance)
{
selInfo.wasSource = true;
}
return true;
}
}
return false;
}
示例5: selectControlHandle
void QSplineEdit::selectControlHandle(int x, int y)
{
m_selected = HNone;
QPointF pmouse(x, y);
QPointF tostart = toDrawSpace(0, m_startValue) - pmouse;
if(tostart.manhattanLength() < 9.0) {
m_selected = HStart;
return;
}
QPointF toend = toDrawSpace(1, m_endValue) - pmouse;
if(toend.manhattanLength() < 9.0) {
m_selected = HEnd;
return;
}
QPointF toone = toDrawSpace(m_startCvx, m_startCvy) - pmouse;
if(toone.manhattanLength() < 9.0) {
m_selected = HControlLeft;
return;
}
QPointF totwo = toDrawSpace(m_endCvx, m_endCvy) - pmouse;
if(totwo.manhattanLength() < 9.0) {
m_selected = HControlRight;
return;
}
}
示例6: minimumDistance
double CubicSegment::minimumDistance(const QPointF &pickPoint, double &tReturnValue) const
{
double actualMinimumDistance = 10000000.;
for (double t = 0.0; t <= 1.0; t += 0.1) {
QPointF samplePoint = sample(t);
QPointF distanceVector = pickPoint - samplePoint;
if (distanceVector.manhattanLength() < actualMinimumDistance) {
actualMinimumDistance = distanceVector.manhattanLength();
tReturnValue = t;
}
}
return actualMinimumDistance;
}
示例7: normalFromTangent
QPointF AudioBarSpectrumItem::normalFromTangent(const QPointF& tangent) {
// returns a normalized normal vector given a tangent vector
if (tangent.manhattanLength() == 0) return QPointF(0, 0);
QPointF n(tangent.y(), tangent.x() * (-1));
n /= QVector2D(n).length();
return n;
}
示例8: createIsles
void Universe::createIsles(const qreal inUniverseWidth, const qreal inUniverseHeight, const uint inNumIsles)
{
srand(time(NULL));
const uint maxWidth = (uint) inUniverseWidth;
const uint maxHeight = (uint) inUniverseHeight;
qreal x, y;
bool tooClose = true; // pos is too close to another isle
for(uint i = 0; i < inNumIsles; i++)
{
do
{
x = rand() % maxWidth; // random pos
y = rand() % maxHeight;
tooClose = false;
for(Isle *isla : m_isles)
{
QPointF p = isla->pos() - QPointF(x, y);
if(p.manhattanLength() < 50.0f) // |p.x| + |p.y| < 50 is too close
{
tooClose = true;
break;
}
}
} while(tooClose);
Isle *isle = new Isle(m_lastInsertedId++, Player::PLAYER_UNSETTLED, QPointF(x, y), Player::colorForOwner(Player::PLAYER_UNSETTLED));
m_isles.append(isle);
}
}
示例9: addCap
void KarbonCalligraphicShape::addCap(int index1, int index2, int pointIndex,
bool inverted)
{
QPointF p1 = m_points[index1]->point();
QPointF p2 = m_points[index2]->point();
// TODO: review why spikes can appear with a lower limit
QPointF delta = p2 - p1;
if (delta.manhattanLength() < 1.0)
return;
QPointF direction = QLineF(QPointF(0, 0), delta).unitVector().p2();
qreal width = m_points[index2]->width();
QPointF p = p2 + direction * m_caps * width;
KoPathPoint * newPoint = new KoPathPoint(this, p);
qreal angle = m_points[index2]->angle();
if (inverted)
angle += M_PI;
qreal dx = std::cos(angle) * width;
qreal dy = std::sin(angle) * width;
newPoint->setControlPoint1(QPointF(p.x() - dx / 2, p.y() - dy / 2));
newPoint->setControlPoint2(QPointF(p.x() + dx / 2, p.y() + dy / 2));
insertPoint(newPoint, KoPathPointIndex(0, pointIndex));
}
示例10: endEdition
void EditorLineItem::endEdition()
{
// check validity
QPointF dist = m_line[BEGIN] - m_line[END];
if (dist.manhattanLength() < 3)
deleteLater();
}
示例11: normalFromTangent
QPointF NodeConnectionLines::normalFromTangent(const QPointF& tangent) {
// returns a normalized normal vector given a tangent vector
if (tangent.manhattanLength() == 0) return QPointF(0, 0);
QPointF n(tangent.y(), tangent.x() * (-1));
n /= QVector2D(n).length();
return n;
}
示例12: moveWhilePressed
bool QKineticScrollerPrivate::moveWhilePressed(QKineticScroller::Input, const QPointF &position, qint64 timestamp)
{
Q_Q(QKineticScroller);
QPointF deltaPixel = position - pressPosition;
bool moveStarted = ((deltaPixel.manhattanLength() / pixelPerMeter) > dragStartDistance);
if (moveStarted) {
qreal deltaXtoY = qAbs(pressPosition.x() - position.x()) - qAbs(pressPosition.y() - position.y());
deltaXtoY /= pixelPerMeter;
QPointF maxPos = q->maximumContentPosition();
bool canScrollX = (maxPos.x() > 0);
bool canScrollY = (maxPos.y() > 0);
if (hOvershootPolicy == QKineticScroller::OvershootAlwaysOn)
canScrollX = true;
if (vOvershootPolicy == QKineticScroller::OvershootAlwaysOn)
canScrollY = true;
if (deltaXtoY < 0) {
if (!canScrollY && (!canScrollX || (-deltaXtoY >= dragStartDirectionErrorMargin)))
moveStarted = false;
} else {
if (!canScrollX && (!canScrollY || (deltaXtoY >= dragStartDirectionErrorMargin)))
moveStarted = false;
}
}
if (moveStarted) {
if (cancelPress)
q->cancelPress(pressPosition);
setState(QKineticScroller::StateDragging);
// subtract the dragStartDistance
deltaPixel = deltaPixel - deltaPixel * (dragStartDistance / deltaPixel.manhattanLength());
if (!deltaPixel.isNull()) {
// handleDrag updates lastPosition, lastTimestamp and velocity
handleDrag(pressPosition + deltaPixel, timestamp);
}
}
return moveStarted;
}
示例13: processObjectPos
void GuiModel::processObjectPos(RpiMsg &inmsg){
uint32_t temp = 0;
float x;
float y;
float angle;
float length;
float width;
double error;
QPointF position;
QPointF position_converted;
QPointF distance;
QString nearest = "ERROR";
int dist = 5000;
distance.setX(500);
distance.setY(500);
QStringList myOptions;
myOptions << "T1" << "T2" << "T3" << "T4" << "O1" << "O2" << "O3" << "O4";
temp = ( (inmsg.msg[1]) << 8 | (inmsg.msg[2]) );
x = float((float)temp/10);
temp = ( (inmsg.msg[3]) << 8 | (inmsg.msg[4]) );
y = float((float)temp/10);
temp = ( (inmsg.msg[5]) << 8 | (inmsg.msg[6]) );
angle = ((float)temp);
temp = ( (inmsg.msg[7]) << 8 | (inmsg.msg[8]) );
length = float((float)temp/10);
temp = ( (inmsg.msg[9]) << 8 | (inmsg.msg[10]) );
width = float((float)temp/10);
position.setX(x);
position.setY(y);
position_converted.setX(x*10);
position_converted.setY(y*10);
switch(inmsg.msg[0]){
case LEAD:
//qDebug() << "Leader Information Identified";
emit updateLeadRover(position, angle);
leadTracker.push_front(position);
leadRoverPosition.setX(position_converted.x());
leadRoverPosition.setY(position_converted.y());
leadRoverAngle = angle;
break;
case FOLLOW:
//qDebug() << "Follower Information Identified";
followTracker.push_front(position);
break;
case OBSTACLE:
//qDebug() << "Obs Information Identified";
for (itt = 4 ; itt < 8 ; itt++){
if(initList.at(itt).second.x() > 0){
distance = initList.at(itt).second - position_converted;
if(distance.manhattanLength() < dist){
nearest = initList.at(itt).first;
dist = distance.manhattanLength();
}
}
}
if (nearest == "ERROR"){
// NO OBSTACLES IN THE INIT LIST
qDebug() << "ERROR: POSSIBLY NO OBSTACLES IN GUIMODEL INITLIST";
}
//qDebug() << "NEAREST OBS" << myOptions.indexOf(nearest);
switch(myOptions.indexOf(nearest)){
case O1:
if(initList.at(4).second.x() >= 0){
//qDebug() << "O1";
emit updateObject("O1", position, 0);
error = (initList.at(4).second - position_converted).manhattanLength();
sensorRunningError += error;
o1RunningError += error;
o1errorCt++;
if(error >= sensorMaxError){
sensorMaxError = error;
}
sensorDivisor++;
}
break;
case O2:
if(initList.at(5).second.x() >=0){
//qDebug() << "O2";
emit updateObject("O2", position, 0);
error= (initList.at(5).second - position_converted).manhattanLength();
sensorRunningError += error;
o2RunningError += error;
//.........这里部分代码省略.........
示例14: paintBezierSegment
void KisToolFreehandHelper::paintBezierSegment(KisPaintInformation pi1, KisPaintInformation pi2,
QPointF tangent1, QPointF tangent2)
{
if (tangent1.isNull() || tangent2.isNull()) return;
const qreal maxSanePoint = 1e6;
QPointF controlTarget1;
QPointF controlTarget2;
// Shows the direction in which control points go
QPointF controlDirection1 = pi1.pos() + tangent1;
QPointF controlDirection2 = pi2.pos() - tangent2;
// Lines in the direction of the control points
QLineF line1(pi1.pos(), controlDirection1);
QLineF line2(pi2.pos(), controlDirection2);
// Lines to check whether the control points lay on the opposite
// side of the line
QLineF line3(controlDirection1, controlDirection2);
QLineF line4(pi1.pos(), pi2.pos());
QPointF intersection;
if (line3.intersect(line4, &intersection) == QLineF::BoundedIntersection) {
qreal controlLength = line4.length() / 2;
line1.setLength(controlLength);
line2.setLength(controlLength);
controlTarget1 = line1.p2();
controlTarget2 = line2.p2();
} else {
QLineF::IntersectType type = line1.intersect(line2, &intersection);
if (type == QLineF::NoIntersection ||
intersection.manhattanLength() > maxSanePoint) {
intersection = 0.5 * (pi1.pos() + pi2.pos());
// dbgKrita << "WARINING: there is no intersection point "
// << "in the basic smoothing algoriths";
}
controlTarget1 = intersection;
controlTarget2 = intersection;
}
// shows how near to the controlTarget the value raises
qreal coeff = 0.8;
qreal velocity1 = QLineF(QPointF(), tangent1).length();
qreal velocity2 = QLineF(QPointF(), tangent2).length();
if (velocity1 == 0.0 || velocity2 == 0.0) {
velocity1 = 1e-6;
velocity2 = 1e-6;
warnKrita << "WARNING: Basic Smoothing: Velocity is Zero! Please report a bug:" << ppVar(velocity1) << ppVar(velocity2);
}
qreal similarity = qMin(velocity1/velocity2, velocity2/velocity1);
// the controls should not differ more than 50%
similarity = qMax(similarity, qreal(0.5));
// when the controls are symmetric, their size should be smaller
// to avoid corner-like curves
coeff *= 1 - qMax(qreal(0.0), similarity - qreal(0.8));
Q_ASSERT(coeff > 0);
QPointF control1;
QPointF control2;
if (velocity1 > velocity2) {
control1 = pi1.pos() * (1.0 - coeff) + coeff * controlTarget1;
coeff *= similarity;
control2 = pi2.pos() * (1.0 - coeff) + coeff * controlTarget2;
} else {
control2 = pi2.pos() * (1.0 - coeff) + coeff * controlTarget2;
coeff *= similarity;
control1 = pi1.pos() * (1.0 - coeff) + coeff * controlTarget1;
}
paintBezierCurve(pi1,
control1,
control2,
pi2);
}
示例15: action
/// \brief Move the enemy along the path
void Enemy::action()
{
float x = this->getCenterPos().x();
float y = this->getCenterPos().y();
const Tile* tile = ((const lo21*)this->game)->getTile(x,y);
if ( tile != NULL && tile->isEndPoint() )
{
game->subLive(1);
game->removeObject(this);
return;
}
else if ( tile != NULL && tile->isWalkable() )
{
vec2f vector = tile->getVector();
QPointF vectorP = vector.second - vector.first;
qreal angle = 90 - std::atan(vectorP.x() / vectorP.y()) * 360.0 / (2*3.14957);
qreal speed = this->getSpeed() * TILE_SIZE/FREQUENCY;
// courbe (changement de direction
if ( (lastVector != vectorP) && (vectorP.x() && vectorP.y()) )
{
// precedent mouvement : haut/bas
if ( lastVector.x() && !lastVector.y() )
{
if (vectorP.y() > 0 && vectorP.x() > 0)
wantedRotation = 90;
else
wantedRotation = -90;
}
// precedent mouvement : gauche/droite
if ( !lastVector.x() && lastVector.y() )
{
if (vectorP.x() > 0 && vectorP.y() > 0)
wantedRotation = -90;
else
wantedRotation = 90;
}
}
if(wantedRotation)
{
float rotationSpeed = this->getSpeed() * 90./FREQUENCY;
float lastWantedRotation=wantedRotation;
if(wantedRotation<0)
{
wantedRotation+=rotationSpeed;
if(wantedRotation>0)
wantedRotation=0;
this->angle-=wantedRotation-lastWantedRotation;
}
else
{
wantedRotation-=rotationSpeed;
if(wantedRotation<0)
wantedRotation=0;
this->angle+=lastWantedRotation-wantedRotation;
}
}
// rectiligne
float dx = speed * vectorP.x() / vectorP.manhattanLength();
float dy = speed * vectorP.y() / vectorP.manhattanLength();
this->moveBy(dx, dy);
this->lastVector = vectorP;
}
else
{
qDebug() << "There is no Walkbale Tile there : " << x << " , " << y;
}
}