[common] update map
This commit is contained in:
@@ -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}';
|
||||
}
|
||||
|
||||
@@ -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}';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user