Fits lines across the sequence of corners

@param numLines number of lines it will fit
761668
boolean fitLinesUsingCorners( int numLines , GrowQueue_I32 cornerIndexes) {
		for (int i = 1; i <= numLines; i++) {
			int index0 = cornerIndexes.get(CircularIndex.addOffset(anchor0, i - 1, cornerIndexes.size));
			int index1 = cornerIndexes.get(CircularIndex.addOffset(anchor0, i, cornerIndexes.size));

			if( index0 == index1 )
				return false;

			if (!fitLine(index0, index1, lines.get(i - 1))) {
				// TODO do something more intelligent here.  Just leave the corners as is?
				return false;
			}
			LineGeneral2D_F64 l = lines.get(i-1);
			if( Double.isNaN(l.A) || Double.isNaN(l.B) || Double.isNaN(l.C)) {
				throw new RuntimeException("This should be impossible");
			}
		}
		return true;
	}
742079
public static List<LineParametric2D_F32>
	pruneSimilarLines( List<LineParametric2D_F32> lines ,
					   float intensity[] ,
					   float toleranceAngle ,
					   float toleranceDist ,
					   int imgWidth ,
					   int imgHeight )
	{

		int indexSort[] = new int[ intensity.length ];
		QuickSort_F32 sort = new QuickSort_F32();
		sort.sort(intensity,0, lines.size(), indexSort);

		float theta[] = new float[ lines.size() ];
		List<LineSegment2D_F32> segments = new ArrayList<>(lines.size());

		for( int i = 0; i < lines.size(); i++ ) {
			LineParametric2D_F32 l = lines.get(i);
			theta[i] = UtilAngle.atanSafe(l.getSlopeY(),l.getSlopeX());
			segments.add( convert(l,imgWidth,imgHeight));
		}

		for( int i = segments.size()-1; i >= 0; i-- ) {
			LineSegment2D_F32 a = segments.get(indexSort[i]);
			if( a == null ) continue;

			for( int j = i-1; j >= 0; j-- ) {
				LineSegment2D_F32 b = segments.get(indexSort[j]);

				if( b == null )
					continue;

				if( UtilAngle.distHalf(theta[indexSort[i]],theta[indexSort[j]]) > toleranceAngle )
					continue;

				Point2D_F32 p = Intersection2D_F32.intersection(a,b,null);
				if( p != null && p.x >= 0 && p.y >= 0 && p.x < imgWidth && p.y < imgHeight ) {
					segments.set(indexSort[j],null);
				} else {
					float distA = Distance2D_F32.distance(a,b.a);
					float distB = Distance2D_F32.distance(a,b.b);

					if( distA <= toleranceDist || distB < toleranceDist ) {
						segments.set(indexSort[j],null);
					}
				}
			}
		}

		List<LineParametric2D_F32> ret = new ArrayList<>();
		for( int i = 0; i < segments.size(); i++ ) {
			if( segments.get(i) != null ) {
				ret.add( lines.get(i));
			}
		}

		return ret;
	}
882492
public void queryCorners(Point2D[] corners) {
		if ((corners == null) || (corners.length < 4))
			throw new IllegalArgumentException();
		if (corners[0] != null)
			corners[0].setCoords(xmin, ymin);
		else
			corners[0] = new Point2D(xmin, ymin);

		if (corners[1] != null)
			corners[1].setCoords(xmin, ymax);
		else
			corners[1] = new Point2D(xmin, ymax);

		if (corners[2] != null)
			corners[2].setCoords(xmax, ymax);
		else
			corners[2] = new Point2D(xmax, ymax);

		if (corners[3] != null)
			corners[3].setCoords(xmax, ymin);
		else
			corners[3] = new Point2D(xmax, ymin);
	}
1223691
public static float Spline(float x, int numKnots, float[] knots) {
        int span;
        int numSpans = numKnots - 3;
        float k0, k1, k2, k3;
        float c0, c1, c2, c3;

        if (numSpans < 1)
            throw new IllegalArgumentException("Too few knots in spline");

        x = x > 1 ? 1 : x;
        x = x < 0 ? 0 : x;
        x *= numSpans;
        span = (int) x;
        if (span > numKnots - 4)
            span = numKnots - 4;
        x -= span;

        k0 = knots[span];
        k1 = knots[span + 1];
        k2 = knots[span + 2];
        k3 = knots[span + 3];

        c3 = -0.5f * k0 + 1.5f * k1 + -1.5f * k2 + 0.5f * k3;
        c2 = 1f * k0 + -2.5f * k1 + 2f * k2 + -0.5f * k3;
        c1 = -0.5f * k0 + 0f * k1 + 0.5f * k2 + 0f * k3;
        c0 = 0f * k0 + 1f * k1 + 0f * k2 + 0f * k3;

        return ((c3 * x + c2) * x + c1) * x + c0;
    }
1255881
public void setLine(Point2D[] points) {
        double[] pd = new double[points.length * 2];
        for (int i = 0; i < points.length; i++) {
            Point2D p = points[i];
            pd[i * 2] = p.getX();
            pd[i * 2 + 1] = p.getY();
        }
        setLine(pd);
    }
