udpate
This commit is contained in:
16
src/common/haxe/ru/m/geom/Line.hx
Normal file
16
src/common/haxe/ru/m/geom/Line.hx
Normal file
@@ -0,0 +1,16 @@
|
||||
package ru.m.geom;
|
||||
|
||||
class Line {
|
||||
|
||||
public var point1(default, null):Point;
|
||||
public var point2(default, null):Point;
|
||||
|
||||
public function new(point1:Point, point2:Point) {
|
||||
this.point1 = point1;
|
||||
this.point2 = point2;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return 'Line{point1=$point1,point2=$point2}';
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,22 @@ class Rectangle {
|
||||
return value;
|
||||
}
|
||||
|
||||
public function getSide(direction:Direction):Point {
|
||||
return center.add(new Point(direction.x * width / 2, direction.y * height / 2));
|
||||
public function getSide(direction:Direction):Line {
|
||||
if (direction.x != 0) {
|
||||
var x = x + (direction.x * -1 + 1) / 2 * width;
|
||||
return new Line(
|
||||
new Point(x, y),
|
||||
new Point(x, y + height)
|
||||
);
|
||||
} else if (direction.y != 0) {
|
||||
var y = y + (direction.y * -1 + 1) / 2 * height;
|
||||
return new Line(
|
||||
new Point(x, y),
|
||||
new Point(x + width, y)
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function set_direction(value:Direction):Direction {
|
||||
@@ -43,4 +57,7 @@ class Rectangle {
|
||||
return value;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return 'Rectangle{x=$x,y=$y,width=$width,height=$height}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user