<commit_before>class LayeredMesh extends Mesh {

	ArrayList<MeshLayer> layers;
	ArrayList<color> layerColors;
	HashMap<Integer, Polygon> polygons;

	// Organizes faces into layers by id as they are added and removed,
	// but underneath the mesh is one cohesive layer, so once a face/vertex is
	// removed it must be re-added as new objects
	public LayeredMesh( ) {
		super();
		this.polygons = new HashMap<Integer, Polygon>();
		this.layers = new ArrayList<MeshLayer>();
		this.layerColors = new ArrayList<color>();
	}

	public LayeredMesh copy() {
		LayeredMesh copy = new LayeredMesh();
		Iterator<Integer> iterator = polygons.keySet().iterator();
		while( iterator.hasNext() ) {
			Integer polyId = iterator.next();
			copy.polygons.put( polyId, this.polygons.get(polyId).copy() );
		}
		for( int i = 0; i < layers.size(); i++ ) {
			copy.layers.add( layers.get(i).copy() );
		}
		copy.layerColors = new ArrayList<color>(this.layerColors);
		return copy;
	}

	public int createNewLayer() {
		this.layers.add( new MeshLayer() );
		return this.layers.size() - 1;
	}

	public void setLayerColors( ArrayList<color> layerColors ) {
		this.layerColors = layerColors;
	}

	public void addTrianglesToNextLayer( ArrayList<Polygon> tris ) {
		createNewLayer();
		addTrianglesToLayer( layers.size() - 1, tris );
	}

	public void addTrianglesToLayer( int layer, ArrayList<Polygon> tris ) {
		// TODO: validate that triangle ID has not already been added?
		if (DEBUG) {
		console.log("*************************");
		console.log("Adding " + tris.size() + " triangles to layer " + layer);
		console.log("*************************");
		}

		if ( layer >= layers.size() ) {
			console.log( "ERROR: layer does not exist, cannot add tris");
			return;
		}
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		for ( int i = 0; i < tris.size(); i++ ) {
			if ( !polygons.containsKey( tris.get(i).id )) {
				// add polygon to master list
				polygons.put( tris.get(i).id, tris.get(i) );
			}
			polyIds.add( tris.get(i).id );
		}
		layers.get(layer).addPolygonsToSubLayer( polyIds );
		addTrianglesToMesh( tris );
	}

	public void removeVertexFromLayer( int layer, Vertex vertex ) {
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		// remove vertex and associated faces from current layer
		this.layers.get(layer).removeVertexFromSubLayer( vertex );
	}

	public void removeFacesFromLayer( int layer, ArrayList<Face> faces ) {
		super.removeFacesFromMesh( faces );
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		for ( int i = 0; i < faces.size(); i++ ) {
			polyIds.add( faces.get(i).id );
		}
		// remove vertex and associated faces from current layer
		this.layers.get(layer).removePolygonsFromSubLayer( polyIds );
	}

	public ArrayList<Integer> getVisiblePolygonIdsByLayer( int layer ) {
		int i, j;
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		if ( 0 > layer || layer >= layers.size() ) {
			console.log("ERROR: layer does not exist, cannot get polygons");
		} else {
			ArrayList<Integer> addedPolys;
			ArrayList<Integer> removedPolys;
			for ( i = 0; i <= layer; i++ ) {
				addedPolys = this.layers.get(i).getPolygonsAddedToLayer();
				for ( j = 0; j < addedPolys.size(); j++ ) {
					polyIds.add( addedPolys.get(j) );
				}
				removedPolys = this.layers.get(i).getPolygonsRemovedFromLayer();
				for ( j = 0; j < removedPolys.size(); j++ ) {
					polyIds.remove( polyIds.indexOf(removedPolys.get(j)) );
				}
			}
		}
		return polyIds;
	}

	public ArrayList<Integer> getVisiblePolygonsByLayer( int layer ) {
		return getPolygonsById( getVisiblePolygonIdsByLayer( layer ) );
	}

	public ArrayList<ArrayList<Integer>> getPolygonIdsAddedBySubLayer(int layer){
		int i;
		ArrayList<ArrayList<Integer>> polyIds =
			new ArrayList<ArrayList<Integer>>();
		if ( 0 > layer || layer >= layers.size() ) {
			console.log("ERROR: layer does not exist, cannot get polygons");
		} else {
			// add sub layer polygons
			for ( i = 0; i < this.layers.get(layer).subLayers.size(); i++ ) {
				polyIds.add(
						layers.get(layer).subLayers.get(i).getPolygonsAddedToLayer());
			}
		}
		return polyIds;
	}

	public ArrayList<Integer> getPolygonsAddedBySubLayer( int layer ) {
		return getPolygonsById( getPolygonIdsAddedBySubLayer( layer ) );
	}

	public ArrayList<ArrayList<Integer>> getPolygonIdsRemovedBySubLayer(int layer){
		int i;
		ArrayList<ArrayList<Integer>> polyIds =
			new ArrayList<ArrayList<Integer>>();
		if ( 0 > layer || layer >= layers.size() ) {
			console.log("ERROR: layer does not exist, cannot get polygons");
		} else {
			// add sub layer polygons
			for ( i = 0; i < this.layers.get(layer).subLayers.size(); i++ ) {
				polyIds.add(
						layers.get(layer).subLayers.get(i).getPolygonsRemovedFromLayer());
			}
		}
		return polyIds;
	}

	public ArrayList<Integer> getPolygonsRemovedBySubLayer( int layer ) {
		return getPolygonsById( getPolygonIdsRemovedBySubLayer( layer ) );
	}

	public ArrayList<Polygon> getPolygonsById( ArrayList<Integer> polyIds ) {
		ArrayList<Polygon> polys = new ArrayList<Polygon>();
		for ( int i = 0; i < polyIds.size(); i++ ){
			polys.add( getPolygonById( polyIds.get(i) ));
		}
		return polys;
	}

	public Polygon getPolygonById( int polyId ) {
		return this.polygons.get( polyId );
	}

}
<commit_msg>get mesh polygons by parent id<commit_after>class LayeredMesh extends Mesh {

	ArrayList<MeshLayer> layers;
	ArrayList<color> layerColors;
	HashMap<Integer, Polygon> polygons;

	// Organizes faces into layers by id as they are added and removed,
	// but underneath the mesh is one cohesive layer, so once a face/vertex is
	// removed it must be re-added as new objects
	public LayeredMesh( ) {
		super();
		this.polygons = new HashMap<Integer, Polygon>();
		this.layers = new ArrayList<MeshLayer>();
		this.layerColors = new ArrayList<color>();
	}

	public LayeredMesh copy() {
		LayeredMesh copy = new LayeredMesh();
		Iterator<Integer> iterator = polygons.keySet().iterator();
		while( iterator.hasNext() ) {
			Integer polyId = iterator.next();
			copy.polygons.put( polyId, this.polygons.get(polyId).copy() );
		}
		for( int i = 0; i < layers.size(); i++ ) {
			copy.layers.add( layers.get(i).copy() );
		}
		copy.layerColors = new ArrayList<color>(this.layerColors);
		return copy;
	}

	public int createNewLayer() {
		this.layers.add( new MeshLayer() );
		return this.layers.size() - 1;
	}

	public void setLayerColors( ArrayList<color> layerColors ) {
		this.layerColors = layerColors;
	}

	public void addTrianglesToNextLayer( ArrayList<Polygon> tris ) {
		createNewLayer();
		addTrianglesToLayer( layers.size() - 1, tris );
	}

	public void addTrianglesToLayer( int layer, ArrayList<Polygon> tris ) {
		// TODO: validate that triangle ID has not already been added?
		if (DEBUG) {
		console.log("*************************");
		console.log("Adding " + tris.size() + " triangles to layer " + layer);
		console.log("*************************");
		}

		if ( layer >= layers.size() ) {
			console.log( "ERROR: layer does not exist, cannot add tris");
			return;
		}
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		for ( int i = 0; i < tris.size(); i++ ) {
			if ( !polygons.containsKey( tris.get(i).id )) {
				// add polygon to master list
				polygons.put( tris.get(i).id, tris.get(i) );
			}
			polyIds.add( tris.get(i).id );
		}
		layers.get(layer).addPolygonsToSubLayer( polyIds );
		addTrianglesToMesh( tris );
	}

	public void removeVertexFromLayer( int layer, Vertex vertex ) {
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		// remove vertex and associated faces from current layer
		this.layers.get(layer).removeVertexFromSubLayer( vertex );
	}

	public void removeFacesFromLayer( int layer, ArrayList<Face> faces ) {
		super.removeFacesFromMesh( faces );
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		for ( int i = 0; i < faces.size(); i++ ) {
			polyIds.add( faces.get(i).id );
		}
		// remove vertex and associated faces from current layer
		this.layers.get(layer).removePolygonsFromSubLayer( polyIds );
	}

	public ArrayList<Integer> getVisiblePolygonIdsByLayer( int layer ) {
		int i, j;
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		if ( 0 > layer || layer >= layers.size() ) {
			console.log("ERROR: layer does not exist, cannot get polygons");
		} else {
			ArrayList<Integer> addedPolys;
			ArrayList<Integer> removedPolys;
			for ( i = 0; i <= layer; i++ ) {
				addedPolys = this.layers.get(i).getPolygonsAddedToLayer();
				for ( j = 0; j < addedPolys.size(); j++ ) {
					polyIds.add( addedPolys.get(j) );
				}
				removedPolys = this.layers.get(i).getPolygonsRemovedFromLayer();
				for ( j = 0; j < removedPolys.size(); j++ ) {
					polyIds.remove( polyIds.indexOf(removedPolys.get(j)) );
				}
			}
		}
		return polyIds;
	}

	public ArrayList<Polygon> getVisiblePolygonsByLayer( int layer ) {
		return getPolygonsById( getVisiblePolygonIdsByLayer( layer ) );
	}

	public ArrayList<ArrayList<Integer>> getPolygonIdsAddedBySubLayer(int layer){
		int i;
		ArrayList<ArrayList<Integer>> polyIds =
			new ArrayList<ArrayList<Integer>>();
		if ( 0 > layer || layer >= layers.size() ) {
			console.log("ERROR: layer does not exist, cannot get polygons");
		} else {
			// add sub layer polygons
			for ( i = 0; i < this.layers.get(layer).subLayers.size(); i++ ) {
				polyIds.add(
						layers.get(layer).subLayers.get(i).getPolygonsAddedToLayer());
			}
		}
		return polyIds;
	}

	public ArrayList<Polygon> getPolygonsAddedBySubLayer( int layer ) {
		return getPolygonsById( getPolygonIdsAddedBySubLayer( layer ) );
	}

	public ArrayList<ArrayList<Integer>> getPolygonIdsRemovedBySubLayer(int layer){
		int i;
		ArrayList<ArrayList<Integer>> polyIds =
			new ArrayList<ArrayList<Integer>>();
		if ( 0 > layer || layer >= layers.size() ) {
			console.log("ERROR: layer does not exist, cannot get polygons");
		} else {
			// add sub layer polygons
			for ( i = 0; i < this.layers.get(layer).subLayers.size(); i++ ) {
				polyIds.add(
						layers.get(layer).subLayers.get(i).getPolygonsRemovedFromLayer());
			}
		}
		return polyIds;
	}

	public ArrayList<Polygon> getPolygonsRemovedBySubLayer( int layer ) {
		return getPolygonsById( getPolygonIdsRemovedBySubLayer( layer ) );
	}

	public ArrayList<Polygon> getPolygonIdsByParentId( int parentId ) {
		ArrayList<Integer> polyIds = new ArrayList<Integer>();
		Iterator<Integer> iterator = polygons.keySet().iterator();
		while( iterator.hasNext() ) {
			Integer polyId = iterator.next();
			if( polygons.get(polyId).parentId == parentId ) {
				polyIds.add(polyId);
			}
		}
		return polyIds;
	}

	public ArrayList<Polygon> getPolygonsByParentId( int parentId ) {
		return getPolygonsById( getPolygonIdsByParentId( parentId ) );
	}

	public ArrayList<Polygon> getPolygonsById( ArrayList<Integer> polyIds ) {
		ArrayList<Polygon> polys = new ArrayList<Polygon>();
		for ( int i = 0; i < polyIds.size(); i++ ){
			polys.add( getPolygonById( polyIds.get(i) ));
		}
		return polys;
	}

	public Polygon getPolygonById( int polyId ) {
		return this.polygons.get( polyId );
	}

}

{'fraction_non_alphanumeric': 0.14541184971098267, 'fraction_numerical': 0.0025289017341040463, 'mean_word_length': 3.9923354373309285, 'pattern_counts': {'":': 0, '<': 110, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1494738', 'n_tokens_mistral': 4063, 'n_tokens_neox': 3636, 'n_words': 897}