[server] add module
This commit is contained in:
53
src/app/haxe/ru/m/draw/DrawPath.hx
Normal file
53
src/app/haxe/ru/m/draw/DrawPath.hx
Normal file
@@ -0,0 +1,53 @@
|
||||
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<DrawCommand>;
|
||||
|
||||
public function new(commands:Array<DrawCommand> = null) {
|
||||
this.commands = commands != null ? commands : [];
|
||||
}
|
||||
|
||||
public function draw(graphics:Graphics):Void {
|
||||
var commands = new Vector<GraphicsPathCommand>();
|
||||
var data = new Vector<Float>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user