inline string ToString(int n)
	{
		Ratio *r = Ratio::FromValue(Value, n);
		string s = r->ToString();
		delete r;
		return s;
	}
Beispiel #2
0
int main(int argc, char **argv) {
   MessageQueue mq;
	 Slow s;
	 Fast f;
	 Ratio r;
	 cout << "Add Publishers " << endl;
	 mq.add_publisher(&s);
	 mq.add_publisher(&f);
	 cout << "Add Subscribers" << endl;
	 mq.add_subscriber((r.get_blackboard()));
	 cout <<  "Subscibing.." << endl;
	 mq.subscribe("global",r.get_blackboard(),2);
	 cout << "start threads" << endl;
	 mq.start();
	 s.start();
	 f.start();
	 r.start();
	 cout << "Wait for joing" << endl;
	 s.join();
	 f.join();
	 r.join();
	 
	 mq.join();
	 cout << "Exiting.. " << endl;
	 return 0;
return 0;
}
	inline double Calculate(double value, int n)
	{
		double p1 = LowerBound->ToDouble(n);
		double p2 = UpperBound->ToDouble(n);
		double x = p1 + value * (p2 - p1);
		return IsDiscrete ? int(x+.5) : x;
	}
Beispiel #4
0
int main () {
	Ratio x (22, 7);
	cout << "x= ";
	x.print();
	cout << "x= " << x.convert() << endl;
	x.invert();
	cout << "x/1= ";
	x.print();
	cout << endl;

}
 static inline void analyze(Ratio const& r,
     int& in_segment_count,
     int& on_end_count,
     int& outside_segment_count)
 {
     if (r.on_end())
     {
         on_end_count++;
     }
     else if (r.in_segment())
     {
         in_segment_count++;
     }
     else
     {
         outside_segment_count++;
     }
 }
    static inline int arrival_value(Ratio const& r_from, Ratio const& r_to)
    {
        //     a1--------->a2
        // b1----->b2
        // a departs: -1

        // a1--------->a2
        //         b1----->b2
        // a arrives: 1

        // a1--------->a2
        //     b1----->b2
        // both arrive there -> r-to = 1/1, or 0/1 (on_segment)

        // First check the TO (for arrival), then FROM (for departure)
        return r_to.in_segment() ? 1
            : r_to.on_segment() ? 0
            : r_from.on_segment() ? -1
            : -1
            ;
    }
Beispiel #7
0
 static inline bool apply(Ratio const& lhs, Ratio const& rhs)
 {
     BOOST_ASSERT(lhs.denominator() != 0);
     BOOST_ASSERT(rhs.denominator() != 0);
     return lhs.numerator() * rhs.denominator()
          < rhs.numerator() * lhs.denominator();
 }
Beispiel #8
0
 static inline bool apply(Ratio const& lhs, Ratio const& rhs)
 {
     BOOST_ASSERT(lhs.denominator() != 0);
     BOOST_ASSERT(rhs.denominator() != 0);
     return geometry::math::equals
         (
             lhs.numerator() * rhs.denominator(),
             rhs.numerator() * lhs.denominator()
         );
 }
Beispiel #9
0
int main(){
	Ratio x;
	x.assign(22,7);
	cout << "x = ";
	x.print();
	cout << " = " << x.convert() << endl;
	x.invert();
	cout << "1/x = "; x.print();
	cout << endl;
}
Beispiel #10
0
void ScrollWindow::go(const Ratio location) {
	const int line = (location * _numLines).toInt();
	if (line < 0 || line > _numLines) {
		error("Index is Out of Range in ScrollWindow");
	}

	_firstVisibleChar = _startsOfLines[line];
	update(true);

	// HACK:
	// It usually isn't possible to set _topVisibleLine >= _numLines, and so
	// update() doesn't. However, in this case we should set _topVisibleLine
	// past the end. This is clearly visible in Phantasmagoria when dragging
	// the slider in the About dialog to the very end. The slider ends up lower
	// than where it can be moved by scrolling down with the arrows.
	if (location.isOne()) {
		_topVisibleLine = _numLines;
	}
}
Beispiel #11
0
void FractionBaseWidget::paintRatio(QPainter & paint, Ratio tmp_ratio, int & x_pos, int & y_pos, QFontMetrics & fm, bool show_mixed, bool addMargin, bool show_center)
{
    QPen pen = paint.pen(); // get the pen
    int fontHeight = fm.lineSpacing(); // get the font height

    int int_numerator, int_denominator, int_mixed;
    QString str_numerator, str_denominator;
    QString str_mixed;

    int fontWidth; // to store the width of the last thing painted
    int tmp_int;

    // check if we have to show the ratio as mixed number
    //         11            1
    // if yes, -- becomes  2 -
    //         5             5
    int_numerator = tmp_ratio.numerator();
    int_denominator = tmp_ratio.denominator();
    if (show_mixed == true && qAbs(int_numerator) >= qAbs(int_denominator)) {
        // calculate the mixed number
        int_mixed = int (int_numerator / int_denominator);

        // the negative sign is in front of the mixed number
        int_numerator = qAbs(int_numerator);
        int_denominator = qAbs(int_denominator);

        // we have to reduce the numerator by the mixed number * denominator
        int_numerator = int_numerator % int_denominator;

        // now we can convert the numbers into strings for painting
        str_mixed.setNum(int_mixed);
        str_numerator.setNum(int_numerator);
        str_denominator.setNum(int_denominator);

        // paint the front part of the mixed number
        paintMiddle(paint, str_mixed, x_pos, y_pos, fm, m_colorNumber);
    } else {

        // don't show the ratio as mixed number
        str_numerator.setNum(int_numerator);
        str_denominator.setNum(int_denominator);
    } // if (show_mixed == true && qAbs(int_numerator) > qAbs(int_denominator))

    // get the text width of the current ratio
    fontWidth = fm.width(str_numerator);
    tmp_int = fm.width(str_denominator);
    if (tmp_int > fontWidth)
        fontWidth = tmp_int;

    // show numerator and denominator in m_colorNumber
    pen.setColor(m_colorNumber);
    paint.setPen(pen);

    // make sure we don't display something like:   0
    //                                            7 -
    //                                              3
    if (!(show_mixed == true && int_numerator == 0)) {
        if (show_center == true)
            x_pos = 80 - fontWidth / 2;
        if (!(int_denominator == 1 && show_mixed == false)) {
            // paint the numerator
            paint.drawText(x_pos, y_pos, fontWidth, fontHeight, Qt::AlignCenter, str_numerator);
            // paint the fraction line between numerator and denominator
            paint.fillRect(x_pos, y_pos + fontHeight + 4, fontWidth, 2, m_colorLine);
            // paint the denominator
            paint.drawText(x_pos, y_pos + fontHeight + 10, fontWidth, fontHeight, Qt::AlignCenter, str_denominator);
        } else {
            // paint the numerator and move the y position down to align with the + signal
            paint.drawText(x_pos, y_pos + fontHeight - fontHeight / 2, fontWidth,
                           fontHeight, Qt::AlignCenter, str_numerator);
        }

        // move the x position to the right by adding the width used for painting
        // the ratio and a margin
        x_pos += fontWidth;

        if (addMargin == true)
            x_pos += _MARGIN_X;
    }

    return;
}
Beispiel #12
0
RatioPosition::RatioPosition(const Ratio &y, const Ratio &x, int) :
 	 _y(y.longVal(), 0), _x(x.longVal(), 0)
{
}
Beispiel #13
0
 static inline bool apply(Ratio const& lhs, Ratio const& rhs)
 {
     return boost::rational<Type>(lhs.numerator(), lhs.denominator())
         == boost::rational<Type>(rhs.numerator(), rhs.denominator());
 }