Esempio n. 1
0
//------------------------------------------------------------------------------
void TStaticObject::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
    if (mFixed) {
        return;
    }

    bool fixedAngle = event->modifiers() == Qt::ControlModifier;
    if (mButton == Qt::LeftButton) {
        // Rotate object
        if (event->modifiers() == Qt::ShiftModifier || fixedAngle) {
            int angle = (int)(event->pos().x() - mCursorPosition.x());
            if (!fixedAngle) {
                angle %= 4;
            }
            angle += rotation();
            angle %= 360;

            if (fixedAngle) {
                angle = (int) angle / 45 * 45;
            }

            setTransformOriginPoint(centerPoint());
            setRotation(angle);
            return;
        }

        // Move object
        setTransformOriginPoint(0, 0);
        QGraphicsItem::setPos(mapToScene(
                event->pos().x() - mCursorPosition.x(),
                event->pos().y() - mCursorPosition.y()));
        setTransformOriginPoint(centerPoint());
    }
}
Esempio n. 2
0
 inline
 Box2d
 Circle2d::bounds() const {
     return Box2d(
         Interval(centerPoint().x() - radius(), centerPoint().x() + radius()),
         Interval(centerPoint().y() - radius(), centerPoint().y() + radius())
     );
 }
Esempio n. 3
0
void Blocks::run () {
    long elementsX = width/size;
    long elementsY = height/size;
    int IDCounter = 0;
    for (int i = 0; i < elementsX-1; i++) {
        for (int j = 0; j < elementsY-1; j++) {
            //Points at the Edge
            Point p1(i*size, j*size, 0);
            Point p2((i+1)*size, j*size, 0);
            Point p3((i+1)*size, (j+1)*size, 0);
            Point p4(i*size, (j+1)*size, 0);            std::vector<Point> edgePoints;

            edgePoints.push_back(p1);
            edgePoints.push_back(p2);
            edgePoints.push_back(p3);
            edgePoints.push_back(p4);


            //Create Edges
            Edge e1(0,1);
            Edge e2(1,2);
            Edge e3(2,3);
            Edge e4(3,0);

            std::vector<Edge> edges;
            edges.push_back(e1);
            edges.push_back(e2);
            edges.push_back(e3);
            edges.push_back(e4);

            //Cretae Face
            std::vector<long> f;
            f.push_back(0);
            f.push_back(1);
            f.push_back(2);
            f.push_back(3);

            Face face(f);
            std::vector<Face> faces;
            faces.push_back(face);

            Point centerPoint((i+0.5)*size, (j+0.5)*size, 0);
            std::vector<Point> centerPoints;
            centerPoints.push_back(centerPoint);

            std::stringstream name;
            name << "Block_" << IDCounter;
            block->setPoints(name.str(), edgePoints);
            block->setEdges(name.str(), edges);
            block->setFaces(name.str(), faces);

            name.clear();
            name << "BlockCenterPoint_" << IDCounter;
            block->setPoints(name.str(), centerPoints);

            IDCounter++;
        }
    }

}
Esempio n. 4
0
Point Window::GetInitialLocation(const Point& initialSize)
{
  void* parent = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetParent(shell->GetControl());

  Point centerPoint(0,0);
  Rectangle parentBounds(0,0,0,0);
  if (parent != 0)
  {
    parentBounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(parent);
    centerPoint.x = parentBounds.x + parentBounds.width/2;
    centerPoint.y = parentBounds.y - parentBounds.height/2;
  }
  else
  {
    parentBounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)
      ->GetScreenSize(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetPrimaryScreenNumber());
    centerPoint.x = parentBounds.width/2;
    centerPoint.y = parentBounds.height/2;
  }

  return Point(centerPoint.x - (initialSize.x / 2),
              std::max<int>(parentBounds.y,
                            std::min<int>(centerPoint.y - (initialSize.y * 2 / 3),
                                          parentBounds.y + parentBounds.height - initialSize.y)));
}
Esempio n. 5
0
QPoint Window::GetInitialLocation(const QPoint& initialSize)
{
  QWidget* parent = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetParent(shell->GetControl());

  QPoint centerPoint(0,0);
  QRect parentBounds(0,0,0,0);
  if (parent != nullptr)
  {
    parentBounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(parent);
    centerPoint.setX(parentBounds.x() + parentBounds.width()/2);
    centerPoint.setY(parentBounds.y() - parentBounds.height()/2);
  }
  else
  {
    parentBounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)
      ->GetScreenSize(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetPrimaryScreenNumber());
    centerPoint.setX(parentBounds.width()/2);
    centerPoint.setY(parentBounds.height()/2);
  }

  return QPoint(centerPoint.x() - (initialSize.x() / 2),
              std::max<int>(parentBounds.y(),
                            std::min<int>(centerPoint.y() - (initialSize.y() * 2 / 3),
                                          parentBounds.y() + parentBounds.height() - initialSize.y())));
}
Esempio n. 6
0
static void testSetOriginAndScale4(BView *view, BRect frame)
{
	frame.InsetBy(2, 2);
	BPoint center = centerPoint(frame);
	
	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
	view->SetOrigin(center);
	view->FillRect(r);
	
	view->SetScale(0.5);
	view->SetHighColor(kRed);
	view->FillRect(r);
	
	view->PushState();
		// 
		view->SetOrigin(center.x+1, center.y);
			// +1 to work around BeOS bug
			// where setting the origin has no
			// effect if it is the same as
			// the previous value althou
			// it is from the "outer" coordinate
			// system
		view->SetHighColor(kGreen);
		view->FillRect(r);
	view->PopState();
}
Esempio n. 7
0
static void testSetPenSize(BView *view, BRect frame)
{
	frame.InsetBy(8, 2);
	float x = centerPoint(frame).x;
	
	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.right, frame.top));
	
	frame.OffsetBy(0, 5);
	view->SetPenSize(1);
	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
	view->SetPenSize(0);
	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));

	frame.OffsetBy(0, 5);
	view->SetPenSize(1);
	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
	view->SetPenSize(2);
	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));

	frame.OffsetBy(0, 5);
	view->SetPenSize(1);
	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
	view->SetPenSize(3);
	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));

	frame.OffsetBy(0, 5);
	view->SetPenSize(1);
	view->StrokeLine(BPoint(frame.left, frame.top), BPoint(x, frame.top));
	view->SetPenSize(4);
	view->StrokeLine(BPoint(x+1, frame.top), BPoint(frame.right, frame.top));
}
Esempio n. 8
0
 inline
 LineSegment2d
 Circle2d::projectedOnto(const Axis2d& axis) const {
     Point2d projectedCenter = centerPoint().projectedOnto(axis);
     Vector2d offset = radius() * axis.directionVector();
     return LineSegment2d(projectedCenter - offset, projectedCenter + offset);
 }
