Sample

Schnappinger/aoi/artofillusion.raytracer.RTEllipsoid

Human rating uses the original dataset scale.

Human2.99
Lines422

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
11.4Δ 12.4
Scalabrino0.5780–1; higher is more readable
18.5Δ 5.3
Dorn0.0080–1; higher is more readable
19.1Δ 4.6
Mi0.4990–1; higher is more readable
33.7Δ 9.9
LLOC249Logical lines; fewer is more readable
10.6Δ 13.2
DeepSeek V4 Pro10.670–20; mean of three runs
10.6Δ 13.2
GPT-6.1 Sol140–20; mean of three runs
16.2Δ 7.6
BTTF0.1360–1; higher is more readable
5.0Δ 18.8
Human2.991–4; original rating
23.8

Views

Source code

/* Copyright (C) 1999-2013 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.raytracer; import artofillusion.material.*; import artofillusion.math.*; import artofillusion.object.*; import artofillusion.texture.*; /** RTEllipsoid represents an ellipsoid to be raytraced. It is defined by specifying a Sphere object, and the transformations to and from local coordinates. */ public class RTEllipsoid extends RTObject { Sphere theSphere; double rx, ry, rz, rx2, ry2, rz2, cx, cy, cz, sy, sz, param[]; boolean bumpMapped, transform, uniform; Mat4 toLocal, fromLocal; public static final double TOL = 1e-12; public RTEllipsoid(Sphere sphere, Mat4 fromLocal, Mat4 toLocal, double param[]) { Vec3 radii = sphere.getRadii(); Vec3 vx = toLocal.timesDirection(Vec3.vx()), vy = toLocal.timesDirection(Vec3.vy()); theSphere = sphere; this.param = param; uniform = sphere.getTextureMapping() instanceof UniformMapping; transform = true; if (vx.x == 1.0 || vx.x == -1.0) { if (vy.y == 1.0 || vy.y == -1.0) { rx = radii.x; ry = radii.y; rz = radii.z; transform = false; } else if (vy.z == 1.0 || vy.z == -1.0) { rx = radii.x; ry = radii.z; rz = radii.y; transform = false; } } else if (vx.y == 1.0 || vx.y == -1.0) { if (vy.x == 1.0 || vy.x == -1.0) { rx = radii.y; ry = radii.x; rz = radii.z; transform = false; } else if (vy.z == 1.0 || vy.z == -1.0) { rx = radii.y; ry = radii.z; rz = radii.x; transform = false; } } else if (vx.z == 1.0 || vx.z == -1.0) { if (vy.x == 1.0 || vy.x == -1.0) { rx = radii.z; ry = radii.x; rz = radii.y; transform = false; } else if (vy.y == 1.0 || vy.y == -1.0) { rx = radii.z; ry = radii.y; rz = radii.x; transform = false; } } if (transform) { rx = radii.x; ry = radii.y; rz = radii.z; this.fromLocal = fromLocal; } cx = fromLocal.m14/fromLocal.m44; cy = fromLocal.m24/fromLocal.m44; cz = fromLocal.m34/fromLocal.m44; rx2 = rx*rx; ry2 = ry*ry; rz2 = rz*rz; sy = rx2/ry2; sz = rx2/rz2; bumpMapped = sphere.getTexture().hasComponent(Texture.BUMP_COMPONENT); this.toLocal = toLocal; } /** Get the TextureMapping for this object. */ public final TextureMapping getTextureMapping() { return theSphere.getTextureMapping(); } /** Get the MaterialMapping for this object. */ public final MaterialMapping getMaterialMapping() { return theSphere.getMaterialMapping(); } /** Determine whether the given ray intersects this sphere. */ public SurfaceIntersection checkIntersection(Ray r) { Vec3 orig = r.getOrigin(), rdir = r.getDirection(); Vec3 v1 = r.tempVec1, v2 = r.tempVec2, dir = r.tempVec3; double a, b, c, d, temp1, temp2; double dist1, dist2 = 0; v1.set(cx-orig.x, cy-orig.y, cz-orig.z); if (transform) { toLocal.transformDirection(v1); dir.set(rdir); toLocal.transformDirection(dir); } else if (uniform) dir = rdir; else dir.set(rdir); temp1 = sy*dir.y; temp2 = sz*dir.z; b = dir.x*v1.x + temp1*v1.y + temp2*v1.z; c = v1.x*v1.x + sy*v1.y*v1.y + sz*v1.z*v1.z - rx2; int numIntersections; if (c > TOL*b) { // Ray origin is outside ellipsoid. if (b <= 0.0) return SurfaceIntersection.NO_INTERSECTION; // Ray points away from the ellipsoid. a = dir.x*dir.x + temp1*dir.y + temp2*dir.z; d = b*b - a*c; if (d < 0.0) return SurfaceIntersection.NO_INTERSECTION; numIntersections = 2; temp1 = Math.sqrt(d); dist1 = (b - temp1)/a; dist2 = (b + temp1)/a; v2.set(orig.x+dist2*dir.x, orig.y+dist2*dir.y, orig.z+dist2*dir.z); projectPoint(v2); } else if (c < -TOL*b) { // Ray origin is inside ellipsoid. a = dir.x*dir.x + temp1*dir.y + temp2*dir.z; d = b*b - a*c; if (d < 0.0) return SurfaceIntersection.NO_INTERSECTION; numIntersections = 1; dist1 = (b + Math.sqrt(d))/a; } else { // Ray origin is on the surface of the ellipsoid. if (b <= 0.0) return SurfaceIntersection.NO_INTERSECTION; // Ray points away from the ellipsoid. a = dir.x*dir.x + temp1*dir.y + temp2*dir.z; d = b*b - a*c; if (d < 0.0) return SurfaceIntersection.NO_INTERSECTION; numIntersections = 1; dist1 = (b + Math.sqrt(d))/a; } v1.set(orig.x+dist1*rdir.x, orig.y+dist1*rdir.y, orig.z+dist1*rdir.z); projectPoint(v1); return new EllipsoidIntersection(this, numIntersections, v1, v2, dist1, dist2); } /** Given a point, project it onto the surface of the ellipsoid. This is necessary to prevent roundoff error. */ private void projectPoint(Vec3 pos) { if (transform) { toLocal.transform(pos); double scale = rx/Math.sqrt(pos.x*pos.x+sy*pos.y*pos.y+sz*pos.z*pos.z); pos.scale(scale); fromLocal.transform(pos); } else { double dx = pos.x-cx, dy = pos.y-cy, dz = pos.z-cz; double scale = rx/Math.sqrt(dx*dx+sy*dy*dy+sz*dz*dz); pos.set(cx+dx*scale, cy+dy*scale, cz+dz*scale); } } /** Get a bounding box for this ellipsoid. */ public BoundingBox getBounds() { if (transform) return (new BoundingBox(-rx, rx, -ry, ry, -rz, rz)).transformAndOutset(fromLocal); else return new BoundingBox(cx-rx, cx+rx, cy-ry, cy+ry, cz-rz, cz+rz); } /** Determine whether any part of the surface of the ellipsoid lies within a bounding box. */ public boolean intersectsBox(BoundingBox bb) { double dx, dy, dz, centerx, centery, centerz; if (transform) { bb = bb.transformAndOutset(toLocal); centerx = centery = centerz = 0.0; } else { centerx = cx; centery = cy; centerz = cz; } Vec3 c = new Vec3(centerx, centery, centerz); // Find the nearest point of the box to the ellipsoid. if (centerx < bb.minx) c.x = bb.minx; else if (centerx > bb.maxx) c.x = bb.maxx; if (centery < bb.miny) c.y = bb.miny; else if (centery > bb.maxy) c.y = bb.maxy; if (centerz < bb.minz) c.z = bb.minz; else if (centerz > bb.maxz) c.z = bb.maxz; // If the ellipsoid lies entirely outside the box, return false. if (!transform) c.set(c.x-centerx, c.y-centery, c.z-centerz); if (c.x*c.x + c.y*c.y*sy + c.z*c.z*sz > rx2) return false; // If the box is completely inside the ellipsoid, return false. Otherwise, return true. dx = 1.0/rx; dy = 1.0/ry; dz = 1.0/rz; c.set((bb.minx-centerx)*dx, (bb.miny-centery)*dy, (bb.minz-centerz)*dz); if (c.length2() > 1.0) return true; c.set((bb.minx-centerx)*dx, (bb.miny-centery)*dy, (bb.maxz-centerz)*dz); if (c.length2() > 1.0) return true; c.set((bb.minx-centerx)*dx, (bb.maxy-centery)*dy, (bb.minz-centerz)*dz); if (c.length2() > 1.0) return true; c.set((bb.minx-centerx)*dx, (bb.maxy-centery)*dy, (bb.maxz-centerz)*dz); if (c.length2() > 1.0) return true; c.set((bb.maxx-centerx)*dx, (bb.miny-centery)*dy, (bb.minz-centerz)*dz); if (c.length2() > 1.0) return true; c.set((bb.maxx-centerx)*dx, (bb.miny-centery)*dy, (bb.maxz-centerz)*dz); if (c.length2() > 1.0) return true; c.set((bb.maxx-centerx)*dx, (bb.maxy-centery)*dy, (bb.minz-centerz)*dz); if (c.length2() > 1.0) return true; c.set((bb.maxx-centerx)*dx, (bb.maxy-centery)*dy, (bb.maxz-centerz)*dz); if (c.length2() > 1.0) return true; return false; } /** Get the transformation from world coordinates to the object's local coordinates. */ public Mat4 toLocal() { return toLocal; } /** * Inner class representing an intersection with an RTEllipsoid. */ private static class EllipsoidIntersection implements SurfaceIntersection { private RTEllipsoid ellipse; private int numIntersections; private double dist1, dist2, r1x, r1y, r1z, r2x, r2y, r2z; private boolean trueNormValid; private Vec3 trueNorm, pos; public EllipsoidIntersection(RTEllipsoid ellipse, int numIntersections, Vec3 point1, Vec3 point2, double dist1, double dist2) { this.ellipse = ellipse; this.numIntersections = numIntersections; this.dist1 = dist1; this.dist2 = dist2; r1x = point1.x; r1y = point1.y; r1z = point1.z; r2x = point2.x; r2y = point2.y; r2z = point2.z; trueNorm = new Vec3(); pos = new Vec3(); } public RTObject getObject() { return ellipse; } public int numIntersections() { return numIntersections; } public void intersectionPoint(int n, Vec3 p) { if (n == 0) p.set(r1x, r1y, r1z); else p.set(r2x, r2y, r2z); } public double intersectionDist(int n) { if (n == 0) return dist1; else return dist2; } public void intersectionProperties(TextureSpec spec, Vec3 n, Vec3 viewDir, double size, double time) { calcTrueNorm(); n.set(trueNorm); TextureMapping map = ellipse.theSphere.getTextureMapping(); pos.set(r1x, r1y, r1z); if (map instanceof UniformMapping) map.getTextureSpec(pos, spec, -n.dot(viewDir), size, time, ellipse.param); else { ellipse.toLocal.transform(pos); map.getTextureSpec(pos, spec, -n.dot(viewDir), size, time, ellipse.param); } if (ellipse.bumpMapped) { if (ellipse.transform) ellipse.fromLocal.transformDirection(spec.bumpGrad); n.scale(spec.bumpGrad.dot(n)+1.0); n.subtract(spec.bumpGrad); n.normalize(); } } public void intersectionTransparency(int n, RGBColor trans, double angle, double size, double time) { TextureMapping map = ellipse.theSphere.getTextureMapping(); if (n == 0) pos.set(r1x, r1y, r1z); else pos.set(r2x, r2y, r2z); if (map instanceof UniformMapping) map.getTransparency(pos, trans, angle, size, time, ellipse.param); else { ellipse.toLocal.transform(pos); map.getTransparency(pos, trans, angle, size, time, ellipse.param); } } public void trueNormal(Vec3 n) { calcTrueNorm(); n.set(trueNorm); } /** Calculate the true normal of the point of intersection. */ private final void calcTrueNorm() { if (trueNormValid) return; trueNormValid = true; if (ellipse.transform) { trueNorm.set(r1x-ellipse.cx, r1y-ellipse.cy, r1z-ellipse.cz); ellipse.toLocal.transformDirection(trueNorm); trueNorm.set(trueNorm.x, trueNorm.y*ellipse.sy, trueNorm.z*ellipse.sz); ellipse.fromLocal.transformDirection(trueNorm); } else trueNorm.set(r1x-ellipse.cx, (r1y-ellipse.cy)*ellipse.sy, (r1z-ellipse.cz)*ellipse.sz); trueNorm.normalize(); } } }

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.20245.905−668.115
Source linesThe number of non-empty source lines.422+168.8
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.68−7.021

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

Score0.578

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.422−13.905
Indentation frequencyHow rapidly indentation changes from line to line.402+13.168
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.402−8.804
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.420.938+5.474
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.128.981−1.798
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.128.986+1.277
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.126−0.278

Intercept 0.07 + feature contributions = -4.797 (log-odds).
Score = sigmoid(-4.797) = 0.008.

Score0.499
Score249
Run 1

The code has a clear class structure and some methods are straightforward, but overall readability suffers from several factors. The constructor contains a deeply nested chain of conditionals (up to 3 levels) with repetitive axis-swapping logic that could be simplified. Variable names like rx, ry, rz, rx2, ry2, rz2, sy, sz, and temp1/temp2 are cryptic and lack clear intent. The checkIntersection method is long and mixes several operations (setup, branching based on ray origin position, distance calculation, projection) without helper methods, making the flow hard to follow. Some lines contain multiple actions (e.g., setting multiple variables). Mathematical operations are compact but sometimes dense, with little explanation. The intersectsBox method repeats nearly identical code 8 times for box corners, which could be looped. Comments exist but are sparse. Overall, the code is functional but falls below good readability standards.

Run 2

The code exhibits moderate readability. It has clear class and method organization with descriptive names, but suffers from several readability issues. The constructor contains a lengthy conditional block for axis alignment detection with repetitive nested if-else statements and magic number comparisons. The checkIntersection method has three similar branches that could be consolidated, with multiple blank lines fragmenting the logic. Variable names like 'sy' and 'sz' are cryptic, while 'temp1' and 'temp2' lack clear intent. The intersectsBox method is repetitive with eight nearly identical bounding box corner checks. Action granularity is generally good with one operation per line, but the mathematical expressions are dense. The code mixes coordinate transformations with intersection logic, making the flow harder to follow. Some methods are well-structured, but the overall complexity of spatial transformations and repeated patterns reduces clarity.

Run 3

The code is generally structured but suffers from several readability issues. The constructor contains deeply nested conditionals (up to 3-4 levels) for axis alignment detection, making it hard to follow. Variable names like 'rx2', 'sy', 'sz', 'v1', 'v2', 'temp1', 'temp2' are terse and non-descriptive. The checkIntersection method has complex branching logic and mixes multiple actions per line (e.g., 'v1.set(cx-orig.x, cy-orig.y, cz-orig.z)'), reducing clarity. Several methods like intersectsBox have repetitive blocks (8 nearly identical corner checks) that could be looped. However, the code has good organization with clear method separation, appropriate use of inner class, helpful comments explaining ray-origin cases and box-intersection logic, and consistent formatting. The use of boolean flags like 'transform' and 'uniform' is clear. Mathematical operations are compact but reduce readability for those unfamiliar with the geometry. Overall structure is logical but implementation details and naming could be more expressive.

Run 1

1. Code Structure: Responsibilities are logically separated into geometry, mapping, and an intersection class, though the constructor mixes initialization with repetitive transformation optimization. 2. Nesting: Generally shallow, with early returns simplifying flow; constructor branches and bump-mapping logic add moderate nesting. 3. Clarity of intent: Method names and explanatory comments establish purpose, but abbreviated fields, generic temporaries, and undocumented mathematical formulas require careful interpretation. 4. Code length: Mostly purposeful, but repeated axis permutations, quadratic calculations, and eight explicit corner checks make it longer than necessary. 5. Action granularity: Most executable lines perform one action; grouped declarations and chained assignments slightly reduce scanability. 6. Reading flow: Methods follow coherent sequences, supported by comments and whitespace, but inconsistent brace indentation, dense arithmetic, and reused mutable vectors interrupt otherwise natural reading.

Run 2

Code Structure: Responsibilities are logically separated into geometry methods and an intersection helper class, though the constructor contains repetitive transformation cases. Nesting: Generally shallow, with early returns keeping intersection and bounding-box checks manageable; constructor branches add moderate nesting. Clarity of intent: Method names and explanatory comments communicate purpose, but abbreviated fields, generic temporary variables, and dense mathematical expressions require careful interpretation. Code length: Reasonable for the functionality, but repeated axis permutations, quadratic calculations, and eight explicit corner checks increase length unnecessarily. Action granularity: Most statements perform one action per line, although grouped declarations and chained assignments obscure individual values. Reading flow: Methods follow coherent procedural sequences, and comments explain geometric cases; inconsistent brace indentation, tightly spaced arithmetic, and switching between local and world coordinates interrupt smooth reading.

Run 3

Code Structure: Responsibilities are logically separated into geometry, mapping access, and an intersection helper class, though the constructor and intersection calculations are lengthy. Nesting: Mostly shallow, with manageable two-level conditional branches and useful early returns. Clarity of intent: Method names and explanatory comments communicate purpose, but abbreviated fields, generic temporaries, and undocumented mathematical formulas require careful interpretation. Code length: Repeated axis-permutation branches, quadratic calculations, and eight explicit corner checks add avoidable repetition. Action granularity: Most statements perform one action per line, although grouped declarations and chained assignments reduce scanability. Reading flow: Methods generally follow a natural sequence, and comments identify important geometric cases; inconsistent brace indentation, dense arithmetic formatting, mutable temporary-vector reuse, and transitions between coordinate systems interrupt that flow. Overall, readable for someone familiar with ray tracing, but clearer naming and factoring repeated logic would improve accessibility.