Select Page
Latest 0.0.3 https://github.com/yichizhang/YZPolygonHelper MIT ios 7.0, requires ARC Foundation, UIKit Yichi Zhang

A few class methods to help working with polygons; such as: find the center (centroid) of a polygon; test if a point is with inside a polygon or not.

Examples

``````    func updateCentroid(){

self.centroidPointView.center =
YZPolygonHelper.findCentroidForNumberOfPoints(
self.controlPointViewsArray.count,

xAtIndexBlock: { (UInt idx) -> CGFloat in

let view:ControlPointView = self.controlPointViewsArray[idx]
return view.center.x
},

yAtIndexBlock:{ (UInt idx) -> CGFloat in

let view:ControlPointView = self.controlPointViewsArray[idx]
return view.center.y
}
)

}``````
``````    var result:Bool =
YZPolygonHelper.isPointContained(
point,
inNumberOfPoints: pointsArray.count,
xAtIndexBlock: { (idx:Int) -> CGFloat in

return pointsArray[idx].x
},
yAtIndexBlock: { (idx:Int) -> CGFloat in

return pointsArray[idx].y
}
)``````

### ‘Find Centroid’

Algorithm by Paul Bourke
http://paulbourke.net/geometry/polygonmesh/

Adapted from the C code provided by ‘squeamish ossifrage’
http://stackoverflow.com/users/1679849/squeamish-ossifrage

### Latest podspec

```{
"name": "YZPolygonHelper",
"version": "0.0.3",
"summary": "A few class methods to help working with polygons.",
"homepage": "https://github.com/yichizhang/YZPolygonHelper",
"type": "MIT",
},
"authors": {
"Yichi Zhang": "[email protected]"
},
"source": {
"git": "https://github.com/yichizhang/YZPolygonHelper.git",
"tag": "0.0.3"
},
"platforms": {
"ios": "7.0"
},
"requires_arc": true,
"source_files": "Source/*.{h,m}",
"frameworks": [
"Foundation",
"UIKit"
]
}```