我有这个方法:
-(CGPoint) getPointOnaLine: (CGPoint) p1: (CGPoint) p2: (int) dt {
CGPoint tempPoint;
float myY = p1.y;
float len = getLineLength( p1, p2 );
float res = 1000;
// do not bother with calculation with small widths
if ( dt == 0 )
return p1;
if ( len < (2 / res ) )
return p2;
float increm = len / res;
// int min = 2;
float dY = p2.y - p1.y;
float dx = p2.x - p1.x;
if ( dx != 0 ) { // slope is infinite
float slope = dY / dx;
float b = p1.y - slope * p1.x;
if ( p1.x < p2.x ) {
for ( float i= p1.x; i<=p2.x; i=i+increm ) {
myY = (slope * i + b);
tempPoint = ccp(i,myY);
len = getLineLength( p1, tempPoint);
if ( len >= dt)
return tempPoint;
}
} else if ( p1.x > p2.x )
for ( float i= p2.x; i<=p1.x; i=i+increm) {
myY = (slope * i + b);
tempPoint = ccp(i,myY);
len = getLineLength( p2, tempPoint);
if ( len >= dt )
return tempPoint;
}
} else {
return p2;
}
return p1;
}
我在另一种方法中使用它:
CGPoint b1, b2, pt;
b1 = getPointOnaLine(originalPoint, bezierPoint, (int)t*stepLine1);
b2 = getPointOnaLine(bezierPoint, targetPoint, (int)t*stepLine2);
bLen = getLineLength(b1,b2);
stepLine3 = bLen / frames;
pt = getPointOnaLine(b1,b2,(int)self.tCGPoint b1, b2, pt;
编译器不断告诉我“赋值中的不兼容类型”,其中我声明了b1,b2和pt。界面是:
-(CGPoint) getPointOnaLine: (CGPoint) p1: (CGPoint) pt2: (int) dt;
如果删除作业,它只会给我一个隐式声明警告。我真的很困惑为什么这不会编译。
克里斯
答案 0 :(得分:2)
你已经定义了一个方法(虽然有一些奇怪的未命名参数)但是你把它称为一个函数。
尝试:
b1 = [self getPointOnaLine:originalPoint :bezierPoint :(int)t*stepLine1];
(更好的是,使用参数名称声明它,使您的未来自我阅读更容易。)
答案 1 :(得分:0)
您正在以c函数样式调用objective-c消息,而不是将其用作
b1 = [self getPointOnaLine:originalPoint :bezierPoint :(int)t*stepLine1];
b2 = [self getPointOnaLine:bezierPoint :targetPoint :(int)t*stepLine2];
如果b1和b2在同一个类中初始化,则self将被定义了getPointOnaLine:bezierPoint
方法的对象替换。