1 23 24 package de.progra.charting.render.shape; 25 26 import java.awt.geom.RectangularShape ; 27 import java.awt.geom.Rectangle2D ; 28 import java.awt.geom.PathIterator ; 29 import java.awt.geom.AffineTransform ; 30 31 35 public class Triangle2D extends RectangularShape { 36 37 protected double x = 0.0; 38 39 protected double y = 0.0; 40 41 protected double width = 0.0; 42 43 protected double height = 0.0; 44 45 protected boolean upsidedown = false; 46 47 48 public Triangle2D(double x, double y, double width, double height, boolean upsidedown) { 49 setFrame(x, y, width, height); 50 this.upsidedown = upsidedown; 51 } 52 53 public boolean contains(double param, double param1) { 54 return false; 55 } 56 57 public boolean contains(double param, double param1, double param2, double param3) { 58 return false; 59 } 60 61 public boolean intersects(double x, double y, double w, double h) { 62 return false; 63 } 64 65 public Rectangle2D getBounds2D() { 66 return new Rectangle2D.Double (x, y, width, height); 67 } 68 69 public double getHeight() { 70 return height; 71 } 72 73 public PathIterator getPathIterator(AffineTransform affineTransform) { 74 return new PathIterator () { 75 int state = 0; 76 int maxstate = 3; 77 78 double[][] dcurrentSegment = {{x + width/2, y}, 79 {x, y + height}, 80 {x + width, y + height}, 81 {0.0, 0.0} }; 82 83 84 double[][] ddowncurrentSegment = {{x, y}, 85 {x + width/2, y + height}, 86 {x + width, y}, 87 {0.0, 0.0} }; 88 89 int[] segment = { PathIterator.SEG_MOVETO, PathIterator.SEG_LINETO, PathIterator.SEG_LINETO, PathIterator.SEG_CLOSE}; 90 91 public int currentSegment(double[] coords) { 92 if(!upsidedown) { 93 coords[0] = dcurrentSegment[state][0]; 94 coords[1] = dcurrentSegment[state][1]; 95 } else { 96 coords[0] = ddowncurrentSegment[state][0]; 97 coords[1] = ddowncurrentSegment[state][1]; 98 } 99 return segment[state]; 100 } 101 102 public int currentSegment(float[] coords){ 103 if(!upsidedown) { 104 coords[0] = (float)dcurrentSegment[state][0]; 105 coords[1] = (float)dcurrentSegment[state][1]; 106 } else { 107 coords[0] = (float)ddowncurrentSegment[state][0]; 108 coords[1] = (float)ddowncurrentSegment[state][1]; 109 } 110 return segment[state]; 111 } 112 113 public int getWindingRule() { return PathIterator.WIND_NON_ZERO; } 114 public boolean isDone() { return (state == maxstate); } 115 public void next() { state++ ; } 116 }; 117 } 118 119 public double getWidth() { 120 return width; 121 } 122 123 public double getX() { 124 return x; 125 } 126 127 public double getY() { 128 return y; 129 } 130 131 public boolean isEmpty() { 132 return (width<= 0.0 || height <= 0.0); 133 } 134 135 public void setFrame(double x, double y, double width, double height) { 136 this.x = x; 137 this.y = y; 138 this.width = width; 139 this.height = height; 140 } 141 } 142 | Popular Tags |