This commit is contained in:
2018-01-12 18:00:32 +03:00
parent b973d0830c
commit 8dc21b41c0
18 changed files with 235 additions and 141 deletions

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

View File

@@ -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}';
}
}