ossimAnnotationObject* ossimAnnotationFontObject::getNewClippedObject(const ossimDrect& rect)const { if(intersects(rect)) { return (ossimAnnotationObject*)dup(); } return (ossimAnnotationObject*)NULL; }
bool KeyboardRouter::KeyboardControllerFactory::intersects( const ControllerFactory& otherFactory) const { const KeyboardControllerFactory* otherKeyboardFactory = dynamic_cast<const KeyboardControllerFactory*>(&otherFactory); if (otherKeyboardFactory) { return intersects(*otherKeyboardFactory); } return false; }
bool GamepadRouter::GamepadControllerFactory::intersects( const ControllerFactory& otherFactory) const { const GamepadControllerFactory* otherGamepadFactory = dynamic_cast<const GamepadControllerFactory*>(&otherFactory); if (otherGamepadFactory) { return intersects(*otherGamepadFactory); } return false; }
/** * ray triangle intersection */ bool UMTriangle::intersects(const UMRay& ray) const { // 3 points const UMVec3d& v0 = mesh_->vertex_list()[vertex_index_.x]; const UMVec3d& v1 = mesh_->vertex_list()[vertex_index_.y]; const UMVec3d& v2 = mesh_->vertex_list()[vertex_index_.z]; return intersects(v0, v1, v2, ray); }
void Physics::detectCollisions (const std::vector<PhysicsObject*>& objects) { // Lets go through each collidable object checking if they collide. for (auto i = 0U; i < objects.size(); ++i) { // Cache the values for the first object. auto first = objects[i]; const auto& check = first->getCollider(); const auto checkLayer = m_layers[check.getLayer()]; auto checkBox = check.getBox(); checkBox.translate (first->getPosition().x, first->getPosition().y); for (auto j = i + 1; j < objects.size(); ++j) { // Cache the values for the second object. auto second = objects[j]; const auto& against = second->getCollider(); // Check if their layers collide. if ((checkLayer | (1 << against.getLayer())) > 0) { // We must now check if the rectangles intersect. auto againstBox = against.getBox(); againstBox.translate (second->getPosition().x, second->getPosition().y); // Check if they intersect. if (checkBox.intersects (againstBox)) { // Determine the desired collision type. if (check.isTrigger()) { first->onTrigger (second); if (against.isTrigger()) { second->onTrigger (first); } } // Collider on trigger. else if (against.isTrigger()) { second->onTrigger (first); } // Collider on collider. else { first->onCollision (second); second->onCollision (first); } } } } } }
XBOOL XXObjectRectangle::SysCallMethod(int id,XSWFCONTEXT*pCnt,XXVARLIST&list) { switch(id) { case _SYSID(clone): pCnt->pStack->Push(Clone()); return XTRUE; case _SYSID(contains): contains(*pCnt,list); return XTRUE; case _SYSID(containsPoint): containsPoint(*pCnt,list); return XTRUE; case _SYSID(containsRectangle): containsRectangle(*pCnt,list); return XTRUE; case _SYSID(equals): equalsRect(*pCnt,list); return XTRUE; case _SYSID(inflate): inflate(*pCnt,list); return XTRUE; case _SYSID(inflatePoint): inflatePoint(*pCnt,list); return XTRUE; case _SYSID(intersection): intersection(*pCnt,list); return XTRUE; case _SYSID(intersects): intersects(*pCnt,list);return XTRUE; case _SYSID(isEmpty): pCnt->pStack->PushBool((width==0&&height==0)); return XTRUE; case _SYSID(offset): offsetRect(*pCnt,list); return XTRUE; case _SYSID(offsetPoint): offsetPoint(*pCnt,list); return XTRUE; case _SYSID(setEmpty): left=top=0; width=height=0; pCnt->pStack->PushConst(XOCT_UNDEFINE); return XTRUE; case _SYSID(toString): { XXVar var; GetString(var); pCnt->pStack->Push(var); }return XTRUE; case _SYSID(union): unionRect(*pCnt,list); return XTRUE; } return XXObject::SysCallMethod(id,pCnt,list); }
std::set<Line> GraphBuilder::getEdges(std::vector<Point> &points) { std::set<Line> lines; //process lines one by one for (std::vector<Point>::iterator it = points.begin(); it != points.end() - 1; ++it) { addLine(Line(*it, *(it + 1)), lines); } //add final line which closes figure addLine(Line(*(points.end() - 1), *(points.begin())), lines); std::map<Line, std::vector<Point>> intersectionPoints; //find points where lines intersect for (std::set<Line>::iterator it = lines.begin(); it != lines.end(); ++it) { Point temp; for (auto it2 = lines.begin(); it2 != it; ++it2) { if (intersects((*it).first, (*it).second, (*it2).first, (*it2).second, temp)) { if (!(std::find(points.begin(), points.end(), temp) != points.end())) { intersectionPoints[*it].push_back(temp); intersectionPoints[*it2].push_back(temp); } } } } //split lines with those intersection points for (auto it = intersectionPoints.begin(); it != intersectionPoints.end(); ++it) { Point current = (*it).first.first; //sort points by distance from starting point std::sort((*it).second.begin(), (*it).second.end(), [¤t](const Point &a, const Point &b) { return sqrt((current.first - a.first) * (current.first - a.first) + (current.second - a.second) * (current.second - a.second)) < sqrt((current.first - b.first) * (current.first - b.first) + (current.second - b.second) * (current.second - b.second)); }); for (size_t j = 0; j < (*it).second.size(); ++j) { lines.insert(Line(current, (*it).second[j])); current = (*it).second[j]; } lines.insert(Line(current, (*it).first.second)); lines.erase((*it).first); } return lines; }
void BouncyBee::checkBombaCollision(Bomba *bomba) { if (!bomba) return; if (intersects(bomba)) { bomba->setRemove(true); hit(bomba->getDamage()); } }
//----------------------------------------------------------------------- std::pair<bool, Real> Math::intersects(const Ray& ray, const vector<Plane>::type& planes, bool normalIsOutside) { list<Plane>::type planesList; for (vector<Plane>::type::const_iterator i = planes.begin(); i != planes.end(); ++i) { planesList.push_back(*i); } return intersects(ray, planesList, normalIsOutside); }
bool CollisionSystem::contains(sf::VertexArray aBounds, sf::Vector2f point) { sf::VertexArray pointVerts(sf::Quads, 4); pointVerts[0].position = sf::Vector2f(point.x, point.y); pointVerts[1].position = sf::Vector2f(point.x+2, point.y); pointVerts[2].position = sf::Vector2f(point.x+2, point.y+2); pointVerts[3].position = sf::Vector2f(point.x, point.y+2); return intersects(aBounds, pointVerts); }
void scrollBar::hoverMoveEvent(QGraphicsSceneHoverEvent *e) { // qDebug() << handlerBuf.x() << handlerBuf.y() << handlerBuf.right() << handlerBuf.bottom(); // qDebug() << e->pos().x() << e->pos().y(); if (_drawOpacity == 0.2 && intersects(e->pos())) { _fade->stop(); _fade->setDirection(QPropertyAnimation::Forward); _fade->start(); } else if (_drawOpacity != 0.2 && !intersects(e->pos()) && _fade->direction() == QPropertyAnimation::Forward) { _fade->stop(); _fade->setDirection(QPropertyAnimation::Backward); _fade->start(); } else graphicsItemBase::hoverMoveEvent(e); }
/// \brief Get the intersection of this interval with another interval. /// Interval<ValueT> intersection(Interval const &Other) const { // If there is no intersection, return an empty Interval. if (!intersects(Other)) return Interval<ValueT>::withStartEnd(Start, Start); auto IntersectStart = std::max(Start, Other.Start); auto IntersectEnd = std::min(End, Other.End); return Interval<ValueT>::withStartEnd(IntersectStart, IntersectEnd); }
Interval Interval::intersect(Interval& other) { Interval result; if (isEmpty() || other.isEmpty()) { return result; } if (intersects(*this, other)) { result = Interval(std::max(_min, other._min), std::min(_max, other._max)); } return result; }
bool Surface::visit (TraverseCallback callback, const Pixel& pix, float min_size) const { if (!intersects (BRect (pix))) return false; int num_inside = 0; float s2 = pix.size / 2; for (int i = 0; i < 4; ++i) { Math::Vector2 n_pt = pix.center; n_pt.x += i & 1 ? -s2 : s2; n_pt.y += i & 2 ? -s2 : s2; num_inside += test_point (n_pt) ? 1 : 0; } bool isec = intersects (pix); if (num_inside == 0 && !isec) return true; else if (num_inside == 4) return callback (pix, true); else if (num_inside < 8 && pix.size <= min_size) return callback (pix, false); float s4 = pix.size / 4; for (int i = 0; i < 4; ++i) { Pixel n_pix = pix; n_pix.center.x += i & 1 ? -s4 : s4; n_pix.center.y += i & 2 ? -s4 : s4; n_pix.size = s2; if (!visit (callback, n_pix, min_size)) return false; } return true; }
// computes distance to other rectangle double IntersectionRectangle::distance(const IntersectionRectangle &ir) const { double dist = 0.0; if(!intersects(ir)) { dist = parallelDist(top(),ir.bottom()); dist = min(dist, parallelDist(left(),ir.right())); dist = min(dist, parallelDist(right(),ir.left())); dist = min(dist, parallelDist(bottom(),ir.top())); } return dist; }
void scrollBar::mousePressEvent(QGraphicsSceneMouseEvent *e) { if (intersects(e->pos())) { _pressed = true; _Yoffset = e->pos().y() - handlerBuf.y(); } else if (e->pos().x() >= _size.width() - 8) setValue(valueRange / deltaHeight * (e->pos().y() - handlerBuf.height() / 2)); else graphicsItemBase::mousePressEvent(e); }
BiIt findIntersection(LineSegment<double, 2> lineSeg, BiIt firstPoint, BiIt lastPoint, double epsilon) { for (BiIt it = firstPoint; it != lastPoint; ++it) { if (intersects(lineSeg, LineSegment<double, 2>(*it, *std::next(it)), epsilon)) return it; } return lastPoint; }
Point MotionPlanner::nearest_env_point(const ExPolygonCollection &env, const Point &from, const Point &to) const { /* In order to ensure that the move between 'from' and the initial env point does not violate any of the configuration space boundaries, we limit our search to the points that satisfy this condition. */ /* Assume that this method is never called when 'env' contains 'from'; so 'from' is either inside a hole or outside all contours */ // get the points of the hole containing 'from', if any Points pp; for (ExPolygons::const_iterator ex = env.expolygons.begin(); ex != env.expolygons.end(); ++ex) { for (Polygons::const_iterator h = ex->holes.begin(); h != ex->holes.end(); ++h) { if (h->contains(from)) { pp = *h; } } if (!pp.empty()) break; } /* If 'from' is not inside a hole, it's outside of all contours, so take all contours' points */ if (pp.empty()) { for (ExPolygons::const_iterator ex = env.expolygons.begin(); ex != env.expolygons.end(); ++ex) { Points contour_pp = ex->contour; pp.insert(pp.end(), contour_pp.begin(), contour_pp.end()); } } /* Find the candidate result and check that it doesn't cross any boundary. (We could skip all of the above polygon finding logic and directly test all points in env, but this way we probably reduce complexity). */ Polygons env_pp = env; while (pp.size() >= 2) { // find the point in pp that is closest to both 'from' and 'to' size_t result = from.nearest_waypoint_index(pp, to); if (intersects((Lines)Line(from, pp[result]), env_pp)) { // discard result pp.erase(pp.begin() + result); } else { return pp[result]; } } // if we're here, return last point if any (better than nothing) if (!pp.empty()) return pp.front(); // if we have no points at all, then we have an empty environment and we // make this method behave as a no-op (we shouldn't get here by the way) return from; }
rspfAnnotationObject* rspfGeoAnnotationGdBitmapFont::getNewClippedObject(const rspfDrect& rect)const { if(intersects(rect)) { if(theProjectedFont.valid()) { return theProjectedFont->getNewClippedObject(rect); } } return (rspfAnnotationObject*)0; }
void AbstractBox::paintEvent(QPaintEvent *e) { Painter p(this); auto clip = e->rect(); auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius)); auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius)); if (paintTopRounded || paintBottomRounded) { auto parts = RectPart::None | 0; if (paintTopRounded) parts |= RectPart::FullTop; if (paintBottomRounded) parts |= RectPart::FullBottom; App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts); } auto other = e->region().intersected(QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius)); if (!other.isEmpty()) { for (auto rect : other.rects()) { p.fillRect(rect, st::boxBg); } } if (!_additionalTitle.isEmpty() && clip.intersects(QRect(0, 0, width(), titleHeight()))) { paintAdditionalTitle(p); } }
bool Meshing::isGood() { //Test poly for(int i=0;i<original_.size()-1;i++){ QLineF line(original_.at(i),original_.at(i+1)); if(intersects(original_,line)){ qDebug() << "Invalid polygon"; return false; } } return true; }
void IntervalRTreeBranchNode::query( double queryMin, double queryMax, index::ItemVisitor * visitor) const { if (! intersects(queryMin, queryMax)) return; if (node1) node1->query( queryMin, queryMax, visitor); if (node2) node2->query( queryMin, queryMax, visitor); }
void KoConnectionShapePrivate::normalPath(const qreal MinimumEscapeLength) { // Clear the path to build it again. path.clear(); path.append(handles[KoConnectionShape::StartHandle]); QList<QPointF> edges1; QList<QPointF> edges2; QPointF direction1 = escapeDirection(KoConnectionShape::StartHandle); QPointF direction2 = escapeDirection(KoConnectionShape::EndHandle); QPointF edgePoint1 = handles[KoConnectionShape::StartHandle] + MinimumEscapeLength * direction1; QPointF edgePoint2 = handles[KoConnectionShape::EndHandle] + MinimumEscapeLength * direction2; edges1.append(edgePoint1); edges2.prepend(edgePoint2); if (handleConnected(KoConnectionShape::StartHandle) && handleConnected(KoConnectionShape::EndHandle)) { QPointF intersection; bool connected = false; do { // first check if directions from current edge points intersect if (intersects(edgePoint1, direction1, edgePoint2, direction2, intersection)) { // directions intersect, we have another edge point and be done edges1.append(intersection); break; } // check if we are going toward the other handle qreal sp = scalarProd(direction1, edgePoint2 - edgePoint1); if (sp >= 0.0) { // if we are having the same direction, go all the way toward // the other handle, else only go half the way if (direction1 == direction2) edgePoint1 += sp * direction1; else edgePoint1 += 0.5 * sp * direction1; edges1.append(edgePoint1); // switch direction direction1 = perpendicularDirection(edgePoint1, direction1, edgePoint2); } else { // we are not going into the same direction, so switch direction direction1 = perpendicularDirection(edgePoint1, direction1, edgePoint2); } } while (! connected); } path.append(edges1); path.append(edges2); path.append(handles[KoConnectionShape::EndHandle]); }
void CollisionSystem::update(entityx::EntityManager& entities, entityx::EventManager& events, float dt) { mTestedMap.clear(); for(auto a : entities.entities_with_components<CNode, CCollider>()) { auto nodeA = a.component<CNode>(); auto colliderA = a.component<CCollider>(); auto transformA = nodeA->getWorldTransform(); if(nodeA->active) { for(auto b : entities.entities_with_components<CNode, CCollider>()) { auto nodeB = b.component<CNode>(); auto colliderB = b.component<CCollider>(); auto transformB = nodeB->getWorldTransform(); if(nodeB->active && a != b) { //If this pair hasn't been tested. if(mTestedMap[a].count(b) == 0) { if(colliderA->getAlignedBounds(transformA).intersects(colliderB->getAlignedBounds(transformB))) { if(intersects(colliderA->getVerts(transformA), colliderB->getVerts(transformB))) { if(colliderA->colliders.count(b) == 0 || colliderB->colliders.count(a) == 0) { colliderA->colliders.emplace(b); colliderB->colliders.emplace(a); }; } else { colliderA->colliders.erase(b); colliderB->colliders.erase(a); } } else { colliderA->colliders.erase(b); colliderB->colliders.erase(a); } mTestedMap[a].emplace(b); mTestedMap[b].emplace(a); } } } } } }
/*public*/ bool Envelope::intersection(const Envelope& env, Envelope& result) const { if (isNull() || env.isNull() || ! intersects(env)) return false; double intMinX = minx > env.minx ? minx : env.minx; double intMinY = miny > env.miny ? miny : env.miny; double intMaxX = maxx < env.maxx ? maxx : env.maxx; double intMaxY = maxy < env.maxy ? maxy : env.maxy; result.init(intMinX, intMaxX, intMinY, intMaxY); return true; }
rspfAnnotationObject* rspfGeoAnnotationLineObject::getNewClippedObject(const rspfDrect& rect)const { if(intersects(rect)) { if(theProjectedLineObject) { return theProjectedLineObject->getNewClippedObject(rect); } } return (rspfAnnotationObject*)0; }
bool find( const T &t ) { extern bool intersects( const T &t1, const T &t2 ); std::vector<T>::reverse_iterator it = family.rbegin(), end = family.rend(); for( ; it != end ; ++it ) if( intersects(*it, t) ) return search = it, true; return search = end, false; }
void CalendarBox::Inner::paintRows(Painter &p, QRect clip) { p.setFont(st::calendarDaysFont); auto ms = getms(); auto y = rowsTop(); auto index = -_context->daysShift(); auto highlightedIndex = _context->highlightedIndex(); for (auto row = 0, rowsCount = _context->rowsCount(), daysCount = _context->daysCount() ; row != rowsCount ; ++row, y += st::calendarCellSize.height()) { auto x = rowsLeft(); if (!myrtlrect(x, y, st::calendarCellSize.width() * kDaysInWeek, st::calendarCellSize.height()).intersects(clip)) { index += kDaysInWeek; continue; } for (auto col = 0; col != kDaysInWeek; ++col, ++index, x += st::calendarCellSize.width()) { auto rect = myrtlrect(x, y, st::calendarCellSize.width(), st::calendarCellSize.height()); auto grayedOut = (index < 0 || index >= daysCount || !rect.intersects(clip)); auto highlighted = (index == highlightedIndex); auto enabled = _context->isEnabled(index); auto innerLeft = x + (st::calendarCellSize.width() - st::calendarCellInner) / 2; auto innerTop = y + (st::calendarCellSize.height() - st::calendarCellInner) / 2; if (highlighted) { PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setBrush(grayedOut ? st::windowBgOver : st::dialogsBgActive); p.drawEllipse(myrtlrect(innerLeft, innerTop, st::calendarCellInner, st::calendarCellInner)); p.setBrush(Qt::NoBrush); } auto it = _ripples.find(index); if (it != _ripples.cend()) { auto colorOverride = [highlighted, grayedOut] { if (highlighted) { return grayedOut ? st::windowBgRipple : st::dialogsRippleBgActive; } return st::windowBgOver; }; it->second->paint(p, innerLeft, innerTop, width(), ms, &(colorOverride()->c)); if (it->second->empty()) { _ripples.erase(it); } } if (highlighted) { p.setPen(grayedOut ? st::windowSubTextFg : st::dialogsNameFgActive); } else if (enabled) { p.setPen(grayedOut ? st::windowSubTextFg : st::boxTextFg); } else { p.setPen(st::windowSubTextFg); } p.drawText(rect, _context->labelFromIndex(index), style::al_center); } } }
bool Aabb::hasCollision(const Aabb& other) const { bool result = false; if (intersects(other) == false) return result; Vector2f overlapMin(std::max(m_min.x, other.m_min.x), std::max(m_min.y, other.m_min.y)); Vector2f overlapMax(std::min(m_max.x, other.m_max.x), std::min(m_max.y, other.m_max.y)); if (contains(other)) result = true; return result; }
AABB AABB::intersection(const AABB &other) const{ if (intersects(other)){ return AABB( max(left, other.left), min(right, other.right), max(top, other.top), min(bot, other.bot) ); } else{ return AABB(); } }