Added first part of fraction4d numbers

This commit is contained in:
Willem Cazander 2022-01-28 11:24:54 +01:00
parent f51a97f449
commit 9808cb2cb0
5 changed files with 454 additions and 0 deletions

View file

@ -0,0 +1,50 @@
package love.distributedrebirth.demo4d.fraction4d;
import java.util.ArrayList;
import java.util.List;
import love.distributedrebirth.demo4d.base2t.V009Tyte;
import love.distributedrebirth.demo4d.base2t.V009TyteBaseAppender;
import love.distributedrebirth.demo4d.base2t.V009TyteIterator;
import love.distributedrebirth.demo4d.base2t.V144Tocta;
public class GroßGetậl {
public static int NUMERATOR_SIZE = 7;
public static int DENOMINATOR_SIZE = 9;
private final V009Tyte[] numerator = new V009Tyte[NUMERATOR_SIZE];
private final V009Tyte[] denominator = new V009Tyte[DENOMINATOR_SIZE];
public GroßGetậl() {
for (int i=0;i<NUMERATOR_SIZE;i++) {
numerator[i] = new V009Tyte();
}
for (int i=0;i<DENOMINATOR_SIZE;i++) {
denominator[i] = new V009Tyte();
}
}
public GroßGetậl(V144Tocta tocta) {
List<V009Tyte> tytes = new ArrayList<>();
tocta.fillTyteValues(new V009TyteBaseAppender(tytes));
for (int i=0;i<NUMERATOR_SIZE;i++) {
numerator[i] = tytes.get(i);
}
for (int i=0;i<DENOMINATOR_SIZE;i++) {
denominator[i] = tytes.get(i+NUMERATOR_SIZE);
}
}
public V144Tocta toTocta() {
List<V009Tyte> tytes = new ArrayList<>();
for (int i=0;i<NUMERATOR_SIZE;i++) {
tytes.add(numerator[i]);
}
for (int i=0;i<DENOMINATOR_SIZE;i++) {
tytes.add(denominator[i]);
}
V009TyteIterator iterator = new V009TyteIterator(tytes.iterator());
V144Tocta result = new V144Tocta(iterator);
return result;
}
}

View file

@ -0,0 +1,68 @@
package love.distributedrebirth.demo4d.fraction4d;
import love.distributedrebirth.demo4d.base2t.T03PartTrit;
import love.distributedrebirth.demo4d.base2t.T08PartOctal;
import love.distributedrebirth.demo4d.base2t.V009Tyte;
public class HebrewGetậl {
private static final double NUMERATOR_ONE = 1d;
private static final int FRACTION_POWER = 10;
private HebrewGetậlLetter letter;
private HebrewGetậlVowel vowel;
public HebrewGetậl() {
this.letter = HebrewGetậlLetter.NONE;
this.vowel = HebrewGetậlVowel.NONE;
}
public HebrewGetậl(HebrewGetậlLetter letter) {
this.letter = letter;
this.vowel = HebrewGetậlVowel.NONE;
}
public HebrewGetậl(V009Tyte tyte) {
int value0 = tyte.getValue(T03PartTrit.PART_1).getValue().ordinalOf(T08PartOctal.PART_1);
int value1 = tyte.getValue(T03PartTrit.PART_2).getValue().ordinalOf(T08PartOctal.PART_2);
int value2 = tyte.getValue(T03PartTrit.PART_3).getValue().ordinalOf(T08PartOctal.PART_3);
int combinedValue = value0 + value1 + value2;
letter = HebrewGetậlLetter.indexOf(combinedValue);
vowel = HebrewGetậlVowel.indexOf(combinedValue >> HebrewGetậlLetter.SHIFT_5);
}
public V009Tyte toTyte() {
int combinedValue = letter.ordinal() + (vowel.ordinal() << HebrewGetậlLetter.SHIFT_5);
T08PartOctal value0 = T08PartOctal.indexOf(T08PartOctal.PART_1, combinedValue);
T08PartOctal value1 = T08PartOctal.indexOf(T08PartOctal.PART_2, combinedValue);
T08PartOctal value2 = T08PartOctal.indexOf(T08PartOctal.PART_3, combinedValue);
return new V009Tyte(value0, value1, value2);
}
public double toDecimalValue(boolean firstChar) {
double fraction = letter.getDecimal();
if (firstChar) {
return fraction; // use full value
}
if (!HebrewGetậlVowel.NONE.equals(vowel)) {
fraction = fraction * Math.pow(FRACTION_POWER, vowel.getFractionOffset());
}
double result = NUMERATOR_ONE/fraction;
return result;
}
public HebrewGetậlLetter getLetter() {
return letter;
}
public void setLetter(HebrewGetậlLetter letter) {
this.letter = letter;
}
public HebrewGetậlVowel getVowel() {
return vowel;
}
public void setVowel(HebrewGetậlVowel vowel) {
this.vowel = vowel;
}
}

