Inherits from NSObject
Declared in KKPointArray.h

Overview

A simple and efficient array of CGPoint structs.

The array is an allocated block of memory instead of boxing the CGPoint in NSValue objects. For most efficient use, set the array’s capacity to hold the same number of points you’re going to add. Otherwise buffer will grow as needed, allocating 50% more memory each time.

Feature set is minimal, please request if you need something. For example there are deliberately no “insert point” or “remove point” methods because they’re probably not going to be used (frequently).

Properties

count

Returns the number of points in the array.

@property (atomic, readonly) NSUInteger count

Declared In

KKPointArray.h

points

Returns the points array. Caution: Do not free() this buffer! Do not use index out of bounds! There are no safety checks here!

@property (atomic, readonly) CGPoint *points

Declared In

KKPointArray.h

Class Methods

pointArrayWithCapacity:

Creates a points array, reserving capacity amount of memory for points.

+ (id)pointArrayWithCapacity:(NSUInteger)capacity

Parameters

capacity

The initial capacity reserved for the array.

Return Value

A new instance.

Declared In

KKPointArray.h

pointArrayWithPoints:count:

Creates a points array by copying count points from the points buffer (array). You can delete (free) your points buffer after calling this method.

+ (id)pointArrayWithPoints:(CGPoint *)points count:(NSUInteger)count

Parameters

points

A memory buffer containing CGPoints. The buffer is copied.

count

The number of CGPoint in the buffer.

Return Value

A new instance.

Declared In

KKPointArray.h

Instance Methods

addPoint:

Adds a single point to the array.

- (void)addPoint:(CGPoint)point

Parameters

point

The point to add.

Declared In

KKPointArray.h

addPoints:count:

Adds the given number of points from an existing CGPoint array or memory buffer.

- (void)addPoints:(CGPoint *)points count:(NSUInteger)count

Parameters

points

Memeory buffer containing points. Buffer is copied.

count

The number of CGPoint in the buffer.

Declared In

KKPointArray.h

lastPoint

The last point in the array.

- (CGPoint)lastPoint

Return Value

The last point in the array.

Declared In

KKPointArray.h

pointAtIndex:

Returns the point at the given index. If the index is out of bounds an exception is raised.

- (CGPoint)pointAtIndex:(NSUInteger)index

Parameters

index

The index of a point.

Return Value

The point at the given index.

Declared In

KKPointArray.h

removeAllPoints

Removes all points from the array. You can then start re-adding points.

- (void)removeAllPoints

Declared In

KKPointArray.h

removeLastPoint

Removes the last point from the array. Does nothing if the array is empty.

- (void)removeLastPoint

Declared In

KKPointArray.h

removePointsStartingAtIndex:

Removes all points from index to last point. Does nothing if index >= count. The array then contains (index - 1) points.

- (void)removePointsStartingAtIndex:(NSUInteger)index

Parameters

index

The lowest index from which to remove all remaining points.

Declared In

KKPointArray.h