public final void setXXX() { final double dep = w4.getDepth(); final double dLat = w4.getLat(); final double dLong = w4.getLong(); w1.setDepth(dep); w1.setLat(dLat); w1.setLong(dLong); assertTrue(w1.equals(w4)); }
/** * note that addToMe changes this object * * @param delta the offset to add to this point */ public void addToMe(final WorldVector delta) { // check we have our model if (_model == null) { _model = new MWC.Algorithms.EarthModels.FlatEarth(); } // do the calculation with our model final WorldLocation res = _model.add(this, delta); // update ourselves to the result setLat(res.getLat()); setLong(res.getLong()); setDepth(res.getDepth()); }
public final void testGetDepth() { assertEquals(w1.getDepth(), 12.5, 0d); }
/** put our keywords into the XML description */ protected static String swapKeywords( final DetectionEvent detection, final Status currentLocation, final String weapon, final TargetType theTarget) { // amend string template to include available parameters final Float brg_degs = detection.getBearing(); final WorldDistance rng = detection.getRange(); // take a copy of the string String working = new String(weapon); // swap the bearing if (brg_degs != null) { final String brg_val = "" + brg_degs.floatValue(); working = replaceAll(working, "$BRG$", brg_val); } // swap the range if (rng != null) { final String rng_val = "" + rng.getValueIn(WorldDistance.YARDS); working = replaceAll(working, "$RNG$", rng_val); } // insert the location of the target if (brg_degs != null) { final float brg_val = brg_degs.floatValue(); // do we know range? if (rng != null) { // yes, compute target location final WorldVector newVector = new WorldVector( MWC.Algorithms.Conversions.Degs2Rads(brg_val), rng.getValueIn(WorldDistance.DEGS), 0); final WorldLocation newLoc = currentLocation.getLocation().add(newVector); // produce strings from this location final String theDepth = "" + newLoc.getDepth(); final String theLat = "" + newLoc.getLat(); final String theLong = "" + newLoc.getLong(); // put these strings into the new behaviour working = replaceAll(working, "$TGT_DEPTH$", theDepth); working = replaceAll(working, "$TGT_LAT$", theLat); working = replaceAll(working, "$TGT_LONG$", theLong); } else { // no, send the weapon down a bearing for XXXX yds // compute target location final double TGT_RANGE = 5000; final WorldVector newVector = new WorldVector( MWC.Algorithms.Conversions.Degs2Rads(brg_val), MWC.Algorithms.Conversions.Yds2Degs(TGT_RANGE), 0); final WorldLocation newLoc = currentLocation.getLocation().add(newVector); // produce strings from this location final String theDepth = "" + newLoc.getDepth(); final String theLat = "" + newLoc.getLat(); final String theLong = "" + newLoc.getLong(); // put these strings into the new behaviour working = replaceAll(working, "$TGT_DEPTH$", theDepth); working = replaceAll(working, "$TGT_LAT$", theLat); working = replaceAll(working, "$TGT_LONG$", theLong); } } if (theTarget != null) { // output the XML header stuff // output the plot final java.io.StringWriter newString = new StringWriter(); // final com.sun.xml.tree.XmlDocument doc = new com.sun.xml.tree.XmlDocument(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc = null; try { DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); final org.w3c.dom.Element type = ASSET.Util.XML.Decisions.Util.TargetTypeHandler.getElement(theTarget, doc); doc.appendChild(type); doc.setNodeValue(type.getTagName()); // doc.changeNodeOwner(type); // doc.setSystemId("ASSET XML Version 1.0"); // Use a Transformer for output TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(newString); transformer.transform(source, result); } catch (ParserConfigurationException e) { e.printStackTrace(); // To change body of catch statement use Options | File Templates. } catch (DOMException e) { e.printStackTrace(); // To change body of catch statement use Options | File Templates. } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) { transformerFactoryConfigurationError .printStackTrace(); // To change body of catch statement use Options | File Templates. } catch (TransformerException e) { e.printStackTrace(); // To change body of catch statement use Options | File Templates. } // // ok, we should be done now // try // { // doc.write(newString); // } // catch(java.io.IOException e) // { // e.printStackTrace(); // } // try to extract the <target type portion if (newString != null) { final String val = newString.toString(); final String startIdentifier = "<TargetType"; final String endIdentifier = "</TargetType"; final int start = val.indexOf(startIdentifier); final int end = val.lastIndexOf(endIdentifier); final String detail = val.substring(start, end + endIdentifier.length() + 1); // lastly, replace the string working = replaceAll(working, "<TargetType/>", detail); } } return working; }