use of java.awt.geom.Point2D in project JMRI by JMRI.
the class LevelXing method drawEditControls.
public void drawEditControls(Graphics2D g2) {
Point2D pt = getCoordsCenter();
g2.setColor(defaultTrackColor);
g2.draw(layoutEditor.trackControlPointRectAt(pt));
pt = getCoordsA();
if (getConnectA() == null) {
g2.setColor(Color.magenta);
} else {
g2.setColor(Color.blue);
}
g2.draw(layoutEditor.trackControlPointRectAt(pt));
pt = getCoordsB();
if (getConnectB() == null) {
g2.setColor(Color.red);
} else {
g2.setColor(Color.green);
}
g2.draw(layoutEditor.trackControlPointRectAt(pt));
pt = getCoordsC();
if (getConnectC() == null) {
g2.setColor(Color.magenta);
} else {
g2.setColor(Color.blue);
}
g2.draw(layoutEditor.trackControlPointRectAt(pt));
pt = getCoordsD();
if (getConnectD() == null) {
g2.setColor(Color.red);
} else {
g2.setColor(Color.green);
}
g2.draw(layoutEditor.trackControlPointRectAt(pt));
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class TrackSegment method getBounds.
/**
* @return the bounds of this track segment
*/
public Rectangle2D getBounds() {
Rectangle2D result;
Point2D ep1 = layoutEditor.getCoords(getConnect1(), getType1());
result = new Rectangle2D.Double(ep1.getX(), ep1.getY(), 0, 0);
Point2D ep2 = layoutEditor.getCoords(getConnect2(), getType2());
result.add(ep2);
return result;
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class TrackSegment method drawDashed.
// drawHidden(Graphics2D g2)
public void drawDashed(Graphics2D g2, boolean mainline) {
if ((!isHidden()) && getDashed() && (mainline == getMainline())) {
setColorForTrackBlock(g2, getLayoutBlock());
float trackWidth = layoutEditor.setTrackStrokeWidth(g2, mainline);
if (getArc()) {
calculateTrackSegmentAngle();
Stroke originalStroke = g2.getStroke();
Stroke drawingStroke = new BasicStroke(trackWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
g2.setStroke(drawingStroke);
g2.draw(new Arc2D.Double(getCX(), getCY(), getCW(), getCH(), getStartadj(), getTmpAngle(), Arc2D.OPEN));
g2.setStroke(originalStroke);
} else if (getBezier()) {
Stroke originalStroke = g2.getStroke();
Stroke drawingStroke = new BasicStroke(trackWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
g2.setStroke(drawingStroke);
Point2D pt1 = layoutEditor.getCoords(getConnect1(), getType1());
Point2D pt2 = layoutEditor.getCoords(getConnect2(), getType2());
int cnt = bezierControlPoints.size();
Point2D[] points = new Point2D[cnt + 2];
points[0] = pt1;
for (int idx = 0; idx < cnt; idx++) {
points[idx + 1] = bezierControlPoints.get(idx);
}
points[cnt + 1] = pt2;
MathUtil.drawBezier(g2, points);
g2.setStroke(originalStroke);
} else {
Point2D end1 = layoutEditor.getCoords(getConnect1(), getType1());
Point2D end2 = layoutEditor.getCoords(getConnect2(), getType2());
double delX = end1.getX() - end2.getX();
double delY = end1.getY() - end2.getY();
double cLength = Math.hypot(delX, delY);
// note: The preferred dimension of a dash (solid + blank space) is
// 5 * the track width - about 60% solid and 40% blank.
int nDashes = (int) (cLength / ((trackWidth) * 5.0));
if (nDashes < 3) {
nDashes = 3;
}
double delXDash = -delX / ((nDashes) - 0.5);
double delYDash = -delY / ((nDashes) - 0.5);
double begX = end1.getX();
double begY = end1.getY();
for (int k = 0; k < nDashes; k++) {
g2.draw(new Line2D.Double(new Point2D.Double(begX, begY), new Point2D.Double(begX + (delXDash * 0.5), begY + (delYDash * 0.5))));
begX += delXDash;
begY += delYDash;
}
}
}
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class TrackSegment method getCentreSeg.
public Point2D getCentreSeg() {
Point2D result = MathUtil.zeroPoint2D();
if ((null != connect1) && (null != connect2)) {
// get the end points
Point2D ep1 = layoutEditor.getCoords(getConnect1(), getType1());
Point2D ep2 = layoutEditor.getCoords(getConnect2(), getType2());
if (getCircle()) {
//TODO: do something here?
//} else if (getArc()) {
//TODO: do something here?
result = center;
} else if (getBezier()) {
//compute result Bezier point for (t == 0.5);
// copy all the control points (including end points) into an array
int len = bezierControlPoints.size() + 2;
Point2D[] points = new Point2D[len];
points[0] = ep1;
for (int idx = 1; idx < len - 1; idx++) {
points[idx] = getBezierControlPoint(idx - 1);
}
points[len - 1] = ep2;
// calculate midpoints of all points (len - 1 order times)
for (int idx = len - 1; idx > 0; idx--) {
for (int jdx = 0; jdx < idx; jdx++) {
points[jdx] = MathUtil.midPoint(points[jdx], points[jdx + 1]);
}
}
result = points[0];
} else {
result = MathUtil.midPoint(ep1, ep2);
}
center = result;
}
return result;
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class TrackSegment method addBezierControlPointBefore.
private void addBezierControlPointBefore(int index) {
Point2D addPoint = getBezierControlPoint(index);
if (index > 0) {
addPoint = MathUtil.midPoint(getBezierControlPoint(index - 1), addPoint);
} else {
Point2D ep1 = layoutEditor.getCoords(getConnect1(), getType1());
addPoint = MathUtil.midPoint(ep1, addPoint);
}
bezierControlPoints.add(index, addPoint);
layoutEditor.redrawPanel();
layoutEditor.setDirty();
}
Aggregations