793320
@javax.annotation.Nonnull
  public Bounds getBounds(@javax.annotation.Nonnull double[][] points) {
    int dim = points[0].length;
    double[] max = IntStream.range(0, dim).mapToDouble(d -> {
      return Arrays.stream(points).mapToDouble(pt -> pt[d]).filter(x -> Double.isFinite(x)).max().orElse(Double.NaN);
    }).toArray();
    double[] min = IntStream.range(0, dim).mapToDouble(d -> {
      return Arrays.stream(points).mapToDouble(pt -> pt[d]).filter(x -> Double.isFinite(x)).min().orElse(Double.NaN);
    }).toArray();
    return new Bounds(max, min);
  }
364331
private String[] fillNonPatternSet(Set set, String[] patterns) {
        ArrayList al = new ArrayList(patterns.length);
        for (int i = 0; i < patterns.length; i++) {
            if (!SelectorUtils.hasWildcards(patterns[i])) {
                set.add(isCaseSensitive() ? patterns[i]
                    : patterns[i].toUpperCase());
            } else {
                al.add(patterns[i]);
            }
        }
        return set.size() == 0 ? patterns
            : (String[]) al.toArray(new String[al.size()]);
    }
857455
protected void createSamplePoints(int numSamples) {
		for( int y = 0; y < numSamples; y++ ) {
			float regionY = (y/(numSamples-1.0f) - 0.5f);

			for( int x = 0; x < numSamples; x++  ) {
				float regionX = (x/(numSamples-1.0f) - 0.5f);
				samplePts.add( new Point2D_F32(regionX,regionY));
			}
		}
	}
825907
def cat(self, numlines=None):
        """"""
        if len(self.titles) == 1:
            lines = self.lines()
            if numlines is not None:
                lines = lines[len(lines)-numlines:]
            log("\n".join(lines))
        else:
            lines = [self._printtuple(line[0], line[1]) for line in self.lines()]
            if numlines is not None:
                lines = lines[len(lines)-numlines:]
            log("".join(lines))
1272489
def fit(self, X, y=None, **fit_params):
        

        # Handle the feature names if they're None.
        if self.features_ is None:

            # If X is a data frame, get the columns off it.
            if is_dataframe(X):
                self.features_ = np.array(X.columns)

            # Otherwise create numeric labels for each column.
            else:
                _, ncols = X.shape
                self.features_ = np.arange(0, ncols)

        return self
7978
def linem(self, lines):
        """"""
        shapeType = POLYLINEM
        self._shapeparts(parts=lines, shapeType=shapeType)
1047016
boolean sanityCheckCornerOrder( int numLines, GrowQueue_I32 corners ) {
		int contourAnchor0 = corners.get(anchor0);
		int previous = 0;
		for (int i = 1; i < numLines; i++) {
			int contourIndex = corners.get(CircularIndex.addOffset(anchor0, i, corners.size()));
			int pixelsFromAnchor0 = CircularIndex.distanceP(contourAnchor0, contourIndex, contour.size());

			if (pixelsFromAnchor0 < previous) {
				return false;
			} else {
				previous = pixelsFromAnchor0;
			}
		}
		return true;
	}
31524
@Override
    public void fit(INDArray data, INDArray labels) {
        fit(data, labels, null, null);
    }
214794
private void updateBounds()
    {
        if (npoints >= MIN_POINTS)
        {
            double boundsMinX = Double.MAX_VALUE;
            double boundsMinY = Double.MAX_VALUE;
            double boundsMaxX = -Double.MAX_VALUE;
            double boundsMaxY = -Double.MAX_VALUE;

            for (int i = 0; i < npoints; i++)
            {
                final double x = xpoints[i];
                boundsMinX = Math.min(boundsMinX, x);
                boundsMaxX = Math.max(boundsMaxX, x);

                final double y = ypoints[i];
                boundsMinY = Math.min(boundsMinY, y);
                boundsMaxY = Math.max(boundsMaxY, y);
            }

            bounds.set(boundsMinX, boundsMinY, boundsMaxX - boundsMinX, boundsMaxY - boundsMinY);
        }
    }
739813
public static void addGeometryToSegments(Geometry geometry, int flag, ArrayList<SegmentString> segments) {
        for (int i = 0; i < geometry.getNumGeometries(); i++) {
            Geometry component = geometry.getGeometryN(i);
            if (component instanceof Polygon) {
                add((Polygon) component, flag, segments);
            } else if (component instanceof LineString) {
                add((LineString) component, flag, segments);
            }
        }
    }
893607
def guess_segments_lines(segments, lines, nearline_tolerance=5.0):
    
    ys = segments[:, 1]
    closeness = numpy.abs(numpy.subtract.outer(ys, lines))  # each row a y, each collumn a distance to each line
    line_of_y = numpy.argmin(closeness, axis=1)
    distance = numpy.min(closeness, axis=1)
    bad = distance > numpy.mean(distance) + nearline_tolerance * numpy.std(distance)
    line_of_y[bad] = -1
    return line_of_y
226332
public void replaceLines(int startLine, int endLine, List<String> replacementLines) {
    Preconditions.checkArgument(startLine <= endLine);
    List<String> originalLines = getLines();
    List<String> newLines = new ArrayList<>();
    for (int i = 0; i < originalLines.size(); i++) {
      int lineNum = i + 1;
      if (lineNum == startLine) {
        newLines.addAll(replacementLines);
      } else if (lineNum > startLine && lineNum <= endLine) {
        // Skip
      } else {
        newLines.add(originalLines.get(i));
      }
    }
    replaceLines(newLines);
  }