void RenderTextTrackCue::repositionCueSnapToLinesSet() { InlineFlowBox* firstLineBox; LayoutUnit step; LayoutUnit position; if (!initializeLayoutParameters(firstLineBox, step, position)) return; bool switched; placeBoxInDefaultPosition(position, switched); // 11. Step loop: If none of the boxes in boxes would overlap any of the boxes // in output and all the boxes in output are within the video's rendering area // then jump to the step labeled done positioning. while (isOutside() || isOverlapping()) { if (!shouldSwitchDirection(firstLineBox, step)) // 13. Move all the boxes in boxes ... // 14. Jump back to the step labeled step loop. moveBoxesByStep(step); else if (!switchDirection(switched, step)) break; // 19. Jump back to the step labeled step loop. } // Acommodate extra top and bottom padding, border or margin. // Note: this is supported only for internal UA styling, not through the cue selector. if (hasInlineDirectionBordersPaddingOrMargin()) moveIfNecessaryToKeepWithinContainer(); }
///////////////////// set pixel void set_pixeli(CLMem* image, int4 ijk, int4 color, int dim_size) { uint channel_type = image->image_format.image_channel_data_type; cl_channel_order channel_order; int4 dim; int d; channel_order = image->image_format.image_channel_order; dim = getDim(image); ijk = getImageArrayCoord(image, ijk); for( d = 0; d < dim_size; d++ ) { if( isOutside(ijk[d], dim[d]) ) return; } if( channel_order == CL_BGRA ) { int tmp; tmp = color[0]; color[0] = color[2]; color[2] = tmp; } if( channel_type == CL_SIGNED_INT8 ) { _set_pixeli_SIGNED_INT8(image, ijk, color); } else if( channel_type == CL_SIGNED_INT16 ) { _set_pixeli_SIGNED_INT16(image, ijk, color); } else if( channel_type == CL_SIGNED_INT32 ) { _set_pixeli_SIGNED_INT32(image, ijk, color); } return; }
double ArizonaTest::binarySearch(const vec3 &direction, PQP_Model &volume, double startValue, double endValue) { //we assume that startValue is inside the model and endValue is outside the model //we find the value in between that is exactly on the model double currentValue = startValue; double currentInterval = (endValue - startValue)/2.0; PQP_REAL pt[3]; PQP_REAL R[3][3]={{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}}; PQP_REAL T[3]={0.0,0.0,0.0}; double closest_dist = 1.0e9, thresh = 0.0, distance; PQP_REAL closest_pt[3], closest_normal[3]; bool success = false; while (1) { pt[0] = currentValue * direction.x(); pt[1] = currentValue * direction.y(); pt[2] = currentValue * direction.z(); distance = GetShortestDist(pt, &volume, R, T, closest_dist, closest_pt, closest_normal, thresh); DBGP("disturbance: " << pt[0] << " " << pt[1] << " " << pt[2]); DBGP("Closest point: " << closest_pt[0] << " " << closest_pt[1] << " " << closest_pt[2] << "; Distance is: " << distance); DBGP("Current interval: " << currentInterval); if(distance < EPSILON){ success = true; break; } if(isOutside(&volume, pt)){ DBGP("outside" << std::endl); if (currentValue <= startValue) { DBGP("Error: startValue is outside of model!"); break; } currentValue -= currentInterval; } else { DBGP("inside" << std::endl); if (currentValue >= endValue) { DBGP("Error: endValue is inside model!"); break; } currentValue += currentInterval; } currentInterval /= 2; if ( fabs(currentInterval) < 1.0e-10 ) { DBGP("Max loops exceeded!"); break; } } if (distance > 10e-5) { DBGA("Binary search failed! distance is " << distance); } else { DBGP("Binary search success!"); } return currentValue; }
T zfLaplacian(const grid<dim,T>& GRID, const vector<int>& x) { T laplacian = 0.0; MMSP::vector<int> s = x; const T& y = GRID(x); for (int i=0; i<dim; i++) { s[i] += 1; const T& yh = (isOutside(s))?y:GRID(s); s[i] -= 2; const T& yl = (isOutside(s))?y:GRID(s); s[i] += 1; double weight = 1.0 / (dx(GRID, i) * dx(GRID, i)); laplacian += weight * (yh - 2.0 * y + yl); } return laplacian; }
void RenderVTTCue::repositionCueSnapToLinesSet() { InlineFlowBox* firstLineBox; LayoutUnit step; LayoutUnit position; if (!findFirstLineBox(firstLineBox)) return; if (!initializeLayoutParameters(firstLineBox, step, position)) return; bool switched; placeBoxInDefaultPosition(position, switched); // 11. Step loop: If none of the boxes in boxes would overlap any of the boxes // in output and all the boxes in output are within the video's rendering area // then jump to the step labeled done positioning. while (isOutside() || isOverlapping()) { if (!shouldSwitchDirection(firstLineBox, step)) { // 13. Move all the boxes in boxes ... // 14. Jump back to the step labeled step loop. moveBoxesByStep(step); } else if (!switchDirection(switched, step)) { break; } // 19. Jump back to the step labeled step loop. } // Acommodate extra top and bottom padding, border or margin. // Note: this is supported only for internal UA styling, not through the cue selector. if (hasInlineDirectionBordersPaddingOrMargin()) { IntRect containerRect = containingBlock()->absoluteBoundingBoxRect(); IntRect cueRect = absoluteBoundingBoxRect(); int topOverflow = cueRect.y() - containerRect.y(); int bottomOverflow = containerRect.y() + containerRect.height() - cueRect.y() - cueRect.height(); int adjustment = 0; if (topOverflow < 0) adjustment = -topOverflow; else if (bottomOverflow < 0) adjustment = bottomOverflow; if (adjustment) setY(y() + adjustment); } }
void generate(int dim, const char* filename) { if (dim!=2) { std::cerr<<"ERROR: CHiMaD problems are 2-D, only!"<<std::endl; std::exit(-1); } int rank=0; #ifdef MPI_VERSION rank = MPI::COMM_WORLD.Get_rank(); #endif const double q[2] = {0.1*std::sqrt(2.0), 0.1*std::sqrt(3.0)}; if (dim==2) { MMSP::grid<2,double> grid(1,0,100,0,120); for (int d=0; d<dim; d++){ dx(grid,d) = deltaX; if (MMSP::x0(grid,d)==MMSP::g0(grid,d)) MMSP::b0(grid,d) = Neumann; // enumerated in MMSP.utility.hpp else if (MMSP::x1(grid,d)==MMSP::g1(grid,d)) MMSP::b1(grid,d) = Neumann; // enumerated in MMSP.utility.hpp } for (int i=0; i<nodes(grid); i++) { MMSP::vector<int> x = position(grid,i); if (isOutside(x)) grid(x) = 0.0; else grid(x) = 0.45 + 0.01 * std::cos(x[0]*dx(grid,0)*q[0] + x[1]*dx(grid,1)*q[1]); } #ifdef MPI_VERSION MPI::COMM_WORLD.Barrier(); #endif output(grid,filename); if (rank==0) std::cout<<"Timestep is "<<dt<<" (Co="<<CFL<<')'<<std::endl; } }
bool EventManager::checkNext(const QPoint &next_m, const QPoint &next_f, const QPoint &next_s, const QPoint &next_t) { if (!isOutside(next_s) || !isEatingHimself(next_s, next_m)) return false; static const QPoint arr[] = {next_f, next_s, next_t}; vector<QPoint> vPoint (arr, arr + sizeof(arr) / sizeof(arr[0])); /* std::vector<QPoint> vPoint; vPoint.push_back(next_f); vPoint.push_back(next_s); vPoint.push_back(next_t); */ for (int i = 0; i < vPoint.size(); ++i) if (_land.getCell(vPoint[i]).getContent() == 'f') { _land.getCell(vPoint[i]).setContent(0); digest(); } /* if (_land.getCell(next_f).getContent() == 'f') { _land.getCell(next_f).setContent(0); digest(); } else if (_land.getCell(next_s).getContent() == 'f') { _land.getCell(next_s).setContent(0); digest(); } else if (_land.getCell(next_t).getContent() == 'f') { _land.getCell(next_t).setContent(0); digest(); } */ return true; }
void RenderTextTrackCue::repositionCueSnapToLinesNotSet() { // 3. If none of the boxes in boxes would overlap any of the boxes in output, and all the boxes in // output are within the video's rendering area, then jump to the step labeled done positioning below. if (!isOutside() && !isOverlapping()) return; // 4. If there is a position to which the boxes in boxes can be moved while maintaining the relative // positions of the boxes in boxes to each other such that none of the boxes in boxes would overlap // any of the boxes in output, and all the boxes in output would be within the video's rendering area, // then move the boxes in boxes to the closest such position to their current position, and then jump // to the step labeled done positioning below. If there are multiple such positions that are equidistant // from their current position, use the highest one amongst them; if there are several at that height, // then use the leftmost one amongst them. moveIfNecessaryToKeepWithinContainer(); int x = 0; int y = 0; if (!findNonOverlappingPosition(x, y)) return; setX(x); setY(y); }
int Game::update() { for (int a = 0; a < 2; ++a) //COOLDOWNS { for (int b = 0; b < 4; ++b) { cooldown[a][b] -= 1; } } for (int a = 0; a < 2; ++a) { for (int i = 0; i < 4; ++i) //MOVEMENT { if (sf::Keyboard::isKeyPressed(key[a][i])) { players[a].accelerate(i); } } if (isOutside(players[a].getPosition())) //someone is out? { return a * -1 + 2; } } int timer = 1; //one second cooldown for everything for (int i = 4; i < 8; ++i) //projectiles/boosts { for (int a = 0; a < 2; ++a) { if (sf::Keyboard::isKeyPressed(key[a][i])) { if (cooldown[a][i - 4] <= 0) { if (i == 4) { int power = 3; //power of forward boost players[a].changeVelocity(sf::Vector2f(power * cos(players[a].getAngle() * (PI / 180)), power * sin(players[a].getAngle() * (PI / 180)))); } else if (i == 5) { int power = -6; //power of backward boost players[a].changeVelocity(sf::Vector2f(power * cos(players[a].getAngle() * (PI / 180)), power * sin(players[a].getAngle() * (PI / 180)))); } else { projectiles[a].push_back(new Projectile(&players[a], i - 6)); } cooldown[a][i - 4] = 60 * timer; } } } } for (int a = 0; a < 2; ++a) { for (unsigned int b = 0; b < projectiles[a].size(); ++b) { if (isOutside(projectiles[a][b]->getPosition())) { delete projectiles[a][b]; projectiles[a].erase(projectiles[a].begin() + b); b--; } else { projectiles[a][b]->update(); } } } players[0].updatePosition(); players[1].updatePosition(); // Check for projectile collisions for (unsigned int i = 0; i < projectiles[1].size(); ++i) { if (getDistance(projectiles[1][i]->getPosition(), players[0].getPosition()) < RADIUS + projectiles[1][i]->getRadius()) { projectiles[1][i]->onEnemy(&players[0]); delete projectiles[1][i]; projectiles[1].erase(projectiles[1].begin() + i); i--; } } for (unsigned int i = 0; i < projectiles[0].size(); ++i) { if (getDistance(projectiles[0][i]->getPosition(), players[1].getPosition()) < RADIUS + projectiles[0][i]->getRadius()) { projectiles[0][i]->onEnemy(&players[1]); delete projectiles[0][i]; projectiles[0].erase(projectiles[0].begin() + i); i--; } } //check for player collisions sf::Vector2f pos1 = players[0].getPosition(); sf::Vector2f pos2 = players[1].getPosition(); float distance = getDistance(pos1, pos2); if (distance < RADIUS*2) //collision { //velocities sf::Vector2f v1 = players[0].getVelocity(); sf::Vector2f v2 = players[1].getVelocity(); double m1 = players[0].getMass(); double m2 = players[1].getMass(); float deltax = players[1].getPosition().x - players[0].getPosition().x; float deltay = players[1].getPosition().y - players[0].getPosition().y; sf::Vector2f p1_vel, p2_vel, collision(deltax, deltay); collision.x /= distance; collision.y /= distance; float ai = dot(v1, collision); float bi = dot(v2, collision); float af = collisionSpeed(ai, bi, m1, m2); float bf = collisionSpeed(bi, ai, m1, m2); v1.x += collision.x * (af - ai); v1.y += collision.y * (af - ai); v2.x += collision.x * (bf - bi); v2.y += collision.y *(bf - bi); players[0].setVelocity(v1); players[1].setVelocity(v2); // Make sure the players are not overlapping distance = -(distance - RADIUS*2)/2; int dirx = (pos1.x > pos2.x) ? 1 : -1; int diry = (pos1.y > pos2.y) ? 1 : -1; pos1 = sf::Vector2f(pos1.x + distance*dirx, pos1.y + distance*diry); pos2 = sf::Vector2f(pos2.x - distance*dirx, pos2.y - distance*diry); players[0].setPosition(pos1); players[1].setPosition(pos2); players[0].updateDirection(); players[1].updateDirection(); } return 0; }
/** * @brief 歩数マップを設定します * @param x 設定するx座標 * @param y 設定するy座標 * @param data 設定する歩数 */ void Footmap::setFootmap(int x, int y, int data){ if(isOutside(x, y)) return; if(data > 255) map[x][y] = 255; else map[x][y] = data; return; }
/** * @brief 歩数マップを取得します * @param x 取得するx座標 * @param y 取得するy座標 * @param out 座標外の返り値 * @return 設定した座標の歩数 */ int Footmap::getFootmap(int x, int y, int out){ if(isOutside(x, y)) return out; else return map[x][y]; }
double ArizonaTest::getScale2Surface(double *dis) { if (coords.empty() || indices.empty()) { DBGA("Unable to compute minimum force; hull not set"); return 0; } if(mIsFlipped){ dis[0] = - dis[0]; dis[1] = - dis[1]; dis[2] = - dis[2]; } // compute the necessary force PQP_REAL v1[3],v2[3],v3[3]; PQP_Model volume = PQP_Model(); //model for the volumn volume.BeginModel(); int triInd = 0; int numIndices = indices.size(); for (int k = 0; k < numIndices - 3; k++) { if(indices[k+3] == -1) // dealing with meaningful vertices. { v1[0]=coords[indices[k]].x(); v1[1]=coords[indices[k]].y(); v1[2]=coords[indices[k]].z(); v2[0]=coords[indices[k+1]].x(); v2[1]=coords[indices[k+1]].y(); v2[2]=coords[indices[k+1]].z(); v3[0]=coords[indices[k+2]].x(); v3[1]=coords[indices[k+2]].y(); v3[2]=coords[indices[k+2]].z(); volume.AddTri(v1,v2,v3,triInd++); } } volume.EndModel(); PQP_REAL pt[3]; pt[0] = (double)(dis[0]*mGrasp->getMaxRadius()); pt[1] = (double)(dis[1]*mGrasp->getMaxRadius()); pt[2] = (double)(dis[2]*mGrasp->getMaxRadius()); vec3 disturbance(pt[0], pt[1], pt[2]); double originalLength = disturbance.len(); double startValue = 0, endValue = originalLength; int loops = 0; while (!isOutside(&volume, pt) ) { pt[0] *= 2; pt[1] *= 2; pt[2] *= 2; startValue = endValue; endValue *= 2; loops ++; if (loops > 20) { DBGA("Failed to find point outside of volume!!!!!"); break; } } disturbance = normalise(disturbance); double length = binarySearch(disturbance, volume, startValue, endValue); return originalLength / length; }
void update(MMSP::grid<dim,T>& grid, int steps) { int rank=0; #ifdef MPI_VERSION rank = MPI::COMM_WORLD.Get_rank(); #endif // Make sure the grid spacing is correct for (int d=0; d<dim; d++) { dx(grid,d) = deltaX; if (MMSP::x0(grid,d)==MMSP::g0(grid,d)) MMSP::b0(grid,d) = Neumann; // enumerated in MMSP.utility.hpp else if (MMSP::x1(grid,d)==MMSP::g1(grid,d)) MMSP::b1(grid,d) = Neumann; // enumerated in MMSP.utility.hpp } ghostswap(grid); // Let's be absolutely explicit about BCs here. MMSP::grid<dim,T> update(grid); for (int d=0; d<dim; d++) { dx(update,d) = deltaX; if (MMSP::x0(update,d)==MMSP::g0(update,d)) MMSP::b0(update,d) = Neumann; // enumerated in MMSP.utility.hpp else if (MMSP::x1(update,d)==MMSP::g1(update,d)) MMSP::b1(update,d) = Neumann; // enumerated in MMSP.utility.hpp } MMSP::grid<dim,T> temp(grid); for (int d=0; d<dim; d++) { dx(temp,d) = deltaX; if (MMSP::x0(temp,d)==MMSP::g0(temp,d)) MMSP::b0(temp,d) = Neumann; // enumerated in MMSP.utility.hpp else if (MMSP::x1(temp,d)==MMSP::g1(temp,d)) MMSP::b1(temp,d) = Neumann; // enumerated in MMSP.utility.hpp } for (int step=0; step<steps; step++) { for (int n=0; n<nodes(grid); n++) { MMSP::vector<int> x = position(grid,n); if (isOutside(x)) { temp(x) = 0.0; } else { double c = grid(x); temp(x) = dfdc(c) - K*zfLaplacian(grid,x); } } #ifdef MPI_VERSION MPI::COMM_WORLD.Barrier(); #endif ghostswap(temp); double energy = 0.0; double mass = 0.0; for (int n=0; n<nodes(grid); n++) { MMSP::vector<int> x = position(grid,n); if (isOutside(x)) { update(x) = 0.0; } else { update(x) = grid(x) + dt*D*zfLaplacian(temp,x); energy += dx(grid)*dy(grid)*energydensity(update(x)); mass += dx(grid)*dy(grid)*update(x); } } #ifdef MPI_VERSION MPI::COMM_WORLD.Barrier(); double myEnergy = energy; double myMass = mass; MPI::COMM_WORLD.Reduce(&myEnergy, &energy, 1, MPI_DOUBLE, MPI_SUM, 0); MPI::COMM_WORLD.Reduce(&myMass, &mass, 1, MPI_DOUBLE, MPI_SUM, 0); #endif if (rank==0) std::cout<<energy<<'\t'<<mass<<'\n'; swap(grid,update); ghostswap(grid); } #ifndef DEBUG if (rank==0) std::cout<<std::flush; #endif }
void SnapToLinesLayouter::layout() { // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings // Step 13, "If cue's text track cue snap-to-lines flag is set". InlineFlowBox* firstLineBox = findFirstLineBox(); if (!firstLineBox) return; // Steps 1-3 skipped. // 4. Horizontal: Let step be the height of the first line box in boxes. // Vertical: Let step be the width of the first line box in boxes. LayoutUnit step = firstLineBox->logicalHeight(); // 5. If step is zero, then jump to the step labeled done positioning below. if (!step) return; // Steps 6-11. LayoutUnit positionAdjustment = computeInitialPositionAdjustment(step); // 12. Move all boxes in boxes ... // Horizontal: ... down by the distance given by position // Vertical: ... right by the distance given by position moveBoxesBy(positionAdjustment); // 13. Remember the position of all the boxes in boxes as their specified // position. m_specifiedPosition = m_cueBox.location(); // 14. Let best position be null. It will hold a position for boxes, much // like specified position in the previous step. // 15. Let best position score be null. // 16. Let switched be false. bool switched = false; // Step 17 skipped. (margin == 0; title area == video area) // 18. Step loop: If none of the boxes in boxes would overlap any of the // boxes in output, and all of the boxes in output are entirely within the // title area box, then jump to the step labeled done positioning below. while (isOutside() || isOverlapping()) { // 19. Let current position score be the percentage of the area of the // bounding box of the boxes in boxes that is outside the title area // box. // 20. If best position is null (i.e. this is the first run through // this loop, switched is still false, the boxes in boxes are at their // specified position, and best position score is still null), or if // current position score is a lower percentage than that in best // position score, then remember the position of all the boxes in boxes // as their best position, and set best position score to current // position score. if (!shouldSwitchDirection(firstLineBox, step)) { // 22. Horizontal: Move all the boxes in boxes down by the distance // given by step. (If step is negative, then this will actually // result in an upwards movement of the boxes in absolute terms.) // Vertical: Move all the boxes in boxes right by the distance // given by step. (If step is negative, then this will actually // result in a leftwards movement of the boxes in absolute terms.) moveBoxesBy(step); // 23. Jump back to the step labeled step loop. continue; } // 24. Switch direction: If switched is true, then move all the boxes in // boxes back to their best position, and jump to the step labeled done // positioning below. // 25. Otherwise, move all the boxes in boxes back to their specified // position as determined in the earlier step. m_cueBox.setLocation(m_specifiedPosition); // XX. If switched is true, jump to the step labeled done // positioning below. if (switched) break; // 26. Negate step. step = -step; // 27. Set switched to true. switched = true; // 28. Jump back to the step labeled step loop. } }
bool intersects(const Rectangle &other) const { return !isOutside(other) && !containsRectangle(other) && other.containsRectangle(*this); }
bool intersectsOrContains(const Rectangle &other) const { return !isOutside(other); }