CPD Results

The following document contains the results of PMD's CPD 6.21.0.

Duplications

File Line
org\djutils\draw\line\Bezier.java 374
org\djutils\draw\line\Bezier.java 749
            Point2d projectedPoint = medianPoint.closestPointOnSegment(prevPoint, nextPoint);
            double errorPosition = medianPoint.distance(projectedPoint);
            if (errorPosition >= epsilon)
            {
                // We need to insert another point
                result.put(medianT, medianPoint);
                continue;
            }
            if (prevPoint.distance(nextPoint) > epsilon)
            {
                // Check for an inflection point by creating additional points at one quarter and three quarters. If these
                // are on opposite sides of the line from prevPoint to nextPoint; there must be an inflection point.
                // https://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line
                double quarterT = (prevT + medianT) / 2;
                double quarterX = Bn(quarterT, px);
                double quarterY = Bn(quarterT, py);
                int sign1 = (int) Math.signum((nextPoint.x - prevPoint.x) * (quarterY - prevPoint.y)
                        - (nextPoint.y - prevPoint.y) * (quarterX - prevPoint.x));
                double threeQuarterT = (nextT + medianT) / 2;
                double threeQuarterX = Bn(threeQuarterT, px);
                double threeQuarterY = Bn(threeQuarterT, py);
                int sign2 = (int) Math.signum((nextPoint.x - prevPoint.x) * (threeQuarterY - prevPoint.y)
                        - (nextPoint.y - prevPoint.y) * (threeQuarterX - prevPoint.x));
                if (sign1 != sign2)
                {
                    // There is an inflection point
                    System.out.println("Detected inflection point between " + prevPoint + " and " + nextPoint);
                    // Inserting the halfway point should take care of this
                    result.put(medianT, medianPoint);
                    continue;
                }
            }
            // TODO check angles
            prevT = nextT;
            prevPoint = nextPoint;
        }
        try
        {
            return new PolyLine2d(result.values().iterator());
File Line
org\djutils\draw\line\PolyLine2d.java 289
org\djutils\draw\line\PolyLine3d.java 249
            Point2d currentPoint = this.points[index];
            if (null != prevPoint && prevPoint.distance(currentPoint) < noiseLevel)
            {
                if (null == list)
                {
                    // Found something to filter; copy this up to (and including) prevPoint
                    list = new ArrayList<>();
                    for (int i = 0; i < index; i++)
                    {
                        list.add(this.points[i]);
                    }
                }
                if (index == this.size() - 1)
                {
                    if (list.size() > 1)
                    {
                        // Replace the last point of the result by the last point of this Line2d
                        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
            }
            else if (null != list)
            {
                list.add(currentPoint);
            }
            prevPoint = currentPoint;
        }
        if (null == list)
        {
            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, this.points[1]);
        }
        try
        {
            return new PolyLine2d(list);
File Line
org\djutils\draw\line\PolyLine2d.java 394
org\djutils\draw\line\PolyLine3d.java 353
    public static PolyLine2d concatenate(final double tolerance, final PolyLine2d... lines) throws DrawException
    {
        if (0 == lines.length)
        {
            throw new DrawException("Empty argument list");
        }
        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 DrawException("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 Line
org\djutils\draw\line\PolyLine2d.java 690
org\djutils\draw\line\PolyLine3d.java 594
            Point2d point = get(index - 1).interpolate(get(index), (end - cumulativeLength) / segmentLength);
            // can be the same due to rounding
            if (!point.equals(pointList.get(pointList.size() - 1)))
            {
                pointList.add(point);
            }
        }
        try
        {
            return instantiate(pointList);
        }
        catch (DrawRuntimeException exception)
        {
            CategoryLogger.always().error(exception, "interval " + start + ".." + end + " too short");
            throw new DrawException("interval " + start + ".." + end + "too short");
        }
    }

    /** {@inheritDoc} */
    @Override
    public PolyLine2d truncate(final double position) throws DrawException
File Line
org\djutils\draw\point\Point2d.java 235
org\djutils\draw\point\Point2d.java 264
    public static Point2d intersectionOfLines(final Point2d line1P1, final Point2d line1P2, final Point2d line2P1,
            final Point2d line2P2)
    {
        double l1p1x = line1P1.x;
        double l1p1y = line1P1.y;
        double l1p2x = line1P2.x - l1p1x;
        double l1p2y = line1P2.y - l1p1y;
        double l2p1x = line2P1.x - l1p1x;
        double l2p1y = line2P1.y - l1p1y;
        double l2p2x = line2P2.x - l1p1x;
        double l2p2y = line2P2.y - l1p1y;
        double denominator = (l2p2y - l2p1y) * l1p2x - (l2p2x - l2p1x) * l1p2y;
        if (denominator == 0.0)
        {
            return null; // lines are parallel (they might even be on top of each other, but we don't check that)
        }
        double u = ((l2p2x - l2p1x) * (-l2p1y) - (l2p2y - l2p1y) * (-l2p1x)) / denominator;
File Line
org\djutils\draw\line\PolyLine2d.java 645
org\djutils\draw\line\PolyLine3d.java 549
            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)
        {