bool Rectangle::intersects(Segment const& segment) const noexcept { return (segment.intersects(Segment(topLeft(), topRight())) || segment.intersects(Segment(topRight(), bottomRight())) || segment.intersects(Segment(bottomLeft(), bottomRight())) || segment.intersects(Segment(topLeft(), bottomLeft()))); }
std::vector<Index::Ptr> HexagonIndex::neighbours(bool gravity) { if (gravity) return { left(), right(), bottomLeft(), bottomRight() }; else return { topLeft(), topRight(), left(), right(), bottomLeft(), bottomRight() }; }
void PlotControl::zoomReset(Zoomer *zoomer) { QRectF rect = zoomer->zoomStack().last(); if (rect.width() > defaultRect.width()) { QPointF topLeft(rect.center().x() - defaultRect.width() * 0.5, rect.center().y() - defaultRect.height() * 0.5); QPointF bottomRight(rect.center().x() + defaultRect.width() * 0.5, rect.center().y() + defaultRect.height() * 0.5); QRectF newRect(topLeft, bottomRight); zoomer->zoom(newRect); } else { QPointF center = rect.center(); if ((center.x() - zoomer->zoomBase().left()) < (defaultRect.width() * 0.5)) { center.setX(zoomer->zoomBase().left() + (defaultRect.width() * 0.5)); } else if ((zoomer->zoomBase().right() - center.x()) < (defaultRect.width() * 0.5)) { center.setX(zoomer->zoomBase().right() - (defaultRect.width() * 0.5)); } QPointF topLeft(center.x() - defaultRect.width() * 0.5, center.y() - defaultRect.height() * 0.5); QPointF bottomRight(center.x() + defaultRect.width() * 0.5, center.y() + defaultRect.height() * 0.5); QRectF newRect(topLeft, bottomRight); zoomer->zoom(newRect); } }
bool Face::contains(cv::Point &p) { if (p.x >= topLeft().x && p.x <= bottomRight().x && p.y >= topLeft().y && p.y <= bottomRight().y) { return(true); } else { return(false); } }
void NodeBackDrop::resize(int w,int h) { QMutexLocker l(&_imp->bboxMutex); QPointF p = pos(); QPointF thisItemPos = mapFromParent(p); QRectF textBbox = _imp->name->boundingRect(); if (w < textBbox.width()) { w = textBbox.width(); } int minH = (textBbox.height() * 1.5) + 20; if (h < minH) { h = minH; } setRect(QRectF(thisItemPos.x(),thisItemPos.y(),w,h)); _imp->header->setRect(QRect(thisItemPos.x(),thisItemPos.y(),w,textBbox.height() * 1.5)); _imp->name->setPos(thisItemPos.x() + w / 2 - textBbox.width() / 2,thisItemPos.y() + 0.25 * textBbox.height()); _imp->label->setPos(thisItemPos.x(), thisItemPos.y() + textBbox.height() * 1.5 + 10); _imp->label->setTextWidth(w); QPolygonF resizeHandle; QPointF bottomRight(thisItemPos.x() + w,thisItemPos.y() + h); resizeHandle.push_back(QPointF(bottomRight.x() - 20,bottomRight.y())); resizeHandle.push_back(bottomRight); resizeHandle.push_back(QPointF(bottomRight.x(), bottomRight.y() - 20)); _imp->resizeHandle->setPolygon(resizeHandle); }
void DX11Widget::paintEvent(QPaintEvent */*e*/) { D_D(DX11Widget); int glowRadius = d->m_ShadowWidth; int radius = d->m_Radius; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); QRect rect = this->rect().marginsRemoved(QMargins(glowRadius, glowRadius, glowRadius, glowRadius)); if (! d->m_Background.isNull()) { painter.drawPixmap(rect, d->m_Background); } else { QPoint topLeft(rect.x(), rect.y()); QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height()); QPainterPath border; border.addRoundedRect(rect, radius, radius); QLinearGradient linearGradient(topLeft, QPoint(topLeft.x(), bottomRight.y())); linearGradient.setColorAt(0.0, BackgroundTopColor); linearGradient.setColorAt(0.2, BackgroundBottonColor); linearGradient.setColorAt(1.0, BackgroundBottonColor); QPen borderPen(BorderColor); painter.setBrush(QBrush(linearGradient)); painter.strokePath(border, borderPen); painter.fillPath(border, palette().background()); } }
void BoundingBoxDoorVisual::generateWireframe() { delete m_wireframe; m_wireframe = new rviz::BillboardLine(m_sceneManager, m_sceneNode); m_wireframe->setLineWidth(m_lineWidth); m_wireframe->setMaxPointsPerLine(2); m_wireframe->setNumLines(12); double w = m_width, h = m_height; Ogre::Vector3 bottomLeft(0, -w, 0), bottomRight(0, 0, 0), topLeft(0, -w, h), topRight(0, 0, h); Ogre::Vector3 rear(m_thickness, 0, 0); // Front quad m_wireframe->addPoint(bottomLeft); m_wireframe->addPoint(bottomRight); m_wireframe->newLine(); m_wireframe->addPoint(bottomRight); m_wireframe->addPoint(topRight); m_wireframe->newLine(); m_wireframe->addPoint(topRight); m_wireframe->addPoint(topLeft); m_wireframe->newLine(); m_wireframe->addPoint(topLeft); m_wireframe->addPoint(bottomLeft); // Rear quad m_wireframe->newLine(); m_wireframe->addPoint(bottomLeft + rear); m_wireframe->addPoint(bottomRight + rear); m_wireframe->newLine(); m_wireframe->addPoint(bottomRight + rear); m_wireframe->addPoint(topRight + rear); m_wireframe->newLine(); m_wireframe->addPoint(topRight + rear); m_wireframe->addPoint(topLeft + rear); m_wireframe->newLine(); m_wireframe->addPoint(topLeft + rear); m_wireframe->addPoint(bottomLeft + rear); // Four connecting lines between front and rear m_wireframe->newLine(); m_wireframe->addPoint(bottomLeft); m_wireframe->addPoint(bottomLeft + rear); m_wireframe->newLine(); m_wireframe->addPoint(bottomRight); m_wireframe->addPoint(bottomRight + rear); m_wireframe->newLine(); m_wireframe->addPoint(topRight); m_wireframe->addPoint(topRight + rear); m_wireframe->newLine(); m_wireframe->addPoint(topLeft); m_wireframe->addPoint(topLeft + rear); m_wireframe->setPosition(Ogre::Vector3(0, 0, 0)); // Ogre::Quaternion orientation; // orientation.FromRotationMatrix(R_do); // m_wireframe->setOrientation(orientation); }
void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint textureId, bool selected) { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(bounds.left(), bounds.right(), bounds.bottom(), bounds.top(), -1.0, 1.0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); if (selected) { glColor3f(.5f, .5f, .5f); } else { glColor3f(1, 1, 1); } glBindTexture(GL_TEXTURE_2D, textureId); glm::vec2 topLeft(iconBounds.left(), iconBounds.top()); glm::vec2 bottomRight(iconBounds.right(), iconBounds.bottom()); glm::vec2 texCoordTopLeft(0.0f, 1.0f); glm::vec2 texCoordBottomRight(1.0f, 0.0f); DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); }
void LocationSampler::sampleEquiDistant(cv::Rect ¤tLocation, std::vector<cv::Rect> &locations) { double centerX = currentLocation.x + currentLocation.width / 2; double centerY = currentLocation.y + currentLocation.height / 2; std::vector<double> radialValues = this->linspace(0, radius, nRadial + 1); std::vector<double> angularValues = this->linspace(0, 2 * M_PI, nAngular +1); int bb_x, bb_y = 0; cv::Rect imageBox(0, 0, this->n, this->m); int halfWidth = cvRound(currentLocation.width / 2.0); int halfHeight = cvRound(currentLocation.height / 2.0); for (int i = 1; i < radialValues.size(); ++i) { for (int j = 1; j < angularValues.size(); ++j) { // get the top left corner bb_x = centerX + (radialValues[i] * cos(angularValues[j])) - halfWidth; bb_y = centerY + (radialValues[i] * sin(angularValues[j])) - halfHeight; cv::Point topLeft(bb_x, bb_y); cv::Point bottomRight(bb_x + currentLocation.width, bb_y + currentLocation.height); if (imageBox.contains(topLeft) && imageBox.contains(bottomRight)) { cv::Rect rect(bb_x, bb_y, currentLocation.width, currentLocation.height); locations.push_back(rect); } } } }
QPainterPath DArrowRectangle::getBottomCornerPath() { qreal delta = shadowBlurRadius() + shadowDistance(); QRect rect = this->rect().marginsRemoved(QMargins(delta, delta, delta, delta)); QPoint cornerPoint(rect.x() + (m_arrowX > 0 ? m_arrowX : rect.width() / 2), rect.y() + rect.height()); QPoint topLeft(rect.x(), rect.y()); QPoint topRight(rect.x() + rect.width(), rect.y()); QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height() - m_arrowHeight); QPoint bottomLeft(rect.x(), rect.y() + rect.height() - m_arrowHeight); int radius = this->m_radius > (rect.height() / 2 - m_arrowHeight) ? rect.height() / 2 -m_arrowHeight : this->m_radius; QPainterPath border; border.moveTo(topLeft.x() + radius, topLeft.y()); border.lineTo(topRight.x() - radius, topRight.y()); border.arcTo(topRight.x() - 2 * radius, topRight.y(), 2 * radius, 2 * radius, 90, -90); border.lineTo(bottomRight.x(), bottomRight.y() - radius); border.arcTo(bottomRight.x() - 2 * radius, bottomRight.y() - 2 * radius, 2 * radius, 2 * radius, 0, -90); border.lineTo(cornerPoint.x() + m_arrowWidth / 2, cornerPoint.y() - m_arrowHeight); border.lineTo(cornerPoint); border.lineTo(cornerPoint.x() - m_arrowWidth / 2, cornerPoint.y() - m_arrowHeight); border.lineTo(bottomLeft.x() + radius, bottomLeft.y()); border.arcTo(bottomLeft.x(), bottomLeft.y() - 2 * radius, 2 * radius, 2 * radius, -90, -90); border.lineTo(topLeft.x(), topLeft.y() + radius); border.arcTo(topLeft.x(), topLeft.y(), 2 * radius, 2 * radius, 180, -90); return border; }
void PlotControl::zoomOut(Zoomer *zoomer) { QRectF rect = zoomer->zoomStack().last(); double dimensionFactor = rect.height() / rect.width(); float newWidth = 1.2 * rect.width(); float x_offset = (newWidth - rect.width()) * 0.5; float newLeftX = std::max((float)zoomer->zoomBase().left(), (float)rect.left() - x_offset); float newRightX = std::min(newLeftX + newWidth, (float)zoomer->zoomBase().right()); newWidth = newRightX - newLeftX; float newHeight = std::min((float)(dimensionFactor * newWidth), (float)zoomer->zoomBase().height()); newWidth = newHeight / dimensionFactor; x_offset = (newWidth - rect.width()) * 0.5; newLeftX = std::max((float)zoomer->zoomBase().left(), (float)rect.left() - x_offset); float y_offset = (newHeight - rect.height()) * 0.5; QPointF topLeft(newLeftX, rect.top() - y_offset); QPointF bottomRight(newLeftX + newWidth, rect.top() - y_offset + newHeight); QRectF newRect(topLeft, bottomRight); zoomer->zoom(newRect); }
BOOL CArcView::IntersectsWithRect(const Rect& rectangle) { Point topLeft(rectangle.GetLeft(), rectangle.GetTop()); Point topRight(rectangle.GetRight(), rectangle.GetTop()); Point bottomLeft(rectangle.GetLeft(), rectangle.GetBottom()); Point bottomRight(rectangle.GetRight(), rectangle.GetBottom()); Point currentPoint(*pathPoints.begin()); for(auto it=pathPoints.begin() + 1; it != pathPoints.end(); ++it) { if(rectangle.Contains(currentPoint)) return TRUE; if(Geometry::LinesIntersect(topLeft, topRight, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(topLeft, bottomLeft, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(bottomLeft, bottomRight, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(topRight, bottomRight, currentPoint, *it)) return TRUE; currentPoint = *it; } return FALSE; }
QRectF XProcessTablePrivate::getExpandBox(qreal initX,qreal initY) { QPointF topLeft(initX,initY + XPT::Constant::RowHeight/2 - XPT::Constant::ExpandBoxSize.height()/2); QPointF bottomRight(initX + XPT::Constant::ExpandBoxSize.width(),initY + XPT::Constant::RowHeight/2 + XPT::Constant::ExpandBoxSize.height()/2); QRectF expandBoxRect(topLeft,bottomRight); return expandBoxRect; }
void TextArea::ContentView::drawRect(KDContext * ctx, KDRect rect) const { // TODO: We're clearing areas we'll draw text over. It's not needed. clearRect(ctx, rect); KDSize charSize = KDText::charSize(m_fontSize); // We want to draw even partially visible characters. So we need to round // down for the top left corner and up for the bottom right one. Text::Position topLeft( rect.x()/charSize.width(), rect.y()/charSize.height() ); Text::Position bottomRight( rect.right()/charSize.width() + 1, rect.bottom()/charSize.height() + 1 ); int y = 0; for (Text::Line line : m_text) { if (y >= topLeft.line() && y <= bottomRight.line() && topLeft.column() < (int)line.length()) { drawLine(ctx, y, line.text(), line.length(), topLeft.column(), bottomRight.column()); } y++; } }
/*! \internal */ void QDeclarativeRectangleMapItem::updateMapItem() { if (!map() || !topLeft().isValid() || !bottomRight().isValid()) return; geometry_.updatePoints(*map(), topLeft_, bottomRight_); QList<QGeoCoordinate> pathClosed; pathClosed << topLeft_; pathClosed << QGeoCoordinate(topLeft_.latitude(), bottomRight_.longitude()); pathClosed << bottomRight_; pathClosed << QGeoCoordinate(bottomRight_.latitude(), topLeft_.longitude()); pathClosed << pathClosed.first(); if (border_.color() != Qt::transparent && border_.width() > 0) { borderGeometry_.updateSourcePoints(*map(), pathClosed); borderGeometry_.updateScreenPoints(*map(), border_.width()); QList<QGeoMapItemGeometry *> geoms; geoms << &geometry_ << &borderGeometry_; QRectF combined = QGeoMapItemGeometry::translateToCommonOrigin(geoms); setWidth(combined.width()); setHeight(combined.height()); } else { borderGeometry_.clear(); setWidth(geometry_.screenBoundingBox().width()); setHeight(geometry_.screenBoundingBox().height()); } setPositionOnMap(pathClosed.at(0), geometry_.firstPointOffset()); update(); }
// vanha void Sprite::createVertexData() { vector2f topLeft(sourceRectPosition.x, sourceRectPosition.y); vector2f bottomLeft(sourceRectPosition.x, sourceRectPosition.y - sourceRectSize.y); vector2f topRight(sourceRectPosition.x - sourceRectSize.x, sourceRectPosition.y); vector2f bottomRight(sourceRectPosition.x - sourceRectSize.x, sourceRectPosition.y - sourceRectSize.y); GLfloat vertex[] = { position.x - origin.x, position.y - origin.y, red, blue, green, topLeft.x, topLeft.y, position.x - origin.x, position.y - origin.y + size.y, red, blue, green, bottomLeft.x, bottomLeft.y, position.x - origin.x + size.x, position.y - origin.y, red, blue, green, topRight.x, topRight.y, position.x - origin.x + size.x, position.y - origin.y + size.y, red, blue, green, bottomRight.x, bottomRight.y }; for (unsigned i = 0; i < 28; ++i) VERTEX_DATA[i] = vertex[i]; // ei pakosta tarvita //texture->CreateBuffer(vertex, sizeof(vertex), INDEX_DATA, 6*4); }
// Tests that translations are properly handled when using KeepTransform. TEST(TransparencyWin, TranslateOpaqueCompositeLayer) { // Fill with white. OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); Color white(0xFFFFFFFF); FloatRect fullRect(0, 0, 16, 16); src->context()->fillRect(fullRect, white); // Scroll down by 8 (coordinate system goes up). src->context()->save(); src->context()->translate(0, -8); Color red(0xFFFF0000); Color green(0xFF00FF00); { // Make the transparency layer after translation will be @ (0, -8) with // size 16x16. TransparencyWin helper; helper.init(src->context(), TransparencyWin::OpaqueCompositeLayer, TransparencyWin::KeepTransform, IntRect(0, 0, 16, 16)); // Draw a red pixel at (15, 15). This should be the at (15, 7) after // the transform. FloatRect bottomRight(15, 15, 1, 1); helper.context()->fillRect(bottomRight, green); helper.composite(); } src->context()->restore(); // Check the pixel we wrote. EXPECT_EQ(green, getPixelAt(src->context(), 15, 7)); }
void FramelessDlg::paintEvent(QPaintEvent *e) { QPainter painter(this); QRect bottom(5, 136, 200, 7); QRect top(5, 0, 200, 3); QRect left(0, 3, 5, 133); QRect right(205, 3, 5, 133); QRect topRight(205, 0, 5, 3); QRect topLeft(0, 0, 5, 3); QRect bottomLeft(0, 136, 5, 7); QRect bottomRight(205, 136, 5, 7); QRect tBottom(5, this->height() - 7, this->width() - 10, 7); QRect tTop(5, 0, this->width() - 10, 3); QRect tLeft(0, 3, 5, this->height() - 10); QRect tRight(this->width() - 5, 3, 5, this->height() - 10); QRect tTopLeft(0, 0, 5, 3); QRect tTopRight(this->width() - 5, 0, 5, 3); QRect tBottomLeft(0, this->height() - 7, 5, 7); QRect tBottomRight(this->width() - 5, this->height() - 7, 5, 7); painter.drawPixmap(tBottom, m_shadow, bottom); painter.drawPixmap(tTop, m_shadow, top); painter.drawPixmap(tLeft, m_shadow, left); painter.drawPixmap(tRight, m_shadow, right); painter.drawPixmap(tTopRight, m_shadow, topRight); painter.drawPixmap(tTopLeft, m_shadow, topLeft); painter.drawPixmap(tBottomLeft, m_shadow, bottomLeft); painter.drawPixmap(tBottomRight, m_shadow, bottomRight); }
void tst_QOpenGL::textureblitterPartTargetRectTransform() { QVector4D topLeft(-1.f, 1.f, 0.f, 1.f); QVector4D bottomLeft(-1.f, -1.f, 0.f, 1.f); QVector4D topRight(1.f, 1.f, 0.f, 1.f); QVector4D bottomRight(1.f, -1.f, 0.f, 1.f); QRectF targetRect(50,50,200,200); QRect viewport(0,0,400,400); //multiply by 2 since coordinate system goes from -1 -> 1; qreal x_point_ratio = (50. / 400.) * 2; qreal y_point_ratio = (50. / 400.) * 2; qreal width_ratio = (200. / 400.) * 2; qreal height_ratio = (200. / 400.) * 2; QMatrix4x4 targetMatrix = QOpenGLTextureBlitter::targetTransform(targetRect, viewport); QVector4D targetTopLeft = targetMatrix * topLeft; QVector4D expectedTopLeft(-1 + x_point_ratio, 1 - y_point_ratio, .0, 1.0); QCOMPARE(targetTopLeft, expectedTopLeft); QVector4D targetBottomLeft = targetMatrix * bottomLeft; QVector4D expectedBottomLeft(-1 + x_point_ratio, 1 - y_point_ratio - height_ratio, 0.0, 1.0); QCOMPARE(targetBottomLeft, expectedBottomLeft); QVector4D targetTopRight = targetMatrix * topRight; QVector4D expectedTopRight(-1 + x_point_ratio + width_ratio, 1 - y_point_ratio, 0.0, 1.0); QCOMPARE(targetTopRight, expectedTopRight); QVector4D targetBottomRight = targetMatrix * bottomRight; QVector4D expectedBottomRight(-1 + x_point_ratio + width_ratio, 1 - y_point_ratio - height_ratio, 0.0, 1.0); QCOMPARE(targetBottomRight, expectedBottomRight); }
Rect2D CircleCollisionHull::getAABB() { Point2D topLeft(m_currentPosition._x - m_radius, m_currentPosition._y - m_radius); Point2D bottomRight(m_currentPosition._x + m_radius, m_currentPosition._y + m_radius); return Rect2D(topLeft, bottomRight); }
void Image3DOverlay::render(RenderArgs* args) { if (!_isLoaded) { _isLoaded = true; _texture = DependencyManager::get<TextureCache>()->getTexture(_url); } if (!_visible || !getParentVisible() || !_texture || !_texture->isLoaded()) { return; } Q_ASSERT(args->_batch); gpu::Batch* batch = args->_batch; float imageWidth = _texture->getWidth(); float imageHeight = _texture->getHeight(); QRect fromImage; if (_fromImage.isNull()) { fromImage.setX(0); fromImage.setY(0); fromImage.setWidth(imageWidth); fromImage.setHeight(imageHeight); } else { float scaleX = imageWidth / _texture->getOriginalWidth(); float scaleY = imageHeight / _texture->getOriginalHeight(); fromImage.setX(scaleX * _fromImage.x()); fromImage.setY(scaleY * _fromImage.y()); fromImage.setWidth(scaleX * _fromImage.width()); fromImage.setHeight(scaleY * _fromImage.height()); } float maxSize = glm::max(fromImage.width(), fromImage.height()); float x = fromImage.width() / (2.0f * maxSize); float y = -fromImage.height() / (2.0f * maxSize); glm::vec2 topLeft(-x, -y); glm::vec2 bottomRight(x, y); glm::vec2 texCoordTopLeft(fromImage.x() / imageWidth, fromImage.y() / imageHeight); glm::vec2 texCoordBottomRight((fromImage.x() + fromImage.width()) / imageWidth, (fromImage.y() + fromImage.height()) / imageHeight); const float MAX_COLOR = 255.0f; xColor color = getColor(); float alpha = getAlpha(); applyTransformTo(_transform, true); Transform transform = _transform; transform.postScale(glm::vec3(getDimensions(), 1.0f)); batch->setModelTransform(transform); batch->setResourceTexture(0, _texture->getGPUTexture()); DependencyManager::get<GeometryCache>()->renderQuad( *batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha) ); batch->setResourceTexture(0, args->_whiteTexture); // restore default white color after me }
void Sprite::Transform(const Mat3 &rhs) { Vector3 topLeft(0 - m_anchor.x, 1 - m_anchor.y); Vector3 topRight(1 - m_anchor.x, 1 - m_anchor.y); Vector3 bottomLeft(0 - m_anchor.x, 0 - m_anchor.y); Vector3 bottomRight(1 - m_anchor.x, 0 - m_anchor.y); Mat3 scale = (scale.CreateScale( Vector3( (float)m_width, (float)m_height))); topLeft = rhs * (scale * topLeft); topRight = rhs * (scale * topRight); bottomLeft = rhs * (scale * bottomLeft); bottomRight = rhs * (scale * bottomRight); topLeft.x = ((2.0f / m_game->GetScreenWidth()) * topLeft.x) - 1.0f; topLeft.y = ((2.0f / m_game->GetScreenHeight()) * topLeft.y) - 1.0f; topRight.x = ((2.0f / m_game->GetScreenWidth()) * topRight.x) - 1.0f; topRight.y = ((2.0f / m_game->GetScreenHeight()) * topRight.y) - 1.0f; bottomLeft.x = ((2.0f / m_game->GetScreenWidth()) * bottomLeft.x) - 1.0f; bottomLeft.y = ((2.0f / m_game->GetScreenHeight()) * bottomLeft.y) - 1.0f; bottomRight.x = ((2.0f / m_game->GetScreenWidth()) * bottomRight.x) - 1.0f; bottomRight.y = ((2.0f / m_game->GetScreenHeight()) * bottomRight.y) - 1.0f; m_vertices[0].Positions[0] = topLeft.x; m_vertices[0].Positions[1] = topLeft.y; m_vertices[1].Positions[0] = topRight.x; m_vertices[1].Positions[1] = topRight.y; m_vertices[2].Positions[0] = bottomLeft.x; m_vertices[2].Positions[1] = bottomLeft.y; m_vertices[3].Positions[0] = bottomRight.x; m_vertices[3].Positions[1] = bottomRight.y; }
void ecFindDialog::OnFindNext(wxCommandEvent& event) { if (!TransferDataFromWindow()) return; if (!wxGetApp().GetConfigToolDoc()) return; ecConfigToolView *pControlView = (ecConfigToolView*) wxGetApp().GetConfigToolDoc()->GetFirstView(); ecConfigItem* item = pControlView->DoFind(wxGetApp().GetSettings().m_findText, this); if (item) { // Is the find window on top of the item? wxRect rect1, rect2; if (wxGetApp().GetTreeCtrl()->GetBoundingRect(item->GetTreeItem(), rect1)) { wxPoint topLeft(rect1.x, rect1.y); wxPoint bottomRight(rect1.GetRight(), rect1.GetBottom()); topLeft = wxGetApp().GetTreeCtrl()->ClientToScreen(topLeft); bottomRight = wxGetApp().GetTreeCtrl()->ClientToScreen(bottomRight); rect2 = GetRect(); // screen coords if (rect2.Inside(topLeft) || rect2.Inside(bottomRight)) { Move(wxPoint(topLeft.x + rect1.width, rect2.y)); } } } }
void ImageProcessor::saveTemplate(cv::Mat& img) { cv::resize(img, img, cv::Size(640, 480)); //assert(img.rows == 480 && img.cols == 640); refImg = img; mat imCorners = Data::loadCorner(); int pad = 0; cv::Point topLeft (imCorners(0,0) - pad, imCorners(0,1) - pad); cv::Point topRight (imCorners(1,0) + pad, imCorners(1,1) - pad); cv::Point bottomRight (imCorners(2,0) + pad, imCorners(2,1) + pad); cv::Point bottomLeft (imCorners(3,0) - pad, imCorners(3,1) + pad); // Init point matcher if (keypointMatcher) { delete keypointMatcher; } keypointMatcher = new BriskKeypointMatcher3D2D( refImg, topLeft, topRight, bottomRight, bottomLeft, *refMesh, modelCamCamera); //cv::line(refImg, cv::Point(0, 0), cv::Point(640, 480), KPT_COLOR); Visualization::DrawAQuadrangle ( refImg, topLeft, topRight, bottomRight, bottomLeft, TPL_COLOR ); Visualization::DrawProjectedMesh( refImg, *refMesh, modelCamCamera, MESH_COLOR ); }
void MeaCircleTool::GetPosition(MeaPositionLogMgr::Position& position) const { MeaUnitsMgr& units = MeaUnitsMgr::Instance(); // Convert the pixel locations to the current units. // FPOINT p1 = units.ConvertCoord(m_center); FPOINT p2 = units.ConvertCoord(m_perimeter); int radius = m_circle.GetRadius(); CPoint topLeft(m_center.x - radius, m_center.y - radius); CPoint bottomRight(m_center.x + radius, m_center.y + radius); FSIZE wh = units.GetWidthHeight(topLeft, bottomRight); double r = wh.cx / 2.0; // Save the positions in the position object. // position.RecordXYV(p1); position.RecordXY1(p2); position.RecordWH(wh); position.RecordDistance(r); position.RecordAngle(MeaLayout::GetAngle(p1, p2)); position.RecordCircleArea(r); }
void Rectangle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glm::vec3 position = getPosition(); glm::vec2 dimensions = getDimensions(); glm::vec2 halfDimensions = dimensions * 0.5f; glm::quat rotation = getRotation(); auto batch = args->_batch; if (batch) { Transform transform; transform.setTranslation(position); transform.setRotation(rotation); batch->setModelTransform(transform); auto geometryCache = DependencyManager::get<GeometryCache>(); if (getIsSolid()) { glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f); geometryCache->bindSimpleProgram(*batch); geometryCache->renderQuad(*batch, topLeft, bottomRight, rectangleColor); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); if (getIsDashedLine()) { glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f); glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f); glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f); geometryCache->renderDashedLine(*batch, point1, point2, rectangleColor); geometryCache->renderDashedLine(*batch, point2, point3, rectangleColor); geometryCache->renderDashedLine(*batch, point3, point4, rectangleColor); geometryCache->renderDashedLine(*batch, point4, point1, rectangleColor); } else { if (halfDimensions != _previousHalfDimensions) { QVector<glm::vec3> border; border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f); border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f); border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f); border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f); border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f); geometryCache->updateVertices(_geometryCacheID, border, rectangleColor); _previousHalfDimensions = halfDimensions; } geometryCache->renderVertices(*batch, gpu::LINE_STRIP, _geometryCacheID); } } } }
void Text3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } Q_ASSERT(args->_batch); auto& batch = *args->_batch; glm::quat rotation; if (_isFacingAvatar) { // rotate about vertical to face the camera rotation = args->_viewFrustum->getOrientation(); } else { rotation = getRotation(); } Transform transform; transform.setTranslation(getPosition()); transform.setRotation(rotation); transform.setScale(getScale()); batch.setModelTransform(transform); const float MAX_COLOR = 255.0f; xColor backgroundColor = getBackgroundColor(); glm::vec4 quadColor(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, getBackgroundAlpha()); glm::vec2 dimensions = getDimensions(); glm::vec2 halfDimensions = dimensions * 0.5f; const float SLIGHTLY_BEHIND = -0.005f; glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(batch, false, true, false, true); DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, quadColor); // Same font properties as textSize() float maxHeight = (float)_textRenderer->computeExtent("Xy").y * LINE_SCALE_RATIO; float scaleFactor = (maxHeight / FIXED_FONT_SCALING_RATIO) * _lineHeight; glm::vec2 clipMinimum(0.0f, 0.0f); glm::vec2 clipDimensions((dimensions.x - (_leftMargin + _rightMargin)) / scaleFactor, (dimensions.y - (_topMargin + _bottomMargin)) / scaleFactor); transform.setTranslation(getPosition()); transform.postTranslate(glm::vec3(-(halfDimensions.x - _leftMargin) , halfDimensions.y - _topMargin, 0.01f)); transform.setScale(scaleFactor); batch.setModelTransform(transform); glm::vec4 textColor = { _color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, getAlpha() }; _textRenderer->draw(batch, 0, 0, _text, textColor); batch.setPipeline(DrawOverlay3D::getOpaquePipeline()); }
auto seriesRect(QChart *chart, QAbstractSeries *series = nullptr) { auto inScene = chart->plotArea(); auto inChart = chart->mapFromScene(inScene); auto inChartRect = inChart.boundingRect(); auto inItem1 = chart->mapToValue(inChartRect.topLeft(), series); auto inItem2 = chart->mapToValue(inChartRect.bottomRight(), series); return QRectF(inItem1, inItem2).normalized(); }
QPainterPath CPcbCircle::path() { QPainterPath ppath; QPoint topLeft(-radius(),-radius()); QPoint bottomRight(radius(),radius()); ppath.addEllipse(QRectF(topLeft,bottomRight)); return ppath.simplified(); }
bool EPItemModel::setData(const QModelIndex &index, const QVariant &value, int role) { _ints[index.row()] = value.toInt(); QModelIndex topLeft(this->index(index.row(),0,QModelIndex())); QModelIndex bottomRight(this->index(index.row(),columnCount(QModelIndex()),QModelIndex())); emit dataChanged(topLeft,bottomRight); return true; }