 import UIKit
 #endif
 import Foundation
+
+private func normalizePoint(source src: CGPoint, in rect: CGRect) -> CGPoint {
+	let origin = rect.origin
+	let size   = rect.size
+	let x = origin.x + (size.width  * src.x)
+	let y = origin.y + (size.height * src.y)
+	return CGPoint(x: x, y: y)
+}
 
 public class CNVectorPath
 {

		set(newval) { mLineWidth = newval }
	}

	public func setLineWidth(width wid: CGFloat) {
		mLineWidth = wid
	}

	private func addPoint(point pt: CGPoint, in area: CGSize){
		if let gr = mGraphics.last {
			switch gr {
			case .path(let path):
				path.add(point: convert(point: pt, in: area))
			}
		} else {
			CNLog(logLevel: .error, message: "Can not happen", atFunction: #function, inFile: #file)

		mPoints.append(pt)
	}

	public func normalize(inRect rect: CGRect) -> Array<CGPoint> {
		var result: Array<CGPoint> = []
		for pt in mPoints {
			let p = normalizePoint(source: pt, in: rect)
			result.append(p)
		}
		return result
	}
}

public class CNVectorRect
{
	public var width:		CGFloat
	public var originPoint:		CGPoint
	public var endPoint:		CGPoint

	public init(lineWidth wid: CGFloat){
		width		= wid
		originPoint	= CGPoint.zero
		endPoint	= CGPoint.zero
	}

	public func normalize(inRect rect: CGRect) -> CGRect? {
		let norigin = normalizePoint(source: originPoint, in: rect)
		let nend    = normalizePoint(source: endPoint, in: rect)
		let x = min(norigin.x, nend.x)
		let y = min(norigin.y, nend.y)
		let width  = abs(nend.x - norigin.x)
		let height = abs(nend.y - norigin.y)
		if width > 0 && height > 0 {
			return CGRect(x: x, y: y, width: width, height: height)
		} else {
			return nil
		}
	}
}

public enum CNVectorGraphics
{
	case path(CNVectorPath)
	case rect(CNVectorRect)
}

public enum CNVectorGraphicsType {
	case path
	case rect
}

public class CNVecroGraphicsGenerator
{
	private var mCurrentType:	CNVectorGraphicsType
	private var mGraphics:		Array<CNVectorGraphics>
	private var mLineWidth:		CGFloat

	public init(type typ: CNVectorGraphicsType){
		mCurrentType	= typ
		mGraphics	= []
		mLineWidth	= 1.0
	}

	public var contents: Array<CNVectorGraphics> { get { return mGraphics }}

	public var currentType: CNVectorGraphicsType {
		get 	    { return mCurrentType	}
		set(newval) { mCurrentType = newval	}
	}

	public var lineWidth: CGFloat {
