Difference between revisions of "U"
Jump to navigation
Jump to search
m (Fix) |
(more content.) |
||
| Line 1: | Line 1: | ||
This page is dedicated for describing the <code>xor.util.ds.U</code> | This page is dedicated for describing the <code>xor.util.ds.U</code> | ||
| + | |||
---- | ---- | ||
| − | U is a immutable data-structure library, where U stands for both Util and Universal. | + | |
| + | 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: | With U, you can write code just like this: | ||
| Line 18: | Line 20: | ||
double latVel = cross(dis, enemy.vel()); | double latVel = cross(dis, enemy.vel()); | ||
double advVel = -dot(dis, enemy.vel()); | double advVel = -dot(dis, enemy.vel()); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | And if you like: | ||
| + | |||
| + | <syntaxhighlight lang="java"> | ||
| + | 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)); | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | With a immutable universal data-structure library, you can easily build data abstraction on top. No longer messy code like this: | ||
| + | |||
| + | <syntaxhighlight lang="java"> | ||
| + | @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(); | ||
| + | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 04:01, 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();
}