Initial commit
This commit is contained in:
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.DS_Store
|
||||||
|
applet
|
||||||
|
application.linux32
|
||||||
|
application.linux64
|
||||||
|
application.windows32
|
||||||
|
application.windows64
|
||||||
|
application.macosx
|
||||||
255
Buffer.pde
Normal file
255
Buffer.pde
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.PrimitiveIterator;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
interface Buffer<T> extends Iterable<T> {
|
||||||
|
static <T> Buffer<T> from(T[] buffer) throws IllegalArgumentException {
|
||||||
|
if (buffer.length < 1) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BoundedBufferArrayImpl<>(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T> Buffer<T> array(int capacity, Class<T> classOfT) throws IllegalArgumentException {
|
||||||
|
if (capacity < 1) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
var buffer = (T[]) Array.newInstance(classOfT, capacity);
|
||||||
|
return new BoundedBufferArrayImpl<>(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T> Buffer<T> boundedList(int capacity) throws IllegalArgumentException {
|
||||||
|
if (capacity < 1) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BoundedBufferListImpl<>(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <T> Buffer<T> unboundedList() throws IllegalArgumentException {
|
||||||
|
return new UnboundedBufferListImpl<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int capacity();
|
||||||
|
|
||||||
|
int size();
|
||||||
|
|
||||||
|
T get();
|
||||||
|
|
||||||
|
T get(int index);
|
||||||
|
|
||||||
|
void add(T value);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
default CappedIterator<T> cappedIterator(int maxCount) {
|
||||||
|
return new CappedIterator<>(iterator(), maxCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<T> descendingIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class CappedIterator<T> implements Iterator<T> {
|
||||||
|
private final Iterator<T> iterator;
|
||||||
|
private final int maxCount;
|
||||||
|
private int count = 0;
|
||||||
|
|
||||||
|
CappedIterator(Iterator<T> iterator, int maxCount) {
|
||||||
|
this.iterator = iterator;
|
||||||
|
this.maxCount = maxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int count() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext() {
|
||||||
|
return count < maxCount && iterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T next() throws NoSuchElementException {
|
||||||
|
if (hasNext()) {
|
||||||
|
var next = iterator.next();
|
||||||
|
count++;
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class BoundedBufferArrayImpl<T> implements Buffer<T> {
|
||||||
|
private final T[] buffer;
|
||||||
|
private int size = 0, cursor = 0;
|
||||||
|
|
||||||
|
BoundedBufferArrayImpl(T[] buffer) throws IllegalArgumentException {
|
||||||
|
this.buffer = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int capacity() {
|
||||||
|
return buffer.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return buffer[cursor];
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(int index) {
|
||||||
|
return buffer[(cursor + index) % buffer.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(T value) {
|
||||||
|
cursor = Math.floorMod(cursor - 1, buffer.length);
|
||||||
|
buffer[cursor] = value;
|
||||||
|
size = Math.max(size + 1, buffer.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
size = 0;
|
||||||
|
Arrays.fill(buffer, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return new AscendingIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<T> descendingIterator() {
|
||||||
|
return new DescendingIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class AscendingIterator implements Iterator<T> {
|
||||||
|
private int pos = cursor, i = 0;
|
||||||
|
|
||||||
|
public boolean hasNext() {
|
||||||
|
return i < size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T next() throws NoSuchElementException {
|
||||||
|
if (hasNext()) {
|
||||||
|
var s = buffer[pos];
|
||||||
|
pos = (pos + 1) % buffer.length;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DescendingIterator implements Iterator<T> {
|
||||||
|
private int pos = size - 1, i = 0;
|
||||||
|
|
||||||
|
public boolean hasNext() {
|
||||||
|
return i > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T next() throws NoSuchElementException {
|
||||||
|
if (hasNext()) {
|
||||||
|
var s = buffer[pos];
|
||||||
|
pos = Math.floorMod(pos - 1, buffer.length);
|
||||||
|
|
||||||
|
i--;
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class BoundedBufferListImpl<T> implements Buffer<T> {
|
||||||
|
private final LinkedList<T> buffer = new LinkedList<>();
|
||||||
|
private final int capacity;
|
||||||
|
|
||||||
|
BoundedBufferListImpl(int capacity) {
|
||||||
|
this.capacity = capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int capacity() {
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return buffer.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return buffer.peekFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(int index) {
|
||||||
|
return buffer.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(T value) {
|
||||||
|
if (size() == capacity) {
|
||||||
|
buffer.pollLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.addFirst(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
buffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return buffer.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<T> descendingIterator() {
|
||||||
|
return buffer.descendingIterator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class UnboundedBufferListImpl<T> implements Buffer<T> {
|
||||||
|
private final LinkedList<T> buffer = new LinkedList<>();
|
||||||
|
|
||||||
|
UnboundedBufferListImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public int capacity() {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return buffer.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return buffer.peekFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(int index) {
|
||||||
|
return buffer.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(T value) {
|
||||||
|
buffer.addFirst(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
buffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return buffer.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<T> descendingIterator() {
|
||||||
|
return buffer.descendingIterator();
|
||||||
|
}
|
||||||
|
}
|
||||||
1961
CruiseControlMX5.pde
Normal file
1961
CruiseControlMX5.pde
Normal file
File diff suppressed because it is too large
Load Diff
76
Rectangle.pde
Normal file
76
Rectangle.pde
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
static class Rectangle {
|
||||||
|
final float left, top, right, bottom, width, height;
|
||||||
|
|
||||||
|
Rectangle(float top, float left, float bottom, float right) {
|
||||||
|
this.top = top;
|
||||||
|
this.left = left;
|
||||||
|
this.bottom = bottom;
|
||||||
|
this.right = right;
|
||||||
|
this.width = right - left;
|
||||||
|
this.height = bottom - top;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Rectangle tlbr(float top, float left, float bottom, float right) {
|
||||||
|
return new Rectangle(top, left, bottom, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Rectangle xywh(float left, float top, float width, float height) {
|
||||||
|
return new Rectangle(top, left, top + height, left + width);
|
||||||
|
}
|
||||||
|
|
||||||
|
float centerX() {
|
||||||
|
return left + width / 2F;
|
||||||
|
}
|
||||||
|
|
||||||
|
float centerY() {
|
||||||
|
return top + height / 2F;
|
||||||
|
}
|
||||||
|
|
||||||
|
PVector center() {
|
||||||
|
return new PVector(centerX(), centerY());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean contains(float x, float y) {
|
||||||
|
return x >= left && x < right && y >= top && y < bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle offset(float dx, float dy) {
|
||||||
|
return xywh(left + dx, top + dy, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle[] splitVerticallyAt(float dx) {
|
||||||
|
return new Rectangle[] {
|
||||||
|
new Rectangle(top, left, bottom, left + dx),
|
||||||
|
new Rectangle(top, left + dx, bottom, right)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle[] splitHorizontallyAt(float dy) {
|
||||||
|
return new Rectangle[] {
|
||||||
|
new Rectangle(top, left, top + dy, right),
|
||||||
|
new Rectangle(top + dy, left, bottom, right)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle[] splitVerticallyInto(int n) {
|
||||||
|
var count = floor(width / n);
|
||||||
|
var result = new Rectangle[count];
|
||||||
|
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
result[i] = new Rectangle(top, lerp(left, right, (float) i / n), bottom, lerp(left, right, (float) (i + 1) / n));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle[] splitHorizontallyInto(int n) {
|
||||||
|
var count = floor(height / n);
|
||||||
|
var result = new Rectangle[count];
|
||||||
|
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
result[i] = new Rectangle(lerp(top, bottom, (float) i / n), left, lerp(top, bottom, (float) (i + 1) / n), right);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
Sample.pde
Normal file
22
Sample.pde
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
static class Sample {
|
||||||
|
final int timestamp;
|
||||||
|
final boolean drawTimeTick;
|
||||||
|
float proportional, integral, derivative;
|
||||||
|
float speed, acceleration;
|
||||||
|
float consigne;
|
||||||
|
float error;
|
||||||
|
int servo;
|
||||||
|
int state;
|
||||||
|
float kp, ki, kd;
|
||||||
|
int speedMin, speedMax;
|
||||||
|
int minSatellites, satellites;
|
||||||
|
boolean switchFlag, speedDiffFlag, minSpeedFlag, maxSpeedFlag, brakeFlag;
|
||||||
|
boolean relay;
|
||||||
|
|
||||||
|
Sample(int timestamp, boolean drawTimeTick) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.drawTimeTick = drawTimeTick;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user