void TaskPointTest::Run() { GeoPoint gp1(Angle::degrees(fixed(20)), Angle::degrees(fixed(50))); GeoPoint gp2(Angle::degrees(fixed(21)), Angle::degrees(fixed(50))); DummyTaskPoint tp1(TaskPoint::AST, gp1, fixed(1234)); DummyTaskPoint tp2(TaskPoint::AAT, gp2, fixed(1337)); DummyTaskPoint tp3(TaskPoint::START, gp1, fixed(1234)); DummyTaskPoint tp4(TaskPoint::FINISH, gp2, fixed(1337)); ok1(tp1.IsIntermediatePoint()); ok1(tp1.GetType() == TaskPoint::AST); ok1(equals(tp1.GetBaseElevation(), 1234)); ok1(!tp1.HasTarget()); ok1(equals(tp1.Distance(gp2), gp1.distance(gp2))); ok1(equals(tp1.GetLocation(), gp1)); ok1(tp2.IsIntermediatePoint()); ok1(tp2.GetType() == TaskPoint::AAT); ok1(tp2.HasTarget()); ok1(!tp3.IsIntermediatePoint()); ok1(tp3.GetType() == TaskPoint::START); ok1(!tp3.HasTarget()); ok1(!tp4.IsIntermediatePoint()); ok1(tp4.GetType() == TaskPoint::FINISH); ok1(!tp4.HasTarget()); }
int main() { // First, some point examples tracktable::TrajectoryPoint tp1(100.0,40); tracktable::TrajectoryPoint tp2(105.0,45); // This works, but... boost::geometry::distance< tracktable::PointBaseLonLat<double>, tracktable::PointBaseLonLat<double> >(tp1,tp2); // This doesn't. Probably a boost geometry registration issue... boost::geometry::distance(tp1,tp2); // Now some point/track distance examples tracktable::TrajectoryPoint tp3(110.0,30); tracktable::TrajectoryPoint tp4(115.0,35); tracktable::TrajectoryPoint tp5(120.0,40); tracktable::TrajectoryPoint tp6(125.0,45); tracktable::PointBaseLonLat<double> ll3(110.0,30); tracktable::PointBaseLonLat<double> ll4(115.0,35); tracktable::PointBaseLonLat<double> ll5(120.0,40); tracktable::PointBaseLonLat<double> ll6(125.0,45); tracktable::Trajectory<tracktable::TrajectoryPoint> tp_traj; tracktable::Trajectory<tracktable::PointBaseLonLat<double> > ll_traj; tp_traj.add_point(tp3); tp_traj.add_point(tp4); tp_traj.add_point(tp5); tp_traj.add_point(tp6); ll_traj.add_point(ll3); ll_traj.add_point(ll4); ll_traj.add_point(ll5); ll_traj.add_point(ll6); // This doesn't work, but probably would if the linestring was registered boost::geometry::distance(ll_traj,ll3); // This doesn't work and needs to linestring and point registered boost::geometry::distance(tp_traj,tp3); // Now some math examples // This doesn't work... boost::geometry::multiply_value(tp3,0.5); // ...but this does. Again, probably a registration issue boost::geometry::multiply_value(ll3,0.5); return 0; }
int main(int argc, char *argv[]) { TreeNode tp1(1); TreeNode tq1(1); TreeNode tp2(2); TreeNode tq2(2); TreeNode tp3(3); TreeNode tq3(3); //tp1.left = &tp2; //tp1.right = &tp3; //tq1.left = &tq2; //tq1.right = &tq3; Solution so; std::cout << so.isSameTree(&tp1, &tp2) << std::endl; return 0; }
void CalligraphicMode::mouseReleaseEvent(QMouseEvent *m) { undoManager->setUndoEnabled(true); PageItem *currItem; m_MouseButtonPressed = false; m_canvas->resetRenderMode(); m->accept(); if (m_doc->appMode == modeDrawCalligraphicLine) { if (RecordP.size() > 1) { UndoTransaction createTransaction; if (UndoManager::undoEnabled()) createTransaction = UndoManager::instance()->beginTransaction(); uint z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, Mxp, Myp, 1, 1, m_doc->itemToolPrefs().calligraphicPenLineWidth, m_doc->itemToolPrefs().calligraphicPenFillColor, m_doc->itemToolPrefs().calligraphicPenLineColor); currItem = m_doc->Items->at(z); currItem->PoLine.resize(0); QList<QPointF> clipU; QList<QPointF> clipL; double mx = sin(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0); double my = cos(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0); for (int px = 0; px < RecordP.size()-1; ++px) { FPoint clp = RecordP.point(px); clipU.append(QPointF(clp.x() - mx, clp.y() - my)); clipL.prepend(QPointF(clp.x() + mx, clp.y() + my)); } QPainterPath ppU = bezierFit(clipU, 5.0); QPainterPath ppL = bezierFit(clipL, 5.0); QPainterPath pp; pp.addPath(ppU); pp.connectPath(ppL); pp.closeSubpath(); currItem->PoLine.fromQPainterPath(pp); FPoint tp2(getMinClipF(&currItem->PoLine)); currItem->setXYPos(tp2.x(), tp2.y(), true); currItem->PoLine.translate(-tp2.x(), -tp2.y()); FPoint tp(getMaxClipF(&currItem->PoLine)); m_doc->sizeItem(tp.x(), tp.y(), currItem, false, false, false); m_doc->adjustItemSize(currItem); m_doc->m_Selection->clear(); m_doc->m_Selection->addItem(currItem); currItem->ClipEdited = true; currItem->FrameType = 3; currItem->OwnPage = m_doc->OnPage(currItem); currItem->PLineArt = Qt::PenStyle(m_doc->itemToolPrefs().calligraphicPenStyle); currItem->setFillShade(m_doc->itemToolPrefs().calligraphicPenFillColorShade); currItem->setLineShade(m_doc->itemToolPrefs().calligraphicPenLineColorShade); currItem->setFillEvenOdd(true); m_view->resetMousePressed(); currItem->checkChanges(); QString targetName = Um::ScratchSpace; if (currItem->OwnPage > -1) targetName = m_doc->Pages->at(currItem->OwnPage)->getUName(); if (createTransaction) createTransaction.commit(targetName, currItem->getUPixmap(), Um::Create + " " + currItem->getUName(), "", Um::ICreate); //FIXME m_canvas->m_viewMode.operItemResizing = false; m_doc->changed(); } if (!PrefsManager::instance()->appPrefs.uiPrefs.stickyTools) { m_view->requestMode(modeNormal); } else m_view->requestMode(m_doc->appMode); return; } m_canvas->setRenderModeUseBuffer(false); m_doc->DragP = false; m_doc->leaveDrag = false; m_view->MidButt = false; if (m_view->groupTransactionStarted()) { for (int i = 0; i < m_doc->m_Selection->count(); ++i) m_doc->m_Selection->itemAt(i)->checkChanges(true); m_view->endGroupTransaction(); } for (int i = 0; i < m_doc->m_Selection->count(); ++i) m_doc->m_Selection->itemAt(i)->checkChanges(true); //Commit drag created items to undo manager. if (m_doc->m_Selection->itemAt(0)!=NULL) { m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)); } //Make sure the Zoom spinbox and page selector don't have focus if we click on the canvas m_view->m_ScMW->zoomSpinBox->clearFocus(); m_view->m_ScMW->pageSelector->clearFocus(); if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action { currItem = m_doc->m_Selection->itemAt(0); m_doc->nodeEdit.finishTransaction(currItem); } }
void PropertiesPalette_XYZ::handleNewH() { if (!m_ScMW || m_ScMW->scriptIsRunning()) return; if ((m_haveDoc) && (m_haveItem)) { double x,y,w,h, gx, gy, gh, gw; x = xposSpin->value() / m_unitRatio; y = yposSpin->value() / m_unitRatio; w = widthSpin->value() / m_unitRatio; h = heightSpin->value() / m_unitRatio; double oldW = (m_item->width() != 0.0) ? m_item->width() : 1.0; double oldH = (m_item->height() != 0.0) ? m_item->height() : 1.0; if (m_doc->m_Selection->isMultipleSelection()) { if (!_userActionOn) m_ScMW->view->startGroupTransaction(); m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); if (keepFrameWHRatioButton->isChecked()) { m_doc->scaleGroup(h / gh, h / gh, false); displayWH((h / gh) * gw, h); } else { m_doc->scaleGroup(1.0, h / gh, false); m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); displayWH(gw, gh); } if (!_userActionOn) { m_ScMW->view->endGroupTransaction(); } } else { bool oldS = m_item->Sizing; m_item->Sizing = false; m_item->OldB2 = m_item->width(); m_item->OldH2 = m_item->height(); if (m_item->asLine()) { if (m_lineMode) { double r = atan2(h-y,w-x)*(180.0/M_PI); m_item->setRotation(r, true); w = sqrt(pow(w-x,2)+pow(h-y,2)); } m_doc->SizeItem(w, m_item->height(), m_item, true, true, false); } else { if (m_item->isTableItem) { int rmo = m_doc->RotMode(); m_doc->RotMode ( 0 ); double dist = h - m_item->height(); PageItem* bb2; PageItem* bb = m_item; while (bb->LeftLink != 0) { bb = bb->LeftLink; } while (bb->RightLink != 0) { bb2 = bb; while (bb2->BottomLink != 0) { m_doc->MoveRotated(bb2->BottomLink, FPoint(0, dist), true); bb2 = bb2->BottomLink; } m_doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb, true); bb = bb->RightLink; } bb2 = bb; while (bb2->BottomLink != 0) { m_doc->MoveRotated(bb2->BottomLink, FPoint(0, dist), true); bb2 = bb2->BottomLink; } m_doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb, true); m_doc->RotMode ( rmo ); if (keepFrameWHRatioButton->isChecked()) { keepFrameWHRatioButton->setChecked(false); displayWH((h / oldH) * m_item->width(), h); handleNewW(); keepFrameWHRatioButton->setChecked(true); } } else { if (keepFrameWHRatioButton->isChecked()) { displayWH((h / oldH) * m_item->width(), h); m_doc->SizeItem((h / oldH) * m_item->width(), h, m_item, true, true, false); } else m_doc->SizeItem(m_item->width(), h, m_item, true, true, false); } } if (m_item->isArc()) { double dw = w - oldW; double dh = h - oldH; PageItem_Arc* item = m_item->asArc(); double dsch = item->arcHeight / oldH; double dscw = item->arcWidth / oldW; item->arcWidth += dw * dscw; item->arcHeight += dh * dsch; item->recalcPath(); FPoint tp2(getMinClipF(&m_item->PoLine)); m_item->PoLine.translate(-tp2.x(), -tp2.y()); m_doc->AdjustItemSize(m_item); } if (m_item->isSpiral()) { PageItem_Spiral* item = m_item->asSpiral(); item->recalcPath(); } m_item->Sizing = oldS; } //emit DocChanged(); m_doc->changed(); m_doc->regionsChanged()->update(QRect()); } }
void ShapePlug::parseGroupProperties(QDomNode &DOC, double &minXCoor, double &minYCoor, double &maxXCoor, double &maxYCoor, bool &firstCheck) { QString FillCol = "White"; QString StrokeCol = "Black"; while(!DOC.isNull()) { double x1, y1, x2, y2; FPointArray PoLine; PoLine.resize(0); QDomElement pg = DOC.toElement(); QString STag = pg.tagName(); if (STag == "svg:line") { x1 = ScCLocale::toDoubleC(pg.attribute("x1")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("y1")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("x2")) * Conversion; y2 = ScCLocale::toDoubleC(pg.attribute("y2")) * Conversion; PoLine.addPoint(x1, y1); PoLine.addPoint(x1, y1); PoLine.addPoint(x2, y2); PoLine.addPoint(x2, y2); } else if (STag == "svg:rect") { x1 = ScCLocale::toDoubleC(pg.attribute("x")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("y")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("width")) * Conversion; y2 = ScCLocale::toDoubleC(pg.attribute("height")) * Conversion; static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 }; for (int a = 0; a < 29; a += 4) { double xa = x2 * rect[a]; double ya = y2 * rect[a+1]; double xb = x2 * rect[a+2]; double yb = y2 * rect[a+3]; PoLine.addPoint(x1+xa, y1+ya); PoLine.addPoint(x1+xb, y1+yb); } } else if ((STag == "svg:polygon") || (STag == "svg:polyline")) { bool bFirst = true; double x = 0.0; double y = 0.0; QString points = pg.attribute( "points" ).simplified().replace(',', " "); QStringList pointList = points.split(' ', QString::SkipEmptyParts); FirstM = true; for( QStringList::Iterator it1 = pointList.begin(); it1 != pointList.end(); it1++ ) { x = ScCLocale::toDoubleC(*(it1++)); y = ScCLocale::toDoubleC(*it1); if( bFirst ) { svgMoveTo(x * Conversion, y * Conversion); bFirst = false; WasM = true; } else { svgLineTo(&PoLine, x * Conversion, y * Conversion); } } if (STag == "svg:polygon") svgClosePath(&PoLine); if (PoLine.size() < 4) { DOC = DOC.nextSibling(); continue; } } else if (STag == "svg:circle") { x1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1; y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1; x1 *= 2.0; y1 *= 2.0; static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0, 0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235, 0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0, 0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765 }; for (int a = 0; a < 29; a += 4) { double xa = x1 * rect[a]; double ya = y1 * rect[a+1]; double xb = x1 * rect[a+2]; double yb = y1 * rect[a+3]; PoLine.addPoint(x2+xa, y2+ya); PoLine.addPoint(x2+xb, y2+yb); } } else if (STag == "svg:ellipse") { x1 = ScCLocale::toDoubleC(pg.attribute("rx")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("ry")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1; y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1; x1 *= 2.0; y1 *= 2.0; static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0, 0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235, 0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0, 0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765 }; for (int a = 0; a < 29; a += 4) { double xa = x1 * rect[a]; double ya = y1 * rect[a+1]; double xb = x1 * rect[a+2]; double yb = y1 * rect[a+3]; PoLine.addPoint(x2+xa, y2+ya); PoLine.addPoint(x2+xb, y2+yb); } } else if (STag == "svg:path") { parseSVG( pg.attribute( "d" ), &PoLine ); if (PoLine.size() < 4) { DOC = DOC.nextSibling(); continue; } } else if (STag == "svg:g") { QDomNode child = DOC.firstChild(); parseGroupProperties(child, minXCoor, minYCoor, maxXCoor, maxYCoor, firstCheck); } if (PoLine.size() < 4) { DOC = DOC.nextSibling(); continue; } FPoint tp2(getMinClipF(&PoLine)); PoLine.translate(-tp2.x(), -tp2.y()); FPoint wh(getMaxClipF(&PoLine)); if (firstCheck) { minXCoor = tp2.x(); minYCoor = tp2.y(); maxXCoor = tp2.x() + wh.x(); maxYCoor = tp2.y() + wh.y(); firstCheck = false; } else { minXCoor = qMin(minXCoor, tp2.x()); minYCoor = qMin(minYCoor, tp2.y()); maxXCoor = qMax(maxXCoor, tp2.x() + wh.x()); maxYCoor = qMax(maxYCoor, tp2.y() + wh.y()); } DOC = DOC.nextSibling(); } }
void ResizeGesture::doResize(bool scaleContent) { PageItem* currItem = m_doc->m_Selection->itemAt(0); QString targetName = Um::SelectionGroup; QPixmap* targetIcon = Um::IGroup; if (!m_doc->m_Selection->isMultipleSelection()) { targetName = currItem->getUName(); targetIcon = currItem->getUPixmap(); } if (!m_transactionStarted) { m_transactionStarted = new UndoTransaction(Um::instance()->beginTransaction(targetName, targetIcon, Um::Resize, "", Um::IResize)); // qDebug() << "ResizeGesture::doResize: begin transaction" << m_transactionStarted; } QRectF newBounds = m_bounds.normalized(); double dw = (newBounds.width() - m_extraWidth) - currItem->width(); double dh = (newBounds.height() - m_extraHeight) - currItem->height(); double dsch = 1.0; double dscw = 1.0; if (currItem->isArc()) { PageItem_Arc* item = currItem->asArc(); if (currItem->height() != 0.0) dsch = item->arcHeight / currItem->height(); if (currItem->width() != 0.0) dscw = item->arcWidth / currItem->width(); } if (m_doc->m_Selection->isMultipleSelection()) { int RotModeBack = m_doc->RotMode(); m_doc->RotMode ( 0 ); double gx, gy, gh, gw; m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); QRectF oldBounds(gx, gy, gw, gh); double scx = oldBounds.width() == 0? 1.0 : (newBounds.width() - m_extraWidth) / oldBounds.width(); double scy = oldBounds.height() == 0? 1.0 : (newBounds.height() - m_extraHeight) / oldBounds.height(); //CB #3012 only scale text in a group if alt is pressed if ((currItem->itemType() == PageItem::TextFrame) && scaleContent) m_doc->scaleGroup(scx, scy, true); else m_doc->scaleGroup(scx, scy, false); double dx = newBounds.x() - oldBounds.x(); double dy = newBounds.y() - oldBounds.y(); if (dx != 0 || dy != 0) m_doc->moveGroup(dx + m_extraX, dy + m_extraY); m_doc->RotMode ( RotModeBack ); } else { if (currItem->itemType() == PageItem::ImageFrame && scaleContent) { double divX = (currItem->width() != 0) ? currItem->width() : 1.0; double divY = (currItem->height() != 0) ? currItem->height() : 1.0; double imgScX = (newBounds.width() - m_extraWidth) / divX * currItem->imageXScale(); double imgScY = (newBounds.height() - m_extraHeight) / divY * currItem->imageYScale(); // The aspect ratio has been fixed, so make the modification in the direction of the larger movement. if (currItem->keepAspectRatio() && currItem->fitImageToFrame()) { if (qAbs((newBounds.width() - m_extraWidth) - currItem->width()) > qAbs((newBounds.height() - m_extraHeight) - currItem->height())) imgScY = imgScX; else imgScX = imgScY; } currItem->setImageXYScale(imgScX, imgScY); } else if (currItem->itemType() == PageItem::ImageFrame && currItem->PictureIsAvailable) { double dx = ((newBounds.x() + m_extraX) - currItem->xPos()); double dy = ((newBounds.y() + m_extraY) - currItem->yPos()); double cosa = cos(currItem->rotation() * M_PI / 180.0); double sina = sin(currItem->rotation() * M_PI / 180.0); double xoff = -(cosa*dx + sina*dy); if (currItem->imageFlippedH()) xoff += (currItem->width() - (newBounds.width() - m_extraWidth)); double yoff = -(cosa*dy - sina*dx); if (currItem->imageFlippedV()) yoff += (currItem->height() - (newBounds.height() - m_extraHeight)); if (xoff != 0.0 || yoff != 0.0) { currItem->moveImageInFrame(xoff / currItem->imageXScale(), yoff / currItem->imageYScale()); } } // We do not want to scale the text of a linked frame // as it would alter text in other frames of the string else if((currItem->itemType() == PageItem::TextFrame) && (currItem->nextInChain() == 0) && (currItem->prevInChain() == 0) && scaleContent) { double divX = (currItem->width() != 0) ? currItem->width() : 1.0; double divY = (currItem->height() != 0) ? currItem->height() : 1.0; double txtScX = (newBounds.width() - m_extraWidth) / divX; double txtScY = (newBounds.height() - m_extraHeight) / divY; if (currItem->itemText.length() != 0) { for (int aa = 0; aa < currItem->itemText.length(); ++aa) { #if 0 // hard to decide if it’s batter to scale or to change font size currItem->itemText.item(aa)->setScaleV( qMax(qMin(qRound(currItem->itemText.item(aa)->scaleV()*txtScY), 4000), 100)); currItem->itemText.item(aa)->setScaleH( qMax(qMin(qRound(currItem->itemText.item(aa)->scaleH() * txtScX), 4000), 100)); #else currItem->itemText.item(aa)->setFontSize( qMax(qMin(currItem->itemText.item(aa)->fontSize() * txtScY, 4000.0), 1.0)); currItem->itemText.item(aa)->setScaleH( qMax(qMin(qRound(currItem->itemText.item(aa)->scaleH() * txtScX / txtScY), 4000), 100)); #endif // We need to scale the linespacing _only once_ per paragraph. if((aa == 0) || ( SpecialChars::isBreak(currItem->itemText.itemText(aa - 1).at(0)))) { ParagraphStyle ps(currItem->itemText.paragraphStyle(aa)); double oldLS(currItem->itemText.paragraphStyle(aa).lineSpacing()); ps.setLineSpacing(qMax(qRound(oldLS * txtScY), 1)); currItem->itemText.setStyle(aa,ps); } } } } currItem->setXYPos(newBounds.x() + m_extraX, newBounds.y() + m_extraY); currItem->setWidth(newBounds.width() - m_extraWidth); currItem->setHeight(newBounds.height() - m_extraHeight); currItem->updateClip(); if (currItem->isArc()) { PageItem_Arc* item = currItem->asArc(); item->arcWidth += dw * dscw; item->arcHeight += dh * dsch; item->recalcPath(); FPoint tp2(getMinClipF(&currItem->PoLine)); currItem->PoLine.translate(-tp2.x(), -tp2.y()); m_doc->AdjustItemSize(currItem); } if (currItem->isSpiral()) { PageItem_Spiral* item = currItem->asSpiral(); item->recalcPath(); } // rotation does not change } m_origBounds = m_bounds; }
void insert_from_file::insert_boost_file(aux_functions aquifer_reference, string elem_run_file, string type, aem_container & the_list, aem_container & the_u_list,vector<aux_polygon> &vec_polygon_ld) { double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; double R = 0; double head = 0; int is_know = 0; double discharge = 0; double Qx = 0; double Qy = 0; int int_type = 0; double condutivity = 0; complex<double> set_previous; complex<double> set_next; double aq_conductivity = aquifer_reference.get_aquifer_conductivity(); ifstream data_file; data_file.open(elem_run_file.c_str()); //this is c_str(), a f&$ing way to convert a string to char *. //const charT* c_str() const >> Returns a pointer to a null-terminated array of characters representing the string's contents. //checking for error if (!data_file) { cerr << "Error! Data file " << data_file << "file cannot be opened! \n" << endl; exit(-1); } vector <line_doublet * >::iterator current; vector <line_doublet * >::iterator previous; vector <line_doublet * >::iterator next; vector <line_doublet * > ld_coords; complex<double> previous_coord(-1, -1); complex<double> ini; vector<point_2d> temp_ld_coords; polygon_2d temp_polygon_ld; aux_polygon temp_aux_polygon_ld; //vector<aux_polygon> vec_polygon_ld; int_type = convert_string_to_int(type);//convert the input string to the well_id line_sink_id line_doublet notation switch (int_type) { case kind_well: cout <<"Inserting Wells"<<endl; while (data_file >> x1 >> y1 >> R >> head >> discharge >> is_know) { complex<double> tp(x1, y1); if (is_know) { the_list.add_element(new well(is_know, head, discharge, tp, R,kind_well)); } else { the_u_list.add_element( new well(is_know, head, discharge, tp, R, kind_well)); } } break; case kind_ls: cout <<"Inserting Line Sinks"<<endl; while (data_file >> x1 >> y1 >> x2 >> y2 >> head >> discharge >> is_know) { complex<double> tp(x1, y1); complex<double> tp2(x2, y2); if (is_know) { the_list.add_element(new line_sink(is_know, head, discharge, tp, tp2, kind_ls)); } else { the_u_list.add_element(new line_sink(is_know, head, discharge, tp, tp2, kind_ls)); } } break; case kind_ld: cout <<"Inserting Line Doublets"<<endl; data_file >> condutivity; data_file.clear(); data_file.seekg(0, ios::beg); data_file >> condutivity; //argh! but needed to jump the first line. while (data_file >> x1 >> y1) { complex<double> tp(x1, y1); ld_coords.push_back(new line_doublet(is_know, head, discharge, tp, condutivity, aq_conductivity, kind_ld)); temp_ld_coords.push_back(make<point_2d> (x1, y1)); } //calculates here part of the matrix, maybe adding to a list previous = ld_coords.end() - 1; current = ld_coords.begin(); next = ld_coords.begin() + 1; for (; current != ld_coords.end(); ++next, ++current, ++previous) { if (next == ld_coords.end()) { next = ld_coords.begin(); } if (previous == ld_coords.end()) { previous = ld_coords.begin(); } (*current)->set_next(*next); (*current)->set_previous(*previous); the_u_list.add_element(*current); } assign(temp_polygon_ld, temp_ld_coords); correct(temp_polygon_ld); cout<< "area "<<area(temp_polygon_ld)<<endl; temp_aux_polygon_ld.set_conductivity(condutivity); temp_aux_polygon_ld.set_polygon(temp_polygon_ld); vec_polygon_ld.push_back(temp_aux_polygon_ld); //cout <<"id: "<<ld_counter_id<<endl; ld_counter_id++; break; case kind_cf: while (data_file >> Qx >> Qy) { complex<double> tp(0, 0); the_list.add_element(new constant_flux(0,0,0,tp,kind_cf,Qx,Qy)); } break; default: cerr << "Element not valid! Wrong number or not implemented" << endl; exit(-1); } cout << "Exiting insert_elements" << endl; }
void Enemy_Avatar_Wander_Character_Role::update(Area_Manager *area) { if (al_get_time() >= next_check) { next_check = al_get_time() + (General::rand()%1000)/1000.0*5.0 + 5.0; const float radius = 200.0f; Map_Entity *player = area->get_entity(0); int layer = player->get_layer(); General::Point<float> player_pos = player->get_position(); Area_Loop *loop = GET_AREA_LOOP; if (!player->input_is_disabled() && layer == entity->get_layer() && !area->point_is_in_no_enemy_zone(player_pos.x, player_pos.y) && !area->get_in_speech_loop() && (!loop || loop->battle_event_is_done()) && loop->get_num_jumping() == 0) { General::Point<float> this_pos = entity->get_position(); if (General::distance(player_pos.x, player_pos.y, this_pos.x, this_pos.y) <= radius) { float dx = player_pos.x - this_pos.x; float dy = player_pos.y - this_pos.y; float angle1 = atan2(dy, dx) + M_PI / 2.0f; float angle2 = angle1 + M_PI; General::Point<float> pp1( player_pos.x + cos(angle1) * General::TILE_SIZE/2, player_pos.y + sin(angle1) * General::TILE_SIZE/2 ); General::Point<float> pp2( player_pos.x + cos(angle2) * General::TILE_SIZE/2, player_pos.y + sin(angle2) * General::TILE_SIZE/2 ); General::Point<float> tp1( this_pos.x + cos(angle1) * General::TILE_SIZE/2, this_pos.y + sin(angle1) * General::TILE_SIZE/2 ); General::Point<float> tp2( this_pos.x + cos(angle2) * General::TILE_SIZE/2, this_pos.y + sin(angle2) * General::TILE_SIZE/2 ); std::vector< General::Line<float> > *lines = area->get_collision_lines(); bool collision = false; for (size_t i = 0; i < lines[layer].size(); i++) { General::Point<float> p1(lines[layer][i].x1, lines[layer][i].y1); General::Point<float> p2(lines[layer][i].x2, lines[layer][i].y2); if (checkcoll_line_line(&pp1, &tp1, &p1, &p2, NULL)) { collision = true; break; } if (checkcoll_line_line(&pp2, &tp2, &p1, &p2, NULL)) { collision = true; break; } } if (!collision) { Battle_Event_Type type = (Battle_Event_Type)(General::rand() % 3); float *inputs = player->get_inputs(); player->set_panning_to_entity(entity->get_id()); player->set_input_disabled(true); if (type != BATTLE_EVENT_SIGHTED && (inputs[Map_Entity::X] != 0.0f || inputs[Map_Entity::Y] != 0.0f)) { General::Direction d = player->get_direction(); float a; if (d == General::DIR_N) { player->get_animation_set()->set_sub_animation("trip-up"); a = M_PI / 2; } else if (d == General::DIR_S) { player->get_animation_set()->set_sub_animation("trip-down"); a = M_PI * 3 / 2; } else if (d == General::DIR_E) { player->get_animation_set()->set_sub_animation("trip"); a = M_PI; } else { player->get_animation_set()->set_sub_animation("trip"); a = 0; } a += ((General::rand()%1000)/1000.0f)*M_PI/3 - M_PI/6; player->get_animation_set()->reset(); if (type == BATTLE_EVENT_TRIPPED) { engine->play_sample("sfx/trip.ogg"); } else if (type == BATTLE_EVENT_SLIPPED) { engine->play_sample("sfx/slip.ogg"); lua_State *stack = area->get_lua_state(); Lua::call_lua(stack, "toss_banana", "iddd>", layer, player_pos.x, player_pos.y, a); } } else { engine->play_sample("sfx/enemy_alerted.ogg"); player->update_direction(false); } GET_AREA_LOOP->set_battle_was_event(type); entity->kamikaze(this_pos.x + dx * 0.9f, this_pos.y + dy * 0.9f); return; } } } } Wander_Character_Role::update(area); }