View file

@ -0,0 +1,98 @@
package love.distributedrebirth.demo4d.fraction4d;
public enum HebrewGetậlLetter {
// Unicode is horror in any language else than ascii;
// VS Alphabet order
// VS Unicode order
// VS Gematria order <== leading but with other decimals
NONE (0, (char) 0x05EF),
LETTER_1 (1, (char) 0x05D0),
LETTER_2 (2, (char) 0x05D1),
LETTER_3 (3, (char) 0x05D2),
LETTER_4 (4, (char) 0x05D3),
LETTER_5 (5, (char) 0x05D4),
LETTER_6 (6, (char) 0x05D5),
LETTER_7 (7, (char) 0x05D6),
LETTER_8 (8, (char) 0x05D7),
LETTER_9 (9, (char) 0x05D8),
LETTER_11 (11, (char) 0x05D9),
LETTER_12 (12, (char) 0x05DB),
LETTER_13 (13, (char) 0x05DC),
LETTER_14 (14, (char) 0x05DE),
LETTER_15 (15, (char) 0x05E0),
LETTER_16 (16, (char) 0x05E1),
LETTER_17 (17, (char) 0x05E2),
LETTER_18 (18, (char) 0x05E4),
LETTER_19 (19, (char) 0x05E6),
LETTER_21 (21, (char) 0x05E7),
LETTER_22 (22, (char) 0x05E8),
LETTER_23 (23, (char) 0x05E9),
LETTER_24 (24, (char) 0x05EA),
LETTER_25 (25, (char) 0x05DA),
LETTER_26 (26, (char) 0x05DD),
LETTER_27 (27, (char) 0x05DF),
LETTER_28 (28, (char) 0x05E3),
LETTER_29 (29, (char) 0x05E5),
/* // OLD
LETTER_11 (10, (char) 0x05D9),
LETTER_12 (20, (char) 0x05DB),
LETTER_13 (30, (char) 0x05DC),
LETTER_14 (40, (char) 0x05DE),
LETTER_15 (50, (char) 0x05E0),
LETTER_16 (60, (char) 0x05E1),
LETTER_17 (70, (char) 0x05E2),
LETTER_18 (80, (char) 0x05E4),
LETTER_19 (90, (char) 0x05E6),
LETTER_21 (100, (char) 0x05E7),
LETTER_22 (200, (char) 0x05E8),
LETTER_23 (300, (char) 0x05E9),
LETTER_24 (400, (char) 0x05EA),
LETTER_25 (500, (char) 0x05DA),
LETTER_26 (600, (char) 0x05DD),
LETTER_27 (700, (char) 0x05DF),
LETTER_28 (800, (char) 0x05E3),
LETTER_29 (900, (char) 0x05E5),
*/
LETTER_31 (31, (char) 0x05BE),
LETTER_32 (32, (char) 0x05C0),
LETTER_33 (33, (char) 0x05C3),
LETTER_34 (34, (char) 0x05C6),
;
public static final byte BITMASK = 0b00011111;
public static final byte SHIFT_5 = 5;
private final int decimal;
private final char character;
private HebrewGetậlLetter(int decimal, char character) {
this.decimal = decimal;
this.character = character;
}
public int getDecimal() {
return decimal;
}
public char getCharacter() {
return character;
}
public static HebrewGetậlLetter indexOf(int index) {
return values()[index & BITMASK];
}
public static HebrewGetậlLetter valueOf(char codePoint) {
for (HebrewGetậlLetter vowel:values()) {
if (vowel.getCharacter() == codePoint) {
return vowel;
}
}
return HebrewGetậlLetter.NONE;
}
}

View file

