CPD Results
The following document contains the results of PMD's CPD 7.7.0.
Duplications
File | Project | Line |
---|---|---|
org/djutils/math/polynomialroots/PolynomialRoots.java | DJUTILS math utilities | 21 |
org/djutils/math/polynomialroots/PolynomialRoots2.java | DJUTILS math utilities | 22 |
private PolynomialRoots() { // Do not instantiate } /** * Emulate the F77 sign function. * @param a the value to optionally sign invert * @param b the sign of which determines what to do * @return if b >= 0 then a; else -a */ private static double sign(final double a, final double b) { return b >= 0 ? a : -a; } /** * LINEAR POLYNOMIAL ROOT SOLVER. * <p> * Calculates the root of the linear polynomial:<br> * q1 * x + q0<br> * Unlike the quadratic, cubic and quartic code, this is NOT derived from that Fortran90 code; it was added for completenes. * @param q1 coefficient of the x term * @param q0 independent coefficient * @return the roots of the equation */ public static Complex[] linearRoots(final double q1, final double q0) { if (q1 == 0) { return new Complex[] {}; // No roots; return empty array } return linearRoots(q0 / q1); } /** * LINEAR POLYNOMIAL ROOT SOLVER. * <p> * Calculates the root of the linear polynomial:<br> * x + q0<br> * Unlike the quadratic, cubic and quartic code, this is NOT derived from that Fortran90 code; it was added for completenes. * @param q0 independent coefficient * @return the roots of the equation */ public static Complex[] linearRoots(final double q0) { return new Complex[] { new Complex(-q0, 0) }; } /** * QUADRATIC POLYNOMIAL ROOT SOLVER * <p> * Calculates all real + complex roots of the quadratic polynomial:<br> * q2 * x^2 + q1 * x + q0<br> * The code checks internally if rescaling of the coefficients is needed to avoid overflow. * <p> * The order of the roots is as follows:<br> * 1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest * negative last).<br> * 2) Since there can be only one complex conjugate pair root, no order is necessary.<br> * q1 : coefficient of x term q0 : independent coefficient * @param q2 coefficient of the quadratic term * @param q1 coefficient of the x term * @param q0 independent coefficient * @return the roots of the equation */ public static Complex[] quadraticRoots(final double q2, final double q1, final double q0) { if (q2 == 0) { return linearRoots(q1, q0); } return quadraticRoots(q1 / q2, q0 / q2); } /** * QUADRATIC POLYNOMIAL ROOT SOLVER * <p> * Calculates all real + complex roots of the quadratic polynomial:<br> * x^2 + q1 * x + q0<br> * The code checks internally if rescaling of the coefficients is needed to avoid overflow. * <p> * The order of the roots is as follows:<br> * 1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest * negative last).<br> * 2) Since there can be only one complex conjugate pair root, no order is necessary.<br> * q1 : coefficient of x term q0 : independent coefficient * @param q1 coefficient of the x term * @param q0 independent coefficient * @return the roots of the equation */ public static Complex[] quadraticRoots(final double q1, final double q0) { boolean rescale; double a0, a1; double k = 0, x, y, z; // Handle special cases. if (q0 == 0.0 && q1 == 0.0) { // Two real roots at 0,0 return new Complex[] { Complex.ZERO, Complex.ZERO }; } else if (q0 == 0.0) { // Two real roots; one of these is 0,0 // x^2 + q1 * x == x * (x + q1) Complex nonZeroRoot = new Complex(-q1); return new Complex[] { q1 > 0 ? Complex.ZERO : nonZeroRoot, q1 <= 0 ? nonZeroRoot : Complex.ZERO }; } else if (q1 == 0.0) { x = Math.sqrt(Math.abs(q0)); if (q0 < 0.0) { // Two real roots, symmetrically around 0 return new Complex[] { new Complex(x, 0), new Complex(-x, 0) }; } else { // Two complex roots, symmetrically around 0 return new Complex[] { new Complex(0, x), new Complex(0, -x) }; } } else { // The general case. Do rescaling, if either squaring of q1/2 or evaluation of // (q1/2)^2 - q0 will lead to overflow. This is better than to have the solver // crashed. Note, that rescaling might lead to loss of accuracy, so we only // invoke it when absolutely necessary. final double sqrtLPN = Math.sqrt(Double.MAX_VALUE); // Square root of the Largest Positive Number rescale = (q1 > sqrtLPN + sqrtLPN); // this detects overflow of (q1/2)^2 if (!rescale) { x = q1 * 0.5; // we are sure here that x*x will not overflow rescale = (q0 < x * x - Double.MAX_VALUE); // this detects overflow of (q1/2)^2 - q0 } if (rescale) { x = Math.abs(q1); y = Math.sqrt(Math.abs(q0)); if (x > y) { k = x; z = 1.0 / x; a1 = sign(1.0, q1); a0 = (q0 * z) * z; } else { k = y; a1 = q1 / y; a0 = sign(1.0, q0); } } else { a1 = q1; a0 = q0; } // Determine the roots of the quadratic. Note, that either a1 or a0 might // have become equal to zero due to underflow. But both cannot be zero. x = a1 * 0.5; y = x * x - a0; if (y >= 0.0) { // Two real roots y = Math.sqrt(y); if (x > 0.0) { y = -x - y; } else { y = -x + y; } if (rescale) { y = y * k; // very important to convert to original z = q0 / y; // root first, otherwise complete loss of } else // root due to possible a0 = 0 underflow { z = a0 / y; } return new Complex[] { new Complex(Math.max(y, z), 0), new Complex(Math.min(y, z), 0) }; } else { // Two complex roots (zero real roots) y = Math.sqrt(-y); if (rescale) { x *= k; y *= k; } return new Complex[] { new Complex(-x, y), new Complex(-x, -y) }; } } } /** * CUBIC POLYNOMIAL ROOT SOLVER. * <p> * Calculates all (real and complex) roots of the cubic polynomial:<br> * c3 * x^3 + c2 * x^2 + c1 * x + c0<br> * The first real root (which always exists) is obtained using an optimized Newton-Raphson scheme. The other remaining roots * are obtained through composite deflation into a quadratic. * <P> * The cubic root solver can handle any size of cubic coefficients and there is no danger of overflow due to proper * rescaling of the cubic polynomial. The order of the roots is as follows: 1) For real roots, the order is according to * their algebraic value on the number scale (largest positive first, largest negative last). 2) Since there can be only one * complex conjugate pair root, no order is necessary. 3) All real roots precede the complex ones. * @param c3 coefficient of the cubic term * @param c2 coefficient of the quadratic term * @param c1 coefficient of the linear term * @param c0 coefficient of the independent term * @return array of Complex with all the roots */ public static Complex[] cubicRoots(final double c3, final double c2, final double c1, final double c0) |
File | Project | Line |
---|---|---|
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 1170 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 1246 |
Serializer[] serializers = TypedMessage.buildEncoderList(false, objectArray); for (int i = 0; i < objectArray.length; i++) { buffer[pointer.getAndIncrement(1)] = serializers[i].fieldType(); } for (int i = 0; i < objects.length; i++) { List<Object> row = objects[i].exportAsList(); Throw.when(row.size() != objectArray.length, SerializationException.class, "List in row %d has %d elements which differs from the %d elements in row 0", i, row.size(), objectArray.length); for (int j = 0; j < row.size(); j++) { serializers[j].serialize(row.get(j), buffer, pointer, endianUtil); } } } @Override public SerializableObject<?>[] deSerialize(final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil) throws SerializationException { int arraySize = endianUtil.decodeInt(buffer, pointer.getAndIncrement(4)); int fieldCount = endianUtil.decodeInt(buffer, pointer.getAndIncrement(4)); Serializer<?>[] deSerializers = new Serializer[fieldCount]; for (int i = 0; i < fieldCount; i++) { Byte key = buffer[pointer.getAndIncrement(1)]; Serializer<?> deSerializer = PRIMITIVE_DATA_DECODERS.get(key); Throw.whenNull(SerializationException.class, "No decoder for %d", key); deSerializers[i] = deSerializer; } MinimalSerializableObject[] result = new MinimalSerializableObject[arraySize]; for (int i = 0; i < arraySize; i++) { List<Object> element = new ArrayList<>(); for (int j = 0; j < fieldCount; j++) { element.add(deSerializers[j].deSerialize(buffer, pointer, endianUtil)); } result[i] = new MinimalSerializableObject(element); } return result; } }; /** Converter for array of SerializebleObject using UTF8 for strings and characters. */ protected static final Serializer<SerializableObject<?>[]> COMPOUND_ARRAY_SERIALIZER_UTF8 = |
File | Project | Line |
---|---|---|
org/djutils/data/serialization/DoubleScalarSerializer.java | DJUTILS sampling / output data storage | 23 |
org/djutils/data/serialization/FloatScalarSerializer.java | DJUTILS sampling / output data storage | 25 |
public class DoubleScalarSerializer<U extends Unit<U>, S extends DoubleScalar<U, S>> implements TextSerializer<S> { /** cache of the retrieved valueOf(String) methods for scalars based on the stored string. */ private static Map<String, Method> valueOfMethodCache = new LinkedHashMap<>(); /** cache of the retrieved unit instances based on the unit string. */ private static Map<String, Unit<?>> unitCache = new LinkedHashMap<>(); /** * Serialize an Scalar value to text in such a way that it can be deserialized with the corresponding deserializer. * @param value the scalar to serialize * @return a string representation of the value that can later be deserialized */ @SuppressWarnings("unchecked") @Override public String serialize(final S value, final String unitString) { if (value == null) { return null; } String key = value.getClass().getSimpleName() + "_" + unitString; Unit<?> unit = unitCache.get(key); if (unit == null) { unit = value.getDisplayUnit().getQuantity().of(unitString); unitCache.put(key, unit); } return String.valueOf(value.getInUnit((U) unit)); } /** * Deserialize a String to the correct Scalar value. The method caches the valueOf(String) method for repeated use. * @param text the text to deserialize * @return the reconstructed scalar */ @SuppressWarnings("unchecked") @Override public S deserialize(final Class<S> type, final String text, final String unit) { if (text == null || text.isEmpty()) { return null; } try { Method valueOfMethod = valueOfMethodCache.get(type.getName()); if (valueOfMethod == null) { valueOfMethod = type.getDeclaredMethod("valueOf", String.class); valueOfMethodCache.put(type.getName(), valueOfMethod); } return (S) valueOfMethod.invoke(null, text + unit); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException exception) { throw new RuntimeException(exception); } } } |
File | Project | Line |
---|---|---|
org/djutils/draw/curve/OffsetFlattener2d.java | DJUTILS - Drawing and animation primitives | 253 |
org/djutils/draw/curve/OffsetFlattener2d.java | DJUTILS - Drawing and animation primitives | 349 |
this.maxAngle = maxAngle; } @Override public PolyLine2d flatten(final OffsetCurve2d curve, final ContinuousPiecewiseLinearFunction of) { Throw.whenNull(curve, "curve"); Flattener.FlattableCurve<Point2d, Double> fc = makeFlattableCurve(curve, of); NavigableMap<Double, Point2d> result = new TreeMap<>(); loadKnots(result, curve, of); Map<Double, Double> directions = new LinkedHashMap<>(); directions.put(0.0, curve.getDirection(0.0, of)); // directions can't do ULP before 0.0 Set<Double> knots = new HashSet<>(); for (double knot : result.keySet()) { if (knot > 0) { directions.put(knot, curve.getDirection(knot - Math.ulp(knot), of)); } if (knot != 0.0 && knot != 1.0) { knots.add(knot); } } // Walk along all point pairs and see if additional points need to be inserted double prevT = result.firstKey(); Point2d prevPoint = result.get(prevT); Map.Entry<Double, Point2d> entry; int iterationsAtSinglePoint = 0; while ((entry = result.higherEntry(prevT)) != null) { double nextT = entry.getKey(); Point2d nextPoint = entry.getValue(); double medianT = (prevT + nextT) / 2; |
File | Project | Line |
---|---|---|
org/djutils/draw/line/PolyLine2d.java | DJUTILS - Drawing and animation primitives | 1170 |
org/djutils/draw/line/PolyLine3d.java | DJUTILS - Drawing and animation primitives | 973 |
List<Point2d> pointList = new ArrayList<>(); int indexInStart = 0; int indexInEnd = 0; while (indexInStart < this.size() && indexInEnd < endLine.size()) { double fractionInStart = lengthAtIndex(indexInStart) / this.length; double fractionInEnd = endLine.lengthAtIndex(indexInEnd) / endLine.length; if (fractionInStart < fractionInEnd) { pointList.add(get(indexInStart).interpolate(endLine.getLocation(fractionInStart * endLine.length), transition.function(fractionInStart))); indexInStart++; } else if (fractionInStart > fractionInEnd) { pointList.add(this.getLocation(fractionInEnd * this.length).interpolate(endLine.get(indexInEnd), transition.function(fractionInEnd))); indexInEnd++; } else { pointList.add(this.get(indexInStart).interpolate(endLine.getLocation(fractionInEnd * endLine.length), transition.function(fractionInStart))); indexInStart++; indexInEnd++; } } return new PolyLine2d(NO_FILTER, pointList); |
File | Project | Line |
---|---|---|
org/djutils/stats/DistNormalTable.java | DJUTILS statistical and data storage utilities | 283 |
org/djutils/stats/DistNormalTable.java | DJUTILS statistical and data storage utilities | 301 |
0.9999999999999999, 0.9999999999999999, 0.9999999999999999, 0.9999999999999999, 0.9999999999999999, /* 8.20 - 8.24 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.25 - 8.29 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.30 - 8.34 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.35 - 8.39 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.40 - 8.44 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.45 - 8.49 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.50 - 8.54 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.55 - 8.59 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.60 - 8.64 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.65 - 8.69 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.70 - 8.74 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.75 - 8.79 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.80 - 8.84 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.85 - 8.89 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.90 - 8.94 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 8.95 - 8.99 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 9.00 - 9.04 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 9.05 - 9.09 */ 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, 1.0000000000000000, /* 9.10 - 9.14 */ |
File | Project | Line |
---|---|---|
org/djutils/math/functions/ArcSine.java | DJUTILS math utilities | 120 |
org/djutils/math/functions/ArcTangent.java | DJUTILS math utilities | 107 |
1, -0.5).scaleBy(this.omega); if (this.chain == null) { return myDerivative.simplify(); } return new Product(myDerivative.simplify(), this.chain.getDerivative()).simplify(); } @Override public MathFunction simplify() { if (this.omega == 0.0) { return Constant.ZERO; } if (this.chain != null && this.chain instanceof Constant) { return new Constant(get(0)).simplify(); } return this; } @Override public double getScale() { return this.omega; } @Override public MathFunction scaleBy(final double scaleFactor) { if (scaleFactor == 0.0) { return Constant.ZERO; } if (scaleFactor == 1.0) { return this; } return new ArcSine(this.chain, scaleFactor * this.omega, this.shift); } @Override public int sortPriority() { return 5; |
File | Project | Line |
---|---|---|
org/djutils/data/json/JsonData.java | DJUTILS sampling / output data storage | 247 |
org/djutils/data/xml/XmlData.java | DJUTILS sampling / output data storage | 264 |
Table table; Consumer<Object[]> unserializableTable; if (tableProperties[2].equals(ListTable.class.getName())) { ListTable listTable = new ListTable(tableProperties[0], tableProperties[1], columns); table = listTable; unserializableTable = ( data ) -> listTable.addRow(data); } else { // fallback ListTable listTable = new ListTable(tableProperties[0], tableProperties[1], columns); table = listTable; unserializableTable = ( data ) -> listTable.addRow(data); } // obtain the serializers TextSerializer<?>[] serializers = new TextSerializer[table.getNumberOfColumns()]; for (int i = 0; i < table.getNumberOfColumns(); i++) { serializers[i] = TextSerializer.resolve(columns.get(i).getValueType()); } |
File | Project | Line |
---|---|---|
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 1152 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 1228 |
Serializer[] serializers = TypedMessage.buildEncoderList(false, objectArray); result += serializers.length; for (int i = 0; i < objectArray.length; i++) { result += objects.length * serializers[i].size(objectArray[i]); } return result; } @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void serialize(final SerializableObject<?>[] objects, final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil) throws SerializationException { SerializableObject<?> so = objects[0]; Object[] objectArray = so.exportAsList().toArray(); endianUtil.encodeInt(objects.length, buffer, pointer.getAndIncrement(4)); endianUtil.encodeInt(objectArray.length, buffer, pointer.getAndIncrement(4)); Serializer[] serializers = TypedMessage.buildEncoderList(false, objectArray); |
File | Project | Line |
---|---|---|
org/djutils/draw/line/PolyLine2d.java | DJUTILS - Drawing and animation primitives | 735 |
org/djutils/draw/line/PolyLine3d.java | DJUTILS - Drawing and animation primitives | 723 |
point.y - (this.y[index - 1] + fraction * (this.y[index] - this.y[index - 1]))); if (distance < bestDistanceExtended && (fraction >= 0.0 && fraction <= 1.0 || (fraction < 0.0 && index == 1) || fraction > 1.0 && index == this.size() - 1)) { bestDistanceExtended = distance; } if (distance < bestDistance && (fraction >= 0.0 || index == 1 && limitHandling != null && !limitHandling) && (fraction <= 1.0 || index == this.size() - 1 && limitHandling != null && !limitHandling)) { bestDistance = distance; result = lengthAtIndex(index - 1) + fraction * (lengthAtIndex(index) - lengthAtIndex(index - 1)); } else if (fraction < 0.0 && limitHandling != null && limitHandling) { distance = Math.hypot(point.x - this.x[index - 1], point.y - this.y[index - 1]); |
File | Project | Line |
---|---|---|
org/djutils/serialization/EndianUtil.java | DJUTILS serialization of data structures | 260 |
org/djutils/serialization/EndianUtil.java | DJUTILS serialization of data structures | 290 |
message[p++] = (byte) ((v >> 24) & 0xFF); message[p++] = (byte) ((v >> 16) & 0xFF); message[p++] = (byte) ((v >> 8) & 0xFF); message[p++] = (byte) (v & 0xFF); } else { message[p++] = (byte) (v & 0xFF); message[p++] = (byte) ((v >> 8) & 0xFF); message[p++] = (byte) ((v >> 16) & 0xFF); message[p++] = (byte) ((v >> 24) & 0xFF); |
File | Project | Line |
---|---|---|
org/djutils/serialization/serializers/ArrayOrMatrixWithUnitSerializer.java | DJUTILS serialization of data structures | 67 |
org/djutils/serialization/serializers/ObjectWithUnitSerializer.java | DJUTILS serialization of data structures | 28 |
} /** * Code a unit. * @param unit the unit to code in the byte array * @param message the byte array * @param pointer the start pointer in the byte array * @param endianUtil encoder to use for multi-byte values */ protected void encodeUnit(final U unit, final byte[] message, final Pointer pointer, final EndianUtil endianUtil) { SerializationUnits unitType = SerializationUnits.getUnitType(unit); message[pointer.getAndIncrement(1)] = unitType.getCode(); DisplayType displayType = DisplayType.getDisplayType(unit); message[pointer.getAndIncrement(1)] = displayType.getByteCode(); } /** * Retrieve and decode a DJUNITS unit. * @param buffer the encoded data * @param pointer position in the encoded data where the unit is to be decoded from * @param endianUtil decoder for multi-byte values * @return Unit */ @SuppressWarnings("unchecked") protected U getUnit(final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil) { SerializationUnits unitType = SerializationUnits.getUnitType(buffer[pointer.getAndIncrement(1)]); DisplayType displayType = DisplayType.getDisplayType(unitType, 0 + buffer[pointer.getAndIncrement(1)]); return (U) displayType.getDjunitsType(); } |
File | Project | Line |
---|---|---|
org/djutils/draw/line/PolyLine2d.java | DJUTILS - Drawing and animation primitives | 490 |
org/djutils/draw/line/PolyLine3d.java | DJUTILS - Drawing and animation primitives | 471 |
Point2d currentPoint = get(index); if (null != prevPoint && prevPoint.distance(currentPoint) < noiseLevel) { if (index == this.size() - 1) { if (list.size() > 1) { // Replace the last point of the result by the last point of this PolyLine2d list.set(list.size() - 1, currentPoint); } else { // Append the last point of this even though it is close to the first point than the noise value to // comply with the requirement that first and last point of this are ALWAYS included in the result. list.add(currentPoint); } } continue; // Do not replace prevPoint by currentPoint } list.add(currentPoint); prevPoint = currentPoint; } if (list.size() == this.x.length) { return this; } if (list.size() == 2 && list.get(0).equals(list.get(1))) { // Insert point 1 of this; it MUST be different from point 0; so we don't have to test for anything. list.add(1, get(1)); } return new PolyLine2d(list); |
File | Project | Line |
---|---|---|
org/djutils/math/functions/ArcSine.java | DJUTILS math utilities | 224 |
org/djutils/math/functions/ArcTangent.java | DJUTILS math utilities | 211 |
result.append("asin("); result.append(this.chain == null ? "x" : this.chain.toString()); if (this.shift != 0.0) { if (this.shift > 0) { result.append("+"); } result.append(printValue(this.shift)); } result.append(")"); return result.toString(); } @Override public int hashCode() { return Objects.hash(this.chain, this.omega, this.shift); } @SuppressWarnings("checkstyle:needbraces") @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; |
File | Project | Line |
---|---|---|
org/djutils/draw/line/PolyLine2d.java | DJUTILS - Drawing and animation primitives | 583 |
org/djutils/draw/line/PolyLine3d.java | DJUTILS - Drawing and animation primitives | 561 |
else if (1 == lines.length) { return lines[0]; } int size = lines[0].size(); for (int i = 1; i < lines.length; i++) { if (lines[i - 1].getLast().distance(lines[i].getFirst()) > tolerance) { throw new IllegalArgumentException( "Lines are not connected: " + lines[i - 1].getLast() + " to " + lines[i].getFirst() + " distance is " + lines[i - 1].getLast().distance(lines[i].getFirst()) + " > " + tolerance); } size += lines[i].size() - 1; } |
File | Project | Line |
---|---|---|
org/djutils/draw/curve/Flattener2d.java | DJUTILS - Drawing and animation primitives | 279 |
org/djutils/draw/curve/OffsetFlattener2d.java | DJUTILS - Drawing and animation primitives | 366 |
directions.put(knot, curve.getDirection(knot - Math.ulp(knot))); } if (knot != 0.0 && knot != 1.0) { knots.add(knot); } } // Walk along all point pairs and see if additional points need to be inserted double prevT = result.firstKey(); Point2d prevPoint = result.get(prevT); Map.Entry<Double, Point2d> entry; int iterationsAtSinglePoint = 0; while ((entry = result.higherEntry(prevT)) != null) { double nextT = entry.getKey(); Point2d nextPoint = entry.getValue(); double medianT = (prevT + nextT) / 2; // Check max angle if (checkDirectionError(prevPoint.directionTo(nextPoint), directions.get(prevT), directions.get(nextT), this.maxAngle)) { // We need to insert another point Point2d medianPoint = curve.getPoint(medianT); |
File | Project | Line |
---|---|---|
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 1401 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 1463 |
size += 4 + string.getBytes(UTF8).length; } } return size; } @Override public void serialize(final String[][] stringMatrix, final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil) throws SerializationException { int height = stringMatrix.length; int width = stringMatrix[0].length; endianUtil.encodeInt(height, buffer, pointer.getAndIncrement(4)); endianUtil.encodeInt(width, buffer, pointer.getAndIncrement(4)); for (int i = 0; i < height; i++) { Throw.when(stringMatrix[i].length != width, SerializationException.class, "Jagged matrix is not allowed"); for (int j = 0; j < width; j++) { |
File | Project | Line |
---|---|---|
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 670 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 1054 |
public void serialize(final byte[][] matrix, final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil) throws SerializationException { int height = matrix.length; int width = matrix[0].length; endianUtil.encodeInt(height, buffer, pointer.getAndIncrement(4)); endianUtil.encodeInt(width, buffer, pointer.getAndIncrement(4)); for (int i = 0; i < height; i++) { Throw.when(matrix[i].length != width, SerializationException.class, "Jagged matrix is not allowed"); for (int j = 0; j < width; j++) { buffer[pointer.getAndIncrement(getElementSize())] = matrix[i][j]; |
File | Project | Line |
---|---|---|
org/djutils/serialization/serializers/DoubleVectorArraySerializer.java | DJUTILS serialization of data structures | 49 |
org/djutils/serialization/serializers/FloatVectorArraySerializer.java | DJUTILS serialization of data structures | 49 |
return result; } @Override public void serialize(final V[] adva, final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil) throws SerializationException { int width = adva.length; int height = adva[0].size(); endianUtil.encodeInt(height, buffer, pointer.getAndIncrement(4)); endianUtil.encodeInt(adva.length, buffer, pointer.getAndIncrement(4)); for (int i = 0; i < width; i++) { V adv = adva[i]; Throw.when(adv.size() != height, SerializationException.class, |
File | Project | Line |
---|---|---|
org/djutils/draw/curve/Flattener2d.java | DJUTILS - Drawing and animation primitives | 203 |
org/djutils/draw/curve/Flattener3d.java | DJUTILS - Drawing and animation primitives | 215 |
Point2d medianPoint = curve.getPoint(medianT); // Check max deviation if (checkPositionError(medianPoint, prevPoint, nextPoint, this.maxDeviation)) { // We need to insert another point result.put(medianT, medianPoint); directions.put(medianT, curve.getDirection(medianT)); continue; } // Check max angle if (checkDirectionError(prevPoint.directionTo(nextPoint), directions.get(prevT), directions.get(nextT), this.maxAngle)) { // We need to insert another point result.put(medianT, medianPoint); directions.put(medianT, curve.getDirection(medianT)); iterationsAtSinglePoint++; Throw.when(iterationsAtSinglePoint == 50, IllegalArgumentException.class, "Required a new point 50 times " + "around the same point (t=%f). Likely there is an (unreported) knot in the Curve2d.", |
File | Project | Line |
---|---|---|
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 670 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 734 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 798 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 862 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 926 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 990 |
org/djutils/serialization/TypedObject.java | DJUTILS serialization of data structures | 1054 |
public void serialize(final byte[][] matrix, final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil) throws SerializationException { int height = matrix.length; int width = matrix[0].length; endianUtil.encodeInt(height, buffer, pointer.getAndIncrement(4)); endianUtil.encodeInt(width, buffer, pointer.getAndIncrement(4)); for (int i = 0; i < height; i++) { Throw.when(matrix[i].length != width, SerializationException.class, "Jagged matrix is not allowed"); for (int j = 0; j < width; j++) { |
File | Project | Line |
---|---|---|
org/djutils/draw/curve/Flattener2d.java | DJUTILS - Drawing and animation primitives | 121 |
org/djutils/draw/curve/Flattener3d.java | DJUTILS - Drawing and animation primitives | 133 |
Point2d medianPoint = curve.getPoint(medianT); // Check max deviation if (checkPositionError(medianPoint, prevPoint, nextPoint, this.maxDeviation)) { // We need to insert another point result.put(medianT, medianPoint); continue; } if (prevPoint.distance(nextPoint) > this.maxDeviation && checkInflectionPoint(curve, prevT, medianT, nextT, prevPoint, nextPoint)) { // There is an inflection point, inserting the halfway point should take care of this result.put(medianT, medianPoint); continue; } if (checkLoopBack(curve.getDirection(prevT), curve.getDirection(nextT))) { // The curve loops back onto itself. Inserting the halfway point should prevent missing out a major detour // This check is NOT needed in the MaxDeviationAndAngle flattener. result.put(medianT, medianPoint); continue; } prevT = nextT; prevPoint = nextPoint; } return new PolyLine2d(result.values().iterator()); |
File | Project | Line |
---|---|---|
org/djutils/math/polynomialroots/PolynomialRoots2.java | DJUTILS math utilities | 517 |
org/djutils/math/polynomialroots/PolynomialRoots2.java | DJUTILS math utilities | 588 |
public static Complex[] rootsDurandKerner(final Complex[] a) { int n = a.length - 1; double radius = 1 + maxAbs(a); // initialize the initial values, not as a real number and not as a root of unity Complex[] p = new Complex[n]; p[0] = new Complex(Math.sqrt(radius), Math.cbrt(radius)); double rot = 350.123 / n; for (int i = 1; i < n; i++) { p[i] = p[0].rotate(rot * i); } double maxError = 1.0; int count = 0; while (maxError > 0 && count < MAX_STEPS_DURAND_KERNER) |
File | Project | Line |
---|---|---|
org/djutils/draw/line/PolyLine2d.java | DJUTILS - Drawing and animation primitives | 716 |
org/djutils/draw/line/PolyLine3d.java | DJUTILS - Drawing and animation primitives | 702 |
result = new Ray2d(getLocation(0.0)).projectOrthogonalFractionalExtended(point); if (null == limitHandling) { return result == 0.0 ? 0.0 : Double.NaN; } // limitHandling is false if (result == 0.0) { return 0.0; } return result > 0 ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; } double bestDistance = Double.POSITIVE_INFINITY; double bestDistanceExtended = Double.POSITIVE_INFINITY; for (int index = 1; index < this.size(); index++) { double fraction = point.fractionalPositionOnLine(this.x[index - 1], this.y[index - 1], this.x[index], this.y[index], |
File | Project | Line |
---|---|---|
org/djutils/stats/summarizers/event/EventBasedCounter.java | DJUTILS statistical and data storage utilities | 47 |
org/djutils/stats/summarizers/event/EventBasedTimestampWeightedTally.java | DJUTILS statistical and data storage utilities | 52 |
org/djutils/stats/summarizers/event/EventBasedWeightedTally.java | DJUTILS statistical and data storage utilities | 49 |
public EventBasedCounter(final String description, final EventProducer eventProducer) { super(description); Throw.whenNull(eventProducer, "eventProducer cannot be null"); this.eventProducer = eventProducer; } @Override public EventListenerMap getEventListenerMap() throws RemoteException { return this.eventProducer.getEventListenerMap(); } @Override public void initialize() { super.initialize(); if (this.eventProducer != null) { try { this.eventProducer.fireEvent(StatisticsEvents.INITIALIZED_EVENT); } catch (RemoteException exception) { throw new RuntimeException(exception); } } } @Override public void notify(final Event event) { |
File | Project | Line |
---|---|---|
org/djutils/data/json/JsonData.java | DJUTILS sampling / output data storage | 222 |
org/djutils/data/xml/XmlData.java | DJUTILS sampling / output data storage | 240 |
if (Integer.valueOf(columnProperties[0]).intValue() != index) { throw new IOException("column nr not ok"); } String type = columnProperties[3]; Class<?> valueClass = Primitive.forName(type); if (valueClass == null) { try { valueClass = Class.forName(type); } catch (ClassNotFoundException exception) { throw new IOException("Could not find class " + type, exception); } } Column<?> column = new Column<>(columnProperties[1], columnProperties[2], valueClass, columnProperties[4]); |
File | Project | Line |
---|---|---|
org/djutils/draw/line/PolyLine2d.java | DJUTILS - Drawing and animation primitives | 850 |
org/djutils/draw/line/PolyLine3d.java | DJUTILS - Drawing and animation primitives | 840 |
Point2d toPoint = get(index); segmentLength = fromPoint.distance(toPoint); cumulativeLength = nextCumulativeLength; nextCumulativeLength = cumulativeLength + segmentLength; if (nextCumulativeLength >= start) { break; } } if (start == nextCumulativeLength) { pointList.add(get(index)); } else { pointList.add(get(index - 1).interpolate(get(index), (start - cumulativeLength) / segmentLength)); if (end > nextCumulativeLength) { pointList.add(get(index)); } } while (end > nextCumulativeLength) { |
File | Project | Line |
---|---|---|
org/djutils/draw/line/Polygon2d.java | DJUTILS - Drawing and animation primitives | 190 |
org/djutils/draw/line/Polygon3d.java | DJUTILS - Drawing and animation primitives | 189 |
if (firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y) { if (doNotModifyList) { result = new ArrayList<>(points.size() - 1); for (int i = 0; i < points.size() - 1; i++) { result.add(points.get(i)); } } else { result.remove(points.size() - 1); } lastPoint = result.get(result.size() - 1); } Throw.when(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y, IllegalArgumentException.class, |
File | Project | Line |
---|---|---|
org/djutils/draw/curve/Flattener2d.java | DJUTILS - Drawing and animation primitives | 272 |
org/djutils/draw/curve/Flattener3d.java | DJUTILS - Drawing and animation primitives | 284 |
Map<Double, Double> directions = new LinkedHashMap<>(); directions.put(0.0, curve.getDirection(0.0)); // directions can't do ULP before 0.0 Set<Double> knots = new HashSet<>(); for (double knot : result.keySet()) { if (knot > 0) { directions.put(knot, curve.getDirection(knot - Math.ulp(knot))); } if (knot != 0.0 && knot != 1.0) { knots.add(knot); } } // Walk along all point pairs and see if additional points need to be inserted double prevT = result.firstKey(); |
File | Project | Line |
---|---|---|
org/djutils/draw/curve/Flattener2d.java | DJUTILS - Drawing and animation primitives | 222 |
org/djutils/draw/curve/Flattener3d.java | DJUTILS - Drawing and animation primitives | 234 |
+ "around the same point (t=%f). Likely there is an (unreported) knot in the Curve2d.", medianT); continue; } iterationsAtSinglePoint = 0; if (prevPoint.distance(nextPoint) > this.maxDeviation && checkInflectionPoint(curve, prevT, medianT, nextT, prevPoint, nextPoint)) { // There is an inflection point, inserting the halfway point should take care of this result.put(medianT, medianPoint); directions.put(medianT, curve.getDirection(medianT)); continue; } prevT = nextT; prevPoint = nextPoint; if (knots.contains(prevT)) { directions.put(prevT, curve.getDirection(prevT + Math.ulp(prevT))); } } return new PolyLine2d(result.values().iterator()); |