use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class GraphicsTransfer2D method transfer.
/**
* Transfers a {@link Polyline2D} into its {@link Shape} representative.
* @param polyline the polyline to be transferred.
* @return the transferred shape.
*/
private static Shape transfer(Polyline2D polyline) {
Path2D result = new java.awt.geom.Path2D.Double();
Point2D[] vertexes = polyline.getVertexes();
result.moveTo(vertexes[0].getX(), vertexes[0].getY());
for (int i = 1; i < vertexes.length; i++) {
result.lineTo(vertexes[i].getX(), vertexes[i].getY());
}
if (polyline.isClosed())
result.closePath();
return result;
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class SVGGroupParser method parsePolyline.
/**
* Parses the current element as a polyline. This polyline is added to the {@code shapes} if it contains a valid points list.
*/
private void parsePolyline() {
String value = reader.getAttributeValue(null, POINTS_ATTRIBUTE);
if (value != null) {
String[] coords = value.split(POINTS_REGEX);
if (coords.length >= 2 && coords.length % 2 == 0) {
//otherwise something is wrong with the points list!
Point2D[] vertexes = new Point2D[coords.length / 2];
for (int i = 0; i < coords.length; i = i + 2) {
vertexes[(i / 2) - 1] = new Point2D(parseNumber(coords[i]), parseNumber(coords[i + 1]));
}
IGeometric2D polyline = new Polyline2D(vertexes, false).transform(currentMatrix);
shapes.add(polyline);
}
}
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class SVGGroupParser method parsePolygon.
/**
* Parses the current element as a polygon. This polygon is added to the {@code shapes} if it contains a valid points list.
*/
private void parsePolygon() {
String value = reader.getAttributeValue(null, POINTS_ATTRIBUTE);
if (value != null) {
String[] coords = value.split(POINTS_REGEX);
if (coords.length >= 2 && coords.length % 2 == 0) {
//otherwise something is wrong with the points list!
Point2D[] vertexes = new Point2D[coords.length / 2];
for (int i = 1; i < coords.length; i = i + 2) {
vertexes[(i - 1) / 2] = new Point2D(parseNumber(coords[i - 1]), parseNumber(coords[i]));
}
IGeometric2D polygon = new Polyline2D(vertexes, true).transform(currentMatrix);
shapes.add(polygon);
}
}
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class SVGGroupParser method parseEllipse.
/**
* Parses the current element as an ellipse. This ellipse is added to the {@code shapes} if it is rendered.
*/
private void parseEllipse() {
String value = reader.getAttributeValue(null, CX_ATTRIBUTE);
final double cx = parseNumber(value);
value = reader.getAttributeValue(null, CY_ATTRIBUTE);
final double cy = parseNumber(value);
value = reader.getAttributeValue(null, RX_ATTRIBUTE);
final double rx = parseNumber(value);
value = reader.getAttributeValue(null, RY_ATTRIBUTE);
final double ry = parseNumber(value);
if (rx != 0.0d && ry != 0.0d) {
//SVG standard specifies that the radius is forced to have a value. Otherwise the rendering for this element is disabled.
IGeometric2D elipse = new Ellipse2D(new Point2D(cx, cy), rx, ry).transform(currentMatrix);
shapes.add(elipse);
}
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class SVGGroupParser method parseCircle.
/**
* Parses the current element as a circle. This circle is added to the {@code shapes} if it is rendered.
*/
private void parseCircle() {
String value = reader.getAttributeValue(null, CX_ATTRIBUTE);
final double cx = parseNumber(value);
value = reader.getAttributeValue(null, CY_ATTRIBUTE);
final double cy = parseNumber(value);
value = reader.getAttributeValue(null, R_ATTRIBUTE);
final double r = parseNumber(value);
if (r != 0.0d) {
//SVG standard specifies that the radius is forced to have a value. Otherwise the rendering for this element is disabled.
IGeometric2D circle = new Circle2D(new Point2D(cx, cy), r).transform(currentMatrix);
shapes.add(circle);
}
}
Aggregations