// VectorSSI - SSI with straight line segments persistable sclass VectorSSI extends AbstractSSI { replace X with short. replace Y with short. replace toX with toShort_enforce. replace toY with toShort_enforce. replace newXArray with newShortArrayOrNull. // core values (mandatory): first column and row occupied settable X x1; settable Y y1; // Curves of x start and x end, relative to (x1, y1) // Both have same length settable InterpolatedDoubleArray leftCurve; settable InterpolatedDoubleArray rightCurve; *(SSI ssi) { ssi.copyAbstractSSI(this); Rect r = ssi.bounds(); x1(toX(r.x1())); y1(toY(r.y1())); int h = r.h(); int[] left = new int[h], right = new int[h]; for y to h: { left[y] = ssi.getLeft(y1+y)-x1; right[y] = ssi.getRight(y1+y)-x1; } leftCurve(CompressToInterpolatedDoubleArray(left)!); rightCurve(CompressToInterpolatedDoubleArray(right)!); } public int height aka h() { ret leftCurve.length(); } int y2() { ret y1+h(); } SSI toSSI aka get() { int h = h(); var ssi = new SSI(y1, y2()); copyAbstractSSI(ssi); int[] left = leftCurve.rounded(); int[] right = rightCurve.rounded(); for y to h: ssi.set(y1+y, x1+left[y], x1+right[y]); ret ssi; } public void drawOn(Graphics2D g) { toSSI().drawOn(g); } // How many points define the shape of this vector SSI // (left + right border) int nPoints() { ret leftCurve.nPillars() + rightCurve.nPillars(); } public long sizeInInts() { // "v", color, x1, y1, height(), leftCurve, rightCurve ret 5+leftCurve.nInts/*_withoutFirstAndLastIndex*/()+rightCurve.nInts/*_withoutFirstAndLastIndex*/(); } // TODO /*VectorSSI reduceToInts(int ints) { ints -= 5; // constant part int nPillars = ints/2; // max pillars we can afford (left+right) }*/ // optimizable public simplyCached Rect bounds() { ret toSSI().bounds(); } public simplyCached int numberOfPixels() { ret toSSI().numberOfPixels(); } public void readWrite(StringHead head) { head.exchangeLine(l0 toLine, l1 fromLine); } S toLine() { L elements = ll("v", colorToString(), x1, y1, height()); addAll(elements, asList(iroundAll(leftCurve.indicesAndValues/*_withoutFirstAndLastIndex*/()))); addAll(elements, asList(iroundAll(rightCurve.indicesAndValues/*_withoutFirstAndLastIndex*/()))); ret spaceCombine(elements); } void fromLine(S line) { Iterator it = splitAtSpaceIterator(line); assertEquals("v", nextFromIterator(it)); x1 = toX(parseInt(nextFromIterator(it))); y1 = toY(parseInt(nextFromIterator(it))); // TODO /*int h = parseInt(nextFromIterator(it)); init(y1, y1+h); for i over data: data[i] = toX(parseInt(nextFromIterator(it)));*/ } }