int main(void)
{
    unsigned int edges[NUM_EDGE];
    int T, i;

    scanf("%d", &T);
    while(T)
    {
        for(i = 0; i < NUM_EDGE; i++)
            scanf("%d", &edges[i]);

        if(isSquare(edges))
            printf("square\n");
        else
        {
            if(isRectangle(edges))
                printf("rectangle\n");
            else
            {
                if(isQuadrangle(edges))
                    printf("quadrangle\n");
                else
                    printf("banana\n");
            }
        }
        T--;
    }
    return 0;
}
Example #2
0
ofVec2f quadWarping::getPointInSquareNormalized(ofVec2f p)
{
	OFAPPLOG->begin("quadWarping::getPointInSquareNormalized()");

	ofVec2f result;

	if (isRectangle())
	{
		OFAPPLOG->println(" is rectangle");

		float mm = (p.x - m_handles[0].x) / ( m_handles[1].x - m_handles[0].x );
		float ll = (p.y - m_handles[0].y) / ( m_handles[3].y - m_handles[0].y );

		result.set(mm, ll);
	}
	else
	{
	   computeCoeffQuadRect();
	   
	   float aa = a[3]*b[2] - a[2]*b[3];

	   float bb = a[3]*b[0] - a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + p.x*b[3] - p.y*a[3];
	   float cc = a[1]*b[0] - a[0]*b[1] + p.x*b[1] - p.y*a[1];

	   float det = sqrt( bb*bb - 4*aa*cc );
	   float mm = (-bb-det)/(2.0*aa);
	   float ll = (p.x-a[0]-a[2]*mm)/(a[1] + a[3]*mm);

	   result.set(ll,1.0f-mm);

	   OFAPPLOG->println("a = "+ofToString(a));
	   OFAPPLOG->println("b = "+ofToString(b));

	   OFAPPLOG->println("aa = "+ofToString(aa));
	   OFAPPLOG->println("bb = "+ofToString(bb));
	   OFAPPLOG->println("cc = "+ofToString(cc));
	   OFAPPLOG->println("bb*bb - 4*aa*cc = "+ofToString(bb*bb - 4*aa*cc));
	   OFAPPLOG->println("det = "+ofToString(det));
	   OFAPPLOG->println("mm = "+ofToString(mm));
	   OFAPPLOG->println("a[1] + a[3]*mm = "+ofToString(a[1] + a[3]*mm));
	   OFAPPLOG->println("ll = "+ofToString(mm));
	
	}

	OFAPPLOG->end();

	return result;
}
Example #3
0
/*public*/
bool
Geometry::covers(const Geometry* g) const
{
#ifdef SHORTCIRCUIT_PREDICATES
	// short-circuit test
	if (! getEnvelopeInternal()->contains(g->getEnvelopeInternal()))
		return false;
#endif
	// optimization for rectangle arguments
	if (isRectangle()) {
		return getEnvelopeInternal()->contains(g->getEnvelopeInternal());
	}

	auto_ptr<IntersectionMatrix> im(relate(g));
	return im->isCovers();
}
Example #4
0
bool
Geometry::contains(const Geometry *g) const
{
#ifdef SHORTCIRCUIT_PREDICATES
	// short-circuit test
	if (! getEnvelopeInternal()->contains(g->getEnvelopeInternal()))
		return false;
#endif

	// optimization for rectangle arguments
	if (isRectangle()) {
		return predicate::RectangleContains::contains((Polygon&)*this, *g);
	}
	if (g->isRectangle()) {
		return predicate::RectangleContains::contains((const Polygon&)*g, *this);
	}

	IntersectionMatrix *im=relate(g);
	bool res=im->isContains();
	delete im;
	return res;
}
Example #5
0
bool
Geometry::intersects(const Geometry *g) const
{
#ifdef SHORTCIRCUIT_PREDICATES
	// short-circuit test
	if (! getEnvelopeInternal()->intersects(g->getEnvelopeInternal()))
		return false;
#endif

	/**
	 * TODO: (MD) Add optimizations:
	 *
	 * - for P-A case:
	 * If P is in env(A), test for point-in-poly
	 *
	 * - for A-A case:
	 * If env(A1).overlaps(env(A2))
	 * test for overlaps via point-in-poly first (both ways)
	 * Possibly optimize selection of point to test by finding point of A1
	 * closest to centre of env(A2).
	 * (Is there a test where we shouldn't bother - e.g. if env A
	 * is much smaller than env B, maybe there's no point in testing
	 * pt(B) in env(A)?
	 */

	// optimization for rectangle arguments
	if (isRectangle()) {
		return predicate::RectangleIntersects::intersects((Polygon&)*this, *g);
	}
	if (g->isRectangle()) {
		return predicate::RectangleIntersects::intersects((const Polygon&)*g, *this);
	}

	IntersectionMatrix *im=relate(g);
	bool res=im->isIntersects();
	delete im;
	return res;
}
Example #6
0
//--------------------------------------------------------------
ofVec2f quadWarping::getPointInQuad(ofVec2f pNormalized)
{
	ofVec2f result;

	if (isRectangle())
	{
		result.x = m_handles[0].x + pNormalized.x * (m_handles[1].x - m_handles[0].x);
		result.y = m_handles[1].y + pNormalized.y * (m_handles[3].y - m_handles[0].y);
	}
	else
	{
		float ll = pNormalized.x;
		float mm = 1.0f-pNormalized.y;

		computeCoeffQuadRect();

		result.x = a[0] + a[1]*ll + a[2]*mm + a[3]*ll*mm;
		result.y = b[0] + b[1]*ll + b[2]*mm + b[3]*ll*mm;
	}

 
	return result;
}
Example #7
0
void asciimage::Shape::renderPolygon(QPainter* painter, int scale, const Style& style) const
{
    Q_ASSERT(type() == Type::POLYGON);

    if (!style.isClosed())
    {
        renderLines(painter, scale, style);
        return;
    }

    Q_ASSERT(points().size() >= 3);

    if (isRectangle() && style.isFilled())
    {
        const QRect b = boundingRect();
        painter->setPen(style.color());
        painter->setBrush(style.color());
        painter->drawRect(scaledOuterRect(b, scale));
    }
    else
    {
        QPolygonF poly;
        for (const QPoint& point : points())
        {
            poly << p(point, scale);
        }
        poly << p(points().first(), scale);

        painter->setRenderHint(QPainter::Antialiasing, true);
        painter->setPen(QPen(style.color(), scale, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
        if (style.isFilled())
        {
            painter->setBrush(style.color());
        }
        painter->drawPolygon(poly);
    }
}
Example #8
0
void testGeometry() {
    cout << "running testGeometry" << endl;
    cout << "Creating Variables" << endl;

    // Variable Declarations
    // Points
    const Point a = Point(0, 0), b = Point(100, 100), c = Point(0, 100);
    const Point e = Point(200, 0), d = Point(100, 0), f = Point(100, 200);
    // Poly's
    const cnt tri {a, e, b};  // non-equal sides
    const cnt square {a, c, b, d};
    const cnt rect {a, c*2, f, d};
    const cnt bigSquare {a*2-b, c*2-b, b*2-b, d*2-b};
    // Fp's
    const Fp testFp1 = Fp({bigSquare, square});
    const Fp testFp2 = Fp({bigSquare});  // not a valid Fp
    const Fp testFp3 = Fp({square});  // not a valid Fp

    cout << "Creating Vectors" << endl;

    // Vectors
    // Poly's
    const vector<cnt> vpoly1 {tri, square, bigSquare};
    const vector<cnt> vpoly2 {tri, square};
    const vector<cnt> vpoly3 {square, bigSquare};
    const vector<cnt> vpoly4 {tri, bigSquare};
    const vector<cnt> vpoly5 {tri};
    const vector<cnt> vpoly6 {square};
    const vector<cnt> vpoly7 {bigSquare};
    // Fp's
    const vector<Fp> vfp1 {testFp1, testFp2, testFp3};
    const vector<Fp> vfp2 {testFp1, testFp2};
    const vector<Fp> vfp3 {testFp2, testFp3};
    const vector<Fp> vfp4 {testFp1, testFp3};
    const vector<Fp> vfp5 {testFp1};
    const vector<Fp> vfp6 {testFp2};
    const vector<Fp> vfp7 {testFp3};

    cout << "Test Methods..." << endl;

    // Test Methods
    // Centroid
    Point tric = centroid(tri);
    Point squarec = centroid(square);
    Point bigsc = centroid(bigSquare);
    cout << "Triangle" << tostr(tri) << tostr(tric) << endl;
    cout << "Square" << tostr(square) << tostr(squarec) << endl;
    cout << "Big Square" << tostr(bigSquare) << tostr(bigsc) << endl;
    cout << "Square & BigSquare Centroid: " << tostr(centroid(vpoly3)) << endl;

    // Dist & Angs
    vector<double> dts = dists(tri);
    vector<double> ans = angles(tri);
    cout << "Triangle lengths: " << vtostr(dts) << endl;
    cout << "Triangle angles: " << vtostr(ans) << endl;
    cout << "Unit Angle: " << "Origin - " << tostr(a) << "; Point - " << tostr(b) << "; Ang - " << angle(a,b) << endl;

    // All same length
    cout << "Triangle all same length? " << allSameLength(tri, (double)0.0) << endl;
    cout << "Square all same length? " << allSameLength(square, (double)0.0) << endl;

    // isPoly
    bool test1 = isPoly(tri, 3, false, false, 0, 0);  // True
    bool test2 = isPoly(tri, 3, true, true, 0, 0);  // False
    bool test3 = isPoly(tri, 4, false, false, 0, 0);  // False
    bool test4 = isRectangle(rect, false, 0, 0);  // True
    bool test5 = isRectangle(rect, true, 0, 0);  // False
    bool test6 = isSquare(square, 0, 0);  // True
    cout << test1 << test2 << test3 << test4 << test5 << test6 << endl;
}