Skip to content

Commit e80e326

Browse files
committed
Format changes.
1 parent eb60154 commit e80e326

File tree

2 files changed

+243
-273
lines changed

2 files changed

+243
-273
lines changed

src/main/java/workspace/ui/ui3d/Axis3D.java

Lines changed: 165 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -5,192 +5,171 @@
55
import workspace.ui.Graphics;
66

77
/**
8-
* Represents a 3D axis visualization that can be rendered with customizable
9-
* visibility for each axis. Each axis is drawn with its corresponding color, as
10-
* defined by the UI constants, and can be toggled on or off individually.
11-
* <p>
12-
* The axis lines are rendered in the X, Y, and Z directions, with their lengths
13-
* determined by the specified size parameter.
14-
* </p>
8+
* Represents a 3D axis visualization that can be rendered with customizable visibility for each
9+
* axis. Each axis is drawn with its corresponding color, as defined by the UI constants, and can be
10+
* toggled on or off individually.
11+
*
12+
* <p>The axis lines are rendered in the X, Y, and Z directions, with their lengths determined by
13+
* the specified size parameter.
1514
*/
1615
public class Axis3D {
1716

18-
/**
19-
* Visibility flag for the X-axis.
20-
*/
21-
private boolean xAxisVisible;
22-
23-
/**
24-
* Visibility flag for the Y-axis.
25-
*/
26-
private boolean yAxisVisible;
27-
28-
/**
29-
* Visibility flag for the Z-axis.
30-
*/
31-
private boolean zAxisVisible;
32-
33-
/**
34-
* The length of each axis, extending equally in both positive and negative
35-
* directions.
36-
*/
37-
private float size;
38-
39-
/**
40-
* Constructs an {@code Axis3D} with the specified size. All axes are visible
41-
* by default.
42-
*
43-
* @param size the length of each axis; must be positive
44-
* @throws IllegalArgumentException if the size is not positive
45-
*/
46-
public Axis3D(float size) {
47-
if (size <= 0) {
48-
throw new IllegalArgumentException("Size must be positive.");
49-
}
50-
this.size = size;
51-
this.xAxisVisible = true;
52-
this.yAxisVisible = true;
53-
this.zAxisVisible = true;
54-
}
55-
56-
/**
57-
* Renders the 3D axis using the provided {@link Graphics} context. The axis
58-
* lines are drawn based on their visibility flags and scaled according to the
59-
* specified stroke weight factor.
60-
*
61-
* @param g the {@link Graphics} context to draw on
62-
* @param scale the scale factor for adjusting the stroke weight; must be
63-
* positive
64-
*/
65-
public void render(Graphics g, float scale) {
66-
if (scale <= 0) {
67-
throw new IllegalArgumentException("Scale must be positive.");
68-
}
69-
g.pushMatrix();
70-
g.strokeWeight(1.5f / scale);
71-
renderXAxis(g);
72-
renderYAxis(g);
73-
renderZAxis(g);
74-
g.popMatrix();
75-
}
76-
77-
/**
78-
* Renders the X-axis if it is visible. The X-axis is drawn in the positive
79-
* and negative X directions with the color defined by
80-
* {@link UiConstants#KEY_AXIS_X_COLOR}.
81-
*
82-
* @param g the {@link Graphics} context to draw on
83-
*/
84-
private void renderXAxis(Graphics g) {
85-
if (!xAxisVisible) {
86-
return;
87-
}
88-
g.setColor(UiValues.getColor(UiConstants.KEY_AXIS_X_COLOR));
89-
g.drawLine(size, 0, 0, 0, 0, 0);
90-
g.drawLine(-size, 0, 0, 0, 0, 0);
91-
}
92-
93-
/**
94-
* Renders the Y-axis if it is visible. The Y-axis is drawn in the positive
95-
* and negative Y directions with the color defined by
96-
* {@link UiConstants#KEY_AXIS_Y_COLOR}.
97-
*
98-
* @param g the {@link Graphics} context to draw on
99-
*/
100-
private void renderYAxis(Graphics g) {
101-
if (!yAxisVisible) {
102-
return;
103-
}
104-
g.setColor(UiValues.getColor(UiConstants.KEY_AXIS_Y_COLOR));
105-
g.drawLine(0, size, 0, 0, 0, 0);
106-
g.drawLine(0, -size, 0, 0, 0, 0);
107-
}
108-
109-
/**
110-
* Renders the Z-axis if it is visible. The Z-axis is drawn in the positive
111-
* and negative Z directions with the color defined by
112-
* {@link UiConstants#KEY_AXIS_Z_COLOR}.
113-
*
114-
* @param g the {@link Graphics} context to draw on
115-
*/
116-
private void renderZAxis(Graphics g) {
117-
if (!zAxisVisible) {
118-
return;
119-
}
120-
g.setColor(UiValues.getColor(UiConstants.KEY_AXIS_Z_COLOR));
121-
g.drawLine(0, 0, size, 0, 0, 0);
122-
g.drawLine(0, 0, -size, 0, 0, 0);
123-
}
124-
125-
/**
126-
* Returns whether the X-axis is visible.
127-
*
128-
* @return {@code true} if the X-axis is visible; {@code false} otherwise
129-
*/
130-
public boolean isXAxisVisible() {
131-
return xAxisVisible;
132-
}
133-
134-
/**
135-
* Sets the visibility of the X-axis.
136-
*
137-
* @param xAxisVisible {@code true} to make the X-axis visible; {@code false}
138-
* to hide it
139-
*/
140-
public void setXAxisVisible(boolean xAxisVisible) {
141-
this.xAxisVisible = xAxisVisible;
142-
}
143-
144-
/**
145-
* Returns whether the Y-axis is visible.
146-
*
147-
* @return {@code true} if the Y-axis is visible; {@code false} otherwise
148-
*/
149-
public boolean isYAxisVisible() {
150-
return yAxisVisible;
151-
}
152-
153-
/**
154-
* Sets the visibility of the Y-axis.
155-
*
156-
* @param yAxisVisible {@code true} to make the Y-axis visible; {@code false}
157-
* to hide it
158-
*/
159-
public void setYAxisVisible(boolean yAxisVisible) {
160-
this.yAxisVisible = yAxisVisible;
161-
}
162-
163-
/**
164-
* Returns whether the Z-axis is visible.
165-
*
166-
* @return {@code true} if the Z-axis is visible; {@code false} otherwise
167-
*/
168-
public boolean isZAxisVisible() {
169-
return zAxisVisible;
170-
}
171-
172-
/**
173-
* Sets the visibility of the Z-axis.
174-
*
175-
* @param zAxisVisible {@code true} to make the Z-axis visible; {@code false}
176-
* to hide it
177-
*/
178-
public void setZAxisVisible(boolean zAxisVisible) {
179-
this.zAxisVisible = zAxisVisible;
180-
}
181-
182-
/**
183-
* Sets the length of each axis, extending equally in both positive and
184-
* negative directions.
185-
*
186-
* @param newSize the new size of the axes; must be positive
187-
* @throws IllegalArgumentException if the new size is not positive
188-
*/
189-
public void setSize(float newSize) {
190-
if (newSize <= 0) {
191-
throw new IllegalArgumentException("Size must be positive.");
192-
}
193-
this.size = newSize;
194-
}
195-
196-
}
17+
/** Visibility flag for the X-axis. */
18+
private boolean xAxisVisible;
19+
20+
/** Visibility flag for the Y-axis. */
21+
private boolean yAxisVisible;
22+
23+
/** Visibility flag for the Z-axis. */
24+
private boolean zAxisVisible;
25+
26+
/** The length of each axis, extending equally in both positive and negative directions. */
27+
private float size;
28+
29+
/**
30+
* Constructs an {@code Axis3D} with the specified size. All axes are visible by default.
31+
*
32+
* @param size the length of each axis; must be positive
33+
* @throws IllegalArgumentException if the size is not positive
34+
*/
35+
public Axis3D(float size) {
36+
if (size <= 0) {
37+
throw new IllegalArgumentException("Size must be positive.");
38+
}
39+
this.size = size;
40+
this.xAxisVisible = true;
41+
this.yAxisVisible = true;
42+
this.zAxisVisible = true;
43+
}
44+
45+
/**
46+
* Renders the 3D axis using the provided {@link Graphics} context. The axis lines are drawn based
47+
* on their visibility flags and scaled according to the specified stroke weight factor.
48+
*
49+
* @param g the {@link Graphics} context to draw on
50+
* @param scale the scale factor for adjusting the stroke weight; must be positive
51+
*/
52+
public void render(Graphics g, float scale) {
53+
if (scale <= 0) {
54+
throw new IllegalArgumentException("Scale must be positive.");
55+
}
56+
g.pushMatrix();
57+
g.strokeWeight(1.5f / scale);
58+
renderXAxis(g);
59+
renderYAxis(g);
60+
renderZAxis(g);
61+
g.popMatrix();
62+
}
63+
64+
/**
65+
* Renders the X-axis if it is visible. The X-axis is drawn in the positive and negative X
66+
* directions with the color defined by {@link UiConstants#KEY_AXIS_X_COLOR}.
67+
*
68+
* @param g the {@link Graphics} context to draw on
69+
*/
70+
private void renderXAxis(Graphics g) {
71+
if (!xAxisVisible) {
72+
return;
73+
}
74+
g.setColor(UiValues.getColor(UiConstants.KEY_AXIS_X_COLOR));
75+
g.drawLine(size, 0, 0, 0, 0, 0);
76+
g.drawLine(-size, 0, 0, 0, 0, 0);
77+
}
78+
79+
/**
80+
* Renders the Y-axis if it is visible. The Y-axis is drawn in the positive and negative Y
81+
* directions with the color defined by {@link UiConstants#KEY_AXIS_Y_COLOR}.
82+
*
83+
* @param g the {@link Graphics} context to draw on
84+
*/
85+
private void renderYAxis(Graphics g) {
86+
if (!yAxisVisible) {
87+
return;
88+
}
89+
g.setColor(UiValues.getColor(UiConstants.KEY_AXIS_Y_COLOR));
90+
g.drawLine(0, size, 0, 0, 0, 0);
91+
g.drawLine(0, -size, 0, 0, 0, 0);
92+
}
93+
94+
/**
95+
* Renders the Z-axis if it is visible. The Z-axis is drawn in the positive and negative Z
96+
* directions with the color defined by {@link UiConstants#KEY_AXIS_Z_COLOR}.
97+
*
98+
* @param g the {@link Graphics} context to draw on
99+
*/
100+
private void renderZAxis(Graphics g) {
101+
if (!zAxisVisible) {
102+
return;
103+
}
104+
g.setColor(UiValues.getColor(UiConstants.KEY_AXIS_Z_COLOR));
105+
g.drawLine(0, 0, size, 0, 0, 0);
106+
g.drawLine(0, 0, -size, 0, 0, 0);
107+
}
108+
109+
/**
110+
* Returns whether the X-axis is visible.
111+
*
112+
* @return {@code true} if the X-axis is visible; {@code false} otherwise
113+
*/
114+
public boolean isXAxisVisible() {
115+
return xAxisVisible;
116+
}
117+
118+
/**
119+
* Sets the visibility of the X-axis.
120+
*
121+
* @param xAxisVisible {@code true} to make the X-axis visible; {@code false} to hide it
122+
*/
123+
public void setXAxisVisible(boolean xAxisVisible) {
124+
this.xAxisVisible = xAxisVisible;
125+
}
126+
127+
/**
128+
* Returns whether the Y-axis is visible.
129+
*
130+
* @return {@code true} if the Y-axis is visible; {@code false} otherwise
131+
*/
132+
public boolean isYAxisVisible() {
133+
return yAxisVisible;
134+
}
135+
136+
/**
137+
* Sets the visibility of the Y-axis.
138+
*
139+
* @param yAxisVisible {@code true} to make the Y-axis visible; {@code false} to hide it
140+
*/
141+
public void setYAxisVisible(boolean yAxisVisible) {
142+
this.yAxisVisible = yAxisVisible;
143+
}
144+
145+
/**
146+
* Returns whether the Z-axis is visible.
147+
*
148+
* @return {@code true} if the Z-axis is visible; {@code false} otherwise
149+
*/
150+
public boolean isZAxisVisible() {
151+
return zAxisVisible;
152+
}
153+
154+
/**
155+
* Sets the visibility of the Z-axis.
156+
*
157+
* @param zAxisVisible {@code true} to make the Z-axis visible; {@code false} to hide it
158+
*/
159+
public void setZAxisVisible(boolean zAxisVisible) {
160+
this.zAxisVisible = zAxisVisible;
161+
}
162+
163+
/**
164+
* Sets the length of each axis, extending equally in both positive and negative directions.
165+
*
166+
* @param newSize the new size of the axes; must be positive
167+
* @throws IllegalArgumentException if the new size is not positive
168+
*/
169+
public void setSize(float newSize) {
170+
if (newSize <= 0) {
171+
throw new IllegalArgumentException("Size must be positive.");
172+
}
173+
this.size = newSize;
174+
}
175+
}

0 commit comments

Comments
 (0)