Question

I want to find points between two CGPoint that lies in the same line. I use slope and x, CGPoints between p1.x and p2.x, to calculate y and than I make an CGPoint from new x and y and finally add it to the result array. but I got this error.

[__NSArrayM CGPointValue]: unrecognized selector sent to instance 0xa08e910 'NSInvalidArgumentException', reason: '-[__NSArrayM CGPointValue]: unrecognized selector sent to instance 0xa08e910'

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

CGPoint p5=CGPointMake(158, 339.5);
CGPoint p6=CGPointMake(156.5, 339.5);
CGPoint p7=CGPointMake(65.5, 312);
CGPoint p8=CGPointMake(44.5, 101);

[pointsinbetween addObject:[NSValue valueWithCGPoint:p5]];
[pointsinbetween addObject:[NSValue valueWithCGPoint:p6]];
[pointsinbetween addObject:[NSValue valueWithCGPoint:p7]];
[pointsinbetween addObject:[NSValue valueWithCGPoint:p8]];
NSLog(@"points in between %@",[self extendedarray:pointsinbetween]);

   }


-(float)slopeCalculator:(CGPoint)firstpoint params:(CGPoint)secondpoint
{
    float tempx=firstpoint.x-secondpoint.x;
    float tempy=firstpoint.y-secondpoint.y;
    if ((tempy>0) && (tempx>0)) {
        return tempy/tempx;
    }
    else{
        return 0;
    }

}

-(NSMutableArray*)findpointnewversion:(CGPoint)firstpoint param:(CGPoint)secpoint nextparam:(float)slope
    {
        NSMutableArray *pointset=[[NSMutableArray alloc]init];
        float y;
        float j=firstpoint.x+0.5;
        int inty;
        while (j< secpoint.x) {

            y=slope*j-slope*firstpoint.x-firstpoint.y;
            float fractional=y-truncf(y);
            if ((y>0) && (slope!=0)) {
                if (fractional>0.5) {
                    inty=(int)y;
                    inty++;
                    CGPoint ptemp=CGPointMake(j,inty);
                    [pointset addObject:[NSValue valueWithCGPoint:ptemp]];
                }
                else{
                    inty=(int)y;
                    CGPoint ptemp=CGPointMake(j,inty);
                    [pointset addObject:[NSValue valueWithCGPoint:ptemp]];

                }

            }
            j=j+0.5;
        }
        return pointset;

}
-(NSMutableArray*)extendedarray:(NSMutableArray*)param
{
    NSMutableArray *extendset=[[NSMutableArray alloc]init];
    int j=0;
    while (j<=param.count) {
        CGPoint p1=CGPointFromString([param objectAtIndex:j]);
        j++;
        CGPoint p2=CGPointFromString([param objectAtIndex:j]);
        j++;
        float slope=[self slopeCalculator:p1 params:p2];
        if (p1.x<p2.x) {
            [extendset addObjectsFromArray:[self findpointnewversion:p1 param:p2 nextparam:slope]];
        } else {
            [extendset addObjectsFromArray:[self findpointnewversion:p2 param:p1 nextparam:slope]];
        }
    }    return extendset;
}
Was it helpful?

Solution

CGPointFromString() cant work because your array doesnt contains Strings but NSValue objects

instead of CGPoint p1=CGPointFromString([param objectAtIndex:j]); do [params[j] CGPointValue];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top