//----------------------------------------------------------------------------
BspPolygon2* Boolean2D::ConstructPentagon ()
{
    const int numVertices = 5;

    double primitiveAngle = Mathd::TWO_PI/numVertices;
    double radius = 0.35*GetWidth();
    double cx = 0.5*GetWidth(), cy = 0.5*GetWidth();

    Vector2d vertices[numVertices];
    for (int i = 0; i < numVertices; ++i)
    {
        double angle = i*primitiveAngle;
        vertices[i].X() = cx + radius*Mathd::Cos(angle);
        vertices[i].Y() = cy + radius*Mathd::Sin(angle);
    }

    BspPolygon2* poly = new0 BspPolygon2();
    for (int i0 = numVertices - 1, i1 = 0; i1 < numVertices; i0 = i1++)
    {
        poly->InsertVertex(vertices[i1]);
        poly->InsertEdge(Edge2(i0, i1));
    }
    poly->Finalize();
    return poly;
}
//----------------------------------------------------------------------------
BspPolygon2* Boolean2D::ConstructInvertedEll ()
{
    double w = (double)GetWidth();
    double d1d8 = 0.125*w;
    double d2d8 = 0.250*w;
    double d3d8 = 0.375*w;
    double d5d8 = 0.625*w;
    double d6d8 = 0.750*w;
    double d7d8 = 0.875*w;

    const int numVertices = 10;
    Vector2d vertices[numVertices] =
    {
        Vector2d(d1d8, d1d8),
        Vector2d(d3d8, d1d8),
        Vector2d(d3d8, d3d8),
        Vector2d(d2d8, d3d8),
        Vector2d(d2d8, d6d8),
        Vector2d(d5d8, d6d8),
        Vector2d(d5d8, d5d8),
        Vector2d(d7d8, d5d8),
        Vector2d(d7d8, d7d8),
        Vector2d(d1d8, d7d8)
    };

    BspPolygon2* poly = new0 BspPolygon2();
    for (int i0 = numVertices - 1, i1 = 0; i1 < numVertices; i0 = i1++)
    {
        poly->InsertVertex(vertices[i1]);
        poly->InsertEdge(Edge2(i0, i1));
    }
    poly->Finalize();
    return poly;
}
Exemple #3
0
//----------------------------------------------------------------------------
BspPolygon2 BspPolygon2::operator& (const BspPolygon2& polygon) const
{
    assertion(mTree != 0, "Tree must exist.\n");

    // intersection
    BspPolygon2 intersect;
    GetInsideEdgesFrom(polygon, intersect);
    polygon.GetInsideEdgesFrom(*this, intersect);
    intersect.Finalize();
    return intersect;
}
//----------------------------------------------------------------------------
BspPolygon2* Boolean2D::ConstructSShape ()
{
    double w = (double)GetWidth();
    double d10d32 = 10.0*w/32.0;
    double d12d32 = 12.0*w/32.0;
    double d13d32 = 13.0*w/32.0;
    double d16d32 = 16.0*w/32.0;
    double d19d32 = 19.0*w/32.0;
    double d20d32 = 20.0*w/32.0;
    double d22d32 = 22.0*w/32.0;
    double d24d32 = 24.0*w/32.0;
    double d26d32 = 26.0*w/32.0;
    double d28d32 = 28.0*w/32.0;

    const int numVertices = 12;
    Vector2d vertices[numVertices] =
    {
        Vector2d(d24d32, d10d32),
        Vector2d(d28d32, d10d32),
        Vector2d(d28d32, d16d32),
        Vector2d(d22d32, d16d32),
        Vector2d(d22d32, d19d32),
        Vector2d(d24d32, d19d32),
        Vector2d(d24d32, d22d32),
        Vector2d(d20d32, d22d32),
        Vector2d(d20d32, d13d32),
        Vector2d(d26d32, d13d32),
        Vector2d(d26d32, d12d32),
        Vector2d(d24d32, d12d32)
    };

    BspPolygon2* poly = new0 BspPolygon2();
    for (int i0 = numVertices - 1, i1 = 0; i1 < numVertices; i0 = i1++)
    {
        poly->InsertVertex(vertices[i1]);
        poly->InsertEdge(Edge2(i0, i1));
    }
    poly->Finalize();
    return poly;
}
//----------------------------------------------------------------------------
BspPolygon2* Boolean2D::ConstructPolyWithHoles ()
{
    double w = (double)GetWidth();
    double d2d16 = 2.0*w/16.0;
    double d3d16 = 3.0*w/16.0;
    double d4d16 = 4.0*w/16.0;
    double d6d16 = 6.0*w/16.0;
    double d14d16 = 14.0*w/16.0;

    const int numVertices = 6;
    Vector2d vertices[numVertices] =
    {
        // outer boundary
        Vector2d(d2d16, d2d16),
        Vector2d(d14d16, d2d16),
        Vector2d(d2d16, d14d16),

        // inner boundary
        Vector2d(d4d16, d3d16),
        Vector2d(d6d16, d6d16),
        Vector2d(d6d16, d3d16)
    };

    BspPolygon2* poly = new0 BspPolygon2();
    for (int i = 0; i < numVertices; ++i)
    {
        poly->InsertVertex(vertices[i]);
    }

    poly->InsertEdge(Edge2(0, 1));
    poly->InsertEdge(Edge2(1, 2));
    poly->InsertEdge(Edge2(2, 0));
    poly->InsertEdge(Edge2(3, 4));
    poly->InsertEdge(Edge2(4, 5));
    poly->InsertEdge(Edge2(5, 3));

    poly->Finalize();
    return poly;
}
//----------------------------------------------------------------------------
BspPolygon2* Boolean2D::ConstructSquare ()
{
    double w = (double)GetWidth();
    double d2d8 = 0.250*w;
    double d6d8 = 0.750*w;

    const int numVertices = 4;
    Vector2d vertices[numVertices] =
    {
        Vector2d(d2d8, d2d8),
        Vector2d(d6d8, d2d8),
        Vector2d(d6d8, d6d8),
        Vector2d(d2d8, d6d8)
    };

    BspPolygon2* poly = new0 BspPolygon2();
    for (int i0 = numVertices - 1, i1 = 0; i1 < numVertices; i0 = i1++)
    {
        poly->InsertVertex(vertices[i1]);
        poly->InsertEdge(Edge2(i0, i1));
    }
    poly->Finalize();
    return poly;
}