You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had a hard time to integrate your lib into my swift project,
(problems with extension translated to unrecongnised convenience init)
So after a while i decided to translate the interpolateCGPointsWithHermite in native swift 2+
I won't do a pull request as it is not appropriated (my opinion)
but I can share that here
I made an extension out of it (as a static helper) it could have been a convenience init or a fully static helper (the choice is your)
extensionUIBezierPath{staticfunc interpolateHermiteFor(points:[CGPoint], closed:Bool= false)->UIBezierPath{
guard points.count >=2else{returnUIBezierPath()}
if points.count ==2{letbezierPath=UIBezierPath()
bezierPath.moveToPoint(points[0])
bezierPath.addLineToPoint(points[1])return bezierPath
}letnCurves= closed ? points.count : points.count -1letpath=UIBezierPath()
for i in 0..<nCurves {varcurPt=points[i]varprevPt:CGPoint,nextPt:CGPoint,endPt:CGPoint
if i ==0{
path.moveToPoint(curPt)}varnexti=(i+1)%points.count
varprevi=(i-1<0? points.count-1 : i-1)
prevPt =points[previ]
nextPt =points[nexti]
endPt = nextPt
varmx:CGFloatvarmy:CGFloat
if closed || i >0{
mx =(nextPt.x - curPt.x)* CGFloat(0.5)
mx +=(curPt.x - prevPt.x)* CGFloat(0.5)
my =(nextPt.y - curPt.y)* CGFloat(0.5)
my +=(curPt.y - prevPt.y)* CGFloat(0.5)}else{
mx =(nextPt.x - curPt.x)* CGFloat(0.5)
my =(nextPt.y - curPt.y)* CGFloat(0.5)}varctrlPt1= CGPointZero
ctrlPt1.x = curPt.x + mx / CGFloat(3.0)
ctrlPt1.y = curPt.y + my / CGFloat(3.0)
curPt =points[nexti]
nexti =(nexti +1)% points.count
previ = i;
prevPt =points[previ]
nextPt =points[nexti]
if closed || i < nCurves-1{
mx =(nextPt.x - curPt.x)* CGFloat(0.5)
mx +=(curPt.x - prevPt.x)* CGFloat(0.5)
my =(nextPt.y - curPt.y)* CGFloat(0.5)
my +=(curPt.y - prevPt.y)* CGFloat(0.5)}else{
mx =(curPt.x - prevPt.x)* CGFloat(0.5)
my =(curPt.y - prevPt.y)* CGFloat(0.5)}varctrlPt2= CGPointZero
ctrlPt2.x = curPt.x - mx / CGFloat(3.0)
ctrlPt2.y = curPt.y - my / CGFloat(3.0)
path.addCurveToPoint(endPt, controlPoint1:ctrlPt1, controlPoint2:ctrlPt2)}
if closed {
path.closePath()}return path
}}
nb: it takes an array of CGPoint as you can do that in swift
The text was updated successfully, but these errors were encountered:
I had a hard time to integrate your lib into my swift project,
(problems with extension translated to unrecongnised convenience init)
So after a while i decided to translate the
interpolateCGPointsWithHermite
in native swift 2+I won't do a pull request as it is not appropriated (my opinion)
but I can share that here
I made an extension out of it (as a static helper) it could have been a convenience init or a fully static helper (the choice is your)
nb: it takes an array of CGPoint as you can do that in swift
The text was updated successfully, but these errors were encountered: