bool VoxelProjectedPolygon::pointInside(const glm::vec2& point) const { // first check the bounding boxes, the point must be fully within the boounding box of this shadow if ((point.x > getMaxX()) || (point.y > getMaxY()) || (point.x < getMinX()) || (point.y < getMinY())) { return false; } float e = (getMaxX() - getMinX()) / 100.0f; // some epsilon // We need to have one ray that goes from a known outside position to the point in question. We'll pick a // start point just outside of our min X glm::vec2 r1p1(getMinX() - e, point.y); glm::vec2 r1p2(point); glm::vec2 r2p1(getVertex(getVertexCount()-1)); // start with last vertex to first vertex glm::vec2 r2p2; // Test the ray against all sides int intersections = 0; for (int i = 0; i < getVertexCount(); i++) { r2p2 = getVertex(i); if (doLineSegmentsIntersect(r1p1, r1p2, r2p1, r2p2)) { intersections++; } r2p1 = r2p2; // set up for next side } // If odd number of intersections, we're inside return ((intersections & 1) == 1); }
//子弹和怪物碰撞 bool GameLayer:: iscollision(Sprite *sprite1, Sprite *sprite2){ auto rect1 = sprite1->getBoundingBox();//子弹 auto rect2 = sprite2->getBoundingBox();//怪物 return !(rect1.getMaxX() < rect2.getMinX() || rect2.getMaxX() < rect1.getMinX() || rect1.getMaxY() < rect2.getMinY() || rect2.getMaxY() <rect1.getMinY()); }
float Field::getDistanceToFieldX(float x) { float distance = 0; if (x < getMinX()) distance = getMinX() - x; else if (x > getMaxX()) distance = x - getMaxX(); return distance; }
bool isOverlapping(const Rectangle& rect) const { /* Ugly, but correct. FIXME */ return (insideInterval(rect.getMinX(), getMinX(), getMaxX()) || insideInterval(rect.getMaxX(), getMinX(), getMaxX()) || insideInterval(getMinX(), rect.getMinX(), rect.getMaxX()) || insideInterval(getMaxX(), rect.getMinX(), rect.getMaxX())) && (insideInterval(rect.getMinY(), getMinY(), getMaxY()) || insideInterval(rect.getMaxY(), getMinY(), getMaxY()) || insideInterval(getMinY(), rect.getMinY(), rect.getMaxY()) || insideInterval(getMaxY(), rect.getMinY(), rect.getMaxY())); }
bool Bonus::isCollidePlayer() { auto player = GameScene::getTankM()->getPlayerTank(); if (player == nullptr) { return false; } auto boundingBox1 = player->getBoundingBox(); auto boundingBox2 = this->getBoundingBox(); /* 不使用intersectsRect,因为边缘重合的时候并不算 */ return !(boundingBox1.getMaxX() <= boundingBox2.getMinX() || boundingBox2.getMaxX() <= boundingBox1.getMinX() || boundingBox1.getMaxY() <= boundingBox2.getMinY() || boundingBox2.getMaxY() <= boundingBox1.getMinY()); }
void Ball::move(float delta) { this->setPosition(getPosition() + getVelocity() * delta); auto bBox = getBoundingBox(); auto ballRight = bBox.getMaxX(); auto ballLeft = bBox.getMinX(); if (ballRight > VisibleRect::right().x) { setPosition(Point(VisibleRect::right().x - radius(), getPosition().y) ); _velocity.x *= -1; } else if (ballLeft < VisibleRect::left().x) { setPosition(Point(VisibleRect::left().x + radius(), getPosition().y) ); _velocity.x *= -1; } if (getPosition().y > VisibleRect::top().y - radius()) { setPosition(Point(getPosition().x, VisibleRect::top().y - radius())); _velocity.y *= -1; } else if (getPosition().y < VisibleRect::bottom().y + radius()) { setPosition(Point(getPosition().x, VisibleRect::bottom().y + radius())); _velocity.y *= -1; } }
bool VoxelProjectedPolygon::occludes(const VoxelProjectedPolygon& occludee, bool checkAllInView) const { // if we are completely out of view, then we definitely don't occlude! // if the occludee is completely out of view, then we also don't occlude it // // this is true, but unfortunately, we're not quite handling projects in the // case when SOME points are in view and others are not. So, we will not consider // occlusion for any shadows that are partially in view. if (checkAllInView && (!getAllInView() || !occludee.getAllInView())) { return false; } // first check the bounding boxes, the occludee must be fully within the boounding box of this shadow if ((occludee.getMaxX() > getMaxX()) || (occludee.getMaxY() > getMaxY()) || (occludee.getMinX() < getMinX()) || (occludee.getMinY() < getMinY())) { return false; } // if we got this far, then check each vertex of the occludee, if all those points // are inside our polygon, then the tested occludee is fully occluded for(int i = 0; i < occludee.getVertexCount(); i++) { if (!pointInside(occludee.getVertex(i))) { return false; } } // if we got this far, then indeed the occludee is fully occluded by us return true; }
bool OctreeProjectedPolygon::pointInside(const glm::vec2& point, bool* matchesVertex) const { OctreeProjectedPolygon::pointInside_calls++; // first check the bounding boxes, the point must be fully within the boounding box of this polygon if ((point.x > getMaxX()) || (point.y > getMaxY()) || (point.x < getMinX()) || (point.y < getMinY())) { return false; } // consider each edge of this polygon as a potential separating axis // check the point against each edge for (int i = 0; i < getVertexCount(); i++) { glm::vec2 start = getVertex(i); glm::vec2 end = getVertex((i + 1) % getVertexCount()); float a = start.y - end.y; float b = end.x - start.x; float c = a * start.x + b * start.y; if (a * point.x + b * point.y < c) { return false; } } return true; }
/*public*/ void Envelope::translate(double transX, double transY) { if (isNull()) return; init(getMinX() + transX, getMaxX() + transX, getMinY() + transY, getMaxY() + transY); }
bool DRect::intersectsRect(const DRect& rect) const { return !( getMaxX() < rect.getMinX() || rect.getMaxX() < getMinX() || getMaxY() < rect.getMinY() || rect.getMaxY() < getMinY()); }
/* Get the rectangle which is big enough to hold both rectangles */ Rectangle getUnion(const Rectangle& rect) const { return Rectangle( std::min(getMinX(), rect.getMinX()), std::max(getMaxX(), rect.getMaxX()), std::min(getMinY(), rect.getMinY()), std::max(getMaxY(), rect.getMaxY())); }
bool Boundingbox::CollideBox(Boundingbox* _Box) { if (getMinX() > _Box->getMaxX()) return false; if (getMaxX() < _Box->getMinX()) return false; if (getMinY() > _Box->getMaxY()) return false; if (getMaxY() < _Box->getMinY()) return false; return true; }
/*public*/ bool Envelope::centre(Coordinate& centre) const { if (isNull()) return false; centre.x=(getMinX() + getMaxX()) / 2.0; centre.y=(getMinY() + getMaxY()) / 2.0; return true; }
// can be optimized with new pointInside() bool OctreeProjectedPolygon::occludes(const OctreeProjectedPolygon& occludee, bool checkAllInView) const { OctreeProjectedPolygon::occludes_calls++; // if we are completely out of view, then we definitely don't occlude! // if the occludee is completely out of view, then we also don't occlude it // // this is true, but unfortunately, we're not quite handling projects in the // case when SOME points are in view and others are not. So, we will not consider // occlusion for any shadows that are partially in view. if (checkAllInView && (!getAllInView() || !occludee.getAllInView())) { return false; } // first check the bounding boxes, the occludee must be fully within the boounding box of this shadow if ((occludee.getMaxX() > getMaxX()) || (occludee.getMaxY() > getMaxY()) || (occludee.getMinX() < getMinX()) || (occludee.getMinY() < getMinY())) { return false; } // we need to test for identity as well, because in the case of identity, none of the points // will be "inside" but we don't want to bail early on the first non-inside point bool potentialIdenity = false; if ((occludee.getVertexCount() == getVertexCount()) && (getBoundingBox().contains(occludee.getBoundingBox())) ) { potentialIdenity = true; } // if we got this far, then check each vertex of the occludee, if all those points // are inside our polygon, then the tested occludee is fully occluded int pointsInside = 0; for(int i = 0; i < occludee.getVertexCount(); i++) { bool vertexMatched = false; if (!pointInside(occludee.getVertex(i), &vertexMatched)) { // so the point we just tested isn't inside, but it might have matched a vertex // if it didn't match a vertext, then we bail because we can't be an identity // or if we're not expecting identity, then we also bail early, no matter what if (!potentialIdenity || !vertexMatched) { return false; } } else { pointsInside++; } } // we're only here if all points are inside matched and/or we had a potentialIdentity we need to check if (pointsInside == occludee.getVertexCount()) { return true; } // If we have the potential for identity, then test to see if we match, if we match, we occlude if (potentialIdenity) { return matches(occludee); } return false; // if we got this far, then we're not occluded }
bool EnemyPlane::isStillOnScreen() { auto boundings = getParent()->getBoundingBox(); bool planeIsOnScreen = ( this->getPositionX()-19 < boundings.getMaxX() && this->getPositionX()-19 > boundings.getMinX() && this->getPositionY()-19 < boundings.getMaxY() && this->getPositionY()-19 > boundings.getMinY()); return planeIsOnScreen; }
void CubeProjectedPolygon::printDebugDetails() const { qCDebug(shared, "CubeProjectedPolygon..." " minX=%f maxX=%f minY=%f maxY=%f", (double)getMinX(), (double)getMaxX(), (double)getMinY(), (double)getMaxY()); qCDebug(shared, " vertex count=%d distance=%f", getVertexCount(), (double)getDistance()); for (int i = 0; i < getVertexCount(); i++) { glm::vec2 point = getVertex(i); qCDebug(shared, " vertex[%d] = %f, %f ", i, (double)point.x, (double)point.y); } }
void VoxelProjectedPolygon::printDebugDetails() const { printf("VoxelProjectedPolygon..."); printf(" minX=%f maxX=%f minY=%f maxY=%f\n", getMinX(), getMaxX(), getMinY(), getMaxY()); printf(" vertex count=%d distance=%f\n", getVertexCount(), getDistance()); for (int i = 0; i < getVertexCount(); i++) { glm::vec2 point = getVertex(i); printf(" vertex[%d] = %f, %f \n", i, point.x, point.y); } }
//---------------------------------------------------------- void ofRectangle::growToInclude(const ofPoint& p){ float x0 = MIN(getMinX(),p.x); float x1 = MAX(getMaxX(),p.x); float y0 = MIN(getMinY(),p.y); float y1 = MAX(getMaxY(),p.y); float w = x1 - x0; float h = y1 - y0; set(x0,y0,w,h); }
//---------------------------------------------------------- void ofRectangle::growToInclude(const ofRectangle& rect){ float x0 = MIN(getMinX(),rect.getMinX()); float x1 = MAX(getMaxX(),rect.getMaxX()); float y0 = MIN(getMinY(),rect.getMinY()); float y1 = MAX(getMaxY(),rect.getMaxY()); float w = x1 - x0; float h = y1 - y0; set(x0,y0,w,h); }
bool Sphere::isIntersects(Vec3 p) { if (getMaxX() > p.getX() && getMinX() < p.getX()) return true; if (getMaxY() > p.getY() && getMinY() < p.getY()) return true; if (getMaxZ() > p.getZ() && getMinZ() < p.getZ()) return true; return false; }
int imageList::createPage(int pageno) { char *s; if (currentPageNo == pageno) return 0; if (currentPageNo >= 1) { /* * We need to unlink the files which change each time a new page is * processed. The final unlink is done by xtmpfile when pre-grohtml * exits. */ unlink(imagePageName); unlink(psPageName); } if (show_progress) { fprintf(stderr, "[%d] ", pageno); fflush(stderr); } #if defined(DEBUGGING) if (debug) fprintf(stderr, "creating page %d\n", pageno); #endif s = make_message("psselect -q -p%d %s %s\n", pageno, psFileName, psPageName); if (s == NULL) sys_fatal("make_message"); html_system(s, 1); s = make_message("echo showpage | " "%s%s -q -dBATCH -dSAFER " "-dDEVICEHEIGHTPOINTS=792 " "-dDEVICEWIDTHPOINTS=%d -dFIXEDMEDIA=true " "-sDEVICE=%s -r%d %s " "-sOutputFile=%s %s -\n", image_gen, EXE_EXT, (getMaxX(pageno) * image_res) / postscriptRes, image_device, image_res, antiAlias, imagePageName, psPageName); if (s == NULL) sys_fatal("make_message"); html_system(s, 1); free(s); currentPageNo = pageno; return 0; }
bool CCRect::containsPoint(const CCPoint& point) const { bool bRet = false; if (point.x >= getMinX() && point.x <= getMaxX() && point.y >= getMinY() && point.y <= getMaxY()) { bRet = true; } return bRet; }
void MainWindow::on_pushButton_4_clicked() { if (!ui->lineEdit_2->text().isEmpty() && ui->lineEdit_2->text().toFloat() <= getMaxX()) { ui->label_3->setText(QString::number(Lagrange::interpolate(ui->lineEdit_2->text().toFloat(), values, rowCount))); ui->label_3->show(); } else { ui->label_3->hide(); } }
void HexaGridMap::updateTrajectory() { ((DrawNode*)this->trajectoryCanvas)->clear(); Point* ptsToDraw = new Point[this->trajectory.size()]; for (int i = 0; i < this->trajectory.size(); i++) { auto name = Utils::generateNameByPoint(this->trajectory.at(i)); auto box = this->getChildByName<HexaGridMapUnit*>(name)->getBoundingBox(); ptsToDraw[i] = Point(box.getMinX()+box.getMaxX(), box.getMinY()+box.getMaxY())/2; } for (int i = 1; i < this->trajectory.size(); i++) { ((DrawNode*)this->trajectoryCanvas)->drawSegment(ptsToDraw[i-1], ptsToDraw[i], 4, Color4F(.5, .25, .25, 1)); } }
/** * @brief AddKeyFrameImageCoverPolicy * add a keyframe taking into account the percentage of image free of features matched * @param frame * @return */ inline bool AddKeyFrameImageCoverPolicy( const StereoFrame& frame, const double imageWidth, const double coverThreshold) { const std::map<MapPoint*, Measurement> &measurements = frame.GetMeasurementsLeft(); double minX = getMinX(measurements); double maxX = getMaxX(measurements); double imageAreaMeasurementFree = (minX + (imageWidth - maxX)) / imageWidth; return imageAreaMeasurementFree > coverThreshold; }
void EnemyObject::walkInZone(const float delta){ auto const rect = getHitbox(); const float minX = rect->getMidX(); const float maxX = rect->getMaxX(); if(maxX >softXMax){ setVelocityX(-speed); setPrevDir(GO_LEFT); objectSprite->setScaleX(-1 * abs(objectSprite->getScale())); }else if(minX < softXMin){ setVelocityX(speed); setPrevDir(GO_RIGHT); objectSprite->setScaleX(1 * abs(objectSprite->getScale())); } }
void MainWindow::on_pushButton_clicked() { gr->points.clear(); gr->setCurveColor(Qt::blue); int maxX = getMaxX(); for (float x = 1; x <= maxX; x += step) { gr->points << QPointF(x, Lagrange::interpolate(x, values, rowCount)); } gr->update(); }
bool ZoneImplementation::isWithinBoundaries(const Vector3& position) { //Remove 1/16th of the size to match client limits. NOTE: it has not been verified to work like this in the client. //Normal zone size is 8192, 1/16th of that is 512 resulting in 7680 as the boundary value. float maxX = getMaxX() * 15 / 16; float minX = getMinX() * 15 / 16; float maxY = getMaxY() * 15 / 16; float minY = getMinY() * 15 / 16; if (maxX >= position.getX() && minX <= position.getX() && maxY >= position.getY() && minY <= position.getY()) { return true; } else { return false; } }
void Rect::merge(const Rect& rect) { float top1 = getMaxY(); float left1 = getMinX(); float right1 = getMaxX(); float bottom1 = getMinY(); float top2 = rect.getMaxY(); float left2 = rect.getMinX(); float right2 = rect.getMaxX(); float bottom2 = rect.getMinY(); origin.x = std::min(left1, left2); origin.y = std::min(bottom1, bottom2); size.width = std::max(right1, right2) - origin.x; size.height = std::max(top1, top2) - origin.y; }
//---------------------------------------------------------- ofRectangle ofRectangle::getIntersection(const ofRectangle& rect) const { float x0 = MAX(getMinX(),rect.getMinX()); float x1 = MIN(getMaxX(),rect.getMaxX()); float w = x1 - x0; if(w < 0.0f) return ofRectangle(0,0,0,0); // short circuit if needed float y0 = MAX(getMinY(),rect.getMinY()); float y1 = MIN(getMaxY(),rect.getMaxY()); float h = y1 - y0; if(h < 0.0f) return ofRectangle(0,0,0,0); // short circuit if needed return ofRectangle(x0,y0,w,h); }