// Create the left walls, start must point to a segment with a wall on the left and a leading // non wall segment. // FIXME: Does not work for a closed ring "by design". void buildWalls(tTrackSeg *start, int side) { if (start == NULL) { return; } tTrackSeg *current = start; bool close = false; // Going down the wall. do { tTrackSeg* s = current->side[side]; tTrackSeg* p = current->prev->side[side]; tTrackSeg* n = current->next->side[side]; // Current segment is a wall? if (s != NULL && s->style == TR_WALL && s->side[side] != NULL) { float h = s->height; t3Dd svl = s->vertex[TR_SL]; t3Dd svr = s->vertex[TR_SR]; t3Dd evl = s->vertex[TR_EL]; t3Dd evr = s->vertex[TR_ER]; static float weps = 0.01f; // Close the start with a ploygon? if (p == NULL || p->style != TR_WALL || (fabs(p->vertex[TR_EL].x - svl.x) > weps) || (fabs(p->vertex[TR_ER].x - svr.x) > weps) || (fabs(h - p->height) > weps) || fixedid == 0) { // Enough space in array? if (fixedid >= sizeof(fixedobjects)/sizeof(fixedobjects[0])) { GfError("fixedobjects full in %s, line %d\n", __FILE__, __LINE__); return; } if (close == true) { dtEndComplexShape(); GfError("Shape not closed %s, line %d\n", __FILE__, __LINE__); } // Start new shape. fixedobjects[fixedid] = dtNewComplexShape(); fixedid++; close = true; dtBegin(DT_POLYGON); dtVertex(svl.x, svl.y, svl.z); dtVertex(svr.x, svr.y, svr.z); dtVertex(svr.x, svr.y, svr.z + h); dtVertex(svl.x, svl.y, svl.z + h); dtEnd(); } // Build sides, left, top, right. Depending on how we want to use it we // can remove top perhaps. // TODO: do we want the top poly? if (close == true) { // Left. dtBegin(DT_POLYGON); dtVertex(svl.x, svl.y, svl.z); dtVertex(svl.x, svl.y, svl.z + h); dtVertex(evl.x, evl.y, evl.z + h); dtVertex(evl.x, evl.y, evl.z); dtEnd(); /* // Top. dtBegin(DT_POLYGON); dtVertex(svl.x, svl.y, svl.z + h); dtVertex(svr.x, svr.y, svr.z + h); dtVertex(evr.x, evr.y, evr.z + h); dtVertex(evl.x, evl.y, evl.z + h); dtEnd();*/ // Right. dtBegin(DT_POLYGON); dtVertex(svr.x, svr.y, svr.z + h); dtVertex(svr.x, svr.y, svr.z); dtVertex(evr.x, evr.y, evr.z); dtVertex(evr.x, evr.y, evr.z + h); dtEnd(); } else { GfError("Shape not open %s, line %d\n", __FILE__, __LINE__); } // Close the end with a ploygon? if (n == NULL || n->style != TR_WALL || (fabs(n->vertex[TR_SL].x - evl.x) > weps) || (fabs(n->vertex[TR_SR].x - evr.x) > weps) || (fabs(h - n->height) > weps)) { if (close == true) { dtBegin(DT_POLYGON); dtVertex(svl.x, svl.y, svl.z); dtVertex(svr.x, svr.y, svr.z); dtVertex(svr.x, svr.y, svr.z + h); dtVertex(svl.x, svl.y, svl.z + h); dtEnd(); dtEndComplexShape(); close = false; } else { GfError("Shape not open %s, line %d\n", __FILE__, __LINE__); } } } current = current->next; } while (current != start); }
void SignalGenerator::ScanBars( pt::ptime dtLast ) { pt::ptime dtBegin( dtLast.date() - gregorian::date_duration( 52 * 7 ), pt::time_duration( 0, 0, 0 ) ); // process ~year of bars try { m_xls.New( 1 ); m_sheet = m_xls.GetWorksheet( 0 ); ExcelFormat::BasicExcelCell* cell; ExcelFormat::CellFormat fmt(m_fmt_mgr); fmt.set_format_string( XLS_FORMAT_DECIMAL ); fmt.set_alignment( ExcelFormat::EXCEL_HALIGN_CENTRED ); int ix( 0 ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "Type" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "Symbol" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "Price" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "Volume" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "BolRange" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "SMA Sig" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "BolUpr" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "BolLwr" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "SMA1" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "SMA2" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "SMA3" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "> PV" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "X Down" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "< R1 X Up" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "< R1 X Down" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "< PV" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "X Up" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "> S1 X Up" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "> S1 X Down" ); cell = m_sheet->Cell( 0, ix++ ); cell->SetFormat( fmt ); cell->SetString( "PV X" ); namespace ph = std::placeholders; mapSymbol_t::iterator iter; ou::tf::InstrumentFilter<mapSymbol_t::iterator,ou::tf::Bars> filter( "/bar/86400", // at least a year's worth of bars dtBegin, dtLast, 200, iter, std::bind( &SignalGenerator::HandleCallBackUseGroup, this, ph::_1, ph::_2, ph::_3 ), std::bind( &SignalGenerator::HandleCallBackFilter, this, ph::_1, ph::_2, ph::_3 ), std::bind( &SignalGenerator::HandleCallBackResults, this, ph::_1, ph::_2, ph::_3 ) ); m_xls.SaveAs( "weeklies.xls" ); m_xls.Close(); } catch( ... ) { std::cout << "Scan Problems" << std::endl; } }
int main(int argc, char** argv) { object1.id = 1; object2.id = 2; /*vec3 boxMax1 = vec3(2, 2, 2); vec3 boxMax2 = vec3(1, 1, 1); boxobj1 = BoundingBox(-boxMax1, boxMax1); boxobj2 = BoundingBox(-boxMax2, boxMax2); */ boxobj1 = BoundingBox(vec3(-0.9438, -0.4669, -0.61679), vec3(0.607788, 1.06996, 0.587146)); boxobj2 = BoundingBox(vec3(1.056195, -0.46690, -0.6167920), vec3(2.6077880000000002, 1.0699599999999998, 0.58714600000000006)); /* DtShapeRef shape1 = dtBox(boxMax1.x * 2, boxMax1.y * 2, boxMax1.z * 2); DtShapeRef shape2 = dtBox(boxMax2.x * 2, boxMax2.y * 2, boxMax2.z * 2); */ vector<Point> solid_points0; vector<CP_Vector3D> points0 = boxobj1.GetAABBVertices(); for(int i = 0; i < points0.size(); i++) solid_points0.push_back(Point(points0[i].x, points0[i].y, points0[i].z)); vector<DtIndex> solid_indices0; auto indices = boxobj1.GetAABBIndices(); for(auto it = indices.begin(); it != indices.end(); it++) solid_indices0.push_back(*it); DtShapeRef shape1 = dtNewComplexShape(); dtVertexBase(&solid_points0[0]); for(int i = 0; i < solid_indices0.size()/3; i++) { dtBegin(DT_SIMPLEX); dtVertexIndex(solid_indices0[i*3+0]); dtVertexIndex(solid_indices0[i*3+1]); dtVertexIndex(solid_indices0[i*3+2]); dtEnd(); } //dtVertexIndices(DT_POLYHEDRON, solid_indices0.size(), &solid_indices0[0]); dtEndComplexShape(); vector<Point> solid_points1; vector<CP_Vector3D> points1 = boxobj2.GetAABBVertices(); for(int i = 0; i < points1.size(); i++) solid_points1.push_back(Point(points1[i].x, points1[i].y, points1[i].z)); auto indices1 = boxobj2.GetAABBIndices(); vector<DtIndex> solid_indices1(indices1.begin(), indices1.end()); DtShapeRef shape2 = dtNewComplexShape(); dtVertexBase(&solid_points1[0]); for(int i = 0; i < solid_indices1.size()/3; i++) { dtBegin(DT_SIMPLEX); dtVertexIndex(solid_indices1[i*3+0]); dtVertexIndex(solid_indices1[i*3+1]); dtVertexIndex(solid_indices1[i*3+2]); dtEnd(); } //dtVertexIndices(DT_POLYHEDRON, solid_indices1.size(), &solid_indices1[0]); dtEndComplexShape(); dtCreateObject(&object1, shape1); dtCreateObject(&object2, shape2); dtDisableCaching(); dtSetDefaultResponse(collide1, DT_SIMPLE_RESPONSE, stdout); if(NO_DISPLAY) return 0; draw(argc, argv); return 0; }
void mmBudgetingPanel::initVirtualListControl() { budget_.clear(); budgetTotals_.clear(); budgetPeriod_.clear(); budgetAmt_.clear(); categoryStats_.clear(); double estIncome = 0.0; double estExpenses = 0.0; double actIncome = 0.0; double actExpenses = 0.0; mmReportBudget budgetDetails; bool evaluateTransfer = false; if (mmIniOptions::instance().budgetIncludeTransfers_) { evaluateTransfer = true; } currentView_ = Model_Infotable::instance().GetStringInfo("BUDGET_FILTER", VIEW_ALL); const wxString budgetYearStr = Model_Budgetyear::instance().Get(budgetYearID_); long year = 0; budgetYearStr.ToLong(&year); wxDateTime dtBegin(1, wxDateTime::Jan, year); wxDateTime dtEnd(31, wxDateTime::Dec, year); monthlyBudget_ = (budgetYearStr.length() > 5); if (monthlyBudget_) { budgetDetails.SetBudgetMonth(budgetYearStr, dtBegin, dtEnd); } else { int day = -1, month = -1; budgetDetails.AdjustYearValues(day, month, dtBegin); budgetDetails.AdjustDateForEndFinancialYear(dtEnd); } mmSpecifiedRange date_range(dtBegin, dtEnd); //Get statistics Model_Budget::instance().getBudgetEntry(budgetYearID_, budgetPeriod_, budgetAmt_); Model_Category::instance().getCategoryStats(categoryStats_ , &date_range, mmIniOptions::instance().ignoreFutureTransactions_ , false, true, (evaluateTransfer ? &budgetAmt_ : 0)); const Model_Subcategory::Data_Set& allSubcategories = Model_Subcategory::instance().all(Model_Subcategory::COL_SUBCATEGNAME); for (const auto& category : Model_Category::instance().all(Model_Category::COL_CATEGNAME)) { double estimated = getEstimate(category.CATEGID, -1); if (estimated < 0) estExpenses += estimated; else estIncome += estimated; double actual = 0; if (currentView_ != VIEW_PLANNED || estimated != 0) { actual = categoryStats_[category.CATEGID][-1][0]; if (actual < 0) actExpenses += actual; else actIncome += actual; } /*************************************************************************** Create a TOTALS entry for the category. ***************************************************************************/ double catTotalsEstimated = estimated; double catTotalsActual = actual; if (DisplayEntryAllowed(category.CATEGID, -1)) budget_.push_back(std::make_pair(category.CATEGID, -1)); for (const auto& subcategory : allSubcategories) { if (subcategory.CATEGID != category.CATEGID) continue; estimated = getEstimate(category.CATEGID, subcategory.SUBCATEGID); if (estimated < 0) estExpenses += estimated; else estIncome += estimated; actual = 0; if (currentView_ != VIEW_PLANNED || estimated != 0) { actual = categoryStats_[category.CATEGID][subcategory.SUBCATEGID][0]; if (actual < 0) actExpenses += actual; else actIncome += actual; } /*************************************************************************** Update the TOTALS entry for the subcategory. ***************************************************************************/ catTotalsEstimated += estimated; catTotalsActual += actual; if (DisplayEntryAllowed(category.CATEGID, subcategory.SUBCATEGID)) budget_.push_back(std::make_pair(category.CATEGID, subcategory.SUBCATEGID)); } budgetTotals_[category.CATEGID].first = catTotalsEstimated; budgetTotals_[category.CATEGID].second = catTotalsActual; if ((!mmIniOptions::instance().budgetSetupWithoutSummaries_ || currentView_ == VIEW_SUMM) && DisplayEntryAllowed(-1, category.CATEGID)) { budget_.push_back(std::make_pair(-1, category.CATEGID)); int transCatTotalIndex = (int)budget_.size() - 1; listCtrlBudget_->RefreshItem(transCatTotalIndex); } } listCtrlBudget_->SetItemCount((int)budget_.size()); wxString est_amount, act_amount, diff_amount; est_amount = Model_Currency::toCurrency(estIncome); act_amount = Model_Currency::toCurrency(actIncome); diff_amount = Model_Currency::toCurrency(estIncome - actIncome); income_estimated_->SetLabelText(est_amount); income_actual_->SetLabelText(act_amount); income_diff_->SetLabelText(diff_amount); if (estExpenses < 0.0) estExpenses = -estExpenses; if (actExpenses < 0.0) actExpenses = -actExpenses; est_amount = Model_Currency::toCurrency(estExpenses); act_amount = Model_Currency::toCurrency(actExpenses); diff_amount = Model_Currency::toCurrency(estExpenses - actExpenses); expenses_estimated_->SetLabelText(est_amount); expenses_actual_->SetLabelText(act_amount); expenses_diff_->SetLabelText(diff_amount); UpdateBudgetHeading(); }