Class PicParallelogram

  • All Implemented Interfaces:
    Element, PicMultiCurveConvertable, PicObjectConstants, ActionFactory, CustomizerFactory
    Direct Known Subclasses:
    PicEllipse

    public class PicParallelogram
    extends DefaultLeafElement
    implements CustomizerFactory, ActionFactory, PicMultiCurveConvertable
    A class implementing a parallelogram. Geometry is fully specified by three corner points (namely, the bottom-left, bottom-right and top-right corners), which thus act as specification-points (see DefaultLeafElement for details), and can be retrieved using getSpecificationPointX/Y. These are obviously stored in the pts ArrayList, as defined in DefaultLeafElement.

    [SR:TODO] add rounded-corners feature.

    Since:
    jPicEdt 1.4
    Version:
    $Id: PicParallelogram.java,v 1.28.2.1 2007/09/02 11:56:27 reynal Exp $
    Author:
    Vincent Guirardel.
    • Field Detail

      • P_BL

        public static final int P_BL
        Bottom-Left corner (also first specification point)
        See Also:
        Constant Field Values
      • P_BR

        public static final int P_BR
        Bottom-Right corner (also second specification point)
        See Also:
        Constant Field Values
      • P_TR

        public static final int P_TR
        Top-Right corner (also third specification point)
        See Also:
        Constant Field Values
      • FIRST_PT

        public static final int FIRST_PT
        Index of first control-point
        See Also:
        Constant Field Values
      • P_SPEC_BL

        public static final int P_SPEC_BL
        1st specification point : Bottom-Left corner
        See Also:
        Constant Field Values
      • P_SPEC_BR

        public static final int P_SPEC_BR
        2nd specification point : Bottom-Right corner
        See Also:
        Constant Field Values
      • P_SPEC_TR

        public static final int P_SPEC_TR
        3rd specification point : Top-Right corner
        See Also:
        Constant Field Values
      • l2rVec

        protected PicVector l2rVec
        "l2rVec" is a vector pointing from P_BL to P_BR (or equally, from P_TL to P_TR) "b2tVec" is a vector pointing from P_BR to P_TR (or equally, from P_BL to P_TL) These two vectors simply define a convenient parallelogram's basis, and are updated by a call to updateParalleloBasis(). They are used e.g. when moving a corner-point.

        An essential function of these vectors is to "retain" the initial parallelogram basis even if the element becomes flat at some point during an edit operation.

    • Constructor Detail

      • PicParallelogram

        public PicParallelogram()
        Creates a new PicParallelogram reduced to (0,0)
        Since:
        jpicedt 1.3.3
      • PicParallelogram

        public PicParallelogram​(PicAttributeSet set)
        Creates a new PicParallelogram reduced to (0,0), with the given attribute set
        Since:
        jpicedt 1.3.3
      • PicParallelogram

        public PicParallelogram​(PicPoint pt1,
                                PicPoint pt2,
                                PicPoint pt3)
        Create a new PicParallelogram object using the 3 given points as 3 consecutive points of the parallelogram, and a default attribute set.
        Since:
        jpicedt 1.4
      • PicParallelogram

        public PicParallelogram​(PicPoint pt1,
                                PicPoint pt2,
                                PicPoint pt3,
                                PicAttributeSet set)
        Create a new PicParallelogram object using the 3 given points as 3 consecutive points of the parallelogram.
        Since:
        jpicedt 1.3.3
      • PicParallelogram

        public PicParallelogram​(PicPoint pt1,
                                PicPoint pt3)
        Create a new rectangle with axes parallel to X- and Y-axes, using the 2 given points to build the diagonal, and a default attribute set.
        Since:
        jpicedt 1.4
      • PicParallelogram

        public PicParallelogram​(PicPoint pt,
                                PicAttributeSet set)
        Create a new PicParallelogram reduced to a point located at the given position
        Since:
        jpicedt 1.3.3
      • PicParallelogram

        public PicParallelogram​(PicParallelogram parallelo)
        "cloning" constructor (to be used by clone())
        Parameters:
        The - PicParallelogram object to clone
        Since:
        jpicedt 1.3.3
    • Method Detail

      • clone

        public java.lang.Object clone()
        Overrides Object.clone() method
        Specified by:
        clone in interface Element
        Overrides:
        clone in class DefaultLeafElement
        Since:
        jpicedt 1.3.3
      • getName

        public java.lang.String getName()
        Description copied from class: DefaultLeafElement
        Returns a non-localised string representing this object's name This default implementation returns the class name.
        Specified by:
        getName in interface Element
        Overrides:
        getName in class DefaultLeafElement
        Returns:
        a localised string that represents this object's name
        Since:
        jpicedt 1.3.3
      • getPointX

        public double getPointX​(int numPoint)
        Return the X-coord of the control-point indexed by numPoint.
        Specified by:
        getPointX in interface Element
        Overrides:
        getPointX in class DefaultLeafElement
        Parameters:
        numPoint - the point index, should be greater or equal to the value returned by getFirstPointIndex, and lower or equal to getLastPointIndex.
        Returns:
        the X-coord of the point indexed by index.
        Since:
        jpicedt 1.3.3
      • getPointY

        public double getPointY​(int numPoint)
        Return the Y-coord of the control-point indexed by numPoint.
        Specified by:
        getPointY in interface Element
        Overrides:
        getPointY in class DefaultLeafElement
        Parameters:
        numPoint - the point index, should be greater or equal to the value returned by getFirstPointIndex, and lower or equal to getLastPointIndex.
        Returns:
        the Y-coord of the point indexed by index.
        Since:
        jpicedt 1.3.3
      • getPoint

        public PicPoint getPoint​(int numPoint,
                                 PicPoint src)
        Return the user-controlled point having the given index. The general contract in Element is to return an IMMUTABLE instance of PicPoint, so that the only way to alter the geometry of this element is by calling the setPoint method.
        Specified by:
        getPoint in interface Element
        Overrides:
        getPoint in class DefaultLeafElement
        Parameters:
        numPoint - the point index, should be greater or equal to the value returned by getFirstPointIndex, and lower or equal to getLastPointIndex.
        Returns:
        the point indexed by numPoint ; if src is null, allocates a new PicPoint and return it, otherwise directly modifies src and returns it as well for convenience.
      • updateParalleloBasis

        protected void updateParalleloBasis()
        Compute the "l2r" and "b2t" vectors of the parallelogram basis from the location of the three specification-points of this parallelogram.
        Since:
        jpicedt 1.3.3
      • toParalleloBasisCoordinates

        protected PicVector toParalleloBasisCoordinates​(PicPoint ptOrg,
                                                        PicPoint ptSrc,
                                                        PicVector ptDest)
        Compute the contravariant coordinate of the given point "ptSrc" along the "l2r" and "b2t" vectors of the parallelogram's basis, the origin of the basis being set at "ptOrg" This simply reduces to a contravariant change of coordinates from the cartesian basis to the (non-orthonormalized) parallelogram basis.
        To wind up : denoting OM = vec(ptOrg -> ptSrc), (e1,e2) the cartesian basis (ie std model-coordinates), and (x',y') the new coords in the (l2r,b2t) basis, yields :
        OM = x e1 + y e2 = x' l2r + y' b2t.
        Change of coordinates is carried out by using elementary geometry. This yields :
        • x' = (OM x b2t).e3/||l2r x b2t||
        • y' = -(OM x l2r).e3/||l2r x b2t||
        where e3 denotes the z-axis unit vector of the (x,y,z) direct diedra.

        Note that updateParalleloBasis must be called beforehands for this method to return a valid results [SR:pending] need to be cleaned up.

        Parameters:
        ptOrg - origin of parallelogram's basis
        ptSrc - source point, coordinates of which have to be converted
        ptDest - if null, gets allocated and returned for convenience ; besides, it is perfectly safe to call this method with ptDest and one of ptOrg and ptSrc referencing the same PicPoint.
        Returns:
        the new coordinates (x',y') along (l2r,b2t), encapsulated in a PicVector
        Since:
        jpicedt 1.3.3
      • setPoint

        public void setPoint​(int numPoint,
                             PicPoint pt,
                             EditPointConstraint constraint)
        Set the coordinate of the control-point indexed by "numPoint" to the given value. The control-policy for the default (null or DEFAULT) constraint is as follows :
        • when moving a corner, the opposite CORNER is kept fixed (ie segments experience a parallel transport)
        • when moving a SIDE_X point, the opposite SEGMENT is kept fixed, so that this operation allows one to change the parallelogram skewness.

        The SQUARE constraint imposes that the parallelogram be a square. The square diagonal is computed from the current control-point and its opposite corner. Other spec' points are set accordingly.

        The CENTER_FIXED constraint imposes that the parallelogram center be kept fixed. Spec' points are set accordingly.

        Specified by:
        setPoint in interface Element
        Overrides:
        setPoint in class DefaultLeafElement
        Parameters:
        numPoint - one of P_TL, P_TR, P_BL, P_BR, SIDE_T, SIDE_B, SIDE_L, SIDE_R or P_CENTER.
        constraint - either null, DEFAULT, CENTER_FIXED or SQUARE
        Since:
        jpicedt 1.3.3
      • getCenterX

        public double getCenterX()
        Return the X-coord of the parallelogram's center
        Since:
        jpicedt 1.3.3
      • getCenterY

        public double getCenterY()
        Return the Y-coord of the parallelogram's center
        Since:
        jpicedt 1.3.3
      • getCenter

        public PicPoint getCenter​(PicPoint src)
        Return the parallelogram's centre
        Returns:
        if src is null, allocates a new PicPoint and return it, otherwise directly modifies src and returns it as well for convenience.
        Since:
        jpicedt 1.3.3
      • rotate

        public void rotate​(PicPoint ptOrg,
                           double angle)
        Rotate this Element by the given angle along the given point
        Specified by:
        rotate in interface Element
        Overrides:
        rotate in class DefaultLeafElement
        Parameters:
        angle - rotation angle in radians
      • shear

        public void shear​(PicPoint ptOrg,
                          double shx,
                          double shy)
        Shear this Element by the given params wrt to the given origin
        Specified by:
        shear in interface Element
        Overrides:
        shear in class DefaultLeafElement
      • getBoundingBox

        public java.awt.geom.Rectangle2D getBoundingBox​(java.awt.geom.Rectangle2D r)
        Returns the bounding box (ie the surrounding rectangle) in double precision Used for instance to determine the arguments of a \\begin{picture} command.

        This implementation compute the bounding-box from the smallest rectangle that encompasses all the specification-points.

        Specified by:
        getBoundingBox in interface Element
        Overrides:
        getBoundingBox in class DefaultLeafElement
        Returns:
        the bounding box (i.e. the surrounding rectangle) in double precision Used e.g. to determine the arguments of the \\begin{picture} command. If r is null, allocate a new rectangle and returns it. Otherwise the source rectangle is modified and returned for convenience. [todo:reynal] this really need to be improved : this method would probably better be moved to the attached view, since the latter knows exactly what the TRUE bounding box is.
        Since:
        jpicedt 1.3.3
      • isRectangle

        public boolean isRectangle()
        Returns true if this parallelogram is a rectangle
      • toString

        public java.lang.String toString()
        Implementation of the Object.toString() method, used for debugging purpose
        Overrides:
        toString in class DefaultLeafElement
      • createActions

        public PEAction[] createActions​(ActionDispatcher actionDispatcher,
                                        ActionLocalizer localizer,
                                        HitInfo hi)
        Create an array of Action's related to this object
        Specified by:
        createActions in interface ActionFactory
        Parameters:
        actionDispatcher - dispatches events to the proper PECanvas
        localizer - i18n localizer for PEAction's
        hi - a HitInfo containing information related to the mouse-event which triggered the popup menu.