@ -0,0 +1,51 @@
package love.distributedrebirth.demo4d.fraction4d;
public enum HebrewGetậlVowel {
NONE (0, (char) 0x0000),
VOWEL_1 (1, (char) 0x05B4),
VOWEL_2 (2, (char) 0x05B5),
VOWEL_3 (3, (char) 0x05B6),
VOWEL_4 (4, (char) 0x05B2),
VOWEL_5 (5, (char) 0x05C7),
VOWEL_6 (6, (char) 0x05B7), // 06 = PATAH
VOWEL_7 (7, (char) 0x05A1),
VOWEL_8 (8, (char) 0x05A2),
VOWEL_9 (9, (char) 0x05A3),
VOWEL_10 (10, (char) 0x05B9), // 10 = POINT HOLAM
VOWEL_16 (16, (char) 0x05B8), // 16 = QAMATS
VOWEL_22 (22, (char) 0x0598),
VOWEL_30 (30, (char) 0x05BB), // 30 = QUBUTS
VOWEL_36 (36, (char) 0x05B3), // 36 = HATAF QAMATS
VOWEL_42 (42, (char) 0x05B1), // 50 = HATEF SEGOL
;
public static final byte BITMASK = 0b00001111;
private final int fractionOffset;
private final char character;
private HebrewGetậlVowel(int fractionOffset, char character) {
this.fractionOffset = fractionOffset;
this.character = character;
}
public int getFractionOffset() {
return fractionOffset;
}
public char getCharacter() {
return character;
}
public static HebrewGetậlVowel indexOf(int index) {
return values()[index & BITMASK];
}
public static HebrewGetậlVowel valueOf(char codePoint) {
for (HebrewGetậlVowel vowel:values()) {
if (vowel.getCharacter() == codePoint) {
return vowel;
}
}
return HebrewGetậlVowel.NONE;
}
}

View file