Esempio n. 9
0
LeastSquaresFitting::InitialGuessForLeastSquaresFitting LeastSquaresFitting::findInitialGuess(const Handle_TColgp_HArray1OfPnt& points)
{
	//Compute center of gravity for point set
	double cx=0.0;
	double cy=0.0;

	for(Standard_Integer i=points->Lower();i<=points->Upper();i++)
	{
		cx += points->Value(i).X();
		cy += points->Value(i).Y();
	}

	cx /= points->Length();
	cy /= points->Length();

	gp_Pnt centerPoint(cx,cy,0.0);

	//Compute average radius
	double averageRadius = 0.0;
	for(Standard_Integer i=points->Lower();i<=points->Upper();i++)
	{
		averageRadius += centerPoint.Distance(points->Value(i));
	}
	averageRadius /= points->Length();

	return InitialGuessForLeastSquaresFitting(centerPoint,averageRadius);
}
Esempio n. 10
0
Vec3d Primitive::centerPoint()
{
	Point centerPoint(0,0,0);

	std::vector<Point> pnts = points();
	foreach(Point p, pnts) centerPoint += p;
	return centerPoint /= pnts.size();
}
Esempio n. 11
0
 inline
 Circle2d
 Circle2d::transformedBy(const TTransformation& transformation) const {
     return Circle2d(
         centerPoint().transformedBy(transformation),
         transformation.scale() * radius()
     );
 }
