[server] add module

This commit is contained in:
2020-03-25 16:24:53 +03:00
parent 821ddbb2a7
commit 8e3b9e2830
99 changed files with 70 additions and 4 deletions

View 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;
}
}