当前位置: 首页>>代码示例>>C++>>正文


C++ Segment类代码示例

本文整理汇总了C++中Segment的典型用法代码示例。如果您正苦于以下问题:C++ Segment类的具体用法?C++ Segment怎么用?C++ Segment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Segment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: switch

void Console::outputAll(Core &core)
{
	cout << "OBJECTS:" << endl;
	if (core.sizeListObj() == 0)
		cout << "	No objects yet." << endl;
	for (size_t i = 0; i < core.sizeListObj(); ++i) {
		Point * newp = 0; Circle *newc = 0; Segment * news = 0;
		switch (core.searchID(core.getObjIDs()[i])->object_type()) {
		case IsPoint: {
			newp = dynamic_cast<Point*>(core.searchID(core.getObjIDs()[i]));
			cout.precision(2);
			cout << setw(8);
			newp->isFixed() ? cout << "(fixed) " : cout << "";
			cout << setw(8) << "POINT ";
			cout << setw(3) << "ID: " << setw(2) << newp->showId();
			cout << setw(6) << "X: " << setw(8) << newp->getX();
			cout << setw(6) << "Y: " << setw(8) << newp->getY();
			newp->isPicked() ? cout << "  <-" : cout << "";
			cout << endl;
		} break;
		case IsSegment: {
			news = dynamic_cast<Segment*>(core.searchID(core.getObjIDs()[i]));
			cout.precision(2);
			cout << setw(8);
			news->isFixed() ? cout << "(fixed) " : cout << "";
			cout << setw(8) << "SEGMENT ";
			cout << setw(3) << "ID: " << setw(2) << news->showId();
			cout << setw(6) << news->getP1()->showId();
			cout << "-----" << news->getP2()->showId();
			news->isPicked() ? cout << setw(16) << "<-" : cout << "";
			cout << endl << endl;
		} break;
		case IsCircle: {
			newc = dynamic_cast<Circle*>(core.searchID(core.getObjIDs()[i]));
			cout.precision(2);
			cout << setw(8);
			Point t = newc->getCenter();
			newc->isFixed() ? cout << "(fixed) " : cout << "";
			cout << setw(8) << "CIRCLE ";
			cout << setw(3) << "ID: " << setw(2) << newc->showId();
			cout << setw(6) << "O: " << setw(8) << newc->getCenter().showId();
			cout << setw(6) << "R: " << setw(8) << newc->getRadius();
			newc->isPicked() ? cout << "  <-" : cout << "";
			cout << endl << endl;
		} break;
		}
	}
	cout << "RESTRICTIONS:" << endl;
	if (core.sizeListRestr() == 0)
		cout << "	No restrictions yet." << endl;
	for (size_t i = 0; i < core.sizeListRestr(); ++i) {
		switch (core.searchIDRestr(core.getRestrIDs()[i])->get_type()) {

		case RT_P2PDIST: {
			auto restr = dynamic_cast<RestrP2PDIST*>(core.searchIDRestr(core.getRestrIDs()[i]));
			cout.precision(2);
			cout << setw(16) << "P2PDIST " << setw(3) << "ID: " << setw(2) << restr->showId();
			cout << setw(13) << "violation: " << setw(8) << restr->violation();
			cout << setw(8) << restr->getP1()->showId() << "---" << restr->getP2()->showId() << endl;
		} break;
		case RT_P2SDIST: {
			auto restr = dynamic_cast<RestrP2SDIST*>(core.searchIDRestr(core.getRestrIDs()[i]));
			cout.precision(2);
			cout << setw(16) << "P2SDIST " << setw(3) << "ID: " << setw(2) << restr->showId();
			cout << setw(13) << "violation: " << setw(8) << restr->violation();
			cout << setw(8) << restr->getP1()->showId() << "---" << restr->getP2()->showId();
			cout << "==" << restr->getP3()->showId() << endl;
		} break;
		case RT_P2SDISTEX: {
			auto restr = dynamic_cast<RestrP2SDISTEX*>(core.searchIDRestr(core.getRestrIDs()[i]));
			cout.precision(2);
			cout << setw(16) << "P2SDISTEX " << setw(3) << "ID: " << setw(2) << restr->showId();
			cout << setw(13) << "violation: " << setw(8) << restr->violation();
			cout << setw(8) << restr->getP1()->showId() << "---" << restr->getP2()->showId();
			cout << "==" << restr->getP3()->showId() << endl;
		} break;
		case RT_S2SANGLE: {
			auto restr = dynamic_cast<RestrS2SANGLE*>(core.searchIDRestr(core.getRestrIDs()[i]));
			cout.precision(2);
			cout << setw(16) << "S2SANGLE " << setw(3) << "ID: " << setw(2) << restr->showId();
			cout << setw(13) << "violation: " << setw(8) << restr->violation();
			cout << setw(8) << restr->getS1()->showId() << "---" << restr->getS2()->showId() << endl;
		} break;
		case RT_S2SORTHO: {
			auto restr = dynamic_cast<RestrS2SORTHO*>(core.searchIDRestr(core.getRestrIDs()[i]));
			cout.precision(2);
			cout << setw(16) << "S2SORTHO " << setw(3) << "ID: " << setw(2) << restr->showId();
			cout << setw(13) << "violation: " << setw(8) << restr->violation();
			cout << setw(8) << restr->getS1()->showId() << "---" << restr->getS2()->showId() << endl;
		} break;
		case RT_S2SPARAL: {
			auto restr = dynamic_cast<RestrS2SPARAL*>(core.searchIDRestr(core.getRestrIDs()[i]));
			cout.precision(2);
			cout << setw(16) << "S2SPARAL " << setw(3) << "ID: " << setw(2) << restr->showId();
			cout << setw(13) << "violation: " << setw(8) << restr->violation();
			cout << setw(8) << restr->getS1()->showId() << "---" << restr->getS2()->showId() << endl;
		} break;
		case RT_S2SEQUALS: {
			auto restr = dynamic_cast<RestrS2SEQUALS*>(core.searchIDRestr(core.getRestrIDs()[i]));
			cout.precision(2);
//.........这里部分代码省略.........
开发者ID:ottenokLeshi,项目名称:4ertiognic,代码行数:101,代码来源:console.cpp

示例2: doGetNextFrame

Boolean ADUFromMP3Source::doGetNextFrame1() {
  // First, check whether we have enough previously-read data to output an
  // ADU for the last-read MP3 frame:
  unsigned tailIndex;
  Segment* tailSeg;
  Boolean needMoreData;

  if (fSegments->isEmpty()) {
    needMoreData = True;
    tailSeg = NULL; tailIndex = 0; // unneeded, but stops compiler warnings
  } else {
    tailIndex = SegmentQueue::prevIndex(fSegments->nextFreeIndex());
    tailSeg = &(fSegments->s[tailIndex]);

    needMoreData
	  = fTotalDataSizeBeforePreviousRead < tailSeg->backpointer // bp points back too far
      || tailSeg->backpointer + tailSeg->dataHere() < tailSeg->aduSize; // not enough data
  }

  if (needMoreData) {
    // We don't have enough data to output an ADU from the last-read MP3
    // frame, so need to read another one and try again:
    doGetNextFrame();
    return True;
  }

  // Output an ADU from the tail segment:
  fFrameSize = tailSeg->headerSize+tailSeg->sideInfoSize+tailSeg->aduSize;
  fPresentationTime = tailSeg->presentationTime;
  fDurationInMicroseconds = tailSeg->durationInMicroseconds;
  unsigned descriptorSize
    = fIncludeADUdescriptors ? ADUdescriptor::computeSize(fFrameSize) : 0;
#ifdef DEBUG
  fprintf(stderr, "m->a:outputting ADU %d<-%d, nbr:%d, sis:%d, dh:%d, (descriptor size: %d)\n", tailSeg->aduSize, tailSeg->backpointer, fFrameSize, tailSeg->sideInfoSize, tailSeg->dataHere(), descriptorSize);
#endif
  if (descriptorSize + fFrameSize > fMaxSize) {
    envir() << "ADUFromMP3Source::doGetNextFrame1(): not enough room ("
	    << descriptorSize + fFrameSize << ">"
	    << fMaxSize << ")\n";
    fFrameSize = 0;
    return False;
  }

  unsigned char* toPtr = fTo;
  // output the ADU descriptor:
  if (fIncludeADUdescriptors) {
    fFrameSize += ADUdescriptor::generateDescriptor(toPtr, fFrameSize);
  }

  // output header and side info:
  memmove(toPtr, tailSeg->dataStart(),
	  tailSeg->headerSize + tailSeg->sideInfoSize);
  toPtr += tailSeg->headerSize + tailSeg->sideInfoSize;

  // go back to the frame that contains the start of our data:
  unsigned offset = 0;
  unsigned i = tailIndex;
  unsigned prevBytes = tailSeg->backpointer;
  while (prevBytes > 0) {
    i = SegmentQueue::prevIndex(i);
    unsigned dataHere = fSegments->s[i].dataHere();
    if (dataHere < prevBytes) {
      prevBytes -= dataHere;
    } else {
      offset = dataHere - prevBytes;
      break;
    }
  }

  // dequeue any segments that we no longer need:
  while (fSegments->headIndex() != i) {
    fSegments->dequeue(); // we're done with it
  }

  unsigned bytesToUse = tailSeg->aduSize;
  while (bytesToUse > 0) {
    Segment& seg = fSegments->s[i];
    unsigned char* fromPtr
      = &seg.dataStart()[seg.headerSize + seg.sideInfoSize + offset];
    unsigned dataHere = seg.dataHere() - offset;
    unsigned bytesUsedHere = dataHere < bytesToUse ? dataHere : bytesToUse;
    memmove(toPtr, fromPtr, bytesUsedHere);
    bytesToUse -= bytesUsedHere;
    toPtr += bytesUsedHere;
    offset = 0;
    i = SegmentQueue::nextIndex(i);
  }


  if (fFrameCounter++%fScale == 0) {
    // Call our own 'after getting' function.  Because we're not a 'leaf'
    // source, we can call this directly, without risking infinite recursion.
    afterGetting(this);
  } else {
    // Don't use this frame; get another one:
    doGetNextFrame();
  }

  return True;
}
开发者ID:Azzuro,项目名称:MediaPortal-1,代码行数:100,代码来源:MP3ADU.cpp

示例3: distance

/**
 *  @brief 点と線分の距離
 *  @param[in] a  判定する点
 *  @param[in] b  判定する線分
 *  @return    点aと線分bの距離
 */
inline double distance(const Point &a, const Segment &b){
	const Point p = b.to_line().projection(a);
	if(intersect(b, p)){ return (a - p).abs(); }
	return std::min((b.a - a).abs(), (b.b - a).abs());
}
开发者ID:logicmachine,项目名称:LibCompetitive-v3,代码行数:11,代码来源:distance.hpp

示例4: newClef

Segment *
SegmentJoinCommand::makeSegment(SegmentVec oldSegments)
{
    // We can proceed even if composition is NULL, just normalize
    // rests will do less.
    Composition *composition = oldSegments[0]->getComposition();

    // Find the leftmost segment's index and the rightmost segment's
    // index.
    timeT t0 = oldSegments[0]->getStartTime();
    timeT t1 = oldSegments[0]->getEndMarkerTime();
    size_t leftmostIndex = 0;
    size_t rightmostIndex = 0;
    for (size_t i = 1; i < oldSegments.size(); ++i) {
        timeT startTime = oldSegments[i]->getStartTime();
        if (startTime < t0) {
            t0 = startTime;
            leftmostIndex = i;
        }
        timeT endMarkerTime = oldSegments[i]->getEndMarkerTime();
        if (endMarkerTime > t1) {
            t1 = endMarkerTime;
            rightmostIndex = i;
        }
    }

    // Always begin with the leftmost segment to keep in the new segment
    // any clef or key change found at the start of this segment.
    Segment *newSegment = oldSegments[leftmostIndex]->clone(false);

    // drop any events beyond the end marker
    newSegment->setEndTime(newSegment->getEndMarkerTime());

    // that duplicated the leftmost segment; now do the rest

    // we normalize rests in any overlapping areas
    timeT overlapStart = 0, overlapEnd = 0;
    bool haveOverlap = false;
    for (size_t i = 0; i < oldSegments.size(); ++i) {

        // Don't add twice the first old segment
        if (i == leftmostIndex) continue;

        Segment *s = oldSegments[i];

        timeT start = s->getStartTime(), end = s->getEndMarkerTime();

        timeT os = 0, oe = 0;
        bool haveOverlapHere = false;

        if (start < newSegment->getEndMarkerTime() &&
            end > newSegment->getStartTime()) {
            haveOverlapHere = true;
            os = std::max(start, newSegment->getStartTime());
            oe = std::min(end, newSegment->getEndMarkerTime());
            RG_DEBUG << "overlap here, os = " << os << ", oe = " << oe;
        }

        if (haveOverlapHere) {
            if (haveOverlap) {
                overlapStart = std::min(overlapStart, os);
                overlapEnd = std::max(overlapEnd, oe);
            } else {
                overlapStart = os;
                overlapEnd = oe;
                haveOverlap = true;
            }
        }

        if (start > newSegment->getEndMarkerTime()) {
            newSegment->setEndMarkerTime(start);
        }

        for (Segment::iterator si = s->begin(); ; ++si) {

            // If we're in the rightmost segment
            if (i == rightmostIndex) {
                // Copy all of the events to the end
                if (si == s->end())
                    break;
            } else {
                // Just copy up to the End Marker of this segment.
                if (!s->isBeforeEndMarker(si))
                    break;
            }

            // weed out duplicate clefs and keys

            if ((*si)->isa(Clef::EventType)) {
                try {
                    Clef newClef(**si);
                    if (newSegment->getClefAtTime
                        ((*si)->getAbsoluteTime() + 1) == newClef) {
                        continue;
                    }
                } catch (...) { }
            }

            if ((*si)->isa(Key::EventType)) {
                try {
//.........这里部分代码省略.........
开发者ID:tedfelix,项目名称:rosegarden,代码行数:101,代码来源:SegmentJoinCommand.cpp

示例5: score

QPointF Pedal::linePos(Grip grip, System** sys) const
      {
      qreal x = 0.0;
      qreal nhw = score()->noteHeadWidth();
      System* s = nullptr;
      if (grip == Grip::START) {
            ChordRest* c = toChordRest(startElement());
            if (c) {
                  s = c->segment()->system();
                  x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
                  if (c->type() == ElementType::REST && c->durationType() == TDuration::DurationType::V_MEASURE)
                        x -= c->x();
                  if (beginHookType() == HookType::HOOK_45)
                        x += nhw * .5;
                  }
            }
      else {
            Element* e = endElement();
            ChordRest* c = toChordRest(endElement());
            if (!e || e == startElement() || (endHookType() == HookType::HOOK_90)) {
                  // pedal marking on single note or ends with non-angled hook:
                  // extend to next note or end of measure
                  Segment* seg = nullptr;
                  if (!e)
                        seg = startSegment();
                  else
                        seg = c->segment();
                  if (seg) {
                        seg = seg->next();
                        for ( ; seg; seg = seg->next()) {
                              if (seg->segmentType() == SegmentType::ChordRest) {
                                    // look for a chord/rest in any voice on this staff
                                    bool crFound = false;
                                    int track = staffIdx() * VOICES;
                                    for (int i = 0; i < VOICES; ++i) {
                                          if (seg->element(track + i)) {
                                                crFound = true;
                                                break;
                                                }
                                          }
                                    if (crFound)
                                          break;
                                    }
                              else if (seg->segmentType() == SegmentType::EndBarLine) {
                                    break;
                                    }
                              }
                        }
                  if (seg) {
                        s = seg->system();
                        x = seg->pos().x() + seg->measure()->pos().x() - nhw * 2;
                        }
                  }
            else if (c) {
                  s = c->segment()->system();
                  x = c->pos().x() + c->segment()->pos().x() + c->segment()->measure()->pos().x();
                  if (c->type() == ElementType::REST && c->durationType() == TDuration::DurationType::V_MEASURE)
                        x -= c->x();
                  }
            if (!s) {
                  int t = tick2();
                  Measure* m = score()->tick2measure(t);
                  s = m->system();
                  x = m->tick2pos(t);
                  }
            if (endHookType() == HookType::HOOK_45)
                  x += nhw * .5;
            else
                  x += nhw;
            }

      *sys = s;
      return QPointF(x, 0);
      }
开发者ID:frankvanbever,项目名称:MuseScore,代码行数:74,代码来源:pedal.cpp

示例6: bots

WindowingResult WindowEvaluator::eval_pt_to_seg(Point origin, Segment target) {
    auto end = target.delta().magsq();

    // if target is a zero-length segment, there are no windows
    if (end == 0) return make_pair(vector<Window>{}, boost::none);

    if (debug) {
        system->drawLine(target, QColor{"Blue"}, "Debug");
    }

    vector<Window> windows = {Window{0, end}};

    // apply the obstacles

    vector<Robot*> bots(system->self.size() + system->opp.size());

    auto filter_predicate = [&](const Robot* bot) -> bool {
        return bot != nullptr && bot->visible &&
               find(excluded_robots.begin(), excluded_robots.end(), bot) ==
                   excluded_robots.end();
    };

    auto end_it = copy_if(system->self.begin(), system->self.end(),
                          bots.begin(), filter_predicate);

    end_it = copy_if(system->opp.begin(), system->opp.end(), end_it,
                     filter_predicate);

    bots.resize(distance(bots.begin(), end_it));

    vector<Point> bot_locations;
    for_each(bots.begin(), bots.end(), [&bot_locations](Robot* bot) {
        bot_locations.push_back(bot->pos);
    });

    bot_locations.insert(bot_locations.end(),
                         hypothetical_robot_locations.begin(),
                         hypothetical_robot_locations.end());

    for (auto& pos : bot_locations) {
        auto d = (pos - origin).mag();
        // whether or not we can ship over this bot
        auto chip_overable = chip_enabled &&
                             (d < max_chip_range - Robot_Radius) &&
                             (d > min_chip_range + Robot_Radius);
        if (!chip_overable) {
            obstacle_robot(windows, origin, target, pos);
        }
    }

    auto p0 = target.pt[0];
    auto delta = target.delta() / end;

    for (auto& w : windows) {
        w.segment = Segment{p0 + delta * w.t0, p0 + delta * w.t1};
        w.a0 = RadiansToDegrees((w.segment.pt[0] - origin).angle());
        w.a1 = RadiansToDegrees((w.segment.pt[1] - origin).angle());
        fill_shot_success(w, origin);
    }

    boost::optional<Window> best{
        !windows.empty(), *max_element(windows.begin(), windows.end(),
                                       [](Window& a, Window& b) -> bool {
                                           return a.segment.delta().magsq() <
                                                  b.segment.delta().magsq();
                                       })};
    if (debug) {
        if (best) {
            system->drawLine(Segment{origin, best->segment.center()},
                             QColor{"Green"}, "Debug");
        }
        for (Window& window : windows) {
            system->drawLine(window.segment, QColor{"Green"}, "Debug");
            system->drawText(QString::number(window.shot_success),
                             window.segment.center() + Point(0, 0.1),
                             QColor{"Green"}, "Debug");
        }
    }

    return make_pair(windows, best);
}
开发者ID:RoboJackets,项目名称:robocup-software,代码行数:81,代码来源:WindowEvaluator.cpp

示例7: main

int main()
{
	int start_s =0, stop_s =0, test_start= 0, test_stop =0;
	dataManipulator dm;
	Segment segData;
	start_s = clock();
	cout << "***************  program starts  "<<"*****************************" << endl;
	//*****************First test case: 100 thousand random integer
	cout<<endl<<"First test case: 10 thousand random Integer: "<<endl;	
	cout<<"Creating random Integers from -100000000 to 100000000.."<<endl;
	const char* testfile1 = dm.createRandomInt(100000);
	cout<<"Read data from file....."<<endl;	
	vector<int> RanIntData = dm.readIntFromFile(testfile1);	
	cout<<"Data read completed, data stored."<<endl;
	cout<<endl<<"Execute some sample query:"<<endl<<endl;
	dm.executeQuery("larger", 10000, RanIntData);	
	dm.executeQuery("smaller", 10000, RanIntData);
	dm.executeQuery("equals",10000,RanIntData);
	dm.executeQuery("larger", 33333,RanIntData);	
	dm.executeQuery("smaller", 20160307, RanIntData);
	dm.executeQuery("between", 33333,20160307, RanIntData);
	dm.executeQuery("between", 10000,33333,RanIntData);
	//****************second test case: 100 thousand random floats
	cout<<endl<<endl<<"Second test case: 100 thousand random Floats: "<<endl;	
	start_s = clock();	
	cout<<"Creating random Float from -100000000 to 100000000.."<<endl;
	const char* testfile2 = dm.createRandomFloat(100000);
	cout<<"Read data from file....."<<endl;	
	vector<float> RanFloatData = dm.readFloatFromFile(testfile2);	
	cout<<"Data read completed, data stored."<<endl;
	cout<<endl<<"Execute some sample query:"<<endl<<endl;
	dm.executeQuery("larger", (float)123.45, RanFloatData);	
	dm.executeQuery("smaller",(float) 123.45, RanFloatData);
	dm.executeQuery("equals",(float)123.45,RanFloatData);
	dm.executeQuery("larger", (float)333.33,RanFloatData);	
	dm.executeQuery("smaller", (float)2016.00, RanFloatData);
	dm.executeQuery("between", (float)-500.0, (float)500.0, RanFloatData);

	//*****************Third test case: 1 Million random integers
	cout << endl << "Third test case: 1 Million random Integer: " << endl;
	start_s = clock();
	cout << "Creating random Integers from -1000000 to 1000000.." << endl;
	const char* testfile3 = segData.createRandomInt(1000000);
	cout << "Read data from file....." << endl;
	segData.readFromFile(testfile3);
	cout<<endl<<"Execute some sample query:"<<endl<<endl;
	segData.getAllCounts();
	segData.query("smaller", 2000);
	segData.query("larger", 2000);
	segData.query("equals",2000);
	segData.query("between",0,1025);
	//*****************Fourth test case: 10 Million random integers
	cout << endl << "Fourth test case: 10 Million random Integer: " << endl;
	start_s = clock();
	cout << "Creating random Integers from -1000000 to 1000000.." << endl;
	const char* testfile4 = segData.createRandomInt(10000000);
	cout << "Read data from file....." << endl;
	segData.readFromFile(testfile4);
	cout<<"Data read completed, data stored."<<endl;
	cout<<endl<<"Execute some sample query:"<<endl<<endl;
	segData.getAllCounts();
	segData.query("smaller", 2000);
	segData.query("larger", 2000);
	segData.query("equals",2000);
	segData.query("between",0,1025);
	//****************Fifth test case: 50 Million random integers
	cout << endl << "Fifth test case: 25 Million random Integer: " << endl;
	start_s = clock();
	cout << "Creating 25 Million random Integers from -1000000 to 1000000.." << endl;
	const char* testfile5 = segData.createRandomInt(25000000);
	cout << "Read data from file....." << endl;
	segData.readFromFile(testfile5);
	cout<<"Data read completed, data stored."<<endl;
	cout<<endl<<"Execute some sample query:"<<endl<<endl;
	segData.getAllCounts();
	segData.query("smaller", 2000);
	segData.query("larger", 2000);
	segData.query("equals",2000);
	segData.query("between",0,1025);
	cout << endl << "*************** End of the program. Total time cost :";
	stop_s = clock();
	cout << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << " ms  " << "*****************************" << endl;
	cout<<"Wish you have a good one! ---Zhichao(Zach)."<<endl;
	return 0;
}
开发者ID:ZachTop,项目名称:Range-Query-more-than-10-millon-objects,代码行数:85,代码来源:main.cpp

示例8: Segment

float FieldController::HoleSquad( const Segment& topSegment, const std::vector<Segment>& modelTopLine )
{
	double holeSquad = 0;
	for (int i = 0, i_end = modelTopLine.size(); i < i_end; ++i)
	{
		double a_length = modelTopLine[i].length();
		double b_length = Segment(modelTopLine[i].start(), Vector2F(modelTopLine[i].start().X(), topSegment.start().Y())).length();
		holeSquad += a_length * b_length;
	}

	return (float)holeSquad;
}
开发者ID:vromanov,项目名称:CuttingProblem,代码行数:12,代码来源:FieldController.cpp

示例9: r

void PositionCursor::move(int tick)
      {
      QRectF r(bbox());
      //
      // set mark height for whole system
      //
      if (_type == CursorType::LOOP_OUT)
        tick --;
      Score* score = _sv->score();
      Measure* measure = score->tick2measureMM(tick);
      if (measure == 0)
            return;
      qreal x;
      int offset = 0;

      Segment* s;
      for (s = measure->first(Segment::Type::ChordRest); s;) {
            int t1 = s->tick();
            int x1 = s->canvasPos().x();
            qreal x2;
            int t2;
            Segment* ns = s->next(Segment::Type::ChordRest);
            if (ns) {
                  t2 = ns->tick();
                  x2 = ns->canvasPos().x();
                  }
            else {
                  t2 = measure->endTick();
                  x2 = measure->canvasPos().x() + measure->width();
                  }
            t1 += offset;
            t2 += offset;
            if (tick >= t1 && tick < t2) {
                  int   dt = t2 - t1;
                  qreal dx = x2 - x1;
                  x = x1 + dx * (tick-t1) / dt;
                  break;
                  }
            s = ns;
            }
      if (s == 0)
            return;

      System* system = measure->system();
      if (system == 0)
            return;
      double y        = system->staffYpage(0) + system->page()->pos().y();
      double _spatium = score->spatium();

      qreal mag = _spatium / (MScore::DPI * SPATIUM20);
      double w  = (_spatium * 2.0 + score->scoreFont()->width(SymId::noteheadBlack, mag))/3;
      double h  = 6 * _spatium;
      //
      // set cursor height for whole system
      //
      double y2 = 0.0;

      for (int i = 0; i < score->nstaves(); ++i) {
            SysStaff* ss = system->staff(i);
            if (!ss->show() || !score->staff(i)->show())
                  continue;
            y2 = ss->y() + ss->bbox().height();
            }
      h += y2;
      y -= 3 * _spatium;

      if (_type == CursorType::LOOP_IN) {
            x = x - _spatium + w/1.5;
            }
      else {
            x = x - _spatium * .5;
            }
      _tick = tick;
      _rect = QRectF(x, y, w, h);
      _sv->update(_sv->matrix().mapRect(r | bbox()).toRect().adjusted(-1,-1,1,1));
      }
开发者ID:riban-bw,项目名称:MuseScore,代码行数:76,代码来源:textcursor.cpp

示例10: Intersects

bool AABB::Intersects(const Segment& s) const { return s.Intersects(*this); }
开发者ID:ptitSeb,项目名称:Eldritch,代码行数:1,代码来源:aabb.cpp

示例11: GET_LOGGER

void Pot_Piecewise::initialize( Conf_Module* config, vector<Module*> dependencies )
{
	GET_LOGGER( "liee.Module.Pot_Piecewise" );
	double epsilon = config->get_double("epsilon") / CONV_au_nm;
	rounding = config->get_array("ellipse")[0] / CONV_au_nm;
	scale_y = rounding / ( config->get_array("ellipse")[1] / CONV_au_eV );
	X = config->get_array("r_list");
	Y = config->get_array("V_list");
	if ( X.size() != Y.size() || X.size() == 0 ) {
		LOG_ERROR( "r_list and V_list are required to have the same size with at least 1 element." )
		exit(1);
	}
	if ( X.size() == 1 ) {  // constant potential
		X.push_back( X[0] + config->get_double("r_range") );
		Y.push_back( Y[0] );
	}

	for ( size_t i = 0; i < X.size(); i++ ) {
		X[i] /= CONV_au_nm;
		Y[i] /= CONV_au_eV;
		if ( i > 0  &&  X[i-1] > X[i] ) {
			LOG_ERROR( "r_list is required to be sorted in ascending order. exiting." )
			exit(1);
		}
		if ( i > 0  &&  X[i-1] == X[i] ) {
			X[i] += epsilon;
		}
	}

	Segment first;
	first.line( X[0], X[1], Y[0], Y[1] );
	segs.push_back( first );

	for ( size_t i = 1; i < X.size()-1; i++ )
	{
		Segment left, right;
		left = segs.back();
		right.line( X[i], X[i+1], Y[i], Y[i+1] );

		if ( rounding > 0  &&  left.m != right.m ) {
			// note: tangential-circle calculation is done in a y-stretched system in order to
			// work with a circle instead of an ellipse. The x-positions are valid in both systems,
			// while the circle centre-V is scaled back to the actual ellipse-centre
			// (V(r) draws the ellipse according to scale_y)
			for ( double rr = rounding; rr > 1e-4 * rounding; rr /= 1.5 )
			{
				Segment sleft, sright, circle;
				double S = scale_y;
				sleft.line( X[i-1], X[i], S*Y[i-1], S*Y[i] );
				sright.line( X[i], X[i+1], S*Y[i], S*Y[i+1] );

				circle.sign = ( left.m > right.m )  ?  +1  : -1;  // sign=+1: circle under the roof-like kink, positive "square-root"-circle is touching tangents and opposite for sign=-1
				double dist = -circle.sign * rr;  // the possible centre-positions for the tangential circle are on a parallel line, distanced 1 rounding-radius in orthogonal direction, either above or below
				double shifted_n_l = (S*Y[i] + dist * sleft.ortho_Y)  - sleft.m  * (X[i] + dist * sleft.ortho_X);  // ordinate of the left-side parallel
				double shifted_n_r = (S*Y[i] + dist * sright.ortho_Y) - sright.m * (X[i] + dist * sright.ortho_X);
				circle.cr = (shifted_n_l - shifted_n_r) / (sright.m - sleft.m);  // circle centre at the intersection of the two parallels
				circle.cV = ( sleft.m * circle.cr + shifted_n_l ) / S;
				circle.start_r = circle.cr - dist * sleft.ortho_X;  // from circle centre back on the normal-vector to the respective lines
				circle.end_r   = circle.cr - dist * sright.ortho_X;
				circle.radius = rr;

				// only accept rounding circle if it does not exceed the middle of neighbouring segments
				if (    circle.start_r > 0.5 * (segs.back().start_r + segs.back().end_r)
				     && circle.end_r   < 0.5 * (right.start_r + right.end_r) )
				{
					segs.back().end_r = circle.start_r;  // reduce left segment extend
					right.start_r = circle.end_r;
					segs.push_back( circle );
					break;
				} // else continue loop with a smaller radius
			}
		}
		segs.push_back( right );
	}
}
开发者ID:tortoiseq,项目名称:liee,代码行数:75,代码来源:potential.cpp

示例12: toLyrics

void ScoreView::lyricsUnderscore()
      {
      Lyrics* lyrics   = toLyrics(editData.element);
      int track        = lyrics->track();
      Segment* segment = lyrics->segment();
      int verse        = lyrics->no();
      Placement placement = lyrics->placement();
      int endTick      = segment->tick(); // a previous melisma cannot extend beyond this point

      changeState(ViewState::NORMAL);

      // search next chord
      Segment* nextSegment = segment;
      while ((nextSegment = nextSegment->next1(SegmentType::ChordRest))) {
            Element* el = nextSegment->element(track);
            if (el &&  el->isChord())
                  break;
            }

      // look for the lyrics we are moving from; may be the current lyrics or a previous one
      // we are extending with several underscores
      Lyrics* fromLyrics = 0;
      while (segment) {
            ChordRest* cr = toChordRest(segment->element(track));
            if (cr) {
                  fromLyrics = cr->lyrics(verse, placement);
                  if (fromLyrics)
                        break;
                  }
            segment = segment->prev1(SegmentType::ChordRest);
            // if the segment has a rest in this track, stop going back
            Element* e = segment ? segment->element(track) : 0;
            if (e && !e->isChord())
                  break;
            }

      _score->startCmd();
      // one-chord melisma?
      // if still at melisma initial chord and there is a valid next chord (if not,
      // there will be no melisma anyway), set a temporary melisma duration
      if (fromLyrics == lyrics && nextSegment)
            lyrics->undoChangeProperty(Pid::LYRIC_TICKS, Lyrics::TEMP_MELISMA_TICKS);

      if (nextSegment == 0) {
            if (fromLyrics) {
                  switch(fromLyrics->syllabic()) {
                        case Lyrics::Syllabic::SINGLE:
                        case Lyrics::Syllabic::END:
                              break;
                        default:
                              fromLyrics->undoChangeProperty(Pid::SYLLABIC, int(Lyrics::Syllabic::END));
                              break;
                        }
                  if (fromLyrics->segment()->tick() < endTick)
                        fromLyrics->undoChangeProperty(Pid::LYRIC_TICKS, endTick - fromLyrics->segment()->tick());
                  }
            // leave edit mode, select something (just for user feedback) and update to show extended melisam
            mscore->changeState(STATE_NORMAL);
            if (fromLyrics)
                  _score->select(fromLyrics, SelectType::SINGLE, 0);
            _score->setLayoutAll();
            _score->endCmd();
            return;
            }

      // if a place for a new lyrics has been found, create a lyrics there

      ChordRest* cr    = toChordRest(nextSegment->element(track));
      Lyrics* toLyrics = cr->lyrics(verse, placement);
      bool newLyrics   = (toLyrics == 0);
      if (!toLyrics) {
            toLyrics = new Lyrics(_score);
            toLyrics->setTrack(track);
            toLyrics->setParent(nextSegment->element(track));
            toLyrics->setNo(verse);
            toLyrics->setPlacement(placement);
            toLyrics->setSyllabic(Lyrics::Syllabic::SINGLE);
            }
      // as we arrived at toLyrics by an underscore, it cannot have syllabic dashes before
      else if (toLyrics->syllabic() == Lyrics::Syllabic::MIDDLE)
            toLyrics->undoChangeProperty(Pid::SYLLABIC, int(Lyrics::Syllabic::BEGIN));
      else if (toLyrics->syllabic() == Lyrics::Syllabic::END)
            toLyrics->undoChangeProperty(Pid::SYLLABIC, int(Lyrics::Syllabic::SINGLE));

      if (fromLyrics) {
            // as we moved away from fromLyrics by an underscore,
            // it can be isolated or terminal but cannot have dashes after
            switch(fromLyrics->syllabic()) {
                  case Lyrics::Syllabic::SINGLE:
                  case Lyrics::Syllabic::END:
                        break;
                  default:
                        fromLyrics->undoChangeProperty(Pid::SYLLABIC, int(Lyrics::Syllabic::END));
                        break;
                  }
            // for the same reason, if it has a melisma, this cannot extend beyond toLyrics
            if (fromLyrics->segment()->tick() < endTick)
                  fromLyrics->undoChangeProperty(Pid::LYRIC_TICKS, endTick - fromLyrics->segment()->tick());
            }
      if (newLyrics)
//.........这里部分代码省略.........
开发者ID:emeraldimp,项目名称:MuseScore,代码行数:101,代码来源:editlyrics.cpp

示例13: overlaps

 bool Rectangle::overlaps(Segment const& segment) const noexcept
 {
     return (contains(segment.start()) || contains(segment.end()) || intersects(segment));
 }
开发者ID:EQ4,项目名称:KiwiGui,代码行数:4,代码来源:KiwiRectangle.cpp

示例14: segment

void Clef::layout()
      {
      // determine current number of lines and line distance
      int   lines;
      qreal lineDist;
      Segment* clefSeg  = segment();

      qDeleteAll(elements);
      elements.clear();

      // check clef visibility and type compatibility
      if (clefSeg && staff()) {
            StaffType* staffType = staff()->staffType();
            bool show            = staffType->genClef();        // check staff type allows clef display
            int tick             = clefSeg->tick();

            // check clef is compatible with staff type group:
            if (ClefInfo::staffGroup(clefType()) != staffType->group()) {
                  if (tick > 0 && !generated()) // if clef is not generated, hide it
                        show = false;
                  else                          // if generated, replace with initial clef type
                        // TODO : instead of initial staff clef (which is assumed to be compatible)
                        // use the last compatible clef previously found in staff
                        _clefTypes = staff()->clefType(0);
                  }

            // if clef not to show or not compatible with staff group
            if (!show) {
                  setbbox(QRectF());
                  qDebug("Clef::layout(): invisible clef at tick %d(%d) staff %d",
                     segment()->tick(), segment()->tick()/1920, staffIdx());
                  return;
                  }
            lines    = staffType->lines();         // init values from staff type
            lineDist = staffType->lineDistance().val();
            }
      else {
            lines    = 5;
            lineDist = 1.0;
            }

      qreal _spatium = spatium();
      qreal yoff     = 0.0;

      Symbol* symbol = new Symbol(score());

      switch (clefType()) {
            case ClefType::G:                              // G clef on 2nd line
                  symbol->setSym(SymId::gClef);
                  yoff = 3.0 * lineDist;
                  break;
            case ClefType::G1:                             // G clef 8va on 2nd line
                  symbol->setSym(SymId::gClef8va);
                  yoff = 3.0 * lineDist;
                  break;
            case ClefType::G2:                             // G clef 15ma on 2nd line
                  symbol->setSym(SymId::gClef15ma);
                  yoff = 3.0 * lineDist;
                  break;
            case ClefType::G3:                             // G clef 8vb on 2nd line
                  symbol->setSym(SymId::gClef8vb);
                  yoff = 3.0 * lineDist;
                  break;
            case ClefType::G3_O:                            // double G clef 8vb on 2nd line
                  symbol->setSym(SymId::gClef8vbOld);
                  yoff = 3.0 * lineDist;
                  break;
            case ClefType::F:                              // F clef on penultimate line
                  symbol->setSym(SymId::fClef);
                  yoff = 1.0 * lineDist;
                  break;
            case ClefType::F8:                             // F clef 8va bassa on penultimate line
                  symbol->setSym(SymId::fClef8vb);
                  yoff = 1.0 * lineDist;
                  break;
            case ClefType::F15:                            // F clef 15ma bassa on penultimate line
                  symbol->setSym(SymId::fClef15mb);
                  yoff = 1.0 * lineDist;
                  break;
            case ClefType::F_B:                            // baritone clef
                  symbol->setSym(SymId::fClef);
                  yoff = 2.0 * lineDist;
                  break;
            case ClefType::F_C:                            // subbass clef
                  symbol->setSym(SymId::fClef);
                  yoff = 0.0;
                  break;
            case ClefType::C1:                             // C clef in 1st line
                  symbol->setSym(SymId::cClef);
                  yoff = 4.0 * lineDist;
                  break;
            case ClefType::C2:                             // C clef on 2nd line
                  symbol->setSym(SymId::cClef);
                  yoff = 3.0 * lineDist;
                  break;
            case ClefType::C3:                             // C clef in 3rd line
                  symbol->setSym(SymId::cClef);
                  yoff = 2.0 * lineDist;
                  break;
            case ClefType::C4:                             // C clef on 4th line
//.........这里部分代码省略.........
开发者ID:NupurMalpani,项目名称:MuseScore,代码行数:101,代码来源:clef.cpp

示例15: areas

bool AreaShader::checkIntersect(const Segment& s) const
{
    const Segment::Areastore& areas(s.getAreas());
    return (areas.count(m_layer) > 0);
}
开发者ID:worldforge,项目名称:mercator,代码行数:5,代码来源:AreaShader.cpp


注:本文中的Segment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。