Esempio n. 12
0
static void testStrokeTriangle(BView *view, BRect frame)
{
	frame.InsetBy(2, 2);
	BPoint points[3];
	points[0] = BPoint(frame.left, frame.bottom);
	points[1] = BPoint(centerPoint(frame).x, frame.top);
	points[2] = BPoint(frame.right, frame.bottom);
	view->StrokeTriangle(points[0], points[1], points[2]); 
}
Esempio n. 13
0
static void testStrokeEllipse(BView *view, BRect frame)
{
	frame.InsetBy(2, 2);
	view->StrokeEllipse(frame);

	view->SetHighColor(kRed);
	float r = frame.Width() / 3;
	float s = frame.Height() / 4;
	view->StrokeEllipse(centerPoint(frame), r, s);
}
Esempio n. 14
0
int QPinchGesture::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGesture::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast<int*>(_v) = QFlag(totalChangeFlags()); break;
        case 1: *reinterpret_cast<int*>(_v) = QFlag(changeFlags()); break;
        case 2: *reinterpret_cast< qreal*>(_v) = totalScaleFactor(); break;
        case 3: *reinterpret_cast< qreal*>(_v) = lastScaleFactor(); break;
        case 4: *reinterpret_cast< qreal*>(_v) = scaleFactor(); break;
        case 5: *reinterpret_cast< qreal*>(_v) = totalRotationAngle(); break;
        case 6: *reinterpret_cast< qreal*>(_v) = lastRotationAngle(); break;
        case 7: *reinterpret_cast< qreal*>(_v) = rotationAngle(); break;
        case 8: *reinterpret_cast< QPointF*>(_v) = startCenterPoint(); break;
        case 9: *reinterpret_cast< QPointF*>(_v) = lastCenterPoint(); break;
        case 10: *reinterpret_cast< QPointF*>(_v) = centerPoint(); break;
        }
        _id -= 11;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setTotalChangeFlags(QFlag(*reinterpret_cast<int*>(_v))); break;
        case 1: setChangeFlags(QFlag(*reinterpret_cast<int*>(_v))); break;
        case 2: setTotalScaleFactor(*reinterpret_cast< qreal*>(_v)); break;
        case 3: setLastScaleFactor(*reinterpret_cast< qreal*>(_v)); break;
        case 4: setScaleFactor(*reinterpret_cast< qreal*>(_v)); break;
        case 5: setTotalRotationAngle(*reinterpret_cast< qreal*>(_v)); break;
        case 6: setLastRotationAngle(*reinterpret_cast< qreal*>(_v)); break;
        case 7: setRotationAngle(*reinterpret_cast< qreal*>(_v)); break;
        case 8: setStartCenterPoint(*reinterpret_cast< QPointF*>(_v)); break;
        case 9: setLastCenterPoint(*reinterpret_cast< QPointF*>(_v)); break;
        case 10: setCenterPoint(*reinterpret_cast< QPointF*>(_v)); break;
        }
        _id -= 11;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 11;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Esempio n. 15
