///////////////////////////////////////////////////////////////////////////// // Distance to next point ///////////////////////////////////////////////////////////////////////////// double CDiscretizedLine::DistanceToNext(int i) const { int Next = NextIndex(i); double dx = vx[Next] - vx[i]; double dy = vy[Next] - vy[i]; return std::sqrt(dx * dx + dy * dy); }
///////////////////////////////////////////////////////////////////////////// // Approximation by n points (almost equidistant) ///////////////////////////////////////////////////////////////////////////// CDiscretizedLine CDiscretizedLine::UniformSplit(int n) const { // // Build return value // CDiscretizedLine dl; dl.Resize(n); // // Same starting and ending points // dl.SetX(0) = X(0); dl.SetY(0) = Y(0); dl.SetX(n - 1) = X(Size() - 1); dl.SetY(n - 1) = Y(Size() - 1); // // Intermediate points // double TotalLength = Length(); int j = 0; double Lj = 0.0; int k = NextIndex(j); double Lk = DistanceToNext(j); for (int i = 1; i < n - 1; i++) { double L = i * TotalLength / (n - 1); while (L > Lk && k < Size() - 1) { j = k; Lj = Lk; k = NextIndex(j); Lk = Lj + DistanceToNext(j); } double t = (L - Lj) / (Lk - Lj); double u = 1.0 - t; dl.SetX(i) = X(j) * u + X(k) * t; dl.SetY(i) = Y(j) * u + Y(k) * t; } return dl; }
void Pages::Update() { if (settings.pages[current_page].top_layout == PageSettings::PageLayout::tlEmpty) current_page = NextIndex(); OpenLayout(settings.pages[current_page]); }
static bool HandleNextRecursive (const unsigned short theIndex, Cell * theCell, MatrixOfCellPtr * theSchema){ LogicAssert (true == IsGoodPtr (theCell)); LogicAssert (true == IsGoodPtr (theSchema)); LogicAssert (true == IsGoodSchema (theSchema)); const unsigned short aTransformedIndex = TransformIndex (theIndex, theCell, theSchema); gNumOfCall++; if (theIndex >= kDim * kDim){ ++gNumOfSolution; if (!(gNumOfSolution % 100000) || true){ const unsigned long aCurrentSolution = gNumOfSolution; ISI_DUMP (aCurrentSolution); ISI_DUMP (gNumOfCall); ISI_DUMP (static_cast <double >(gNumOfCall)/aCurrentSolution); DumpMatrix ("theRowVector", theSchema [0]); ISI_DUMP (BoolToStr (IsGoodSolution (theSchema))); } return false; } LogicAssert (/*(theIndex >= 0) &&*/ (theIndex < kDim * kDim)); if (theCell [aTransformedIndex].GetStatus () == CellStatus::ConstantInputInitValue){ return HandleNextRecursive (NextIndex (theIndex), theCell, theSchema); } bool rit = false; for (CellValue aValue = 0; aValue < kDim; ++aValue){ LogicAssert (theCell [aTransformedIndex].GetValue () != aValue+1); LogicAssert (theCell [aTransformedIndex].GetValue () == 0); const bool aGood = IsGoodSchemaAvailable (theSchema, aValue, aTransformedIndex); if (aGood){ theCell [aTransformedIndex].SetValue (aValue + 1); rit = HandleNextRecursive (NextIndex (theIndex), theCell, theSchema); if (rit){ break; } else{ theCell [aTransformedIndex].SetValue (0); } } } return rit; }
bool CFlip::Tick(const float& rfDelta) { // call script bool res = CallScript<script_flip_tick>("tick", script_flip_tick_default)(rfDelta); res = CurrentEffect()->Tick(rfDelta) || res; res = NextIndex(rfDelta) || res; return res; }
void PageActions::Next() { LeavePage(); PagesState &state = CommonInterface::SetUIState().pages; state.current_index = NextIndex(); state.special_page.SetUndefined(); Update(); RestoreMapZoom(); }
///////////////////////////////////////////////////////////////////////////// // Simple tangent: parallel to the previous-next line ///////////////////////////////////////////////////////////////////////////// void CDiscretizedLine::SimpleTangent(int i, double &dx, double &dy) const { int prev = PreviousIndex(i); int next = NextIndex(i); dx = vx[next] - vx[prev]; dy = vy[next] - vy[prev]; double n = std::sqrt(dx * dx + dy * dy); if (n > 0.0) { dx /= n; dy /= n; } }
/*---------------------------------------------------------------------------*/ tcp_stream * StreamDequeue(stream_queue_t sq) { index_type h = sq->_head; index_type t = sq->_tail; if (h != t) { tcp_stream *stream = sq->_q[h]; StreamMemoryBarrier(sq->_q[h], sq->_head); sq->_head = NextIndex(sq, h); assert(stream); return stream; } return NULL; }
/*---------------------------------------------------------------------------*/ int SBEnqueue(sb_queue_t sq, struct tcp_send_buffer *buf) { index_type h = sq->_head; index_type t = sq->_tail; index_type nt = NextIndex(sq, t); if (nt != h) { sq->_q[t] = buf; SBMemoryBarrier(sq->_q[t], sq->_tail); sq->_tail = nt; return 0; } TRACE_ERROR("Exceed capacity of buf queue!\n"); return -1; }
/*---------------------------------------------------------------------------*/ struct tcp_send_buffer *SBDequeue(sb_queue_t sq) { index_type h = sq->_head; index_type t = sq->_tail; if (h != t) { struct tcp_send_buffer *buf = sq->_q[h]; SBMemoryBarrier(sq->_q[h], sq->_head); sq->_head = NextIndex(sq, h); assert(buf); return buf; } return NULL; }
/*---------------------------------------------------------------------------*/ int StreamEnqueue(stream_queue_t sq, tcp_stream *stream) { index_type h = sq->_head; index_type t = sq->_tail; index_type nt = NextIndex(sq, t); if (nt != h) { sq->_q[t] = stream; StreamMemoryBarrier(sq->_q[t], sq->_tail); sq->_tail = nt; return 0; } TRACE_ERROR("Exceed capacity of stream queue!\n"); return -1; }
///////////////////////////////////////////////////////////////////////////// // Test for angle ///////////////////////////////////////////////////////////////////////////// bool CDiscretizedLine::IsAngle(int i) const { if ((i == 0 || i == Size() - 1) && !IsClosed()) return true; int Next = NextIndex(i); int Prev = PreviousIndex(i); double x1 = vx[Next] - vx[i]; double y1 = vy[Next] - vy[i]; double x2 = vx[Prev] - vx[i]; double y2 = vy[Prev] - vy[i]; double det = x1 * y2 - x2 * y1; double n1 = x1 * x1 + y1 * y1; double n2 = x2 * x2 + y2 * y2; return std::fabs(det / std::sqrt(n1 * n2)) > 0.4; // ??? }
LoopTreeNode* LoopBlocking:: ApplyBlocking( const CompSliceDepGraphNode::FullNestInfo& nestInfo, LoopTreeDepComp& comp, DependenceHoisting &op, LoopTreeNode *&top) { const CompSliceNest& slices = *nestInfo.GetNest(); if (DebugLoop()) { std::cerr << "\n Blocking slices: " << slices.toString() << "\n"; } LoopTreeNode *head = 0; AstInterface& fa = LoopTransformInterface::getAstInterface(); for (int j = FirstIndex(); j >= 0; j = NextIndex(j)) { top = op.Transform( comp, slices[j], top); SymbolicVal b = BlockSize(j); if (DebugLoop()) { std::cerr << "\n after slice " << j << " : \n"; //top->DumpTree(); comp.DumpTree(); comp.DumpDep(); std::cerr << "\n blocking size for this loop is " << b.toString() << "\n"; } if (!(b == 1)) { LoopTreeNode *n = LoopTreeBlockLoop()( top, SymbolicVar(fa.NewVar(fa.GetType("int")), AST_NULL), b); if (DebugLoop()) { std::cerr << "\n after tiling loop with size " << b.toString() << " : \n"; //top->DumpTree(); comp.DumpTree(); comp.DumpDep(); } if (head == 0) head = n; else { while (n->FirstChild() != head) LoopTreeSwapNodePos()( n->Parent(), n); } } } return head; }
LoopTreeNode* LoopBlocking:: ApplyBlocking( const CompSliceDepGraphNode::FullNestInfo& nestInfo, LoopTreeDepComp& comp, DependenceHoisting &op, LoopTreeNode *&top) { const CompSliceNest& slices = *nestInfo.GetNest(); LoopTreeNode *head = 0; AstInterface& fa = LoopTransformInterface::getAstInterface(); for (int j = FirstIndex(); j >= 0; j = NextIndex(j)) { top = op.Transform( comp, slices[j], top); SymbolicVal b = BlockSize(j); if (!(b == 1)) { LoopTreeNode *n = LoopTreeBlockLoop()( top, SymbolicVar(fa.NewVar(fa.GetType("int")), AST_NULL), b); if (head == 0) head = n; else { while (n->FirstChild() != head) LoopTreeSwapNodePos()( n->Parent(), n); } } } return head; }
///////////////////////////////////////////////////////////////////////////// // Circular tangent: tangent to the circumscribed circle ///////////////////////////////////////////////////////////////////////////// void CDiscretizedLine::CircularTangent(int i0, double &dx, double &dy) const { if (Size() < 3) { SimpleTangent(i0, dx, dy); return; } int i1 = NextIndex(i0); int i2 = PreviousIndex(i0); if (i1 == i0) i1 = i2 - 1; if (i2 == i0) i2 = i1 + 1; double dx20 = vx[i1] - vx[i2]; double dy20 = vy[i1] - vy[i2]; double dx21 = vx[i1] - vx[i0]; double dy21 = vy[i1] - vy[i0]; double dx10 = vx[i0] - vx[i2]; double dy10 = vy[i0] - vy[i2]; double c = dx20 * dx10 + dy20 * dy10; double s = dx20 * dy10 - dy20 * dx10; dx = c * dx21 - s * dy21; dy = s * dx21 + c * dy21; double n = std::sqrt(dx * dx + dy * dy); if (n > 0.0) { dx /= n; dy /= n; } }
void Pages::Next() { current_page = NextIndex(); Update(); }