// scan lpsz for a number of hex digits (at most 8); update lpsz, return // value in Value; check for chDelim; return TRUE for success. BOOL HexStringToDword(LPCTSTR * lplpsz, DWORD * lpValue, int cDigits, TCHAR chDelim) { int ich; LPCTSTR lpsz = *lplpsz; DWORD Value = 0; BOOL fRet = TRUE; for (ich = 0; ich < cDigits; ich++) { TCHAR ch = lpsz[ich]; if (InRange(ch, TEXT('0'), TEXT('9'))) { Value = (Value << 4) + ch - TEXT('0'); } else if ( InRange( (ch |= (TEXT('a')-TEXT('A'))), TEXT('a'), TEXT('f')) ) { Value = (Value << 4) + ch - TEXT('a') + 10; } else return(FALSE); } if (chDelim) { fRet = (lpsz[ich++]==chDelim); } *lpValue = Value; *lplpsz = lpsz+ich; return fRet; }
void Try(int x, int y) { int i; for(i=0; i<8; i++) { if(!InRange(x+dx[i])) continue; if(!InRange(y+dy[i])) continue; if(bVisited[x+dx[i]][y+dy[i]]) continue; bVisited[x+dx[i]][y+dy[i]] = 1; cntVisited ++; seqVisited[x+dx[i]][y+dy[i]] = ++seq; if(cntVisited == (N+1)*(N+1)) FindSolution(); else { if(x==4 && y==3) { int x6=0; x6++; } Try(x+dx[i], y+dy[i]); } bVisited[x+dx[i]][y+dy[i]] = 0; cntVisited --; seqVisited[x+dx[i]][y+dy[i]] =0, seq--; } }
bool Value::isConvertibleTo(ValueType other) const { switch (other) { case nullValue: return (isNumeric() && asDouble() == 0.0) || (type_ == booleanValue && value_.bool_ == false) || (type_ == stringValue && asString() == "") || (type_ == arrayValue && value_.map_->size() == 0) || (type_ == objectValue && value_.map_->size() == 0) || type_ == nullValue; case intValue: return isInt() || (type_ == realValue && InRange(value_.real_, minInt, maxInt)) || type_ == booleanValue || type_ == nullValue; case uintValue: return isUInt() || (type_ == realValue && InRange(value_.real_, 0, maxUInt)) || type_ == booleanValue || type_ == nullValue; case realValue: return isNumeric() || type_ == booleanValue || type_ == nullValue; case booleanValue: return isNumeric() || type_ == booleanValue || type_ == nullValue; case stringValue: return isNumeric() || type_ == booleanValue || type_ == stringValue || type_ == nullValue; case arrayValue: return type_ == arrayValue || type_ == nullValue; case objectValue: return type_ == objectValue || type_ == nullValue; } JSON_ASSERT_UNREACHABLE; return false; }
int numDecodings(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function if(s.size() == 0) return 0; vector<int> dp(s.size(), 0); int num = 0; //Initialize int iter = s.size() - 1; if(InRange(s[iter] - '0', 1, 26)) dp[iter] = 1; if(--iter >= 0) { num = s[iter] - '0'; if(InRange(num, 1, 26)) { dp[iter] += dp[iter + 1]; num = num * 10 + s[iter + 1] - '0'; if(InRange(num, 1, 26)) dp[iter] += 1; } } for(iter = s.size() - 3; iter >= 0; --iter) { num = 0; for(int j = iter; j <= iter + 1; ++j) { num = num * 10 + s[j] - '0'; if(InRange(num, 1, 26)) dp[iter] += dp[j + 1]; else break; } } return dp[0]; }
void GetBoxIndex(int RowX, int RowY, int &BoxXIndex, int &BoxYIndex) { if (RowX < 3) {BoxXIndex = 0;} else if (InRange(2, 6, RowX)) {BoxXIndex = 1;} else if (InRange(5, 9, RowX)) {BoxXIndex = 2;} if (RowY < 3) {BoxYIndex = 0;} else if (InRange(2, 6, RowY)) {BoxYIndex = 1;} else if (InRange(5, 9, RowY)) {BoxYIndex = 2;} }
int GetBits(char x) { if (InRange((char) (x & (~0x20)), 'A', 'F')) { return (x & (~0x20)) - 'A' + 0xa; } else if (InRange(x, '0', '9')) { return x - '0'; } return 0; }
void SplitterSystem::InitParticle(Particle *p) { p->mPos = emitter.mPosition; p->mVel = Vec2(5, 5); p->mAcc = Vec2(10, 10); p->mMaxTime = InRange(emitter.mParams.mMinLifeTimeMs, emitter.mParams.mMaxLifeTimeMs) / 1000.0f; p->mTime = p->mMaxTime; p->mOrientation = InRange(0.0f, 3.141592f * 2.0f); p->mTint = Color::White; p->mScale = Vec2(1, 1); p->mAngularVelocity = r2() * .008f; p->mDir = { InRange(-.6f, .6f), InRange(-.6f, .6f) }; p->mAcc = Vec2(r2() * 70, r1() * -750); }
bool wxGBSizerItem::Intersects(const wxGBPosition& pos, const wxGBSpan& span) { int row, col, endrow, endcol; int otherrow, othercol, otherendrow, otherendcol; GetPos(row, col); GetEndPos(endrow, endcol); otherrow = pos.GetRow(); othercol = pos.GetCol(); otherendrow = otherrow + span.GetRowspan() - 1; otherendcol = othercol + span.GetColspan() - 1; // is the other item's start or end in the range of this one? if (( InRange(otherrow, row, endrow) && InRange(othercol, col, endcol) ) || ( InRange(otherendrow, row, endrow) && InRange(otherendcol, col, endcol) )) return true; // is this item's start or end in the range of the other one? if (( InRange(row, otherrow, otherendrow) && InRange(col, othercol, otherendcol) ) || ( InRange(endrow, otherrow, otherendrow) && InRange(endcol, othercol, otherendcol) )) return true; return false; }
void WireSim::PowerAdjacentNodes( int x, int y, bool respectChannels ) { WireNode activeNode = GetNode( x, y, m_activeBuffer ); for( int dx = -1; dx <= 1; dx++ ) { for( int dy = -1; dy <= 1; dy++ ) { // Only directly-adjacent if( ( dx == 0 || dy == 0 ) && InRange( x + dx, y + dy ) ) { // Affect anything except none-type and only no-powered nodes WireNode& nextNode = GetNode( x + dx, y + dy, m_nextBuffer ); bool isNoneType = WireNodeType(nextNode.m_type) == cWireNodeType_None; bool sharesChannels = ( nextNode.m_channels & activeNode.m_channels ) != 0; if( ( !respectChannels || ( respectChannels && sharesChannels ) ) && ( !isNoneType && nextNode.m_power == 0 ) ) { // Max out power nextNode.m_power |= WireNode::cMaxPower; } } } } }
void CEventBattery::HandlePhoneEventL(TPhoneFunctions event) { __FLOG(_L("HandlePhoneEventL()")); if (event != ENotifyBatteryStatusChange) return; if (InRange()) { // inside range // Before trigger the event perform an additional check, just in case. if (!iWasInRange) { iWasInRange = ETrue; // Triggers the In-Action SendActionTriggerToCoreL(); } } else { // not connected if (iWasInRange) { iWasInRange = EFalse; // Triggers the unplug action if (iBatteryParams.iExitAction != 0xFFFFFFFF) { SendActionTriggerToCoreL(iBatteryParams.iExitAction); } } } iPhone->NotifyBatteryStatusChange(iBatteryInfoPckg); }
void Sprites::OutputSprite(ULO spriteNo, ULO startCylinder, ULO cylinderCount) { if (SpriteState[spriteNo].armed) { ULO pixel_index = 0; // Look for start of sprite output if (!SpriteState[spriteNo].serializing && InRange(spriteNo, startCylinder, cylinderCount)) { SpriteState[spriteNo].serializing = true; pixel_index = SpriteState[spriteNo].x - startCylinder + 1; } if (SpriteState[spriteNo].serializing) { // Some output of the sprite will occur in this range. ULO pixel_count = cylinderCount - pixel_index; ULO pixelsLeft = 16 - SpriteState[spriteNo].pixels_output; if (pixel_count > pixelsLeft) { pixel_count = pixelsLeft; } if (BitplaneUtility::IsHires()) { pixel_index *= 2; // Hires coordinates } Merge(spriteNo, SpriteState[spriteNo].pixels_output, pixel_index, pixel_count); SpriteState[spriteNo].pixels_output += pixel_count; SpriteState[spriteNo].serializing = (SpriteState[spriteNo].pixels_output < 16); } } }
void D435DepthNoiseModel::ApplyNoise(const uint32_t width, const uint32_t height, float *data) { if (data == nullptr) { return; } float f = 0.5f * (width / tanf(h_fov / 2.0f)); float multiplier = (subpixel_err) / (f * baseline * 1e6f); Eigen::Map<Eigen::VectorXf> data_vector_map(data, width * height); // Formula taken from the Intel Whitepaper: // "Best-Known-Methods for Tuning Intel RealSense™ D400 Depth Cameras for Best Performance". // We are using the theoretical RMS model formula. Eigen::VectorXf rms_noise = (data_vector_map * 1000.0).array().square() * multiplier; Eigen::VectorXf noise = rms_noise.array().square(); // Sample noise for each pixel and transform variance according to error at this depth. for (int i = 0; i < width * height; ++i) { if (InRange(data_vector_map[i])) { data_vector_map[i] += this->dist(this->gen) * std::min(((float)noise(i)), max_stdev); } else { data_vector_map[i] = this->bad_point; } } }
//================================================================================================= uint StringToVersion(cstring version) { string s(version); uint major, minor, patch; int result = sscanf_s(version, "%u.%u.%u", &major, &minor, &patch); if(result != 3 || !InRange(major, 0u, 255u) || !InRange(minor, 0u, 255u) || !InRange(patch, 0u, 255u)) { result = sscanf_s(version, "%u.%u", &major, &minor); if(result != 2 || !InRange(major, 0u, 255u) || !InRange(minor, 0u, 255u)) return -1; else return (major << 16) | (minor << 8); } else return ((major << 16) | (minor << 8) | patch); }
// -------------------------------------------------- void SampleDiscrete(TempMesh& out,IfcFloat a, IfcFloat b) const { ai_assert(InRange(a) && InRange(b)); const size_t cnt = EstimateSampleCount(a,b); out.verts.reserve(out.verts.size() + cnt); BOOST_FOREACH(const CurveEntry& entry, curves) { const size_t cnt = out.verts.size(); entry.first->SampleDiscrete(out); if (!entry.second && cnt != out.verts.size()) { std::reverse(out.verts.begin()+cnt,out.verts.end()); } } }
bool Aircraft::Colliding(const Aircraft &Other) const { const sf::Vector2f &Me = Shape.getPosition(); const sf::Vector2f &Pos = Other.Shape.getPosition(); return OnRunway() == Other.OnRunway() && InRange(Me, Pos, (Radius + Other.Radius) / 1.3f); }
// When we want to check for collisions we check the 8 surrounding // squares; I chose this because the bounding spheres method looked // ugly void MazeGame::DetectCollisions(Float3 &offset) { // Get the position of the player in the maze matrix int x = round(player_->x / cube_size_); int y = round(player_->z / cube_size_); // For each of the 8 surrounding squares for (int i = -1; i <= 1; ++i) for (int j = -1; j <= 1; ++j) { if (i == 0 && j == 0) continue; /* I chose to leave this commented because it did not behave as I wanted; * It prevents my sphere to pass through cube corners (checks the diagonal * cubes for collisions) but the movement is not natural at all * (the sphere tends to glitch when moving while hugging a wall) if (i != 0 && j != 0 && actual_maze_[x + i][y + j] == '#') if (InRange((player_->x + offset.x), ((x + i) * cube_size_)) && InRange((player_->z + offset.z), ((y + j) * cube_size_))) { offset.x = 0; offset.z = 0; } */ if (i != 0 && actual_maze_[x + i][y] == '#') if (InRange((player_->x + offset.x), ((x + i) * cube_size_))) offset.x = 0; if (j != 0 && actual_maze_[x][y + j] == '#') if (InRange((player_->z + offset.z), ((y + j) * cube_size_))) offset.z = 0; } // If the "portal" is reached we just spawn it // somwhere else (we're devilishly intelligent!); // Doing so will prevent our little ball from ever // leaving the labyrinth! Mwahahahaha! if (x == round(portal_->x / cube_size_) && y == round(portal_->z / cube_size_)) { portal_->x = -1; ++score_; PlaceRandObject(portal_); } }
void Hex::SetSquareOccupied(int i, bool b) { VERIFY_MODEL(InRange(m_squares, i)); if (b) m_occupied.insert(i); else m_occupied.erase(i); }
Ulong PrimesTable::TableBuffer::GetNumber(Ulong Index_) { if (!InRange(Index_)) return 0; Index_ -= LowBound(); return _Table[Index_]; }
Cmd::ProcessResult ColoniseCmd::Process(const Input::CmdMessage& msg, CommitSession& session) { auto& m = VerifyCastInput<const Input::CmdColonisePos>(msg); auto positions = GetPositions(session.GetGame()); VERIFY_INPUT_MSG("invalid pos index", m.m_iPos == -1 || InRange(positions, m.m_iPos)); return ProcessResult(new ColoniseSquaresCmd(m_colour, session.GetGame(), positions[m.m_iPos])); }
SpecularTransmission::SpecularTransmission(SpectrumCoef_d i_transmittance, double i_refractive_index_inner, double i_refractive_index_outer): BxDF(BxDFType(BSDF_TRANSMISSION | BSDF_SPECULAR)), m_transmittance(i_transmittance), m_refractive_index_inner(i_refractive_index_inner), m_refractive_index_outer(i_refractive_index_outer), m_fresnel(i_refractive_index_inner, i_refractive_index_outer) { ASSERT(InRange(i_transmittance,0.0,1.0)); ASSERT(i_refractive_index_inner>0.0 && i_refractive_index_outer>0.0); }
bool CClimableObject::InTouch(CPHCharacter *actor)const { VERIFY(actor); Fvector dir; const float normal_tolerance=0.05f; float foot_radius=actor->FootRadius(); return (DDToPlain(actor,dir)<foot_radius+m_norm.magnitude()+normal_tolerance&& DDSideToAxis(actor,dir)<m_side.magnitude())&&InRange(actor); }
bool XRefTable::HasChanged(int num) { ASSERT(InRange(num)); if (num >= mXRef->getSize()) return true; if (num == 0) return true; XRefEntry* o = mXRef->getEntry(num); XRefEntry* n = GetXRef(num); return o->offset != n->offset || o->gen != n->gen || o->type != n->type; }
void SpinControl::SetValue(const wxString& textValue) { double doubleValue; if (textValue.ToDouble(&doubleValue) && InRange(doubleValue)) { DoSetValue(doubleValue); } else { m_text->SetValue(textValue); m_text->SetSelection(0, -1); m_text->SetInsertionPointEnd(); } }
OrenNayar::OrenNayar(SpectrumCoef_d i_reflectance, double i_sigma): BxDF(BxDFType(BSDF_REFLECTION | BSDF_DIFFUSE)), m_reflectance(i_reflectance) { ASSERT(InRange(i_reflectance,0.0,1.0)); ASSERT(i_sigma>=0.0 && i_sigma<=1.0); double sigma_sqr = i_sigma*i_sigma; m_A = 1.0 - (0.5 * sigma_sqr / (sigma_sqr + 0.33)); m_B = 0.45 * sigma_sqr / (sigma_sqr + 0.09); }
void CountDecodeWay(string &s, int level){ if(level == s.size()) wayNum++; else { int num = 0; for(int j = level; j < s.size(); ++j) { num = num * 10 + s[j] - '0'; if(InRange(num, 1, 26)) CountDecodeWay(s, j + 1); else break; } } }
/** * Function GetPointToLineSegmentDistance * Get distance between line segment and point * @param x,y = point * @param xi,yi Start point of the line segament * @param xf,yf End point of the line segment * @return the distance */ double GetPointToLineSegmentDistance( int x, int y, int xi, int yi, int xf, int yf ) { // test for vertical or horizontal segment if( xf==xi ) { // vertical line segment if( InRange( y, yi, yf ) ) return abs( x - xi ); else return std::min( Distance( x, y, xi, yi ), Distance( x, y, xf, yf ) ); } else if( yf==yi ) { // horizontal line segment if( InRange( x, xi, xf ) ) return abs( y - yi ); else return std::min( Distance( x, y, xi, yi ), Distance( x, y, xf, yf ) ); } else { // oblique segment // find a,b such that (xi,yi) and (xf,yf) lie on y = a + bx double b = (double) (yf - yi) / (xf - xi); double a = (double) yi - b * xi; // find c,d such that (x,y) lies on y = c + dx where d=(-1/b) double d = -1.0 / b; double c = (double) y - d * x; // find nearest point to (x,y) on line through (xi,yi) to (xf,yf) double xp = (a - c) / (d - b); double yp = a + b * xp; // find distance if( InRange( xp, xi, xf ) && InRange( yp, yi, yf ) ) return Distance( x, y, xp, yp ); else return std::min( Distance( x, y, xi, yi ), Distance( x, y, xf, yf ) ); } }
void WireSim::Simulate() { // Clear next buffer m_nextBuffer = ( m_activeBuffer + 1 ) % 2; memset( (void*)m_nodeBuffer[ m_nextBuffer ], 0, sizeof(WireNode) * m_width * m_height ); WireNode cDefaultNode; // For each source element, simulate results from active to next buffer, then flip for( int y = 0; y < m_height; y++) { for( int x = 0; x < m_width; x++) { // Retrieve all adjacent cells, placing into list with our cell in the middle; // Any cells out of range will point to a default empty cell WireNode wireNodes[3][3]; for( int dx = -1; dx <= 1; dx++ ) { for( int dy = -1; dy <= 1; dy++ ) { if( InRange( dx + 1, dy + 1 ) ) { wireNodes[ dy + 1 ][ dx + 1 ] = GetNode( x + dx, y + dy ); } else { wireNodes[ dy + 1 ][ dx + 1 ] = cDefaultNode; } } } // Simulate this specific node and the surrounding set WireNode resultNode = SimulateNode( x, y, wireNodes ); WireNode& outputNode = GetNode( x, y, m_nextBuffer ); // Copy type and mask (this never changes) outputNode.m_type = resultNode.m_type; outputNode.m_channels = resultNode.m_channels; // Only copy power change based on mask rules: only copy if they share a mask if( (outputNode.m_channels & resultNode.m_channels) != 0 ) { // Always copy the biggest power value outputNode.m_power |= resultNode.m_power; } } } // Flip buffers m_activeBuffer = m_nextBuffer; }
void test1() { const unsigned N = 100; std::unique_ptr<int> ia[N]; for (unsigned i = 0; i < N; ++i) ia[i].reset(new int(i)); std::unique_ptr<int> ib[N]; OutRange r = std::move_backward(InRange(std::make_iter_range(ia, ia+N)), OutRange(std::make_single_iter_backward_range(ib+N))); assert(base(r).base() == ib); for (unsigned i = 0; i < N; ++i) assert(*ib[i] == i); }
bool SpinControl::DoSetValue(double value) { if (!InRange(value)) return false; wxString str(wxString::Format(m_format.c_str(), value)); if (value == m_value && str == m_text->GetValue()) return false; str.ToDouble(&m_value); m_text->SetValue(str); m_text->SetInsertionPointEnd(); m_text->DiscardEdits(); return true; }
void test() { const unsigned N = 1000; int ia[N]; for (unsigned i = 0; i < N; ++i) ia[i] = i; int ib[N] = {0}; OutRange r = std::move_backward(InRange(std::make_iter_range(ia, ia+N)), OutRange(std::make_single_iter_backward_range(ib+N))); assert(base(r).base() == ib); for (unsigned i = 0; i < N; ++i) assert(ia[i] == ib[i]); }