MCPcopy Create free account
hub / github.com/cinder/Cinder / parsePath

Function parsePath

src/cinder/svg/Svg.cpp:1332–1489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1330}
1331
1332Shape2d parsePath( const std::string &p )
1333{
1334 const char* s = p.c_str();
1335 vec2 v0, v1, v2;
1336 vec2 lastPoint, lastPoint2;
1337
1338 Shape2d result;
1339 bool done = false;
1340 bool firstCmd = true;
1341 char prevCmd = '\0';
1342 while( ! done ) {
1343 char cmd = readNextCommand( &s );
1344 switch( cmd ) {
1345 case 'm':
1346 case 'M':
1347 v0.x = parseFloat( &s ); v0.y = parseFloat( &s );
1348 if( ( ! firstCmd ) && ( cmd == 'm' ) )
1349 v0 += lastPoint;
1350 result.moveTo( v0 );
1351 lastPoint2 = lastPoint;
1352 lastPoint = v0;
1353 while( nextItemIsFloat( s ) ) {
1354 v0.x = parseFloat( &s ); v0.y = parseFloat( &s );
1355 if( cmd == 'm' )
1356 v0 += lastPoint;
1357 result.lineTo( v0 );
1358 lastPoint2 = lastPoint;
1359 lastPoint = v0;
1360 }
1361 break;
1362 case 'l':
1363 case 'L':
1364 do {
1365 v0.x = parseFloat( &s ); v0.y = parseFloat( &s );
1366 if( cmd == 'l' )
1367 v0 += lastPoint;
1368 result.lineTo( v0 );
1369 lastPoint2 = lastPoint;
1370 lastPoint = v0;
1371 } while( nextItemIsFloat( s ) );
1372 break;
1373 case 'H':
1374 case 'h':
1375 do {
1376 float x = parseFloat( &s );
1377 v0 = vec2( ( cmd == 'h' ) ? (lastPoint.x + x) : x, lastPoint.y );
1378 result.lineTo( v0 );
1379 lastPoint2 = lastPoint;
1380 lastPoint = v0;
1381 } while( nextItemIsFloat( s ) );
1382 break;
1383 case 'V':
1384 case 'v':
1385 do {
1386 float y = parseFloat( &s );
1387 v0 = vec2( lastPoint.x, ( cmd == 'v' ) ? (lastPoint.y + y) : (y) );
1388 result.lineTo( v0 );
1389 lastPoint2 = lastPoint;

Callers 1

PathMethod · 0.85

Calls 13

readNextCommandFunction · 0.85
parseFloatFunction · 0.85
nextItemIsFloatFunction · 0.85
readFlagFunction · 0.85
ellipticalArcFunction · 0.85
backMethod · 0.80
c_strMethod · 0.45
moveToMethod · 0.45
lineToMethod · 0.45
curveToMethod · 0.45
quadToMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected