/* * binarygrid.cpp * * Created on: 8 nov. 2014 * Author: rene */ #include #include "element.h" #include "binarygrid.h" /* * */ BinaryGrid::BinaryGrid( Diagram* d ) { diagram = d; reset(); } /* * */ BinaryGrid::~BinaryGrid() { } /* * */ QString reverse( QString s ) { QString ret = ""; const int nb = s.count(); for(int i=0; i elements = diagram -> elements(); for ( int i=0; i terminals().size() == 0 ) continue; vec2d topLeft, bottomRight; rect2side( &topLeft, &bottomRight, element -> boundingRectTrue() ); add2grid( topLeft, bottomRight, 3 ); QList conductors = element->conductors(); const int nb = conductors.size(); for( int i=0; i 8 bits ??? if ( uMask == 64 ) mask[n] = (U64)-1; for( int i=0; i 8 bits ??? if ( uMask == 64 ) mask[n] = (U64)-1; for( int i=0; i v2.x || v1.y > v2.y ) { vec2d v = vec2d( v1 ); v1 = v2; v2 = v; } } /* * */ void BinaryGrid::add2grid( Conductor* pConductor ) { QList vec2ds = pConductor -> getVec2ds(); const int nb = vec2ds.size() - 1; for( int i=0; iscenePos()) ); vec2d v2 = vec2d( vec2ds[i+1] + vec2d(pConductor->scenePos()) ); orderVect( v1, v2 ); vec2d vDir = vec2d( v1, v2 ); if ( vDir.dot( vec2d(0.0,1.0) ) == 0 ) add2grid( v1, v2, VERT); else add2grid( v1, v2, HORI ); } } /* * */ bool BinaryGrid::testMask( U64* mask, int lineBeg, int lineEnd, int map ) { for ( int i=lineBeg; i<=lineEnd; i++ ) { for( int j=0; j<5; j++ ) { U64 val = 0; if ( (map & HORI) == HORI ) val = bitHrzt[i][j]; if ( (map & VERT) == VERT ) val = bitVrtc[i][j]; if ( (val|mask[j]) != (val^mask[j]) ) return true; } } return false; } /* * */ bool BinaryGrid::test( vec2d p1, vec2d p2 ) { qDebug() <<"BinaryGrid::test"; orderVect( p1, p2 ); // printVec2d( "p1 : ", p1 ); // printVec2d( "p2 : ", p2 ); double left = vec2d(p1).mul(vec2d(1.0,0.0)).addCoord(); double right = vec2d(p2).mul(vec2d(1.0,0.0)).addCoord(); double top = vec2d(p1).mul(vec2d(0.0,1.0)).addCoord(); double bottom = vec2d(p2).mul(vec2d(0.0,1.0)).addCoord(); int map; vec2d vDir = vec2d( p1, p2 ); if ( vDir.dot( vec2d(0.0,1.0) ) == 0 ) map = HORI; else map = VERT; // compute mask 0 and mask 1 U64 M0[5]; computeFirstMask( left, M0 ); U64 M1[5]; computeSecondMask( right, M1 ); // mask = mask0 xor mask1 U64 mask[5]; for( int i=0; i<5; i++ ) mask[i] = M0[i] ^ M1[i]; int idx0 = computeFirstLine(top); int idx1 = computeLastLine(bottom); // qDebug() << "idx 0 : "<< idx0; // qDebug() << "idx 1 : "<< idx1; // // debugGrid( idx0-2, idx1+2); return testMask( mask, idx0, idx1, map ); } /* * */ bool BinaryGrid::computeMinSegment( vec2d p1, vec2d p2 ) { qDebug() <<"BinaryGrid::test"; orderVect( p1, p2 ); // printVec2d( "p1 : ", p1 ); // printVec2d( "p2 : ", p2 ); double left = vec2d(p1).mul(vec2d(1.0,0.0)).addCoord(); double right = vec2d(p2).mul(vec2d(1.0,0.0)).addCoord(); double top = vec2d(p1).mul(vec2d(0.0,1.0)).addCoord(); double bottom = vec2d(p2).mul(vec2d(0.0,1.0)).addCoord(); int map; vec2d vDir = vec2d( p1, p2 ); if ( vDir.dot( vec2d(0.0,1.0) ) == 0 ) map = HORI; else map = VERT; // compute mask 0 and mask 1 U64 M0[5]; computeFirstMask( left, M0 ); U64 M1[5]; computeSecondMask( right, M1 ); // mask = mask0 xor mask1 U64 mask[5]; for( int i=0; i<5; i++ ) mask[i] = M0[i] ^ M1[i]; int idx0 = computeFirstLine(top); int idx1 = computeLastLine(bottom); // qDebug() << "idx 0 : "<< idx0; // qDebug() << "idx 1 : "<< idx1; // // debugGrid( idx0-2, idx1+2); return testMask( mask, idx0, idx1, map ); }