From 5ce6a8f7b30b54b1d728c0571de799e99c79934c Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 6 May 2024 23:54:37 -0500 Subject: add nice vowel positions --- src/language.test.ts | 17 ++++++++++++++++- src/language.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/language.test.ts b/src/language.test.ts index 62b03a2..3564363 100644 --- a/src/language.test.ts +++ b/src/language.test.ts @@ -130,7 +130,6 @@ test('all consonants can be selected', () => { }, ]); - expect(lang.pickConsonants( [ lang.ConsonantPlace.Bilabial, lang.ConsonantPlace.Alveolar ], [ lang.ConsonantManner.Plosive, lang.ConsonantManner.Tap ], @@ -139,3 +138,19 @@ test('all consonants can be selected', () => { 'p', 'b', 'ⱱ̟', 't', 'd', 'ɾ̥', 'ɾ', ]); }); + + +test('vowel positions work correctly', () => { + expect( + lang._vowelXY(lang.VowelHeight.Open, lang.VowelDepth.Back) + ).toEqual([0, 0]); + expect( + lang._vowelXY(lang.VowelHeight.NearOpen, lang.VowelDepth.Central) + ).toEqual([1.5, 1]); + expect( + lang._vowelXY(lang.VowelHeight.Close, lang.VowelDepth.Front) + ).toEqual([8, 6]); + expect( + lang._vowelXY(lang.VowelHeight.Close, lang.VowelDepth.Back) + ).toEqual([0, 6]); +}); diff --git a/src/language.ts b/src/language.ts index c0360b8..dd96b8d 100644 --- a/src/language.ts +++ b/src/language.ts @@ -20,6 +20,36 @@ export interface VowelFeatures { nasal: boolean; } + +// convert a vowel height/depth combo to an x/y position +// (for use in creating nicely spaced vowel inventories) +export function _vowelXY( + height: VowelHeight, + depth: VowelDepth +): [number, number] { + const y = { + [VowelHeight.Open]: 0, + [VowelHeight.NearOpen]: 1, + [VowelHeight.OpenMid]: 2, + [VowelHeight.Mid]: 3, + [VowelHeight.CloseMid]: 4, + [VowelHeight.NearClose]: 5, + [VowelHeight.Close]: 6, + }[height]; + + const slope = { + [VowelDepth.Front]: 1, + [VowelDepth.Central]: 2, + [VowelDepth.Back]: 3, + }[depth]; + + if (slope === 3) { return [ 0, y ]; } + + const x = (y + 2) / slope; + return [x, y]; +} + + // convert a set of vowel features to an IPA representation export function vowelFeaturesToIpa(features: VowelFeatures): string { const ipa = () => { @@ -141,6 +171,8 @@ export interface ConsonantFeatures { } +// convert a set of consonant features to IPA +// returns the empty string if the proposed consonant does not exist export function consonantFeaturesToIpa(features: ConsonantFeatures): string { switch (features.place) { case ConsonantPlace.Bilabial: -- cgit v1.2.1