0
int main(int argc, char *argv[])
{
	//Create a circle like before
	gp_Pnt centerPoint(2.5,2.5,0);
	gp_Dir normalDirection(0.0,0.0,1.0);
	gp_Dir xDirection(1.0,0.0,0.0);
	gp_Ax2 axis(centerPoint,normalDirection,xDirection);

	//Creating the circle
	gp_Circ circle(axis,2.5);

	Standard_Integer resolution = 20;

	//Here, an array of gp_Pnt is allocated, with 500 elements
	//Note that the indexing runs from 1 to 500, instead of the
	//standard convention of 0-499
	TColgp_Array1OfPnt pointsOnCircle(1,resolution);

	//Distribute the points and write them out to a file
	PointOnCurveDistribution::distributePointsOnCurve(circle,pointsOnCircle,0.0,2.0*PI,resolution);
	WriteCoordinatesToFile::writeCoordinatesToFile("chapter3points.txt",pointsOnCircle);

	//Sum the area of the small triangles, to get an approximate area
	//The for loop builds triangles with two corners on the circumference
	//and the center of the circle as third point
	double totalArea = 0.0;
	for(Standard_Integer i=1;i<=resolution;i++)
	{
		gp_Pnt firstPntOfTriangle = pointsOnCircle.Value(i);
		gp_Pnt secondPntOfTriangle;
		if(i != resolution)
		{
			secondPntOfTriangle = pointsOnCircle.Value(i+1);
		}
		else
		{
			//If we are at the end of the array, take the first point
			//because of periodicity
			secondPntOfTriangle = pointsOnCircle.Value(1);
		}
		gp_Pnt thirdPntOfTriangle = centerPoint;
		//A Handle (like a smart pointer) is built to an array of points
		Handle_TColgp_HArray1OfPnt trianglePointsArray = new TColgp_HArray1OfPnt(1,3);
		trianglePointsArray->ChangeValue(1) = firstPntOfTriangle;
		trianglePointsArray->ChangeValue(2) = secondPntOfTriangle;
		trianglePointsArray->ChangeValue(3) = thirdPntOfTriangle;
		totalArea += AreaCalculations::calculateTriangleArea(trianglePointsArray);
		
	}
	std::cout << "Polygonized area: " << totalArea << std::endl;
	std::cout << "Reference area: " << circle.Area() << std::endl;
	std::cout << "Error " << fabs(totalArea-circle.Area())/circle.Area() << std::endl;

	return 0;
}
Esempio n. 16
0
static void testSetOrigin2(BView *view, BRect frame)
{
	BPoint center = centerPoint(frame);
	BRect r(0, 0, center.x, center.y);
	view->SetOrigin(center);
	view->PushState();
		view->SetOrigin(BPoint(-center.x, 0));
		view->FillRect(r);
	view->PopState();	
	// black rectangle in left, bottom corner
}
Esempio n. 17
0
static void testDrawBitmapAtPoint(BView *view, BRect frame) {
	frame.InsetBy(2, 2);
	
	BRect bounds(frame);
	bounds.OffsetTo(0, 0);
	bounds.right /= 2;
	bounds.bottom /= 2;
	
	BBitmap bitmap(bounds, B_RGBA32);
	fillBitmap(bitmap);
	view->DrawBitmap(&bitmap, centerPoint(frame));
}
Esempio n. 18
0
static void testFillTriangleGradientConic(BView* view, BRect frame)
{
	BGradientConic gradient(0, 0, 10);
	gradient.AddColor(kRed, 0);
	gradient.AddColor(kBlue, 255);
	frame.InsetBy(2, 2);
	BPoint points[3];
	points[0] = BPoint(frame.left, frame.bottom);
	points[1] = BPoint(centerPoint(frame).x, frame.top);
	points[2] = BPoint(frame.right, frame.bottom);
	view->FillTriangle(points[0], points[1], points[2], gradient);
}
Esempio n. 19
0
static void testSetOriginAndScale(BView *view, BRect frame)
{
	frame.InsetBy(2, 2);
	BPoint center = centerPoint(frame);
	
	BRect r(0, 0, frame.IntegerWidth() / 2, frame.IntegerHeight() / 2);
	view->SetOrigin(center);
	view->FillRect(r);
	
	view->SetScale(0.5);
	view->SetHighColor(kRed);
	view->FillRect(r);
}
/**************************************************************************
* AEarthWindow :: paintWorld - paint a view of Earth from space           *
**************************************************************************/
bool AEarthWindow :: computeWorld()
{
  const float
    xRadiusFactor[4] = {1.45, 1.55, 1.60, 1.65},
    yRadiusFactor[4] = {(0.7 - 1.0/8), (0.7 - 1.0/16),
                        (0.7 - 1.0/32), (0.7 - 1.0/64)};
  const IRectangle
    psRect(rect());

/*------------------------------------------------------------------------|
| Construct the IGRect2D space to form the background of the scene.       |
-------------------------------------------------------------------------*/

  IGPoint2D
     bottomLeftPoint(0, 0),
     bottomRightPoint(psRect.width(), 0),
     topLeftPoint(0, psRect.height()),
     topRightPoint(psRect.width(), psRect.height());

  spaceDimensions.setPoint(0, bottomLeftPoint);
  spaceDimensions.setPoint(1, bottomRightPoint);
  spaceDimensions.setPoint(2, topRightPoint);
  spaceDimensions.setPoint(3, topLeftPoint);

/*------------------------------------------------------------------------|
| Compute the dimensions for the earthArcs.                               |
-------------------------------------------------------------------------*/

  IGPoint2D centerPoint(psRect.width() / 2, -psRect.height() * 0.2);
  int xRad, yRad;
  for(int i=0;i<=atmosphereLayers;i++)
     {
        yRad = yRadiusFactor[i] * psRect.height();
        xRad = xRadiusFactor[i] * yRad;
        IGRect2D arcBoundsRect(0, 2 * yRad, 2 * xRad, 0);
        arcDimensions[i].setBounds(arcBoundsRect);
        arcDimensions[i].setCenter(centerPoint);
     }


/*------------------------------------------------------------------------|
| Call computeStars() to compuet the dimensions for the stars.            |
| Then call paintWorld() that uses all these dimensions to create the     |
| objects to be painted.                                                  |
-------------------------------------------------------------------------*/
  computeStars();
  paintWorld();
  refresh();
  return true;

} /* end AEarthWindow :: paintWorld(..) */
Esempio n. 21
0
void MScenePrivate::touchPointMirrorMousePosToPointStartPos(QTouchEvent::TouchPoint &point, const QGraphicsSceneMouseEvent *event)
{
    Q_Q(MScene);

    if (q->views().size() > 0) {
        QPointF windowPos(q->views().at(0)->pos());
        QSize resolution = MDeviceProfile::instance()->resolution();
        QPointF centerPoint(resolution.width() / 2, resolution.height() / 2);

        QPointF mirrorPoint = centerPoint + (centerPoint - event->screenPos() + windowPos);

        point.setStartPos(mirrorPoint);
        point.setStartScenePos(mirrorPoint);
        point.setStartScreenPos(mirrorPoint + windowPos);
    }
}
Esempio n. 22
0
	Math::BoundingBox3D PaintCellInfo::getBoundingBox(const Math::HexHeightMap& height_map) const {

		Math::BoundingBox3D bounding_box;

		Math::Point center_pos = centerPoint(height_map);
		center_pos.setCoord(center_pos.getCoord(PaintCell::PAINT_AXIS)+PAINT_CELL_LIFT_AMOUNT, PaintCell::PAINT_AXIS);

		bounding_box.setCorners(center_pos, center_pos);

		for (short i = 0; i < PaintCell::CELL_VERTICES; i++) {
			Math::Point p = vertexPoint(height_map, i);
			p.setCoord(p.getCoord(PaintCell::PAINT_AXIS)+PAINT_CELL_LIFT_AMOUNT, PaintCell::PAINT_AXIS);
			bounding_box.expandToInclude(p);
		}

		return bounding_box;
	}
