Added NCR use the magic sparkler if block end unused.
This commit is contained in:
parent
efc932a7d4
commit
62bdf94435
|
@ -284,6 +284,9 @@ public class FourCornerZionStenoLexer {
|
|||
|
||||
class StenoScannerNCR18 extends StenoScanner {
|
||||
|
||||
private final int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group
|
||||
private final int numeratorBank[] = new int[64];
|
||||
|
||||
public StenoScannerNCR18() {
|
||||
super(FourCornerDotCake.FC_NCR1632_XD.getStart(), FourCornerDotCake.FC_NCR1632_XN.getStop());
|
||||
}
|
||||
|
@ -299,42 +302,51 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
|
||||
private void handlePoints(List<Integer> slicedPoints) {
|
||||
int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group
|
||||
int numeratorBank[] = new int[64];
|
||||
boolean errorZeroSparks = true;
|
||||
boolean errorUnusedSparks = true;
|
||||
bankReset();
|
||||
boolean magicSparkler = true;
|
||||
for (Integer cakePoint : slicedPoints) {
|
||||
if (cakePoint >= FourCornerDotCake.FC_NCR1632_XD.getStart() && cakePoint <= FourCornerDotCake.FC_NCR1632_XD.getStop()) {
|
||||
int denominatorX = cakePoint - FourCornerDotCake.FC_NCR1632_XD.getStart();
|
||||
denominatorBank[denominatorX / 512] = denominatorX % 512;
|
||||
errorUnusedSparks = true;
|
||||
magicSparkler = true;
|
||||
continue;
|
||||
}
|
||||
int numeratorX = cakePoint - FourCornerDotCake.FC_NCR1632_XN.getStart();
|
||||
numeratorBank[numeratorX / 512] = numeratorX % 512;
|
||||
|
||||
if (cakePoint > FourCornerDotCake.FC_NCR1632_XN.getStart() + 512) {
|
||||
errorUnusedSparks = true;
|
||||
magicSparkler = true;
|
||||
continue; // Only fire fraction on lowest value select
|
||||
}
|
||||
BigInteger denominator = BigInteger.ONE;
|
||||
for (int i=0; i<denominatorBank.length;i++) {
|
||||
denominator = denominator.add(BigInteger.valueOf(denominatorBank[i]).shiftLeft(i*9));
|
||||
}
|
||||
BigInteger numerator = BigInteger.ONE;
|
||||
for (int i=0; i<numeratorBank.length;i++) {
|
||||
numerator = numerator.add(BigInteger.valueOf(numeratorBank[i]).shiftLeft(i*9));
|
||||
}
|
||||
handler.strobeNCR1632(denominator, numerator);
|
||||
errorZeroSparks = false;
|
||||
errorUnusedSparks = false;
|
||||
bankFire();
|
||||
magicSparkler = false;
|
||||
}
|
||||
if (errorZeroSparks) {
|
||||
smokeSignals.burnNCR1632ZeroSparks(currLine, currCol);
|
||||
} else if (errorUnusedSparks) {
|
||||
smokeSignals.burnNCR1632UnusedSparks(currLine, currCol);
|
||||
if (magicSparkler) {
|
||||
fireSignals.fireStateNCR1632Sparkler();
|
||||
bankFire();
|
||||
}
|
||||
}
|
||||
|
||||
private void bankReset() {
|
||||
for (int i=0;i<denominatorBank.length;i++) {
|
||||
denominatorBank[i] = 0;
|
||||
}
|
||||
for (int i=0;i<numeratorBank.length;i++) {
|
||||
numeratorBank[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void bankFire() {
|
||||
BigInteger denominator = BigInteger.ONE;
|
||||
for (int i=0; i<denominatorBank.length;i++) {
|
||||
denominator = denominator.add(BigInteger.valueOf(denominatorBank[i]).shiftLeft(i*9));
|
||||
}
|
||||
BigInteger numerator = BigInteger.ONE;
|
||||
for (int i=0; i<numeratorBank.length;i++) {
|
||||
numerator = numerator.add(BigInteger.valueOf(numeratorBank[i]).shiftLeft(i*9));
|
||||
}
|
||||
handler.strobeNCR1632(denominator, numerator);
|
||||
}
|
||||
}
|
||||
|
||||
class StenoScannerUNI21 extends StenoScanner {
|
||||
|
|
|
@ -34,6 +34,8 @@ public interface FourCornerZionStenoLexerFire {
|
|||
|
||||
void fireStateScanner(int blockStart, int blockStop, int cakePoint);
|
||||
|
||||
void fireStateNCR1632Sparkler();
|
||||
|
||||
interface Adapter extends FourCornerZionStenoLexerFire {
|
||||
|
||||
@Override
|
||||
|
@ -47,5 +49,9 @@ public interface FourCornerZionStenoLexerFire {
|
|||
@Override
|
||||
default void fireStateScanner(int blockStart, int blockStop, int cakePoint) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void fireStateNCR1632Sparkler() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,11 +49,6 @@ public interface FourCornerZionStenoLexerSmoke {
|
|||
void burnUNI21UnusedBigIndian(int line, int col);
|
||||
|
||||
|
||||
void burnNCR1632ZeroSparks(int line, int col);
|
||||
|
||||
void burnNCR1632UnusedSparks(int line, int col);
|
||||
|
||||
|
||||
interface Adapter extends FourCornerZionStenoLexerSmoke {
|
||||
|
||||
@Override
|
||||
|
@ -87,13 +82,5 @@ public interface FourCornerZionStenoLexerSmoke {
|
|||
@Override
|
||||
default void burnUNI21UnusedBigIndian(int line, int col) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void burnNCR1632ZeroSparks(int line, int col) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void burnNCR1632UnusedSparks(int line, int col) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,24 +42,26 @@ import org.x4o.fc18.cake2.zero33.FCDotDEC0127DashPX0;
|
|||
public class LexerNCRTest {
|
||||
|
||||
@Test
|
||||
public void testNCRInvalid() throws Exception {
|
||||
TestSmokeReader smokeReader = new TestSmokeReader();
|
||||
public void testNCRMagicSparkler() throws Exception {
|
||||
TestFireWalker fireWalker = new TestFireWalker();
|
||||
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
|
||||
lexer.withSmokeSignals(smokeReader);
|
||||
lexer.withFireSignals(fireWalker);
|
||||
List<Integer> cdc = new ArrayList<>();
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1);
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*3) + 1); /// auto NXX_001
|
||||
cdc.addAll(FCDotDEC0127DashPX0.ESC_STOP.toInt18BaklavaPoints());
|
||||
|
||||
Assertions.assertEquals(0, fireWalker.ncrMagicSparks);
|
||||
lexer.read(cdc);
|
||||
Assertions.assertEquals(-1, smokeReader.errorNCRUnusedSparks);
|
||||
Assertions.assertEquals(0, smokeReader.errorNCRZeroSparks);
|
||||
Assertions.assertEquals(1, fireWalker.ncrMagicSparks);
|
||||
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 2);
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // normal NXX_123
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() + (512*4) + 2); /// auto NXX_123 + this
|
||||
|
||||
smokeReader.reset();
|
||||
fireWalker.reset();
|
||||
lexer.read(cdc);
|
||||
Assertions.assertEquals(0, smokeReader.errorNCRUnusedSparks);
|
||||
Assertions.assertEquals(-1, smokeReader.errorNCRZeroSparks);
|
||||
Assertions.assertEquals(2, fireWalker.ncrMagicSparks);
|
||||
|
||||
Assertions.assertEquals("¹/₁₃₄₂₁₇₇₂₉¹²³/₁¹³⁷⁴³⁸⁹⁵³⁵⁹⁵/₁", FourCornerUnicodeDisplay.text().renderFromInt18(cdc));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2014, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.fc18.zion7;
|
||||
|
||||
/**
|
||||
* Walks four corner lexer fire signals.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2025
|
||||
*/
|
||||
public class TestFireWalker implements FourCornerZionStenoLexerFire.Adapter {
|
||||
|
||||
int currentLine;
|
||||
int currentColumn;
|
||||
int scanBlockStart;
|
||||
int scanBlockStop;
|
||||
int scanCakePoint;
|
||||
int ncrMagicSparks;
|
||||
|
||||
public TestFireWalker() {
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
currentLine = 0;
|
||||
currentColumn = 0;
|
||||
scanBlockStart = 0;
|
||||
ncrMagicSparks = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireStateLine(int line) {
|
||||
currentLine = line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireStateColumn(int column) {
|
||||
currentColumn = column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireStateScanner(int blockStart, int blockStop, int cakePoint) {
|
||||
scanBlockStart = blockStart;
|
||||
scanBlockStop = blockStop;
|
||||
scanCakePoint = cakePoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireStateNCR1632Sparkler() {
|
||||
ncrMagicSparks++;
|
||||
}
|
||||
}
|
|
@ -23,15 +23,13 @@
|
|||
package org.x4o.fc18.zion7;
|
||||
|
||||
/**
|
||||
* Tests four corner lexer parts.
|
||||
* Reads four corner lexer smoke signals.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2025
|
||||
*/
|
||||
public class TestSmokeReader implements FourCornerZionStenoLexerSmoke.Adapter {
|
||||
|
||||
int errorNCRZeroSparks;
|
||||
int errorNCRUnusedSparks;
|
||||
int errorUNI21UnusedBigIndian;
|
||||
int errorUnsupport;
|
||||
int errorRecursive;
|
||||
|
@ -41,23 +39,11 @@ public class TestSmokeReader implements FourCornerZionStenoLexerSmoke.Adapter {
|
|||
}
|
||||
|
||||
public void reset() {
|
||||
errorNCRZeroSparks = -1;
|
||||
errorNCRUnusedSparks = -1;
|
||||
errorUNI21UnusedBigIndian = -1;
|
||||
errorUnsupport = -1;
|
||||
errorRecursive = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void burnNCR1632ZeroSparks(int line, int col) {
|
||||
errorNCRZeroSparks = line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void burnNCR1632UnusedSparks(int line, int col) {
|
||||
errorNCRUnusedSparks = line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void burnUNI21UnusedBigIndian(int line, int col) {
|
||||
errorUNI21UnusedBigIndian = line;
|
||||
|
|
Loading…
Reference in a new issue