ios - Split UIBezierPath -
i'm having trouble figuring out how implement following requirement:
users allowed draw arbitrary uibezierpath made bunch of points (which have available), can this:
now need able delete of intersections of curve. in end results like:
however need figuring out how this. @ first instance tried code similar 1 (warning: test, might not correct or crash).
-(void)splitpaths:(nsmutablearray *)sourcepoints paths:(nsmutablearray *)paths { nslog(@"splitting points: %d",sourcepoints.count); for(int i= 0; < sourcepoints.count ; i++) { cgpoint pointone = [[sourcepoints objectatindex:i] cgpointvalue]; for(int j= i+1; j< sourcepoints.count; j++) { cgpoint pointtwo = [[sourcepoints objectatindex:j] cgpointvalue]; if(cgpointequaltopoint(pointone, pointtwo)) { nsrange initialrange = nsmakerange(0, i); nsrange pathrange = nsmakerange(i, j - i); nsrange finalrange = nsmakerange(j, sourcepoints.count - 1); nsarray *firstarray = [sourcepoints subarraywithrange:initialrange]; nsarray *patharray = [sourcepoints subarraywithrange:pathrange]; nsarray *finalarray = [sourcepoints subarraywithrange:finalrange]; [paths addobject:patharray]; nsmutablearray *remainingpoints = [nsmutablearray arraywitharray:[firstarray arraybyaddingobjectsfromarray:finalarray]]; [self splitpaths:remainingpoints paths:paths]; } } } }
which recursive function split each "segment" of curve. hope can idea of i'm trying do... seems don't have points accurate enough cgpointequaltopoint return yes.
so question if got idea on how achieve this. or maybe better algorithm or example. great. lot.
Comments
Post a Comment