Esempio n. 23
0
void GraphicsLayerChromium::updateLayerSize()
{
    IntSize layerSize(m_size.width(), m_size.height());
    if (m_transformLayer) {
        m_transformLayer->setBounds(layerSize);
        // The anchor of the contents layer is always at 0.5, 0.5, so the position is center-relative.
        FloatPoint centerPoint(m_size.width() / 2, m_size.height() / 2);
        m_layer->setPosition(centerPoint);
    }

    m_layer->setBounds(layerSize);

    // Note that we don't resize m_contentsLayer. It's up the caller to do that.

    // If we've changed the bounds, we need to recalculate the position
    // of the layer, taking anchor point into account.
    updateLayerPosition();
}
Esempio n. 24
0
	void PaintCellInfo::calcNormal(const Math::HexHeightMap& height_map) {

		normal = Math::Point();

		Math::Point center_pos = centerPoint(height_map);
		for (int i = 0; i < PaintCell::CELL_VERTICES; i++) {

			Math::Point vertex_point = vertexPoint(height_map, i);
			
			Math::HexGrid::HexIndex next_vert_index = Math::HexGrid::vertexIndex(uIndex, vIndex, (i+1) % PaintCell::CELL_VERTICES);
			normal += Math::Geometry::triangleNormal(center_pos,
				vertexPoint(height_map, (i+1) % PaintCell::CELL_VERTICES),
				vertex_point);
		}

		normal.normalize();

	}
float LocalTransformOptimization::calculateError(LtoState& state) {
	float positionError = 0;
	tf::Transform cameraToHead = state.getCameraToHead();
	int numOfPoints = this->measurePoints.size();

	// calculate centroid
	float centerX = 0, centerY = 0, centerZ = 0;
	for (int i = 0; i < numOfPoints; i++) {
		MeasurePoint& current = this->measurePoints[i];
		//tf::Transform opicalToFixed = current.opticalToFixed(cameraToHead);
		tf::Transform opicalToFixed = current.opticalToFixed(state);
		tf::Vector3 transformedPoint = opicalToFixed * current.measuredPosition;
		centerX += transformedPoint.getX();
		centerY += transformedPoint.getY();
		centerZ += transformedPoint.getZ();
	}
	tf::Vector3 centerPoint(centerX / numOfPoints, centerY / numOfPoints,
			centerZ / numOfPoints);

	// calculate marker error
	this->calculateMarkerError(state, centerPoint, positionError);

	// calculate ground error
	float groundError = 0;

	float groundAngle;
	this->calculateGroundAngleError(state, groundAngle);
	float groundDist;
	this->calculateGroundDistanceError(state, groundDist);
	groundError = groundAngle + groundDist; // cout << "groundAngle " << groundAngle << " groundDist " << groundDist << "\n";

	return parameter.getMarkerWeight() * positionError
			+ parameter.getGroundWeight() * groundError;

//	return error + fabs(fabs(d) - 0.02)
//			+ fabs(tf::Vector3(a, b, c).normalized().angle(tf::Vector3(0, 0, 1)));

//	return error + roll + pitch;

//	return d * d
//			+ tf::Vector3(a, b, c).normalized().angle(tf::Vector3(0, 0, 1))
//					* tf::Vector3(a, b, c).normalized().angle(
//							tf::Vector3(0, 0, 1));
}
Esempio n. 26
0
void FormEditorItem::setAttentionScale(double sinusScale)
{
    if (!qFuzzyIsNull(sinusScale)) {
        double scale = std::sqrt(sinusScale);
        m_attentionTransform.reset();
        QPointF centerPoint(qmlItemNode().instanceBoundingRect().center());
        m_attentionTransform.translate(centerPoint.x(), centerPoint.y());
        m_attentionTransform.scale(scale * 0.15 + 1.0, scale * 0.15 + 1.0);
        m_attentionTransform.translate(-centerPoint.x(), -centerPoint.y());
        m_inverseAttentionTransform = m_attentionTransform.inverted();
        prepareGeometryChange();
        setTransform(qmlItemNode().instanceTransform());
        setTransform(m_attentionTransform, true);
    } else {
        m_attentionTransform.reset();
        prepareGeometryChange();
        setTransform(qmlItemNode().instanceTransform());
    }
}
Esempio n. 27
0
void ScaledPixmap::paintEvent(QPaintEvent* event)
{
    QPainter painter(this);

    if (!m_pixmap.isNull())
    {
        QPoint centerPoint(0, 0);
        QSize scaledSize = overscaleEnabled() ? size() : (fitsToScreen(size()) ? m_originalSize : size());

        QPixmap scaledPixmap = m_pixmap.scaled(scaledSize, m_keepAspectRatio ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio);

        centerPoint.setX((size().width() - scaledPixmap.width()) / 2);
        centerPoint.setY((size().height() - scaledPixmap.height()) / 2);

        painter.drawPixmap(centerPoint, scaledPixmap);
    }

    QLabel::paintEvent(event);
}
Esempio n. 28
0
static void testSetOrigin(BView *view, BRect frame)
{
	BPoint origin = view->Origin();
	BPoint center = centerPoint(frame);
	view->SetOrigin(center);

	BRect r(0, 0, center.x, center.y);
	view->SetHighColor(kBlue);
	view->FillRect(r);
	
	view->SetOrigin(origin);
	view->SetHighColor(kRed);
	view->FillRect(r);
	
	// red rectangle in left, top corner
	// blue rectangle in right, bottom corner
	// the red rectangle overwrites the
	// top, left pixel of the blue rectangle
}
Esempio n. 29
0
 Box3d
 Circle3d::bounds() const {
     double nx2 = normalVector().x() * normalVector().x();
     double ny2 = normalVector().y() * normalVector().y();
     double nz2 = normalVector().z() * normalVector().z();
     double dx = radius() * sqrt(ny2 + nz2);
     double dy = radius() * sqrt(nx2 + nz2);
     double dz = radius() * sqrt(nx2 + ny2);
     return Box3d(
         Interval(centerPoint().x() - dx, centerPoint().x() + dx),
         Interval(centerPoint().y() - dy, centerPoint().y() + dy),
         Interval(centerPoint().z() - dz, centerPoint().z() + dz)
     );
 }
Esempio n. 30
0
QList<Point> ChartLine::getPoints()
{
    if (numberOfPoints == 0)
        return QList<Point>();

    QList<Point> points;
    //points.reserve(numberOfPoints);

    if (fabs(angle) < EPS_ZERO)
    {
        double dx = (end.x - start.x) / (numberOfPoints - 1);
        double dy = (end.y - start.y) / (numberOfPoints - 1);

        for (int i = 0; i < numberOfPoints; i++)
            if (reverse)
                points.insert(0, Point(start.x + i*dx, start.y + i*dy));
            else
                points.append(Point(start.x + i*dx, start.y + i*dy));
    }
    else
    {
        Point center = centerPoint(start, end, angle);
        double radius = (start - center).magnitude();
        double startAngle = atan2(center.y - start.y, center.x - start.x) / M_PI*180 - 180;
        double theta = angle / double(numberOfPoints - 1);

        for (int i = 0; i < numberOfPoints; i++)
        {
            double arc = (startAngle + i*theta)/180.0*M_PI;

            double x = radius * cos(arc);
            double y = radius * sin(arc);

            if (reverse)
                points.insert(0, Point(center.x + x, center.y + y));
            else
                points.append(Point(center.x + x, center.y + y));
        }
    }

    return points;
}