Sample

Schnappinger/aoi/artofillusion.TriMeshSelectionUtilities

Human rating uses the original dataset scale.

Human2.71
Lines321

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
15.4Δ 1.1
Scalabrino0.4710–1; higher is more readable
6.8Δ 9.7
Dorn0.0220–1; higher is more readable
23.8Δ 7.3
Mi0.1230–1; higher is more readable
11.2Δ 5.3
LLOC178Logical lines; fewer is more readable
15.3Δ 1.2
DeepSeek V4 Pro14.670–20; mean of three runs
34.8Δ 18.3
GPT-6.1 Sol140–20; mean of three runs
16.2Δ 0.3
BTTF0.2480–1; higher is more readable
16.5Δ 0.0
Human2.711–4; original rating
16.5

Views

Source code

/* Copyright (C) 2005 by Peter Eastman This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package artofillusion; import artofillusion.math.*; import artofillusion.object.*; import artofillusion.object.TriangleMesh.*; import artofillusion.ui.*; import java.util.*; /** This class provides a variety of static methods for selecting parts of TriangleMeshes in different ways. */ public class TriMeshSelectionUtilities { /** Convert one type of selection (point, edge, or face) to a different one. @param mesh the mesh the selection applies to @param oldMode the selection mode of the old selection @param selection the old selection @param newMode the new selection mode @return a selection in the new mode which corresponds to the old selection as closely as possible */ public static boolean[] convertSelection(TriangleMesh mesh, int oldMode, boolean selection[], int newMode) { Vertex v[] = (Vertex []) mesh.getVertices(); Edge e[] = mesh.getEdges(); Face f[] = mesh.getFaces(); boolean newSel[]; if (newMode == oldMode) return (boolean []) selection.clone(); if (newMode == MeshEditController.POINT_MODE) { newSel = new boolean [v.length]; if (oldMode == MeshEditController.EDGE_MODE) { for (int i = 0; i < e.length; i++) if (selection[i]) newSel[e[i].v1] = newSel[e[i].v2] = true; } else { for (int i = 0; i < f.length; i++) if (selection[i]) newSel[f[i].v1] = newSel[f[i].v2] = newSel[f[i].v3] = true; } } else if (newMode == MeshEditController.EDGE_MODE) { newSel = new boolean [e.length]; if (oldMode == MeshEditController.POINT_MODE) { for (int i = 0; i < e.length; i++) newSel[i] = (selection[e[i].v1] && selection[e[i].v2]); } else { for (int i = 0; i < f.length; i++) if (selection[i]) newSel[f[i].e1] = newSel[f[i].e2] = newSel[f[i].e3] = true; } } else { newSel = new boolean [f.length]; if (oldMode == MeshEditController.POINT_MODE) { for (int i = 0; i < f.length; i++) newSel[i] = (selection[f[i].v1] && selection[f[i].v2] && selection[f[i].v3]); } else { for (int i = 0; i < f.length; i++) newSel[i] = (selection[f[i].e1] && selection[f[i].e2] && selection[f[i].e3]); } } return newSel; } /** Find the boundary of the current selection. @param mesh the mesh the selection applies to @param oldMode the selection mode of the old selection @param selection the old selection @return a selection in edge mode which corresponds to the boundary of the old selection */ public static boolean[] findSelectionBoundary(TriangleMesh mesh, int oldMode, boolean selection[]) { boolean edgeSelection[] = convertSelection(mesh, oldMode, selection, MeshEditController.EDGE_MODE); boolean faceSelection[] = convertSelection(mesh, oldMode, selection, MeshEditController.FACE_MODE); Edge e[] = mesh.getEdges(); Face f[] = mesh.getFaces(); boolean newSel[] = new boolean [e.length]; for (int i = 0; i < e.length; i++) newSel[i] = (edgeSelection[i] && (!faceSelection[e[i].f1] || e[i].f2 == -1 || !faceSelection[e[i].f2])); return newSel; } /** Select an edge loop from a single edge. @param mesh the mesh the selection applies to @param startEdge the index of the edge from which to find an edge loop @return a selection containing all the edges in the loop, or null if no loop could be found */ private static boolean[] findSingleEdgeLoop(TriangleMesh mesh, int startEdge) { Vertex v[] = (Vertex []) mesh.getVertices(); Edge e[] = mesh.getEdges(); Face f[] = mesh.getFaces(); boolean newSel[] = new boolean [e.length]; int currentEdge = startEdge; int currentVert = e[startEdge].v1; while (true) { if (newSel[currentEdge]) { if (currentEdge == startEdge) return newSel; // This is a good edge loop. return null; // The path looped back on itself without hitting the original edge. } // Find the next edge which is most nearly parallel to this one. newSel[currentEdge] = true; Vec3 dir1 = v[e[currentEdge].v1].r.minus(v[e[currentEdge].v2].r); dir1.normalize(); int vertEdges[] = v[currentVert].getEdges(); int bestEdge = -1; double maxDot = -1.0; for (int i = 0; i < vertEdges.length; i++) { if (vertEdges[i] == currentEdge) continue; Vec3 dir2 = v[e[vertEdges[i]].v1].r.minus(v[e[vertEdges[i]].v2].r); dir2.normalize(); double dot = dir1.dot(dir2); if (e[currentEdge].v1 == e[vertEdges[i]].v1 || e[currentEdge].v2 == e[vertEdges[i]].v2) dot = -dot; if (dot > maxDot) { maxDot = dot; bestEdge = vertEdges[i]; } } currentEdge = bestEdge; currentVert = (e[currentEdge].v1 == currentVert ? e[currentEdge].v2 : e[currentEdge].v1); } } /** Select an edge loop from each edge that is currently selected. @param mesh the mesh the selection applies to @param selection the current selection (in edge mode) @return a selection containing all the edges in the loops, or null if no loop could be found for one or more edges */ public static boolean[] findEdgeLoops(TriangleMesh mesh, boolean selection[]) { boolean newSel[] = new boolean [selection.length]; for (int i = 0; i < selection.length; i++) if (selection[i]) { boolean loop[] = findSingleEdgeLoop(mesh, i); if (loop == null) return null; for (int j = 0; j < loop.length; j++) newSel[j] |= loop[j]; } return newSel; } /** Select an edge strip from a single edge. @param mesh the mesh the selection applies to @param startEdge the index of the edge from which to find an edge strip @return a selection containing all the edges in the strip, or null if no strip could be found */ private static boolean[] findSingleEdgeStrip(TriangleMesh mesh, int startEdge) { Vertex v[] = (Vertex []) mesh.getVertices(); Edge e[] = mesh.getEdges(); Face f[] = mesh.getFaces(); boolean newSel[] = new boolean [e.length]; int currentEdge = startEdge; int prevEdge = startEdge; while (true) { if (newSel[currentEdge]) { if (currentEdge == startEdge) return newSel; // This is a good edge strip. return null; // The path looped back on itself without hitting the original edge. } newSel[currentEdge] = true; Edge ce = e[currentEdge]; Vec3 dir1 = v[ce.v1].r.minus(v[ce.v2].r); dir1.normalize(); int bestEdge = -1; double maxDot = -1.0; // Record every neighbor of each vertex of the current edge. HashSet v1neighbors = new HashSet(); int v1edges[] = v[ce.v1].getEdges(); for (int i = 0; i < v1edges.length; i++) { Edge ed = e[v1edges[i]]; if (ed != ce) v1neighbors.add(new Integer(ed.v1 == ce.v1 ? ed.v2 : ed.v1)); } HashSet v2neighbors = new HashSet(); int v2edges[] = v[ce.v2].getEdges(); for (int i = 0; i < v2edges.length; i++) { Edge ed = e[v2edges[i]]; if (ed != ce) v2neighbors.add(new Integer(ed.v1 == ce.v2 ? ed.v2 : ed.v1)); } // Look for candidates to be the next edge in the strip. A candidate is an edge which connects // a neighbor of v1 to a neighbor of v2. Iterator n2iter = v2neighbors.iterator(); while (n2iter.hasNext()) { int neighbor = ((Integer) n2iter.next()).intValue(); int neighborEdges[] = v[neighbor].getEdges(); for (int i = 0; i < neighborEdges.length; i++) { if (neighborEdges[i] == prevEdge) continue; Edge ed = e[neighborEdges[i]]; if (v1neighbors.contains(new Integer(ed.v1)) || v1neighbors.contains(new Integer(ed.v2))) { // This edge is a candidate. See how close it is to being parallel to the current edge. Vec3 dir2 = v[ed.v1].r.minus(v[ed.v2].r); dir2.normalize(); double dot = Math.abs(dir1.dot(dir2)); if (dot > maxDot) { maxDot = dot; bestEdge = neighborEdges[i]; } } } } if (bestEdge == -1) return null; // There may also be a diagonal edge between the current and next edges. Check for one, // and select it. ArrayList faceList1 = new ArrayList(); faceList1.add(f[ce.f1]); if (ce.f2 != -1) faceList1.add(f[ce.f2]); ArrayList faceList2 = new ArrayList(); faceList2.add(f[e[bestEdge].f1]); if (e[bestEdge].f2 != -1) faceList2.add(f[e[bestEdge].f2]); for (int i = 0; i < faceList1.size(); i++) { Face fc1 = (Face) faceList1.get(i); for (int j = 0; j < faceList2.size(); j++) { Face fc2 = (Face) faceList2.get(j); if (fc1.e1 == fc2.e1 || fc1.e1 == fc2.e2 || fc1.e1 == fc2.e3) { newSel[fc1.e1] = true; break; } if (fc1.e2 == fc2.e1 || fc1.e2 == fc2.e2 || fc1.e2 == fc2.e3) { newSel[fc1.e2] = true; break; } if (fc1.e3 == fc2.e1 || fc1.e3 == fc2.e2 || fc1.e3 == fc2.e3) { newSel[fc1.e3] = true; break; } } } prevEdge = currentEdge; currentEdge = bestEdge; } } /** Select an edge strip from each edge that is currently selected. @param mesh the mesh the selection applies to @param selection the current selection (in edge mode) @return a selection containing all the edges in the strips, or null if no strip could be found for one or more edges */ public static boolean[] findEdgeStrips(TriangleMesh mesh, boolean selection[]) { boolean newSel[] = new boolean [selection.length]; for (int i = 0; i < selection.length; i++) if (selection[i]) { boolean loop[] = findSingleEdgeStrip(mesh, i); if (loop == null) return null; for (int j = 0; j < loop.length; j++) newSel[j] |= loop[j]; } return newSel; } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.14456.274−477.057
Source linesThe number of non-empty source lines.321+128.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.544−6.815

Intercept 8.87 + feature contributions = -346.603 (log-odds).
Score = sigmoid(-346.603) = 0.

Score0.471

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.322−10.365
Indentation frequencyHow rapidly indentation changes from line to line.275+8.775
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.274−5.867
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.320.894+4.076
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.121.96−1.501
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.121.978+1.164
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.114−0.162

Intercept 0.07 + feature contributions = -3.809 (log-odds).
Score = sigmoid(-3.809) = 0.022.

Score0.123
Score178
Run 1

The code is well-structured with clear separation of methods and good Javadoc comments. It follows a logical flow and maintains a consistent style throughout. The action granularity is generally good, with one main operation per line. However, there are some readability issues: use of raw types (HashSet, ArrayList, Iterator) instead of generics, magic numbers (-1), and some deeply nested conditional blocks, especially in findSingleEdgeStrip and the face comparison sections. The findSingleEdgeStrip method is quite long and complex. Variable names like e, f, v are concise but somewhat vague. Several lines are dense, packing multiple operations. Overall the code is understandable for domain experts but could benefit from refactoring into smaller helper methods and modernizing with generics.

Run 2

The code has clear method separation and each method has a single responsibility, with reasonable Javadoc comments explaining intent. Nesting is mostly flat, but some methods (e.g., findSingleEdgeStrip) contain multiple nested loops and conditionals that reduce readability. Variable names are generally descriptive, though some are abbreviated (e.g., 'v', 'e', 'f', 'ce'). The action granularity is good; most lines perform one operation. However, some multi-action lines like 'newSel[e[i].v1] = newSel[e[i].v2] = true;' are less clear. The reading flow is acceptable, but the use of primitive arrays instead of collection types adds mental overhead. Unused variable 'f' in findSingleEdgeLoop and 'Face f[]' in findSelectionBoundary suggests minor cleanup is needed. Overall, the code is readable but could benefit from refactoring more complex blocks into helper methods, using descriptive variable names, and reducing deeply nested loops.

Run 3

The code has a clear overall structure with documented methods, but readability suffers from several issues. Method names and Javadoc comments are helpful, but the logic within methods is often dense and hard to follow. It uses deep nesting in a few places (especially in `findSingleEdgeStrip`), multiple actions per line, and ambiguous variable names like `v`, `e`, `f`, `ce`, `ed`, etc. The `convertSelection` method is relatively clear, but the selection boundary and edge loop/strip methods feel tangled. Loops are straightforward, but there are several repeated structural patterns that increase verbosity. Overall, it is maintainable by someone familiar with the domain, but not immediately accessible to a general programmer.

Run 1

1. Code Structure: Methods are logically separated by selection operation, with private helpers for individual loops and strips. However, findSingleEdgeStrip combines several substantial tasks. 2. Nesting: Conversion and wrapper methods have manageable nesting, but strip traversal contains deeply nested loops and conditionals. 3. Clarity of intent: Descriptive method names, Javadoc, and algorithm comments explain the purpose well. Abbreviations such as v, e, f, ce, and fc1 make implementation details harder to follow. 4. Code length: Mostly purposeful, but repeated neighbor collection, face comparisons, and selection aggregation could be extracted into helpers. Unused variables and verbose legacy collection syntax add clutter. 5. Action granularity: Most statements perform one action, though chained assignments update several selection entries at once, and complex indexed expressions require extra parsing. 6. Reading flow: Consistent indentation, whitespace, comments, and early returns support natural reading. Omitted braces, lengthy boolean expressions, raw collections, and the long strip-finding method interrupt that flow.

Run 2

Code Structure: Methods are logically grouped by selection operation, with useful private helpers, but strip traversal combines several responsibilities. Nesting: Most methods have manageable nesting; candidate searches and shared-face checks in findSingleEdgeStrip are deeply nested. Clarity of intent: Descriptive method names, Javadocs, and algorithm comments explain the purpose well, while abbreviated variables, raw collections, and unused declarations reduce clarity. Code length: Generally reasonable, but the long strip method and repeated neighbor and face comparisons could be extracted into helpers. Action granularity: Most lines perform one action, although chained assignments update several selections at once and complex expressions require extra parsing. Reading flow: Consistent formatting, sequential algorithm stages, and early returns support natural reading; omitted braces, dense indexing, and repetitive conditionals occasionally interrupt it.

Run 3

1. Code Structure: Related operations are organized into clearly named methods, with private helpers separating single-edge traversal from selection aggregation. The strip helper could be decomposed further. 2. Nesting: Most methods have manageable nesting, but strip candidate searches and shared-face checks contain several nested loops and conditionals. 3. Clarity of intent: Javadocs and algorithm comments explain purpose well; abbreviated names, raw collections, and unused variables reduce clarity. 4. Code length: Generally purposeful, though repeated neighbor collection and shared-edge comparisons make the strip implementation unnecessarily lengthy. 5. Action granularity: Most lines perform one action, but chained assignments update multiple selection entries, and dense Boolean expressions require careful reading. 6. Reading flow: Consistent formatting, logical method ordering, and early returns support natural flow. Omitted braces, lengthy traversal methods, and repeated indexed expressions make complex sections harder to follow.