001/*
002 *   CircleInfo  -- An object that packages together information about circles.
003 *
004 *   Copyright (C) 2009-2016, by Joseph A. Huwaldt.
005 *   All rights reserved.
006 *   
007 *   This library is free software; you can redistribute it and/or
008 *   modify it under the terms of the GNU Lesser General Public
009 *   License as published by the Free Software Foundation; either
010 *   version 2.1 of the License, or (at your option) any later version.
011 *   
012 *   This library is distributed in the hope that it will be useful,
013 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 *   Library General Public License for more details.
016 *
017 *  You should have received a copy of the GNU Lesser General Public License
018 *  along with this program; if not, write to the Free Software
019 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020 *  Or visit:  http://www.gnu.org/licenses/lgpl.html
021 */
022package geomss.geom;
023
024import jahuwaldt.js.param.Parameter;
025import javax.measure.quantity.Angle;
026import javax.measure.quantity.Dimensionless;
027import javax.measure.quantity.Length;
028import javax.measure.unit.NonSI;
029import javolution.xml.XMLFormat;
030import javolution.xml.XMLSerializable;
031import javolution.xml.stream.XMLStreamException;
032
033/**
034 * An simple container that packages together information about circles.
035 *
036 * <p> Modified by: Joseph A. Huwaldt </p>
037 *
038 * @author Joseph A. Huwaldt, Date: May 29, 2009
039 * @version September 13, 2016
040 */
041public class CircleInfo implements XMLSerializable {
042    private static final long serialVersionUID = 1L;
043
044    /**
045     * THe radius of the circle in length units.
046     */
047    public Parameter<Length> radius;
048
049    /**
050     * The center or origin of the circle.
051     */
052    public GeomPoint center;
053
054    /**
055     * The direction of the circles X axis.
056     */
057    public GeomVector<Dimensionless> xhat;
058
059    /**
060     * The direction of the circles Y axis.
061     */
062    public GeomVector<Dimensionless> yhat;
063
064    /**
065     * The angle between the start and end of the circle (if represented as a circular
066     * arc).
067     */
068    public Parameter<Angle> angle = Parameter.TWOPI_ANGLE;
069
070    /**
071     * Return a String representation of this object.
072     *
073     * @return A String representation of this object.
074     */
075    @Override
076    public String toString() {
077        StringBuilder buff = new StringBuilder("radius = ");
078        buff.append(radius);
079        buff.append(", center = ");
080        buff.append(center);
081        buff.append(", xhat = ");
082        buff.append(xhat);
083        buff.append(", yhat = ");
084        buff.append(yhat);
085        buff.append(", angle = ");
086        buff.append(angle.to(NonSI.DEGREE_ANGLE));
087        return buff.toString();
088    }
089
090    /**
091     * Holds the default XML representation for this object.
092     */
093    protected static final XMLFormat<CircleInfo> XML = new XMLFormat<CircleInfo>(CircleInfo.class) {
094
095        @Override
096        public CircleInfo newInstance(Class<CircleInfo> cls, InputElement xml) throws XMLStreamException {
097            return new CircleInfo();
098        }
099
100        @Override
101        public void read(InputElement xml, CircleInfo obj) throws XMLStreamException {
102
103            //  Read in the parameters of the circle.
104            obj.radius = xml.get("Radius");
105            obj.center = xml.get("Center");
106            obj.xhat = xml.get("XHat");
107            obj.yhat = xml.get("YHat");
108            obj.angle = xml.get("Angle");
109            
110        }
111
112        @Override
113        public void write(CircleInfo obj, OutputElement xml) throws XMLStreamException {
114            //  Write out the parameters of the circle.
115            xml.add(obj.radius, "Radius");
116            xml.add(obj.center, "Center");
117            xml.add(obj.xhat, "XHat");
118            xml.add(obj.yhat, "YHat");
119            xml.add(obj.angle, "Angle");
120        }
121    };
122}