U

From Robowiki
Revision as of 05:01, 15 August 2017 by Xor (talk | contribs) (more content.)
Jump to navigation Jump to search

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();
}