Skip to content

Commit

Permalink
improve group finding
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarSaharoy committed Oct 15, 2024
1 parent c22b135 commit e8b61a7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions js/construct-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { infoLog, successLog, errorLog } from "./log.js"
import { getVerts, getTransforms } from "./parse-svg.js"


const containsPathsOnly = elm => [...elm.children].every( child => child.matches("path") );
const containsPathsOnly = elm => elm.childElementCount > 0 && [...elm.children].every( child => child.matches("path") );
const containsOneGroup = elm => [...elm.children].filter( child => child.matches("g") ).length === 1;
const containsOnePath = elm => [...elm.children].filter( child => child.matches("path") ).length === 1;
const containsOneOf = candidates => elm => candidates.filter( candidate => elm.contains(candidate) ).length === 1;
Expand All @@ -29,14 +29,15 @@ function getKeyAndSubdivisionRule( subdivisionOuterGroup ) {

export function constructRules( svg, filename ) {

infoLog(`Finding inner subdivision groups...`);

infoLog(`Finding subdivision groups...`);
const groups = [ ...svg.querySelectorAll( "g" ) ];
const subdivisionInnerGroups = groups.filter( containsPathsOnly );
successLog(`Found ${groups.length} subdivision groups!`);

infoLog(`Finding inner subdivision groups...`);
const subdivisionInnerGroups = groups.filter( containsPathsOnly );
successLog(`Found ${subdivisionInnerGroups.length} inner subdivision groups!`);
infoLog(`Finding outer subdivision groups...`);

infoLog(`Finding outer subdivision groups...`);
const subdivisionOuterGroups =
groups
.filter( containsOneGroup )
Expand Down

0 comments on commit e8b61a7

Please sign in to comment.