Commit 76dbbcef authored by Libor's avatar Libor
Browse files

Templated data types - Real and Index.

parent 8c6b8199
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
#ifndef _TNLAREA2D_H_INCLUDED_
#define _TNLAREA2D_H_INCLUDED_

template< typename Real >
class tnlArea2D
{
public:
    tnlArea2D( unsigned startX,
               unsigned endX,
               unsigned startY,
               unsigned endY );
    tnlArea2D( Real startX,
               Real endX,
               Real startY,
               Real endY );

    unsigned getStartX();
    Real getStartX();

    unsigned getEndX();
    Real getEndX();

    unsigned getLengthX();
    Real getLengthX();

    unsigned getStartY();
    Real getStartY();

    unsigned getEndY();
    Real getEndY();

    unsigned getLengthY();
    Real getLengthY();

    ~tnlArea2D(){};

private:
    unsigned startX;
    unsigned endX;
    unsigned startY;
    unsigned endY;
    Real startX;
    Real endX;
    Real startY;
    Real endY;
};

#include "tnlArea2D_impl.h"
+17 −10
Original line number Diff line number Diff line
@@ -3,10 +3,11 @@

#include "tnlArea2D.h"

tnlArea2D::tnlArea2D( unsigned startX,
                      unsigned endX,
                      unsigned startY,
                      unsigned endY )
template< typename Real >
tnlArea2D< Real >::tnlArea2D( Real startX,
                              Real endX,
                              Real startY,
                              Real endY )
{
    this->startX = startX;
    this->endX = endX;
@@ -14,32 +15,38 @@ tnlArea2D::tnlArea2D( unsigned startX,
    this->endY = endY;
}

unsigned tnlArea2D::getStartX()
template< typename Real >
Real tnlArea2D< Real >::getStartX()
{
    return this->startX;
}

unsigned tnlArea2D::getEndX()
template< typename Real >
Real tnlArea2D< Real >::getEndX()
{
    return this->endX;
}

unsigned tnlArea2D::getLengthX()
template< typename Real >
Real tnlArea2D< Real >::getLengthX()
{
    return this->endX - this->startX;
}

unsigned tnlArea2D::getStartY()
template< typename Real >
Real tnlArea2D< Real >::getStartY()
{
    return this->startY;
}

unsigned tnlArea2D::getEndY()
template< typename Real >
Real tnlArea2D< Real >::getEndY()
{
    return this->endY;
}

unsigned tnlArea2D::getLengthY()
template< typename Real >
Real tnlArea2D< Real >::getLengthY()
{
    return this->endY - this->startY;
}
+8 −7
Original line number Diff line number Diff line
#ifndef _TNLCIRCLE2D_H_INCLUDED_
#define _TNLCIRCLE2D_H_INCLUDED_

template< typename Real >
class tnlCircle2D
{
public:
@@ -8,15 +9,15 @@ public:
                 unsigned b,
                 unsigned r );

    bool isIntercept( float x1,
                      float x2,
                      float y1,
                      float y2,
    bool isIntercept( Real x1,
                      Real x2,
                      Real y1,
                      Real y2,
                      bool verbose = false );

    bool isInInterval( float x1,
                       float x2,
                       float x );
    bool isInInterval( Real x1,
                       Real x2,
                       Real x );

    ~tnlCircle2D();

+16 −13
Original line number Diff line number Diff line
@@ -5,7 +5,8 @@
#include <cmath>
#include "tnlCircle2D.h"

tnlCircle2D::tnlCircle2D( unsigned a,
template< typename Real >
tnlCircle2D< Real >::tnlCircle2D( unsigned a,
                                  unsigned b,
                                  unsigned r )
{
@@ -14,10 +15,11 @@ tnlCircle2D::tnlCircle2D( unsigned a,
    this->r = r;
}

bool tnlCircle2D::isIntercept( float x1,
                               float x2,
                               float y1,
                               float y2,
template< typename Real >
bool tnlCircle2D< Real >::isIntercept( Real x1,
                                       Real x2,
                                       Real y1,
                                       Real y2,
                                       bool verbose )
{
    if( this->isInInterval( x1, x2, this->a - this->r ) &&
@@ -32,9 +34,9 @@ bool tnlCircle2D::isIntercept( float x1,
    else if( verbose )
        std::cout << "Circle is not inside area." << std::endl;

    float R = this->r * this->r;
    Real R = this->r * this->r;

    float aux = x1 - this->a;
    Real aux = x1 - this->a;
    if( R - aux * aux >= 0 &&
        ( this->isInInterval( y1, y2, sqrt( R - aux * aux ) + this->b ) ||
        this->isInInterval( y1, y2, -sqrt( R - aux * aux ) + this->b ) ) )
@@ -80,9 +82,10 @@ bool tnlCircle2D::isIntercept( float x1,
    return false;
}

bool tnlCircle2D::isInInterval( float x1,
                                float x2,
                                float x )
template< typename Real >
bool tnlCircle2D< Real >::isInInterval( Real x1,
                                        Real x2,
                                        Real x )
{
    return ( ( x1 <= x ) and ( x <= x2 ) );
}
+18 −16
Original line number Diff line number Diff line
@@ -3,33 +3,35 @@

#include "tnlNode.h"

template< int LogX,
          int LogY = LogX >
class tnlInternalNode : public tnlNode< LogX, LogY >
template< typename Real,
          typename Index,
          Index LogX,
          Index LogY = LogX >
class tnlInternalNode : public tnlNode< Real, Index, LogX, LogY >
{
public:
    tnlInternalNode( tnlArea2D* area,
                     tnlCircle2D* circle,
                     int X,
                     int Y,
                     int level );
    tnlInternalNode( tnlArea2D< Real >* area,
                     tnlCircle2D< Real >* circle,
                     Index X,
                     Index Y,
                     Index level );

    void setNode( int splitX,
                  int splitY,
                  int depth );
    void setNode( Index splitX,
                  Index splitY,
                  Index depth );

    void setChildren( int splitX,
                      int splitY,
                      int depth );
    void setChildren( Index splitX,
                      Index splitY,
                      Index depth );

    void write( fstream& f,
                int level );
                Index level );

    ~tnlInternalNode();

private:
    tnlBitmaskArray< LogX * LogY >* bitmaskArray;
    tnlNode< LogX, LogY >* children[ LogX * LogY ];
    tnlNode< Real, Index, LogX, LogY >* children[ LogX * LogY ];
};


Loading