Logo Search packages:      
Sourcecode: latexdraw version File versions  Download package

Triangle.java

package latexDraw.figures;

import static java.lang.Math.toDegrees;

import java.awt.*;
import java.awt.geom.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Vector;

import latexDraw.figures.properties.BordersMovable;
import latexDraw.psTricks.DviPsColors;
import latexDraw.psTricks.PSTricksConstants;
import latexDraw.ui.LaTeXDrawFrame;
import latexDraw.ui.components.Delimitor;
import latexDraw.ui.components.MagneticGrid;
import latexDraw.util.LaTeXDrawPoint2D;


/** 
 * This class defines a triangle.<br>
 *<br>
 * This file is part of LaTeXDraw.<br>
 * Copyright (c) 2005-2008 Arnaud BLOUIN<br>
 *<br>
 *  LaTeXDraw is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.<br>
 *<br>
 *  LaTeXDraw is distributed without any warranty; without even the 
 *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 *  PURPOSE. See the GNU General Public License for more details.<br>
 * <br>
 * 01/20/06<br>
 * @author Arnaud BLOUIN<br>
 * @version 2.0.0<br>
 */
00039 public class Triangle extends LaTeXDrawPolygon implements BordersMovable
{
      private static final long serialVersionUID = 1L;

      /** The number of points in a triangle */
00044       public static final short NB_PTS_TRIANGLE = 3;

      

      /**
       * The constructor by default
       */
00051       public Triangle(boolean increaseMeter)
      {
            this(new LaTeXDrawPoint2D(), new LaTeXDrawPoint2D(), new LaTeXDrawPoint2D(), new LaTeXDrawPoint2D(), increaseMeter);
      }
      
      
      
      
      /**
       * @param f The figure to copy.
       * @param sameNumber True if the figure will have the same number of the copy.
       */
00063       public Triangle(Figure f, boolean sameNumber)
      {
            super(f, sameNumber);
            
            if(f==null)
                  return ;
            
            LaTeXDrawRectangle b = f.getBorders();
            if(b==null) return ;
            
            borders = new LaTeXDrawRectangle(getPoint(0), getPoint(1), getPoint(2), getPoint(3), false);
            updateGravityCenter();
            shape = getInsideOutsideOrMiddleBorders();
            updateGravityCenter();
            isBordersMovable = true;
      }

      
      /**
       * The constructor using four points
       * @param pt1 The top left point of rectangle containing the triangle
       * @param pt2 The top right point of the rectangle containing the triangle
       * @param pt3 The bottom left point
       * @param pt4 The bottom right point
       */
00088       public Triangle(LaTeXDrawPoint2D pt1, LaTeXDrawPoint2D pt2, LaTeXDrawPoint2D pt3, LaTeXDrawPoint2D pt4, boolean increaseMeter)
      {
            super(pt1, pt2, pt3, pt4, increaseMeter);
            borders = new LaTeXDrawRectangle(pt1, pt2, pt3, pt4, false);
            shape = getInsideOutsideOrMiddleBorders();
            updateGravityCenter();
            isBordersMovable = true;
      }
      
      

      
      @Override
00101       public boolean addPoint(LaTeXDrawPoint2D pt)
      {
            if(pts==null) pts = new Vector<LaTeXDrawPoint2D>();
            
            if(pt!=null)
            {
                  Delimitor d = new Delimitor(pt);
                  d.setColorSet3();
                  delimiters.add(d);
                  pts.add(pt);
                  
                  return true;
            }
            return false;
      }

      
      
      
      @Override
00121       public Shape createShape2D() 
      {
            LaTeXDrawPoint2D NW = getTheNWPoint(), SE = getTheSEPoint();
            Shape area = createNonRotatedShape2D();

            if(rotationAngle % (Math.PI*2)!= 0.)
            {
                  double cx = (NW.x + SE.x) / 2., cy = (NW.y + SE.y) / 2.;
                  double c2x = Math.cos(rotationAngle) * cx - Math.sin(rotationAngle)* cy;
                  double c2y = Math.sin(rotationAngle) * cx + Math.cos(rotationAngle)* cy;

                  AffineTransform at = AffineTransform.getTranslateInstance(cx - c2x, cy - c2y);
                  at.rotate(rotationAngle);
                  area = at.createTransformedShape(area);
            }

            return area;
      }

      
      
      
      
      @Override
00145       public Shape createNonRotatedShape2D() 
      {
            Shape area;
            Shape s = getInsideOutsideOrMiddleBorders();

            if(hasDoubleBoundary)
            {
                  Shape[] s2 = getDbleBoundariesOutInOrMiddle(s);
                  Shape min;
                  Shape max;

                  if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                  {
                        max = s;
                        min = s2[1];
                  }
                  else
                        if(bordersPosition.equals(PSTricksConstants.BORDERS_MIDDLE))
                        {
                              max = s2[0];
                              min = s2[1];
                        }
                        else
                        {
                              max = s2[0];
                              min = s;
                        }

                  area = new Area(max);
                  ((Area)area).exclusiveOr(new Area(min));
            }
            else
                  area = s;
            
            return area;
      }
      
      

      
      
      @Override
00187       public void draw(Graphics2D g, Object antiAlias, Object rendering, Object alphaInter, Object colorRendering) 
      {
            LaTeXDrawPoint2D NW = borders.getTheNWPoint(), SE = borders.getTheSEPoint();
            double cx = (NW.x+SE.x)/2., cy = (NW.y+SE.y)/2.;
            double c2x = Math.cos(rotationAngle)*cx - Math.sin(rotationAngle)*cy;
            double c2y = Math.sin(rotationAngle)*cx + Math.cos(rotationAngle)*cy;
            double c3x = Math.cos(-rotationAngle)*(cx-c2x) - Math.sin(-rotationAngle)*(cy-c2y);
            double c3y = Math.sin(-rotationAngle)*(cx-c2x) + Math.cos(-rotationAngle)*(cy-c2y);
            double dx=0, dy=0;
            boolean changeFillStyle = false;
            
            if(rotationAngle%(Math.PI*2)!=0)
            {           
                  g.rotate(rotationAngle);
                  g.translate(c3x,c3y);
            }
            
            if(hasShadow)
            {
                  LaTeXDrawPoint2D cg = getGravityCenter();
                  LaTeXDrawPoint2D shadowCg = (LaTeXDrawPoint2D)cg.clone();
                  shadowCg.setLocation(cg.x+shadowSize, cg.y);
                  shadowCg = Figure.rotatePoint(shadowCg, cg, shadowAngle);
                  dx = shadowCg.x-cg.x;
                  dy = cg.y-shadowCg.y;
            }
            
            Color formerCol = g.getColor();

            if(hasDoubleBoundary)
            {
                  Shape s0 = shape;
                  Shape s[] = getDbleBoundariesOutInOrMiddle(s0);
                  Shape s1, s2, s3;

                  if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                  {
                        s1 = s0;
                        s2 = s[0];
                        s3 = s[1];
                  }
                  else
                        if(bordersPosition.equals(PSTricksConstants.BORDERS_MIDDLE))
                        {
                              s1 = s[0];
                              s2 = s0;
                              s3 = s[1];
                        }
                        else
                        {
                              s1 = s[0];
                              s2 = s[1];
                              s3 = s0;
                        }

                  if(lineStyle.equals(PSTricksConstants.LINE_NONE_STYLE))
                  {
                        if(hasShadow)
                        {
                              g.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                              g.translate(dx, dy);
                              g.setColor(shadowColor);
                              g.fill(s1);
                              g.draw(s1);
                              g.translate(-dx, -dy);
                              
                              if(!isFilled)
                              {
                                    changeFillStyle = true;
                                    isFilled = true;
                              }
                        }
                        g.setColor(doubleColor);
                        g.setStroke(new BasicStroke((float)(doubleSep + thickness), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                        g.draw(s2);
                        fillFigure(g, antiAlias, rendering, alphaInter, colorRendering,s3);
                        g.setColor(linesColor);
                        g.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                        g.draw(s1);
                        g.draw(s3);
                  }
                  else
                  {
                        if(hasShadow)
                        {
                              g.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                              g.translate(dx, dy);
                              g.setColor(shadowColor);
                              g.fill(s1);
                              g.draw(s1);
                              g.translate(-dx, -dy);
                              
                              g.setColor(interiorColor);
                              g.setStroke(new BasicStroke((float)(thickness*2+doubleSep), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                              g.draw(s2);
                              
                              if(!isFilled)
                              {
                                    changeFillStyle = true;
                                    isFilled = true;
                              }
                        }

                        if(lineStyle.equals(PSTricksConstants.LINE_DOTTED_STYLE))
                              g.setStroke(new BasicStroke((float)(thickness*2+doubleSep), BasicStroke.CAP_ROUND,
                                          BasicStroke.JOIN_MITER, 1.f, new float[]{ 0, (float)(thickness*2+doubleSep + dotSep) }, 0));
                        else
                              g.setStroke(new BasicStroke((float)(thickness*2+doubleSep),
                                          BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.f, new float[] { blackDashLength, whiteDashLength }, 0));
                              
                        fillFigure(g, antiAlias, rendering, alphaInter, colorRendering, s2);
                        g.setColor(linesColor);
                        g.draw(s2);
                        g.setStroke(new BasicStroke((float)doubleSep, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                        g.setColor(doubleColor);
                        g.draw(s2);
                  }                       
            }
            else
            {
                  if(hasShadow)
                  {
                        g.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                        g.translate(dx, dy);
                        g.setColor(shadowColor);
                        g.fill(shape);
                        g.draw(shape);
                        g.translate(-dx, -dy);
                        
                        if(!isFilled)
                        {
                              changeFillStyle = true;
                              isFilled = true;
                        }
                        
                        g.setColor(interiorColor);
                        g.draw(shape);
                  }
                  
                  if(lineStyle.equals(PSTricksConstants.LINE_NONE_STYLE))
                        g.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
                  else
                        if(lineStyle.equals(PSTricksConstants.LINE_DOTTED_STYLE))
                              g.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND,
                                                      BasicStroke.JOIN_MITER, 1.f, new float[] { 0, thickness + dotSep }, 0));
                        else
                              g.setStroke(new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.f,
                                                new float[] { blackDashLength, whiteDashLength }, 0));
                  
                  if(shape==null)
                        shape = getInsideOutsideOrMiddleBorders();
                  
                  fillFigure(g, antiAlias, rendering, alphaInter, colorRendering,shape);
                  g.setColor(linesColor);
                  g.draw(shape);
            }

            if(changeFillStyle) isFilled = false;
            g.setColor(formerCol);

            if(rotationAngle%(Math.PI*2)!=0)
            {
                  g.translate(-c3x, -c3y);
                  g.rotate(-rotationAngle);
            }

            if(isSelected)
                  borders.draw(g, false, antiAlias, rendering, alphaInter, colorRendering);
      }


      
      
      
      @Override
00362       public void setLastPoint(LaTeXDrawPoint2D pt)
      {
            borders.setLastPoint(pt);
            updateGravityCenter();
            shape = getInsideOutsideOrMiddleBorders();
      }
      
      
      
      
      @Override
00373       public void setFirstPoint(LaTeXDrawPoint2D pt)
      {
            borders.setFirstPoint(pt);
            updateGravityCenter();
            shape = getInsideOutsideOrMiddleBorders();
      }
      
      

      @Override
00383       public synchronized void setBordersPosition(String doubleLinePosition)
      {
            super.setBordersPosition(doubleLinePosition);
            shape = getInsideOutsideOrMiddleBorders();
      }
      
      
      
      
      @Override
00393       public synchronized void setRotationAngle(double theta)
      {
            if(!Double.isNaN(theta) && !Double.isInfinite(theta))
            {
                  rotationAngle = theta%(Math.PI*2);
                  
                  if(borders!=null)
                        borders.setRotationAngle(rotationAngle);
            }
      }
      
      
      
      
      @Override
00408       public synchronized void shift(double shiftX,double shiftY) 
      {
            if(shiftX==0 && shiftY==0) return ;

            borders.shift(shiftX, shiftY);
            updateShape();
      }

      
      
      
      
      @Override
00421       public void onDragged(Point formerPt, Point newPt) throws Exception
      {
            if(formerPt.equals(newPt)) return;
            
            borders.onDragged(formerPt, newPt);
            rotationAngle = borders.getRotationAngle();//update the angle (when rotation)
            updateShape();
      }
      
      
      
      

      @Override
00435       public synchronized String getCodePSTricks(DrawBorders drawBorders, float ppc)
      {
            LaTeXDrawPoint2D d = drawBorders.getOriginPoint();
            LaTeXDrawPoint2D NW = getTheNWPoint(), SE = getTheSEPoint();
            float baseX = (float) ((NW.x+SE.x)/2. - d.x), baseY = (float) (d.y - SE.y) ;
            String add="", fillType=""; //$NON-NLS-1$ //$NON-NLS-2$ 
            String addBegin = "";//$NON-NLS-1$
            String addEnd = "";//$NON-NLS-1$
            LaTeXDrawPoint2D pt1 = borders.getPoint(0), pt2 = borders.getPoint(2);
            boolean isFilledWasChanged = false;
            
            if(pt1.y>pt2.y || rotationAngle%(Math.PI*2)!=0.)
            {
                  double angle = -Math.toDegrees(rotationAngle);
                  if(pt1.y>pt2.y) angle-=180;
                  double angleRad = Math.toRadians(angle);
                  
                  double cx = (gravityCenter.x-d.x)/ppc;
                  double cy = (d.y-gravityCenter.y)/ppc;
                  double x = -Math.cos(angleRad)*cx+Math.sin(angleRad)*cy+cx;
                  double y = -Math.sin(angleRad)*cx-Math.cos(angleRad)*cy+cy;
                  
                  if(Math.abs(x) < 0.001) x = 0;
                  if(Math.abs(y) < 0.001) y = 0;
                  
                  addBegin +="\\rput{"+(float)angle+ "}("+(float)x+','+(float)y+"){"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                  addEnd = "}"; //$NON-NLS-1$
            }
            
            if(hasShadow)
            {
                  fillType+=",shadow=true";//$NON-NLS-1$
                  fillType+=",shadowangle="+(float)(Math.toDegrees(shadowAngle)-(pt1.y>pt2.y?180:0));//$NON-NLS-1$
                  
                  if(((float)shadowSize)!=((float)DEFAULT_SHADOW_SIZE))
                        fillType+=",shadowsize="+(float)(shadowSize/PPC);//$NON-NLS-1$
                  
                  if(!shadowColor.equals(PSTricksConstants.DEFAULT_SHADOW_COLOR))
                  {
                        String name = DviPsColors.getColourName(shadowColor);
                        if(name==null)
                        {
                              name = "color"+number+'e';//$NON-NLS-1$
                              DviPsColors.addUserColour(shadowColor, name); 
                        }
                        fillType += ",shadowcolor=" + name; //$NON-NLS-1$
                  }
                  if(!isFilled)
                  {
                        isFilled = true;
                        isFilledWasChanged = true;
                  }
            }
            
            String str = getPSTricksCodeFilling(ppc);
            if(str.length()>0) fillType=fillType+','+str;
            
            str = getPSTricksCodeLine(ppc);
            if(str.length()>0) add=add+','+str;
            
            add+=",dimen="+bordersPosition;  //$NON-NLS-1$

            if(hasDoubleBoundary)
            {
                  add+=",doubleline=true,doublesep="+(float)(doubleSep/ppc); //$NON-NLS-1$
                  
                  if(doubleColor!=PSTricksConstants.DEFAULT_DOUBLE_COLOR)
                  {
                        String name = DviPsColors.getColourName(doubleColor);
                        if(name==null)
                        {
                              name = "color"+number+'d';//$NON-NLS-1$
                              DviPsColors.addUserColour(doubleColor, name); 
                        }
                        add+= ",doublecolor="+name; //$NON-NLS-1$
                  }
            }
            
            if(Math.abs(baseX) < 0.001) baseX = 0;
            if(Math.abs(baseY) < 0.001) baseY = 0;
            if(isFilledWasChanged) isFilled = false;
            
            return addBegin+"\\pstriangle[linewidth=" +  //$NON-NLS-1$
                          (thickness/ppc ) + add + fillType + "]("  //$NON-NLS-1$
                        + (baseX/ppc) + ',' + (baseY/ppc) + ")("  //$NON-NLS-1$
                        + (float)(Math.abs(NW.x-SE.x)/ppc) + ',' 
                        + (float)(Math.abs(NW.y-SE.y)/ppc) + ')'+addEnd;
      }


      
      

      /**
       * Allows to get the south-east point by taking into account
       * the angle of rotation.
       * @return The south-east point of the rotated rectangle
       */
      @Override
00534       public LaTeXDrawPoint2D getTheSERotatedPoint()
      {
            if(borders!=null)
                  return borders.getTheSERotatedPoint();
            return null;
      }
      
      
      
      
      
      /**
       * Allows to get the north-west point by taking into account
       * the angle of rotation.
       * @return The north-west point of the rotated rectangle
       */
      @Override
00551       public LaTeXDrawPoint2D getTheNWRotatedPoint()
      {
            if(borders!=null)
                  return borders.getTheNWRotatedPoint();
            return null;
      }
      
      

      
      @Override
00562       public boolean isIn(LaTeXDrawPoint2D p)
      {
            LaTeXDrawPoint2D pt = rotateInvertPoint(p);
            
            if(isSelected && (borders.dNE.isIn(pt) || borders.dNW.isIn(pt) || 
                  borders.dSE.isIn(pt) || borders.dSW.isIn(pt) || borders.dS.isIn(pt)  || 
                  borders.dN.isIn(pt) || borders.dE.isIn(pt)  || borders.dW.isIn(pt)))
                  return true;
            
            GeneralPath path;
            
            if(hasDoubleBoundary)
            {
                  if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                         path = getBorders(0, true);
                  else if(bordersPosition.equals(PSTricksConstants.BORDERS_MIDDLE))
                         path = getBorders(thickness*2+doubleSep, false);
                  else path = getBorders((thickness*2+doubleSep)*2, false);

                  if(!path.contains(pt))
                        return false;

                  if(isFilled || hasShadow || hasGradient())
                        return true;
                  
                  if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                        path = getBorders((thickness*2+doubleSep)*2, true);
                  else if(bordersPosition.equals(PSTricksConstants.BORDERS_MIDDLE))
                        path = getBorders(doubleSep+2*thickness, true);
                  else path = getBorders(0, true);
            }
            else
            {
                  if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                         path = getBorders(0, true);
                  else if(bordersPosition.equals(PSTricksConstants.BORDERS_MIDDLE))
                         path = getBorders(thickness, false);
                  else path = getBorders(thickness*2, false);
            
                  if(!path.contains(pt))
                        return false;

                  if(isFilled || hasShadow || hasGradient())
                        return true;
                  
                  if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                         path = getBorders(thickness*2, true);
                  else if(bordersPosition.equals(PSTricksConstants.BORDERS_MIDDLE))
                         path = getBorders(thickness, true);
                  else path = getBorders(0, true);
            }
            
            return !path.contains(pt);
      }

      
      
      
      
      @Override
      public Object clone() throws CloneNotSupportedException
      {
            Triangle t = (Triangle) super.clone();
            t.borders = new LaTeXDrawRectangle(t.getPoint(0), t.getPoint(1), t.getPoint(2), t.getPoint(3), false);
            t.setThickness(thickness);
            t.updateShape();
            
            return t;
      }
      

      
      @SuppressWarnings("unchecked")
      private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
      {
            canHaveShadow = true;
            interiorColor = (Color) ois.readObject();
            lineStyle = (String) ois.readObject();
            rotationAngle = ois.readDouble();
            thickness = ois.readFloat();
            isFilled = ois.readBoolean();
            isSelected = ois.readBoolean();
            isOnRotation = ois.readBoolean();
            linesColor = (Color) ois.readObject();
            blackDashLength = ois.readFloat();
            dotSep = ois.readFloat();
            whiteDashLength = ois.readFloat();
            pts = (Vector) ois.readObject();
            borders = (LaTeXDrawRectangle) ois.readObject();
            
            delimiters = new Vector();
            for(int i=0, size = pts.size();i<size; i++)
                  delimiters.add(new Delimitor(pts.elementAt(i)));
                  
            if(LaTeXDrawFrame.getVersionOfFile().compareTo("1.5")>=0)//$NON-NLS-1$
            {
                  hasDoubleBoundary = ois.readBoolean();
                  doubleColor = (Color)ois.readObject();
                  doubleSep = ois.readDouble();
                  bordersPosition = (String)ois.readObject();
                  if(!(LaTeXDrawFrame.getVersionOfFile().compareTo("1.6")>=0)) //$NON-NLS-1$
                        ois.readBoolean();
                  hatchingAngle = ois.readDouble();
                  hatchingColor = (Color)ois.readObject();
                  hatchingStyle = (String)ois.readObject();
                  hatchingWidth = ois.readFloat();
                  
                  if(LaTeXDrawFrame.getVersionOfFile().compareTo("1.6") < 0)//$NON-NLS-1$
                  {
                        if(hatchingStyle.equals(DECREPETED_FILL_CROSS))
                              hatchingStyle = PSTricksConstants.TOKEN_FILL_CROSSHATCH;
                        else if(hatchingStyle.equals(DECREPETED_FILL_HORIZ))
                              hatchingStyle = PSTricksConstants.TOKEN_FILL_HLINES;
                        else if(hatchingStyle.equals(DECREPETED_FILL_VERT))
                              hatchingStyle = PSTricksConstants.TOKEN_FILL_VLINES;
                        else if(hatchingStyle.equals(DECREPETED_FILL_NO))
                              hatchingStyle = PSTricksConstants.TOKEN_FILL_NONE;
                  }
            }
            else
            {
                  hasDoubleBoundary  = DEFAULT_HAS_DOUBLE_BOUNDARY;
                  doubleColor = DEFAULT_DOUBLE_COLOR;
                  doubleSep   = DEFAULT_DOUBLESEP;
                  bordersPosition = DEFAULT_BORDERS_POSITION;
                  hatchingAngle = DEFAULT_HATCH_ANGLE;
                  hatchingColor = DEFAULT_HATCH_COL;
                  hatchingStyle = DEFAULT_HATCH_STYLE;
                  hatchingWidth = DEFAULT_HATCH_WIDTH;
            }
            
            if(LaTeXDrawFrame.getVersionOfFile().compareTo("1.7")>=0) //$NON-NLS-1$
            {
                  hasShadow   = ois.readBoolean();
                  shadowAngle = ois.readDouble();
                  shadowSize  = ois.readDouble();
                  shadowColor = (Color)ois.readObject();
                  gradientEndColor = (Color)ois.readObject();
                  gradientStartColor = (Color)ois.readObject();
                  gradientAngle = ois.readDouble();
                  gradientMidPoint = ois.readDouble();
            }
            else
            {
                  hasShadow   = DEFAULT_SHADOW_HAS;
                  shadowAngle = DEFAULT_SHADOW_ANGLE;
                  shadowSize  = DEFAULT_SHADOW_SIZE;
                  shadowColor = DEFAULT_SHADOW_COLOR;
                  gradientEndColor = PSTricksConstants.DEFAULT_GRADIENT_END_COLOR;
                  gradientStartColor = PSTricksConstants.DEFAULT_GRADIENT_START_COLOR;
                  gradientAngle = DEFAULT_GRADIENT_ANGLE;
                  gradientMidPoint = DEFAULT_GRADIENT_MID_POINT;
            }
            
            if(LaTeXDrawFrame.getVersionOfFile().compareTo("1.8")>=0) //$NON-NLS-1$
                  hatchingSep = ois.readDouble();
            else
                  hatchingSep = DEFAULT_HATCH_SEP;
            
            shape = getInsideOutsideOrMiddleBorders();
      }
      


      

      @Override
00729       protected GeneralPath getBorders(double gap, boolean into)
      {
            if(gap==0.)
                  return getMiddleBorders();
            
            GeneralPath gp = new GeneralPath();
            LaTeXDrawPoint2D pt1 = getPoint(0), pt2 = getPoint(-1);
            
            if(pt1.x<pt2.x+thickness && pt1.x>pt2.x-thickness)
            {
                  gp.moveTo((float)(pt1.x+pt2.x)/2f, (float)pt1.y);
                  gp.lineTo((float)(pt1.x+pt2.x)/2f, (float)pt2.y);
            }
            else
            {
                  if(!into) 
                        gap*=-1;
                  
                  LaTeXDrawPoint2D p1 = new LaTeXDrawPoint2D((pt1.x+pt2.x)/2., pt1.y);
                  LaTeXDrawPoint2D p2 = new LaTeXDrawPoint2D(pt2.x, pt2.y);
                  LaTeXDrawPoint2D p3 = new LaTeXDrawPoint2D(pt1.x, pt2.y);
                double cornerGap1 = Figure.getCornerGap(new LaTeXDrawPoint2D(p1.x, p2.y), p1, p2, gap)/2.;
                double cornerGap2 = Figure.getCornerGap(getGravityCenter(), p2, p3, gap)/2.;
                
                if(p2.x<p3.x)
                  cornerGap2*=-1;
                
                if(p1.y>p2.y)
                  cornerGap1*=-1;
                
                gp.moveTo((float)p1.x, (float)(p1.y + cornerGap1));
                gp.lineTo((float)(p2.x - cornerGap2), (float)(p2.y + (p1.y>p2.y ? gap/2. : -gap/2.)));
                gp.lineTo((float)(p3.x + cornerGap2), (float)(p2.y + (p1.y>p2.y ? gap/2. : -gap/2.)));
                gp.closePath();
            }
                  
            return gp;
      }
      
      

      public GeneralPath getInsideBorders()
      {
            return getBorders(thickness, true);
      }


      
      
      
      public GeneralPath getOutsideBorders()
      {
            return getBorders(thickness, false);
      }

      
      

      
      public GeneralPath getMiddleBorders()
      {
            LaTeXDrawPoint2D pt1 = getPoint(0), pt2 = getPoint(-1);
            GeneralPath gp = new GeneralPath();
            
            gp.moveTo((float)(pt2.x + pt1.x)/2f, (float)pt1.y);
            gp.lineTo((float)pt1.x, (float)pt2.y);
            gp.lineTo((float)pt2.x, (float)pt2.y);
            gp.closePath();

            return gp;
      }


      
      
      
      @Override
      public GeneralPath getInsideOutsideOrMiddleBorders()
      {
            GeneralPath path;
            
            if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                  path = getInsideBorders();
            else
                  if(bordersPosition.equals(PSTricksConstants.BORDERS_OUTSIDE))
                        path = getOutsideBorders();
                  else
                        path = getMiddleBorders();

            return path;
      }
      
      
      
      
      
      
      @Override
00827       public GeneralPath[] getDbleBoundariesOutside(Shape classicBord)
      {
            LaTeXDrawPoint2D pt1 = getPoint(0), pt2 = getPoint(-1);
            GeneralPath[] sx = new GeneralPath[2];
            
            if(pt1.x<pt2.x+thickness && pt1.x>pt2.x-thickness)
            {
                  sx[0] = new GeneralPath(classicBord);
                  sx[1] = new GeneralPath(classicBord);
            }
            else
            {
                  sx[0] = getBorders(3*thickness+2*doubleSep, false);
                  sx[1] = getBorders(2*thickness+doubleSep, false);
            }
            
            return sx;
      }


      
      

      @Override
00851       public GeneralPath[] getDbleBoundariesInside(Shape classicBord)
      {
            LaTeXDrawPoint2D pt1 = getPoint(0), pt2 = getPoint(-1);
            GeneralPath[] sx = new GeneralPath[2];
            
            if(pt1.x<pt2.x+thickness && pt1.x>pt2.x-thickness)
            {
                  sx[0] = new GeneralPath(classicBord);
                  sx[1] = new GeneralPath(classicBord);
            }
            else
            {
                  sx[1] = getBorders(3*thickness+2*doubleSep, true);
                  sx[0] = getBorders(2*thickness+doubleSep, true);
            }
            
            return sx;
      }


      
      

      @Override
00875       public GeneralPath[] getDbleBoundariesMiddle(Shape classicBord)
      {
            LaTeXDrawPoint2D pt1 = getPoint(0), pt2 = getPoint(-1);
            GeneralPath[] sx = new GeneralPath[2];
            
            if(pt1.x<pt2.x+thickness && pt1.x>pt2.x-thickness)
            {
                  sx[0] = new GeneralPath(classicBord);
                  sx[1] = new GeneralPath(classicBord);
            }
            else
            {
                  sx[0] = getBorders(thickness+doubleSep, false);
                  sx[1] = getBorders(thickness+doubleSep, true);
            }
            
            return sx;

      }
      
      
      
      @Override
00898       public GeneralPath[] getDbleBoundariesOutInOrMiddle(Shape classicBord)
      {
            GeneralPath[] path;

            if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                  path = getDbleBoundariesInside(classicBord);
            else
                  if(bordersPosition.equals(PSTricksConstants.BORDERS_OUTSIDE))
                        path = getDbleBoundariesOutside(classicBord);
                  else
                        path = getDbleBoundariesMiddle(classicBord);

            return path;
      }

      
      
      @Override
00916       public synchronized void setThickness(float val)
      {
            if(!Double.isInfinite(val) && !Double.isNaN(val) && val>0)
            {
                  thickness = val;
                  shape = getInsideOutsideOrMiddleBorders();
                  borders.setThickness(thickness);
            }
      }
      
      
      
      @Override
      @Deprecated
00930       public void updateBorders()
      {
            /*
             * Update the borders change the points of the triangle. 
             */
      }
      
      
      
      @Override
00940       public Shape createShadowShape()
      {
            if(!canHaveShadow || !hasShadow) return shape;
            
            Shape shadowS;
            
            if(hasDoubleBoundary)
            {
                  if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                         shadowS = getBorders(0, true);
                  else 
                        if(bordersPosition.equals(PSTricksConstants.BORDERS_MIDDLE))
                         shadowS = getBorders(thickness*2+doubleSep, false);
                  else 
                        shadowS = getBorders((thickness*2+doubleSep)*2, false);
            }
            else
            {
                  if(bordersPosition.equals(PSTricksConstants.BORDERS_INSIDE))
                         shadowS = getBorders(0, false);
                  else 
                        if(bordersPosition.equals(PSTricksConstants.BORDERS_MIDDLE))
                         shadowS = getBorders(thickness, false);
                  else 
                        shadowS = getBorders(thickness*2, false);
            }
            
            double dx=0, dy=0;
            LaTeXDrawPoint2D cg = getGravityCenter();
            LaTeXDrawPoint2D shadowCg = (LaTeXDrawPoint2D)cg.clone();
            AffineTransform at = new AffineTransform();
            
            shadowCg.setLocation(cg.x+shadowSize, cg.y);
            shadowCg = Figure.rotatePoint(shadowCg, cg, shadowAngle);
            dx = shadowCg.x-cg.x;
            dy = cg.y-shadowCg.y;
            at.translate(dx, dy);
            
            return at.createTransformedShape(shadowS);
      }

      
      
      
      @Override
00985       public String getPSTricksCodeFilling(float ppc)
      {
            String str="fillstyle=";//$NON-NLS-1$

            if(hatchingStyle.equals(PSTricksConstants.TOKEN_FILL_NONE))
            {
                  if(isFilled)
                        str += "solid"; //$NON-NLS-1$
                  else str = "";//$NON-NLS-1$
            }
            else
                  if(hatchingStyle.equals(PSTricksConstants.TOKEN_FILL_GRADIENT))
                  {
                        str+= "gradient,gradlines=2000";//$NON-NLS-1$
                        
                        if(!gradientStartColor.equals(PSTricksConstants.DEFAULT_GRADIENT_START_COLOR))
                        {
                              String name = DviPsColors.getColourName(gradientStartColor);
                              if(name==null)
                              {
                                    name = "color"+number+'g';//$NON-NLS-1$
                                    DviPsColors.addUserColour(gradientStartColor, name); 
                              }
                              str += ",gradbegin=" + name; //$NON-NLS-1$
                        }
                        
                        if(!gradientEndColor.equals(PSTricksConstants.DEFAULT_GRADIENT_END_COLOR))
                        {
                              String name = DviPsColors.getColourName(gradientEndColor);
                              if(name==null)
                              {
                                    name = "color"+number+'f';//$NON-NLS-1$
                                    DviPsColors.addUserColour(gradientEndColor, name); 
                              }
                              str += ",gradend=" + name; //$NON-NLS-1$
                        }
                        
                        if(gradientMidPoint!=PSTricksConstants.DEFAULT_GRADIENT_MID_POINT)
                              str+=",gradmidpoint="+(float)gradientMidPoint;//$NON-NLS-1$
                        
                        boolean reverse = getPoint(0).y>getPoint(2).y;
                        if(Math.toDegrees(gradientAngle)!=PSTricksConstants.DEFAULT_GRADIENT_ANGLE ||
                                    (reverse && (Math.toDegrees(gradientAngle)+180)!=PSTricksConstants.DEFAULT_GRADIENT_ANGLE))
                              str+=",gradangle="+(float)(toDegrees(gradientAngle)-//$NON-NLS-1$
                                           (reverse? 180 : 0));
                  }
                  else
                  {
                        if(hatchingStyle.equals(PSTricksConstants.TOKEN_FILL_CROSSHATCH))
                              str += "crosshatch"; //$NON-NLS-1$
                        else
                              if (hatchingStyle.equals(PSTricksConstants.TOKEN_FILL_HLINES))
                                    str += "hlines"; //$NON-NLS-1$
                              else
                                    str += "vlines"; //$NON-NLS-1$
      
                        if(isFilled)
                              str += "*"; //$NON-NLS-1$
      
                        str += ",hatchwidth=" + (hatchingWidth / ppc) + ",hatchangle=" + //$NON-NLS-1$ //$NON-NLS-2$
                                    (float)Math.toDegrees(hatchingAngle);
                        if(!hatchingColor.equals(PSTricksConstants.DEFAULT_HATCHING_COLOR))
                        {
                              String name = DviPsColors.getColourName(hatchingColor);
                              if(name==null)
                              {
                                    name = "color"+number+'c';//$NON-NLS-1$
                                    DviPsColors.addUserColour(hatchingColor, name); 
                              }
                              str += ",hatchcolor=" + name; //$NON-NLS-1$
                        }
                  }
            
            if(isFilled)
            {
                  if (!interiorColor.equals(PSTricksConstants.DEFAULT_INTERIOR_COLOR))
                  {
                        String name = DviPsColors.getColourName(interiorColor);
                        if(name==null)
                        {
                              name = "color"+number+'b';//$NON-NLS-1$
                              DviPsColors.addUserColour(interiorColor, name); 
                        }
                        str += ",fillcolor=" + name; //$NON-NLS-1$
                  }
            }
            
            return str;
      }
      
      
      
      @Override
      @Deprecated
01079       public void updateBorders(LaTeXDrawPoint2D pt)
      {
            // Nothing must be done.
      }
      
      
      @Override
01086       public void mirrorHorizontal(LaTeXDrawPoint2D origin)
      {
            borders.mirrorHorizontal(origin);
            updateShape();
      }



      @Override
01095       public void mirrorVertical(LaTeXDrawPoint2D origin)
      {
            borders.mirrorVertical(origin);
            updateShape();
      }




      @Override
01105       public synchronized LaTeXDrawPoint2D getLastPoint()
      {
            return borders.getLastPoint();
      }
      
      
      @Override
01112       public void updateToGrid(MagneticGrid grid)
      {
            borders.updateToGrid(grid);
            updateShape();
      }
      
      
      @Override
01120       public void rescaleX(double formerX, double newX, double percent, LaTeXDrawRectangle bound)
      {
            borders.rescaleX(formerX, newX, percent, bound);
            updateShape();
      }




      @Override
01130       public void rescaleY(double formerY, double newY, double percent, LaTeXDrawRectangle bound)
      {
            borders.rescaleY(formerY, newY, percent, bound);
            updateShape();
      }
      
      
      
      
      /**
       * Computes the altitude ha of the <b>right-triangle<b> ABC, right in A.
       * @param a The point A.
       * @param b The point B.
       * @param c The point C.
       * @return The altitude ha or 0.
       * @since 2.0.0
       */
01147       public static double getAltitude(Point2D a, Point2D b, Point2D c)
      {
            if(a==null || b==null || c==null)
                  return 0.;
            
            double ac = a.distance(c), ab = a.distance(b);
            
            if(((float)ab) == ((float)ac))
                  return a.distance((b.getX()+c.getX())/2., (b.getY()+c.getY())/2.);
            
            return ab * ac / b.distance(c);
      }
      
      
      
      
      @Override
      public int hashCode()
      {
            return (int)(super.hashCode()/3.5);
      }
}

Generated by  Doxygen 1.6.0   Back to index