[common] update map

This commit is contained in:
2018-01-12 22:24:27 +03:00
parent 8dc21b41c0
commit 14d2b863c5
11 changed files with 156 additions and 166 deletions

View File

@@ -4,12 +4,32 @@ class Line {
public var point1(default, null):Point;
public var point2(default, null):Point;
public var center(get, null):Point;
public function new(point1:Point, point2:Point) {
this.point1 = point1;
this.point2 = point2;
}
private function get_center():Point {
return new Point(
point1.x + (point2.x - point1.x) / 2,
point1.y + (point2.y - point1.y) / 2
);
}
public function setLength(value:Float):Line {
var center = this.center;
var width = point2.x - point1.x;
var height = point2.y - point1.y;
var kW = width > 0 ? (width + height) / width : 0;
var kH = height > 0 ? (width + height) / height : 0;
return new Line(
center.add(new Point(-kW * value / 2, -kH * value / 2)),
center.add(new Point(kW * value / 2, kH * value / 2))
);
}
public function toString():String {
return 'Line{point1=$point1,point2=$point2}';
}

View File

@@ -57,6 +57,10 @@ class Rectangle {
return value;
}
public function contain(point:Point):Bool {
return point.x >= x && point.y >= y && point.x <= width && point.y <= height;
}
public function toString():String {
return 'Rectangle{x=$x,y=$y,width=$width,height=$height}';
}