@ -0,0 +1,187 @@
package love.distributedrebirth.demo4d.fraction4d;
import java.util.ArrayList;
import java.util.List;
import love.distributedrebirth.demo4d.base2t.T04PartQuad;
import love.distributedrebirth.demo4d.base2t.V018Tord;
import love.distributedrebirth.demo4d.base2t.V036Teger;
public class HebrewGê̄ld {
private final HebrewGetậl nummerAlphabet;
private final HebrewGetậl nummerDeelA;
private final HebrewGetậl nummerDeelB;
private final HebrewGetậl nummerDeelC;
private final double totalDecimalValue;
private static final Character LEFT_TO_RIGHT_MARK = 0x200E;
private static final Character RIGHT_TO_LEFT_MARK = 0x200F;
public HebrewGê̄ld(V036Teger teger) {
this(
new HebrewGetậl(teger.getTytePart(T04PartQuad.PART_1)),
new HebrewGetậl(teger.getTytePart(T04PartQuad.PART_2)),
new HebrewGetậl(teger.getTytePart(T04PartQuad.PART_3)),
new HebrewGetậl(teger.getTytePart(T04PartQuad.PART_4))
);
}
public HebrewGê̄ld(HebrewGetậl nummerAlphabet, HebrewGetậl nummerDeelA, HebrewGetậl nummerDeelB, HebrewGetậl nummerDeelC) {
this.nummerAlphabet = nummerAlphabet;
this.nummerDeelA = nummerDeelA;
this.nummerDeelB = nummerDeelB;
this.nummerDeelC = nummerDeelC;
this.totalDecimalValue = calculateDecimalValue();
}
public HebrewGê̄ld(String money) {
if (money == null) {
throw new NullPointerException("Can't parse null money");
}
if (money.isEmpty()) {
throw new IllegalArgumentException("Can't parse zero money length");
}
if (money.length() > 8) { // RL + 4 chars + 3 vowels
throw new IllegalArgumentException("Money length should not exceed 8 codepoints");
}
List<HebrewGetậl> result = new ArrayList<>();
HebrewGetậl geldDigit = null;
for (int i=0;i<money.length();i++) {
char codePoint = (char) money.codePointAt(i);
if (LEFT_TO_RIGHT_MARK.equals(codePoint)) {
continue;
}
if (RIGHT_TO_LEFT_MARK.equals(codePoint)) {
continue;
}
if (geldDigit != null) {
HebrewGetậlVowel vowel = HebrewGetậlVowel.valueOf(codePoint);
if (!HebrewGetậlVowel.NONE.equals(vowel)) {
geldDigit.setVowel(vowel);
result.add(geldDigit);
geldDigit = null;
continue;
} else {
result.add(geldDigit);
}
}
HebrewGetậlLetter letter = HebrewGetậlLetter.valueOf(codePoint);
if (HebrewGetậlLetter.NONE.equals(letter)) {
throw new IllegalArgumentException("Unknown fraction codepoint: 0x"+Integer.toHexString(codePoint));
}
geldDigit = new HebrewGetậl(letter);
}
if (geldDigit != null) {
result.add(geldDigit);
}
if (result.isEmpty()) {
throw new IllegalArgumentException("No hebrew money found");
}
HebrewGetậl full = result.get(0);
HebrewGetậl deelA = null;
HebrewGetậl deelB = null;
HebrewGetậl deelC = null;
if (result.size() > 1) {
deelA = result.get(1);
} else {
deelA = new HebrewGetậl();
}
if (result.size() > 2) {
deelB = result.get(2);
} else {
deelB = new HebrewGetậl();
}
if (result.size() > 3) {
deelC = result.get(3);
} else {
deelC = new HebrewGetậl();
}
this.nummerAlphabet = full;
this.nummerDeelA = deelA;
this.nummerDeelB = deelB;
this.nummerDeelC = deelC;
this.totalDecimalValue = calculateDecimalValue();
}
private double calculateDecimalValue() {
boolean hasFourDigits =
!HebrewGetậlLetter.NONE.equals(nummerDeelA.getLetter()) &&
!HebrewGetậlLetter.NONE.equals(nummerDeelB.getLetter()) &&
!HebrewGetậlLetter.NONE.equals(nummerDeelC.getLetter());
double totalDecimalValue = nummerAlphabet.toDecimalValue(hasFourDigits);
if (!HebrewGetậlLetter.NONE.equals(nummerDeelA.getLetter())) {
totalDecimalValue += nummerDeelA.toDecimalValue(false);
}
if (!HebrewGetậlLetter.NONE.equals(nummerDeelB.getLetter())) {
totalDecimalValue += nummerDeelB.toDecimalValue(false);
}
if (!HebrewGetậlLetter.NONE.equals(nummerDeelC.getLetter())) {
totalDecimalValue += nummerDeelC.toDecimalValue(false);
}
return totalDecimalValue;
}
public HebrewGetậl getNummerAlphabet() {
return nummerAlphabet;
}
public HebrewGetậl getNummerDeelA() {
return nummerDeelA;
}
public HebrewGetậl getNummerDeelB() {
return nummerDeelB;
}
public HebrewGetậl getNummerDeelC() {
return nummerDeelC;
}
public double getTotalDecimalValue() {
return totalDecimalValue;
}
public V036Teger toTeger() {
return new V036Teger(
new V018Tord(nummerAlphabet.toTyte(), nummerDeelA.toTyte()),
new V018Tord(nummerDeelB.toTyte(), nummerDeelC.toTyte())
);
}
public String toHebrewString() {
return toHebrewString(false);
}
public String toHebrewString(boolean reverse) {
StringBuilder buf = new StringBuilder();
buf.append(RIGHT_TO_LEFT_MARK);
buf.append(nummerAlphabet.getLetter().getCharacter());
if (!HebrewGetậlVowel.NONE.equals(nummerAlphabet.getVowel())) {
buf.append(nummerAlphabet.getVowel().getCharacter());
}
if (!HebrewGetậlLetter.NONE.equals(nummerDeelA.getLetter())) {
buf.append(nummerDeelA.getLetter().getCharacter());
if (!HebrewGetậlVowel.NONE.equals(nummerDeelA.getVowel())) {
buf.append(nummerDeelA.getVowel().getCharacter());
}
}
if (!HebrewGetậlLetter.NONE.equals(nummerDeelB.getLetter())) {
buf.append(nummerDeelB.getLetter().getCharacter());
if (!HebrewGetậlVowel.NONE.equals(nummerDeelB.getVowel())) {
buf.append(nummerDeelB.getVowel().getCharacter());
}
}
if (!HebrewGetậlLetter.NONE.equals(nummerDeelC.getLetter())) {
buf.append(nummerDeelC.getLetter().getCharacter());
if (!HebrewGetậlVowel.NONE.equals(nummerDeelC.getVowel())) {
buf.append(nummerDeelC.getVowel().getCharacter());
}
}
if (reverse) {
buf.reverse(); // ImGui skips RL marker so renders wrong....
}
return buf.toString();
}
}