Skip to content

Commit 21acf39

Browse files
committed
fixes!
1 parent 975407f commit 21acf39

File tree

4 files changed

+97
-75
lines changed

4 files changed

+97
-75
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ minecraft_version = 1.20
66
yarn_mappings = 1.20+build.1
77
loader_version = 0.14.22
88

9-
mod_version = 2.6.0
9+
mod_version = 2.6.1
1010
maven_group = net.krlite
1111
archives_base_name = equator
1212

src/main/java/net/krlite/equator/Equator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class Equator implements ModInitializer {
88
public static final String NAME = "Equator", ID = "equator";
99
public static final Logger LOGGER = LoggerFactory.getLogger(ID);
10-
public static final boolean DEBUG = false;
10+
public static final boolean DEBUG = true;
1111

1212
@Override
1313
public void onInitialize() {

src/main/java/net/krlite/equator/render/renderer/Flat.java

Lines changed: 87 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -953,13 +953,13 @@ public class Oval implements Renderable {
953953
// Constructors
954954

955955
public Oval(
956-
double offset, double radians, double breadth,
956+
double offset, double arc, Breadth breadth,
957957
@Nullable AccurateColor colorCenter, @Nullable ColorTable colors,
958958
double opacityMultiplier,
959959
ColorStandard.MixMode mixMode, VertexProvider outline, OvalMode mode
960960
) {
961961
this.offset = Theory.mod(offset, 2 * Math.PI);
962-
this.radians = Theory.clamp(radians, -2 * Math.PI, 2 * Math.PI);
962+
this.arc = Theory.clamp(arc, -2 * Math.PI, 2 * Math.PI);
963963
this.breadth = breadth;
964964

965965
this.colorCenter = AccurateColor.notnull(colorCenter);
@@ -971,8 +971,8 @@ public Oval(
971971
this.mode = mode;
972972
}
973973

974-
public Oval(double offset, double radians, AccurateColor color) {
975-
this(offset, radians, 0, color, null, 1, ColorStandard.MixMode.BLEND, VertexProvider.NONE, OvalMode.FILL);
974+
public Oval(double offset, double arc, AccurateColor color) {
975+
this(offset, arc, new Breadth.Constant(0), color, null, 1, ColorStandard.MixMode.BLEND, VertexProvider.NONE, OvalMode.FILL);
976976
}
977977

978978
public Oval(AccurateColor color) {
@@ -985,42 +985,69 @@ public Oval() {
985985

986986
// Fields
987987

988+
public abstract static class Breadth {
989+
public abstract double breadth(double radius);
990+
991+
public Vector vertexAt(Box box, double offset, double multiplier) {
992+
double
993+
x = Math.cos(offset) * (box.w() / 2),
994+
y = Math.sin(offset) * (box.h() / 2),
995+
radius = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
996+
997+
return box.center().add(Vector.fromCartesian(
998+
Math.cos(offset) * (box.w() / 2 + breadth(radius) * multiplier),
999+
Math.sin(offset) * (box.h() / 2 + breadth(radius) * multiplier)
1000+
));
1001+
}
1002+
1003+
public static class Constant extends Breadth {
1004+
private final double breadth;
1005+
1006+
public Constant(double breadth) {
1007+
this.breadth = breadth;
1008+
}
1009+
1010+
@Override
1011+
public double breadth(double radius) {
1012+
return breadth;
1013+
}
1014+
}
1015+
1016+
public static class Dynamic extends Breadth {
1017+
private final double scalar;
1018+
1019+
public Dynamic(double scalar) {
1020+
this.scalar = scalar;
1021+
}
1022+
1023+
@Override
1024+
public double breadth(double radius) {
1025+
return radius * scalar;
1026+
}
1027+
}
1028+
}
1029+
9881030
public enum VertexProvider {
9891031
NONE(
9901032
(box, offset, breadth) -> box.center(),
991-
(box, offset, breadth) -> box.center().add(Vector.fromCartesian(
992-
Math.cos(offset) * (box.w() / 2),
993-
Math.sin(offset) * (box.h() / 2)
994-
))
1033+
(box, offset, breadth) -> breadth.vertexAt(box, offset, 0)
9951034
),
9961035
INNER(
997-
(box, offset, breadth) -> box.center().add(Vector.fromCartesian(
998-
Math.cos(offset) * (box.w() / 2 - breadth),
999-
Math.sin(offset) * (box.h() / 2 - breadth)
1000-
)),
1036+
(box, offset, breadth) -> breadth.vertexAt(box, offset, -1),
10011037
NONE.outerVertexFunction
10021038
),
10031039
OUTER(
10041040
NONE.outerVertexFunction,
1005-
(box, offset, breadth) -> box.center().add(Vector.fromCartesian(
1006-
Math.cos(offset) * (box.w() / 2 + breadth),
1007-
Math.sin(offset) * (box.h() / 2 + breadth)
1008-
))
1041+
(box, offset, breadth) -> breadth.vertexAt(box, offset, 1)
10091042
),
10101043
BOTH(
1011-
(box, offset, breadth) -> box.center().add(Vector.fromCartesian(
1012-
Math.cos(offset) * (box.w() / 2 - breadth / 2),
1013-
Math.sin(offset) * (box.h() / 2 - breadth / 2)
1014-
)),
1015-
(box, offset, breadth) -> box.center().add(Vector.fromCartesian(
1016-
Math.cos(offset) * (box.w() / 2 + breadth / 2),
1017-
Math.sin(offset) * (box.h() / 2 + breadth / 2)
1018-
))
1044+
(box, offset, breadth) -> breadth.vertexAt(box, offset, -0.5),
1045+
(box, offset, breadth) -> breadth.vertexAt(box, offset, 0.5)
10191046
);
10201047

10211048
@FunctionalInterface
1022-
interface VertexFunction {
1023-
@NotNull Vector vertexAt(Box box, double offset, double breadth);
1049+
public interface VertexFunction {
1050+
@NotNull Vector vertexAt(Box box, double offset, Breadth breadth);
10241051
}
10251052

10261053
private final VertexFunction innerVertexFunction, outerVertexFunction;
@@ -1030,11 +1057,11 @@ interface VertexFunction {
10301057
this.outerVertexFunction = outerVertexFunction;
10311058
}
10321059

1033-
public @NotNull Vector innerVertexAt(Box box, double offset, double breadth) {
1060+
public @NotNull Vector innerVertexAt(Box box, double offset, Breadth breadth) {
10341061
return innerVertexFunction.vertexAt(box, offset, breadth);
10351062
}
10361063

1037-
public @NotNull Vector outerVertexAt(Box box, double offset, double breadth) {
1064+
public @NotNull Vector outerVertexAt(Box box, double offset, Breadth breadth) {
10381065
return outerVertexFunction.vertexAt(box, offset, breadth);
10391066
}
10401067
}
@@ -1185,7 +1212,8 @@ interface ColorFunction {
11851212
}
11861213
}
11871214

1188-
private final double offset, radians, breadth;
1215+
private final double offset, arc;
1216+
private final Breadth breadth;
11891217
private final @NotNull AccurateColor colorCenter;
11901218
private final @NotNull ColorTable colors;
11911219
private final double opacityMultiplier;
@@ -1199,11 +1227,11 @@ public double offset() {
11991227
return offset;
12001228
}
12011229

1202-
public double radians() {
1203-
return radians;
1230+
public double arc() {
1231+
return arc;
12041232
}
12051233

1206-
public double breadth() {
1234+
public Breadth breadth() {
12071235
return breadth;
12081236
}
12091237

@@ -1234,51 +1262,59 @@ public OvalMode mode() {
12341262
// Mutators
12351263

12361264
public Oval parent(UnaryOperator<Flat> flat) {
1237-
return flat.apply(Flat.this).new Oval(offset(), radians(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode());
1265+
return flat.apply(Flat.this).new Oval(offset(), arc(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode());
12381266
}
12391267

12401268
public Oval offset(double offset) {
1241-
return new Oval(offset, radians(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode());
1269+
return new Oval(offset, arc(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode());
12421270
}
12431271

1244-
public Oval radians(double radians) {
1272+
public Oval arc(double radians) {
12451273
return new Oval(offset(), radians, breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode());
12461274
}
12471275

1248-
public Oval breadth(double breadth) {
1249-
return new Oval(offset(), radians(), breadth, colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode());
1276+
public Oval breadth(Breadth breadth) {
1277+
return new Oval(offset(), arc(), breadth, colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode());
12501278
}
12511279

12521280
public Oval colorCenter(@Nullable AccurateColor colorCenter) {
1253-
return new Oval(offset(), radians(), breadth(), colorCenter, colors(), opacityMultiplier(), mixMode(), outline(), mode());
1281+
return new Oval(offset(), arc(), breadth(), colorCenter, colors(), opacityMultiplier(), mixMode(), outline(), mode());
12541282
}
12551283

12561284
public Oval colors(@Nullable ColorTable colors) {
1257-
return new Oval(offset(), radians(), breadth(), colorCenter(), colors, opacityMultiplier(), mixMode(), outline(), mode());
1285+
return new Oval(offset(), arc(), breadth(), colorCenter(), colors, opacityMultiplier(), mixMode(), outline(), mode());
12581286
}
12591287

12601288
public Oval addColor(double offset, @Nullable AccurateColor color) {
1261-
return new Oval(offset(), radians(), breadth(), colorCenter(), colors().putColor(offset, color), opacityMultiplier(), mixMode(), outline(), mode());
1289+
return new Oval(offset(), arc(), breadth(), colorCenter(), colors().putColor(offset, color), opacityMultiplier(), mixMode(), outline(), mode());
12621290
}
12631291

12641292
public Oval opacityMultiplier(double opacityMultiplier) {
1265-
return new Oval(offset(), radians(), breadth(), colorCenter(), colors(), opacityMultiplier, mixMode(), outline(), mode());
1293+
return new Oval(offset(), arc(), breadth(), colorCenter(), colors(), opacityMultiplier, mixMode(), outline(), mode());
12661294
}
12671295

12681296
public Oval mixMode(ColorStandard.MixMode mixMode) {
1269-
return new Oval(offset(), radians(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode, outline(), mode());
1297+
return new Oval(offset(), arc(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode, outline(), mode());
12701298
}
12711299

12721300
public Oval outline(VertexProvider outline) {
1273-
return new Oval(offset(), radians(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline, mode());
1301+
return new Oval(offset(), arc(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline, mode());
12741302
}
12751303

1276-
public Oval outline(VertexProvider outline, double breadth) {
1304+
public Oval outline(VertexProvider outline, Breadth breadth) {
12771305
return outline(outline).breadth(breadth);
12781306
}
12791307

1308+
public Oval outlineConstant(VertexProvider outline, double breadth) {
1309+
return outline(outline).breadth(new Breadth.Constant(breadth));
1310+
}
1311+
1312+
public Oval outlineDynamic(VertexProvider outline, double scalar) {
1313+
return outline(outline).breadth(new Breadth.Dynamic(scalar));
1314+
}
1315+
12801316
public Oval mode(OvalMode mode) {
1281-
return new Oval(offset(), radians(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode);
1317+
return new Oval(offset(), arc(), breadth(), colorCenter(), colors(), opacityMultiplier(), mixMode(), outline(), mode);
12821318
}
12831319

12841320
// Properties
@@ -1290,11 +1326,11 @@ public Oval mode(OvalMode mode) {
12901326
}
12911327

12921328
private @NotNull Vector innerVertexAt(double offset) {
1293-
return outline().innerVertexAt(box(), offset, radians());
1329+
return outline().innerVertexAt(box(), offset, breadth());
12941330
}
12951331

12961332
private @NotNull Vector outerVertexAt(double offset) {
1297-
return outline().outerVertexAt(box(), offset, radians());
1333+
return outline().outerVertexAt(box(), offset, breadth());
12981334
}
12991335

13001336
public boolean hasCenter() {
@@ -1331,11 +1367,11 @@ private double delta() {
13311367
}
13321368

13331369
private double clampOffset(double offset) {
1334-
return Theory.clamp(offset, offset() - radians(), offset() + radians());
1370+
return Theory.clamp(offset, offset() - arc(), offset() + arc());
13351371
}
13361372

13371373
private double nextOffset(double offset) {
1338-
boolean positive = radians() >= 0;
1374+
boolean positive = arc() >= 0;
13391375

13401376
if (positive) {
13411377
return offset + delta();
@@ -1345,22 +1381,20 @@ private double nextOffset(double offset) {
13451381
}
13461382

13471383
private boolean isOffsetLegal(double offset) {
1348-
return radians() >= 0 ? offset <= offset() + radians() + delta() : offset >= offset() + radians() - delta();
1384+
return arc() >= 0 ? offset <= offset() + arc() + delta() : offset >= offset() + arc() - delta();
13491385
}
13501386

13511387
// Interface Implementations
13521388

13531389
@Override
13541390
public boolean isRenderable() {
1355-
return (hasCenter() || hasColor()) && !Theory.looseEquals(radians(), 0) && Renderable.isLegal(box());
1391+
return (hasCenter() || hasColor()) && !Theory.looseEquals(arc(), 0) && Renderable.isLegal(box());
13561392
}
13571393

13581394
@Override
13591395
public void render() {
13601396
if (!isRenderable()) return;
13611397

1362-
if (outline() != VertexProvider.NONE && Theory.looseEquals(breadth(), 1)) return;
1363-
13641398
RenderSystem.enableBlend();
13651399
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
13661400
RenderSystem.disableCull(); // Prevents triangles from being culled

src/main/java/net/krlite/equator/test/CanvasScreen.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
package net.krlite.equator.test;
22

3-
import net.krlite.equator.input.Keyboard;
43
import net.krlite.equator.input.Mouse;
54
import net.krlite.equator.math.algebra.Curves;
6-
import net.krlite.equator.math.algebra.Quaternion;
75
import net.krlite.equator.math.geometry.flat.Box;
86
import net.krlite.equator.render.frame.FrameInfo;
97
import net.krlite.equator.render.renderer.Flat;
108
import net.krlite.equator.visual.animation.animated.AnimatedDouble;
11-
import net.krlite.equator.visual.color.AccurateColor;
129
import net.krlite.equator.visual.color.Palette;
1310
import net.krlite.equator.visual.text.Paragraph;
1411
import net.krlite.equator.visual.text.Section;
15-
import net.minecraft.block.Blocks;
1612
import net.minecraft.client.MinecraftClient;
1713
import net.minecraft.client.gui.DrawContext;
1814
import net.minecraft.client.gui.screen.Screen;
19-
import net.minecraft.client.sound.PositionedSoundInstance;
20-
import net.minecraft.sound.SoundEvents;
2115
import net.minecraft.text.Text;
2216

23-
import java.util.Map;
24-
2517
public class CanvasScreen extends Screen {
2618
public CanvasScreen() {
2719
super(Text.of("Canvas"));
@@ -181,7 +173,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
181173
box.render(context, flat -> flat.new Rectangle().colors(AccurateColor.MAGENTA));
182174
*/
183175

184-
FrameInfo.scaled().scaleCenter(0.3 * animation.value()).render(context, flat -> flat.new Rectangle().colors(Palette.MAGENTA));
176+
// FrameInfo.scaled().scaleCenter(0.3 * animation.value()).render(context, flat -> flat.new Rectangle().colors(Palette.MAGENTA));
185177

186178
/*
187179
FrameInfo.scaled().squareInner().scale(0.4).scale(animation.value()).leftCenter(FrameInfo.scaled().scaleCenter(0.7)).render(context,
@@ -202,17 +194,13 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
202194
203195
*/
204196

205-
/*
206-
box.render(context,
207-
flat -> flat.new Oval(Palette.CORAL)
208-
.mode(Flat.Oval.OvalMode.GRADIANT_OUT)
209-
.addColor(0, Palette.WHITE)
210-
.addColor(Math.PI, Palette.CYAN)
211-
.outline(Flat.Oval.VertexProvider.NONE, 5)
212-
.offset(-0.5)
213-
.radians(1)
197+
FrameInfo.scaled().scaleCenter(0.5).render(context, flat -> flat.new Oval(Palette.CORAL)
198+
.mode(Flat.Oval.OvalMode.FILL_GRADIANT_OUT)
199+
.addColor(0, Palette.WHITE)
200+
.addColor(Math.PI, Palette.CYAN)
201+
.outlineDynamic(Flat.Oval.VertexProvider.INNER, 0.25)
202+
//.offset(-0.5)
203+
.arc(2 * Curves.Sinusoidal.EASE.apply(-Math.PI, Math.PI, System.currentTimeMillis() / 1000.0))
214204
);
215-
216-
*/
217205
}
218206
}

0 commit comments

Comments
 (0)