Difference between revisions of "U"
Jump to navigation
Jump to search
(more content.) |
(more content.) |
||
Line 45: | Line 45: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | With a immutable universal data-structure library, you can easily build data abstraction on top. No longer messy code like this: | + | With a immutable universal data-structure library, you can easily build data abstraction on top. |
+ | |||
+ | <strong>No longer messy code like this:</strong> | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
Line 53: | Line 55: | ||
double latVel = Math.sin(event.getHeadingRadians() - absoluteBearing) * event.getVelocity(); | double latVel = Math.sin(event.getHeadingRadians() - absoluteBearing) * event.getVelocity(); | ||
double advVel = -Math.cos(event.getHeadingRadians() - absoluteBearing) * event.getVelocity(); | double advVel = -Math.cos(event.getHeadingRadians() - absoluteBearing) * event.getVelocity(); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | write like this: | ||
+ | |||
+ | <syntaxhighlight lang="java"> | ||
+ | @Override | ||
+ | protected void onUpdated() { | ||
+ | Vec dis = displacement(bot.pos(), enemy.pos()); | ||
+ | double latVel = cross(dis, enemy.vel()); | ||
+ | double advVel = -dot(dis, enemy.vel()); | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 04:05, 15 August 2017
This page is dedicated for describing the xor.util.ds.U
U is a immutable universal data-structure library, where U stands for both Util and Universal.
With U, you can write code just like this:
Vec dis = displacement(bot.pos(), enemy.pos());
dis = rotate(dis, radians(PI / 2));
Point projected = project(bot.pos(), dis);
Or even this:
Vec dis = displacement(bot.pos(), enemy.pos());
double latVel = cross(dis, enemy.vel());
double advVel = -dot(dis, enemy.vel());
And if you like:
import xor.util.ds.*;
import static xor.util.ds.U.*;
class Wave {
private final double fireTime;
private final Point source;
private final Direction direction;
Wave(double fireTime, @NotNull Point source, @NotNull Direction direction) {
this.fireTime = fireTime;
this.source = source;
this.direction = direction;
}
public @NotNull Vec traveled(double now, double speed) {
return project(source, direction, speed * (now - fireTime));
}
}
With a immutable universal data-structure library, you can easily build data abstraction on top.
No longer messy code like this:
@Override
public final void onScannedRobot(@NotNull ScannedRobotEvent event) {
double absoluteBearing = this.getHeadingRadians() + event.getBearingRadians();
double latVel = Math.sin(event.getHeadingRadians() - absoluteBearing) * event.getVelocity();
double advVel = -Math.cos(event.getHeadingRadians() - absoluteBearing) * event.getVelocity();
}
write like this:
@Override
protected void onUpdated() {
Vec dis = displacement(bot.pos(), enemy.pos());
double latVel = cross(dis, enemy.vel());
double advVel = -dot(dis, enemy.vel());
}