package ru.m.draw; import flash.display.Graphics; import flash.display.GraphicsPathCommand; import flash.Vector; enum DrawCommand { MOVE_TO(x:Float, y:Float); LINE_TO(x:Float, y:Float); CURVE_TO(cx:Float, cy:Float, ax:Float, ay:Float); } class DrawPath { public var commands(default, null):Array; public function new(commands:Array = null) { this.commands = commands != null ? commands : []; } public function draw(graphics:Graphics):Void { var commands = new Vector(); var data = new Vector(); for (command in this.commands) { switch command { case MOVE_TO(x, y): commands.push(GraphicsPathCommand.MOVE_TO); data.push(x); data.push(y); case LINE_TO(x, y): commands.push(GraphicsPathCommand.LINE_TO); data.push(x); data.push(y); case CURVE_TO(cx, cy, ax, ay): commands.push(GraphicsPathCommand.CURVE_TO); data.push(cx); data.push(cy); data.push(ax); data.push(ay); } } graphics.drawPath(commands, data); } public function move(mx:Float, my:Float):DrawPath { var result = new DrawPath(); result.commands = commands.map(command -> switch command { case MOVE_TO(x, y): MOVE_TO(x + mx, y + my); case LINE_TO(x, y): LINE_TO(x + mx, y + my); case CURVE_TO(cx, cy, ax, ay): CURVE_TO(cx + mx, cy + my, ax + mx, ay + my); }); return result; } }