2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - Scilab Enterprises - Calixte Denizet
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
12 package org.scilab.forge.scirenderer.implementation.g2d.motor;
15 import java.awt.Color;
16 import java.awt.Graphics2D;
17 import java.util.ArrayList;
18 import java.util.List;
19 import org.scilab.forge.scirenderer.implementation.g2d.*;
21 import org.scilab.forge.scirenderer.tranformations.Vector3d;
24 * @author Calixte DENIZET
26 public class PolyLine {
27 /* extends AbstractDrawable3DObject {
29 private boolean monochromatic;
30 private Stroke stroke;
33 public PolyLine(Vector3d[] vertices, Color[] colors, Stroke stroke, Shape clip) throws InvalidPolygonException {
34 super(vertices, colors);
35 this.monochromatic = isMonochromatic(colors);
41 protected Path2D getProjectedPolyLine() {
43 Path2D.Double path = new Path2D.Double();
46 for (i = 0; i < vertices.length; i++) {
47 if (!AbstractDrawable3DObject.isNanOrInf(vertices[i])) {
52 if (i < vertices.length) {
53 path.moveTo(vertices[i].getX(), vertices[i].getY());
55 boolean broken = false;
56 for (; i < vertices.length; i++) {
57 if (AbstractDrawable3DObject.isNanOrInf(vertices[i])) {
64 path.moveTo(vertices[i].getX(), vertices[i].getY());
66 path.lineTo(vertices[i].getX(), vertices[i].getY());
75 public void draw(Graphics2D g2d) {
76 Shape oldClip = g2d.getClip();
77 Stroke oldStroke = g2d.getStroke();
82 g2d.setColor(colors[0]);
83 g2d.setStroke(stroke);
84 g2d.draw(getProjectedPolyLine());
86 Vector3D start = null;
89 float[] dashArray = stroke.getDashArray();
90 float lwidth = stroke.getLineWidth();
91 for (int i = 0; i < vertices.length; i++) {
92 if (AbstractDrawable3DObject.isNanOrInf(vertices[i])) {
99 Stroke nstroke = new G2DStroke(lwidth, dashArray, cumLen);
100 g2d.setStroke(nstroke);
102 g2d.draw(new Line2D.Double(start.getX(), start.getY(), vertices[i].getX(), vertices[i].getY()));
103 cumLen += Math.hypot(start.getX() - vertices[i].getX(), start.getY() - vertices[i].getY());
109 g2d.setClip(oldClip);
110 g2d.setStroke(oldStroke);