001: /*
002: JOpenChart Java Charting Library and Toolkit
003: Copyright (C) 2001 Sebastian MŸller
004: http://jopenchart.sourceforge.net
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: Triangle2D.java
021: Created on 11. September 2002, 22:01
022: */
023:
024: package de.progra.charting.render.shape;
025:
026: import java.awt.geom.RectangularShape;
027: import java.awt.geom.Rectangle2D;
028: import java.awt.geom.PathIterator;
029: import java.awt.geom.AffineTransform;
030:
031: /**
032: * This class implements a triangular shape.
033: * @author smueller
034: */
035: public class Triangle2D extends RectangularShape {
036:
037: protected double x = 0.0;
038:
039: protected double y = 0.0;
040:
041: protected double width = 0.0;
042:
043: protected double height = 0.0;
044:
045: protected boolean upsidedown = false;
046:
047: /** Creates a new instance of Triangle2D */
048: public Triangle2D(double x, double y, double width, double height,
049: boolean upsidedown) {
050: setFrame(x, y, width, height);
051: this .upsidedown = upsidedown;
052: }
053:
054: public boolean contains(double param, double param1) {
055: return false;
056: }
057:
058: public boolean contains(double param, double param1, double param2,
059: double param3) {
060: return false;
061: }
062:
063: public boolean intersects(double x, double y, double w, double h) {
064: return false;
065: }
066:
067: public Rectangle2D getBounds2D() {
068: return new Rectangle2D.Double(x, y, width, height);
069: }
070:
071: public double getHeight() {
072: return height;
073: }
074:
075: public PathIterator getPathIterator(AffineTransform affineTransform) {
076: return new PathIterator() {
077: int state = 0;
078: int maxstate = 3;
079:
080: double[][] dcurrentSegment = { { x + width / 2, y },
081: { x, y + height }, { x + width, y + height },
082: { 0.0, 0.0 } };
083:
084: double[][] ddowncurrentSegment = { { x, y },
085: { x + width / 2, y + height }, { x + width, y },
086: { 0.0, 0.0 } };
087:
088: int[] segment = { PathIterator.SEG_MOVETO,
089: PathIterator.SEG_LINETO, PathIterator.SEG_LINETO,
090: PathIterator.SEG_CLOSE };
091:
092: public int currentSegment(double[] coords) {
093: if (!upsidedown) {
094: coords[0] = dcurrentSegment[state][0];
095: coords[1] = dcurrentSegment[state][1];
096: } else {
097: coords[0] = ddowncurrentSegment[state][0];
098: coords[1] = ddowncurrentSegment[state][1];
099: }
100: return segment[state];
101: }
102:
103: public int currentSegment(float[] coords) {
104: if (!upsidedown) {
105: coords[0] = (float) dcurrentSegment[state][0];
106: coords[1] = (float) dcurrentSegment[state][1];
107: } else {
108: coords[0] = (float) ddowncurrentSegment[state][0];
109: coords[1] = (float) ddowncurrentSegment[state][1];
110: }
111: return segment[state];
112: }
113:
114: public int getWindingRule() {
115: return PathIterator.WIND_NON_ZERO;
116: }
117:
118: public boolean isDone() {
119: return (state == maxstate);
120: }
121:
122: public void next() {
123: state++;
124: }
125: };
126: }
127:
128: public double getWidth() {
129: return width;
130: }
131:
132: public double getX() {
133: return x;
134: }
135:
136: public double getY() {
137: return y;
138: }
139:
140: public boolean isEmpty() {
141: return (width <= 0.0 || height <= 0.0);
142: }
143:
144: public void setFrame(double x, double y, double width, double height) {
145: this.x = x;
146: this.y = y;
147: this.width = width;
148: this.height = height;
149: }
150: }
|