Skip to content

Commit a0255d4

Browse files
authored
Merge pull request #49 from MathisBurger/feature/translations
Implemented some more stochastical and default features.
2 parents 6e06763 + 2a5ef4e commit a0255d4

29 files changed

Lines changed: 384 additions & 4 deletions

src/lib/custom-math.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
2+
* This method rounds thhe given number to the fixed number of decimals
23
*
34
* @param val the initial number
45
* @param decimals the number of decimals after the komma
56
* @returns the rounded value
6-
*
7-
* This method rounds thhe given number to the fixed number of decimals
87
*/
98
function roundTo(val: number, decimals: number): number {
109
const multiplicator = Math.pow(10, decimals);
@@ -13,4 +12,21 @@ function roundTo(val: number, decimals: number): number {
1312
return +pre.toFixed(decimals);
1413
}
1514

16-
export { roundTo };
15+
/**
16+
* Calculates the faculty of the given number and
17+
* returns it.
18+
*
19+
* @param num The´number that faculty should be calculated
20+
* @returns The faculty value of the given number
21+
*/
22+
function faculty(num: number): number {
23+
let cache = 1;
24+
let run = 1;
25+
while (run <= num) {
26+
cache = cache * run;
27+
run++;
28+
}
29+
return cache;
30+
}
31+
32+
export { roundTo, faculty };

src/lib/defaults-provider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { GeoLayerParameter, GeoLayerCoordinate } from '$src/typings/geo-layer';
2+
import type { NCR } from '$src/typings/ncr';
23
import type { Triangle } from '$src/typings/triangle';
34
import type { Vector } from '$src/typings/vector';
45

@@ -7,6 +8,7 @@ interface DefaultsProviderInterface {
78
getGeoLayerParameterDefault(): GeoLayerParameter;
89
getGeoLayerCoordinateDefault(): GeoLayerCoordinate;
910
getDefaultTriangle(): Triangle;
11+
getDefaultNCR(): NCR;
1012
}
1113

1214
// Provides some functions to generate default values.
@@ -54,4 +56,12 @@ export class DefaultsProvider implements DefaultsProviderInterface {
5456
getVectorDefault(): Vector {
5557
return { x: 0, y: 0, z: 0 };
5658
}
59+
60+
/**
61+
* Returns a default NCR.
62+
* @returns The generated NCR
63+
*/
64+
getDefaultNCR(): NCR {
65+
return { n: 0, k: 0 };
66+
}
5767
}

src/lib/footer.svelte

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script lang="ts">
2+
</script>
3+
4+
<div class="footer">
5+
<div class="footer-copyright">©{new Date().getFullYear()} Mathis Burger</div>
6+
</div>
7+
8+
<style lang="scss">
9+
@import '../styles/footer.scss';
10+
</style>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { faculty } from '$lib/custom-math';
2+
import type { NCR } from '$src/typings/ncr';
3+
4+
/**
5+
* Calculates an nCr of a input.
6+
*
7+
* @param ncr Instance of the ncr value
8+
* @returns number The nCr value of the calculation
9+
*/
10+
export function calculateNCr(ncr: NCR): number {
11+
const top = faculty(ncr.n);
12+
const bottom = faculty(ncr.k) * faculty(ncr.n - ncr.k);
13+
return top / bottom;
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script lang="ts">
2+
import type { NCR } from '$src/typings/ncr';
3+
export let bindValue: NCR;
4+
</script>
5+
6+
<div class="ncr-outer-wrapper">
7+
<div class="ncr-input-symbols">(</div>
8+
<div class="ncr-input">
9+
<input type="number" class="ncr-input-field" bind:value={bindValue.n} />
10+
<input type="number" class="ncr-input-field" bind:value={bindValue.k} />
11+
</div>
12+
<div class="ncr-input-symbols">)</div>
13+
</div>
14+
15+
<style lang="scss">
16+
@import '../../styles/ncr.scss';
17+
</style>

src/routes/__error.svelte

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
import { _ } from 'svelte-i18n';
3+
</script>
4+
5+
<div class="centered">
6+
<div class="container">
7+
<div class="error-heading">404 Not Found</div>
8+
<div class="error-container">
9+
{$_('notFound')}
10+
</div>
11+
</div>
12+
</div>
13+
14+
<style lang="scss">
15+
@import '../styles/general.scss';
16+
@import '../styles/error.scss';
17+
</style>

src/routes/__layout.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import Navbar from '$lib/navbar.svelte';
3+
import Footer from '$lib/footer.svelte';
34
import { theme } from '../lib/theme';
45
import '../i18n.ts';
56
import { waitLocale } from 'svelte-i18n';
@@ -21,4 +22,5 @@
2122
{#await preload() then _}
2223
<Navbar />
2324
<slot />
25+
<Footer />
2426
{/await}

src/routes/basic/faculty.svelte

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script lang="ts">
2+
import { faculty } from '$lib/custom-math';
3+
4+
let input = 0;
5+
</script>
6+
7+
<div class="centered">
8+
<div class="container">
9+
<input class="larger-input" type="number" bind:value={input} />
10+
<div class="result-form">
11+
{faculty(input)}
12+
</div>
13+
</div>
14+
</div>
15+
16+
<style lang="scss">
17+
@import '../../styles/general.scss';
18+
</style>

src/routes/basic/index.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ListSelector from '../../lib/listSelector.svelte';
33
import type { ListSelectorElement } from '../../typings/ListSelectorElement';
44
import { _ } from 'svelte-i18n';
5+
import { roundTo } from '$lib/custom-math';
56
67
let apps: ListSelectorElement[] = [
78
{
@@ -18,6 +19,16 @@
1819
name: $_('basic.function-solver.title'),
1920
description: $_('basic.function-solver.description'),
2021
route: '/basic/function-solver'
22+
},
23+
{
24+
name: $_('basic.faculty.title'),
25+
description: $_('basic.faculty.description'),
26+
route: '/basic/faculty'
27+
},
28+
{
29+
name: $_('basic.logarithm.title'),
30+
description: $_('basic.logarithm.description'),
31+
route: '/basic/logarithm'
2132
}
2233
];
2334
</script>

src/routes/basic/logarithm.svelte

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="ts">
2+
let input = 0;
3+
</script>
4+
5+
<div class="centered">
6+
<div class="container">
7+
<input class="larger-input" type="number" bind:value={input} />
8+
<div class="result-form">
9+
{Math.log(input)}
10+
</div>
11+
</div>
12+
</div>
13+
14+
<style lang="scss">
15+
@import '../../styles/general.scss';
16+
</style>

0 commit comments

Comments
 (0)