 		mPoints.append(pt)
 	}
 
-	public func points(inRect rect: CGRect) -> Array<CGPoint> {
-		let origin = rect.origin
-		let size   = rect.size
+	public func normalize(inRect rect: CGRect) -> Array<CGPoint> {
 		var result: Array<CGPoint> = []
 		for pt in mPoints {
-			let x = origin.x + (size.width  * pt.x)
-			let y = origin.y + (size.height * pt.y)
-			let p = CGPoint(x: x, y: y)
+			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 mGraphics:	Array<CNVectorGraphics>
-	private var mLineWidth:	CGFloat
-	public init(){
+	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 func addDown(point pt: CGPoint, in area: CGSize) {
-		let newpath = CNVectorPath(lineWidth: mLineWidth)
-		newpath.add(point: convert(point: pt, in: area))
-		mGraphics.append(.path(newpath))
-	}
-
-	public func addDrag(point pt: CGPoint, in area: CGSize){
-		addPoint(point: pt, in: area)
-	}
-
-	public func addUp(point pt: CGPoint, in area: CGSize){
-		addPoint(point: pt, in: area)
+	public var currentType: CNVectorGraphicsType {
+		get 	    { return mCurrentType	}
+		set(newval) { mCurrentType = newval	}
 	}
 
 	public var lineWidth: CGFloat {

import UIKit
#endif
import Foundation

public class CNVectorPath
{

		set(newval) { mLineWidth = newval }
	}

	public func addDown(point pt: CGPoint, in area: CGSize) {
		switch mCurrentType {
		case .path:
			let newpath = CNVectorPath(lineWidth: mLineWidth)
			newpath.add(point: convert(point: pt, in: area))
			mGraphics.append(.path(newpath))
		case .rect:
			let newrect = CNVectorRect(lineWidth: mLineWidth)
			newrect.originPoint = convert(point: pt, in: area)
			newrect.endPoint    = newrect.originPoint
			mGraphics.append(.rect(newrect))
		}
	}

	public func addDrag(point pt: CGPoint, in area: CGSize){
		switch mCurrentType {
		case .path:
			addPath(point: pt, in: area)
		case .rect:
			addRect(point: pt, in: area)
		}
	}

	public func addUp(point pt: CGPoint, in area: CGSize){
		switch mCurrentType {
		case .path:
			addPath(point: pt, in: area)
		case .rect:
			addRect(point: pt, in: area)
		}
	}

	private func addPath(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))
			case .rect(_):
				CNLog(logLevel: .error, message: "Unexpected object", atFunction: #function, inFile: #file)
			}
		} else {
			CNLog(logLevel: .error, message: "Can not happen", atFunction: #function, inFile: #file)
		}
	}

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