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);
}
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class CspViewCtrl method visualize.
protected void visualize(VAR var) {
Point2D pos = getPosition(var);
String label = var.getName();
VAL value = null;
Color fillColor = null;
if (assignment != null)
value = assignment.getValue(var);
if (value != null) {
label += " = " + value;
fillColor = colorMapping.get(value);
}
Circle circle = new Circle(pos.getX(), pos.getY(), 20);
circle.setStroke(Color.BLACK);
circle.setFill(fillColor != null ? fillColor : Color.WHITE);
Text t1 = new Text(pos.getX() + 25, pos.getY(), label);
t1.setTextOrigin(VPos.CENTER);
Text t2 = new Text(pos.getX(), pos.getY() + 40, csp.getDomain(var).toString());
pane.getChildren().addAll(circle, t1, t2);
}
Aggregations