Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/edu/macalester/graphics/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
* A line segment that can be drawn on the screen.
* <p>
* A line has a "start point" and an "end point". The only distinction is that the start point is
* the line’s {@link getPosition() position}. If you call {@link setPosition(Point) setPosition()}
* or {@link moveBy(Point) moveBy()}, both endpoints will move so the line segment has the same
* the line’s {@link #getPosition() position}. If you call {@link #setPosition(Point) setPosition()}
* or {@link #moveBy(Point) moveBy()}, both endpoints will move so the line segment has the same
* length and angle, and the start point will end up at the position you specify.
* <p>
* To move one endpoint without affecting the other, use {@link setStartPosition(Point) setStartPosition()}
* and {@link setEndPosition(Point) setEndPosition()}.
* To move one endpoint without affecting the other, use {@link #setStartPosition(Point) setStartPosition()}
* and {@link #setEndPosition(Point) setEndPosition()}.
*
* @author Bret Jackson
*/
Expand Down Expand Up @@ -129,6 +129,20 @@ public double getY2() {
return shape.getY2() + getY();
}

/**
* Returns the endpoint of the line segment marked as the “start,” which is (x1, y1). This
* method is equivalent to getPosition(), but note that calling {@link #setStartPosition(Point)}
* moves only that endpoint, whereas calling {@link #setPosition(Point)} moves the entire line
* (i.e. it moves both endpoints by the same amount).
*
* @see #getX1()
* @see #getY1()
* @see #setStartPosition(Point)
*/
public Point getStartPosition() {
return getPosition();
}

/**
* Sets the line's starting position to (x, y) without affecting the end position.
*/
Expand All @@ -145,6 +159,17 @@ public void setStartPosition(Point p) {
setStartPosition(p.getX(), p.getY());
}

/**
* Returns the endpoint of the line segment marked as the “end,” which is (x2, y2).
*
* @see #getX2()
* @see #getY2()
* @see #getStartPosition()
*/
public Point getEndPosition() {
return new Point(getX2(), getY2());
}

/**
* Sets the line's ending position to (x, y) without affecting the start position.
*/
Expand Down
3 changes: 2 additions & 1 deletion test/edu/macalester/graphics/LineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ void horizontal() {
line = new Line(10, 50, 90, 50);
}


@RenderingTest(modes = { STROKED, HIT_TEST })
void diagonal() {
line = new Line(new Point(1, 2), new Point(3, 4));
Expand All @@ -32,5 +31,7 @@ void diagonal() {
assertEquals(21, line.getY1());
assertEquals(51, line.getX2());
assertEquals(9, line.getY2());
assertEquals(new Point(31, 21), line.getStartPosition());
assertEquals(new Point(51, 9), line.getEndPosition());
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading