<commit_before>/*
 * Copyright (c) 2015 Raytheon BBN Technologies Corp
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bbn.poi.xdgf.parsers;


import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Comparator;

import org.apache.poi.POIXMLException;
import org.apache.poi.xdgf.usermodel.XDGFShape;

import com.bbn.poi.xdgf.geom.GeomUtils;
import com.bbn.poi.xdgf.parsers.rx.SpatialTools;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.tinkerpop.blueprints.Vertex;

public class ShapeData {

	// orders by largest first
	public static class OrderByLargestAreaFirst implements Comparator<ShapeData> {
		@Override
		public int compare(ShapeData o1, ShapeData o2) {
			return Float.compare(o2.area, o1.area);
		}
	}
	
	public XDGFShape shape = null; // don't use this
	
	public Vertex vertex;
	
	// in global coordinates
	public Rectangle rtreeBounds;	// don't use this except for the rtree, as this is in different precision!
	public float area;
	
	// in global coordinates
	public Path2D path1D = null;
	public Point2D path1Dstart = null;
	public Point2D path1Dend = null;
	
	public Path2D path2D = null;
	public boolean hasGeometry;
	
	public Rectangle2D bounds;
	
	public Point2D textCenter = null;
	
	// don't store the actual shape, just useful attributes needed later
	// -> allows us to join/split shapes at will
	public long shapeId;
	public boolean hasText;
	public boolean isTextbox;
	
	public Color lineColor;
	public Integer linePattern;
	
	public boolean removed = false;
	public boolean isInteresting = false;
	
	
	public ShapeData(XDGFShape shape, AffineTransform globalTransform) {
		
		// calculate bounding boxes + other geometry information we'll need later
		Path2D.Double shapeBounds = shape.getBoundsAsPath();
		
		shapeBounds.transform(globalTransform);
		shapeBounds = GeomUtils.roundPath(shapeBounds);
		
		Path2D path = shape.getPath();
		
		// some 1d shapes don't have a path associated with them, 
		// if they have subshapes... 
		if (shape.isShape1D() && path != null) {
			path1D = path;
			path1D.transform(globalTransform);
			path1D = GeomUtils.roundPath(path1D);
			hasGeometry = true;
			
			calculate1dEndpoints();
		} else {
			path2D = shapeBounds;<commit_msg>Set 1D shape boundaries from path, to deal with infinite line<commit_after>/*
 * Copyright (c) 2015 <NAME> Corp
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bbn.poi.xdgf.parsers;


import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Comparator;

import org.apache.poi.POIXMLException;
import org.apache.poi.xdgf.usermodel.XDGFShape;

import com.bbn.poi.xdgf.geom.GeomUtils;
import com.bbn.poi.xdgf.parsers.rx.SpatialTools;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.tinkerpop.blueprints.Vertex;

public class ShapeData {

	// orders by largest first
	public static class OrderByLargestAreaFirst implements Comparator<ShapeData> {
		@Override
		public int compare(ShapeData o1, ShapeData o2) {
			return Float.compare(o2.area, o1.area);
		}
	}
	
	public XDGFShape shape = null; // don't use this
	
	public Vertex vertex;
	
	// in global coordinates
	public Rectangle rtreeBounds;	// don't use this except for the rtree, as this is in different precision!
	public float area;
	
	// in global coordinates
	public Path2D path1D = null;
	public Point2D path1Dstart = null;
	public Point2D path1Dend = null;
	
	public Path2D path2D = null;
	public boolean hasGeometry;
	
	public Rectangle2D bounds;
	
	public Point2D textCenter = null;
	
	// don't store the actual shape, just useful attributes needed later
	// -> allows us to join/split shapes at will
	public long shapeId;
	public boolean hasText;
	public boolean isTextbox;
	
	public Color lineColor;
	public Integer linePattern;
	
	public boolean removed = false;
	public boolean isInteresting = false;
	
	
	public ShapeData(XDGFShape shape, AffineTransform globalTransform) {
		
		Path2D shapeBounds;
		Path2D path = shape.getPath();
		
		// some 1d shapes don't have a path associated with them, 
		// if they have subshapes... 
		if (shape.isShape1D() && path != null) {
			path1D = path;
			path1D.transform(globalTransform);
			path1D = GeomUtils.roundPath(path1D);
			hasGeometry = true;
			
			calculate1dEndpoints();
			shapeBounds = path1D; // use path as bounds
		} else {
			// calculate bounding boxes + other geometry information we'll need later
			shapeBounds = shape.getBoundsAsPath();
			
			shapeBounds.transform(globalTransform);
			shapeBounds = GeomUtils.roundPath(shapeBounds);
			
			path2D = shapeBounds;
{'fraction_non_alphanumeric': 0.08424098025867938, 'fraction_numerical': 0.012253233492171545, 'mean_word_length': 3.9553119730185498, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672508', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1769, 'n_words': 594}