001/** 002 * CSTCurve -- Implementation and interface in common to all CST curves. 003 * 004 * Copyright (C) 2014-2015, by Joseph A. Huwaldt. All rights reserved. 005 * 006 * This library is free software; you can redistribute it and/or modify it under the terms 007 * of the GNU Lesser General Public License as published by the Free Software Foundation; 008 * either version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 012 * PARTICULAR PURPOSE. See the GNU Library General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public License along with 015 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - 016 * Suite 330, Boston, MA 02111-1307, USA. Or visit: http://www.gnu.org/licenses/lgpl.html 017 */ 018package geomss.geom.cst; 019 020import geomss.geom.*; 021import jahuwaldt.js.param.Parameter; 022import static java.util.Objects.nonNull; 023import static java.util.Objects.requireNonNull; 024import javax.measure.quantity.Dimensionless; 025import javax.measure.quantity.Length; 026import javolution.util.FastMap; 027import javolution.xml.XMLFormat; 028import javolution.xml.stream.XMLStreamException; 029 030/** 031 * The interface and implementation in common to all Class-Shape-Transform (CST) planar 032 * curves. This curve type is useful for defining smooth aircraft component shapes with 033 * a minimum number of defining parameters. 034 * 035 * <p> Modified by: Joseph A. Huwaldt </p> 036 * 037 * @author Joseph A. Huwaldt, Date: October 7, 2015 038 * @version November 28, 2015 039 */ 040@SuppressWarnings({"serial", "CloneableImplementsClone"}) 041public abstract class CSTCurve extends AbstractCurve<CSTCurve> { 042 043 /** 044 * Return the class function associated with this CST curve. 045 * @return The class function associated with this CST curve. 046 */ 047 public abstract CSTClassFunction getCFunction(); 048 049 /** 050 * Return the shape function associated with this CST curve. 051 * @return The shape function associated with this CST curve. 052 */ 053 public abstract CSTShapeFunction getSFunction(); 054 055 /** 056 * Return the offset of the trailing edge of the curve from the chord line. 057 * @return The offset of the trailing edge of the curve from the chord line. 058 */ 059 public abstract Parameter<Length> getOffsetTE(); 060 061 /** 062 * Return the chord length of the curve. This defines the scale or size of the curve. 063 * @return The chord length of the curve. 064 */ 065 public abstract Parameter<Length> getChord(); 066 067 /** 068 * Return the origin of the leading edge of this curve. This defines the s=0 location 069 * of the curve in space. 070 * @return The origin of the leading edge of this curve. 071 */ 072 public abstract Point getOrigin(); 073 074 /** 075 * Return the chord-wise direction of this curve (the curve X-direction). 076 * @return The chord-wise direction of this curve. 077 */ 078 public abstract Vector<Dimensionless> getXhat(); 079 080 /** 081 * Return the in-plane direction of this curve perpendicular to the chord-wise 082 * direction (the curve Y-direction). 083 * @return The in-plane direction of this curve perpendicular to Xhat. 084 */ 085 public abstract Vector<Dimensionless> getYhat(); 086 087 /** 088 * Return an immutable version of this CST curve. 089 * 090 * @return an immutable version of this curve. 091 */ 092 public abstract BasicCSTCurve immutable(); 093 094 095 /** 096 * Returns the number of child-elements that make up this geometry element. This 097 * implementation always returns 0. 098 * 099 * @return Always returns 0. 100 */ 101 @Override 102 public int size() { 103 return 0; 104 } 105 106 /** 107 * Return <code>true</code> if this curve is degenerate (i.e.: has length less than 108 * the specified tolerance). 109 * 110 * @param tol The tolerance for determining if this curve is degenerate. May not be 111 * null. 112 * @return true if this curve is degenerate. 113 */ 114 @Override 115 public boolean isDegenerate(Parameter<Length> tol) { 116 return !getChord().isLargerThan(requireNonNull(tol)); 117 } 118 119 /** 120 * Return <code>true</code> if this curve is planar or <code>false</code> if it is 121 * not. BasicCSTCurve objects are always planar, so this always returns true. 122 * 123 * @param tol The geometric tolerance to use in determining if the curve is planar. 124 * Ignored by this implementation. 125 * @return Always returns true. 126 */ 127 @Override 128 public boolean isPlanar(Parameter<Length> tol) { 129 return true; 130 } 131 132 /** 133 * Returns transformed version of this element. The returned object implements 134 * {@link geomss.geom.GeomTransform} and contains this element as a child. 135 * 136 * @param transform The transformation to apply to this geometry. May not be null. 137 * @return A new triangle that is identical to this one with the specified 138 * transformation applied. 139 * @throws DimensionException if this point is not 3D. 140 */ 141 @Override 142 public CSTCurveTrans getTransformed(GTransform transform) { 143 return CSTCurveTrans.newInstance(this, requireNonNull(transform)); 144 } 145 146 /** 147 * Holds the default XML representation for this object. 148 */ 149 @SuppressWarnings("FieldNameHidesFieldInSuperclass") 150 protected static final XMLFormat<CSTCurve> XML = new XMLFormat<CSTCurve>(CSTCurve.class) { 151 152 @Override 153 public void read(XMLFormat.InputElement xml, CSTCurve obj) throws XMLStreamException { 154 String name = xml.getAttribute("name", (String)null); 155 if (nonNull(name)) 156 obj.setName(name); 157 FastMap userData = xml.get("UserData", FastMap.class); 158 if (nonNull(userData)) { 159 obj.putAllUserData(userData); 160 } 161 } 162 163 @Override 164 public void write(CSTCurve obj, XMLFormat.OutputElement xml) throws XMLStreamException { 165 String name = obj.getName(); 166 if (nonNull(name)) 167 xml.setAttribute("name", name); 168 FastMap userData = (FastMap)obj.getAllUserData(); 169 if (!userData.isEmpty()) 170 xml.add(userData, "UserData", FastMap.class); 171 } 172 }; 173 174}