Skip to content

Commit

Permalink
yqy
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAsmirko committed Mar 12, 2021
1 parent 040e2d6 commit dd7bd5a
Show file tree
Hide file tree
Showing 95 changed files with 146 additions and 29 deletions.
Binary file modified .gradle/6.7.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/6.7.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/6.7.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/6.7.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified build/classes/kotlin/main/Constants.class
Binary file not shown.
Binary file added build/classes/kotlin/main/LeftViewType.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$buttonInBox$1$1$1.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$buttonInBox$1$2$1.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$buttonInBox$1$3$1.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$buttonInBox$1$4.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$buttonInBox$2.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$drawPoints$sorted$1.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$main$1$1$1$2.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$main$1$1.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$main$1.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt$plotView$1.class
Binary file not shown.
Binary file removed build/classes/kotlin/main/MainKt$points$1.class
Binary file not shown.
Binary file modified build/classes/kotlin/main/MainKt.class
Binary file not shown.
Binary file added build/classes/kotlin/main/MethodType.class
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/build-history.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
씈�����������������������������������������������
씈�����������������������������������������������켈쨉ﴉ쐊쐊쐊쐊쐊쐊
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/jvm/kotlin/constants.tab
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
쐅현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현
쐅현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현현������������������
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/jvm/kotlin/proto.tab
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/jvm/kotlin/proto.tab.len
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
�
�팩팩팩팩팩�패패패패패패쌩쌩쌩쌩
Binary file modified build/kotlin/compileKotlin/caches-jvm/jvm/kotlin/proto.tab_i
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions build/kotlin/compileKotlin/caches-jvm/lookups/counters.tab
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
74
71
93
90
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/file-to-id.tab
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/id-to-file.tab
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/id-to-file.tab.len
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/id-to-file.tab_i
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/lookups.tab
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/lookups.tab.len
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/lookups.tab.values
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/lookups.tab.values.at
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
ήσ�τίΛαΡύιώΟΟΰΕίΨΣΙΟΜδΫΨΛΕΪΒϊέΞΜΔτΒαΟΕΖσιΧΡΔΟρΔδΟΐΐτΩβΦΕΘΐΣζΪΝΦΗέδέΚοΗΧθι�θάγθλιΤζ�ψτρμΪίηΦΗ υοΩέγίΩ ϋτίΪδβί �χζΪτΪ
Ш МЙ Р ш
п
Ж Ж
а В
Л Ъ
у Ф К Ч
Ь
Ь в ц Я Ъ
Ш
ю
й
п ъ П ф ф И Ч с ъ ц
В
ь Ъ ы
У
ь
Ъ Ь р
э С
У Ч У я
Г ш
й Ы
Ы Д Н я
С И
и Х
ы
и к
б
ь ш
ч Ь
з
т Ш у
ж в
Е Ф
ж
Б з
з
М
И
ч о
Б
в п
б
М м Ц
Ф ф
о
д п
З Ж
Binary file modified build/kotlin/compileKotlin/caches-jvm/lookups/lookups.tab_i
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/last-build.bin
Binary file not shown.
Binary file added img/Screenshot 2021-03-12 at 09.13.56.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 89 additions & 23 deletions src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Canvas
Expand All @@ -17,29 +18,52 @@ import androidx.compose.ui.layout.WithConstraints
import androidx.compose.ui.unit.dp
import model.PlotData
import model.interpolators.DichotomyInterpolator
import kotlin.math.log2
import kotlin.math.pow
import kotlin.math.sin

object Constants {
const val POINT_RADIUS = 0.5f
const val L_BOUND = -10f
const val R_BOUND = 10f
const val L_BOUND = 1f
const val R_BOUND = 6f
const val NUM_POINTS = 100
const val TITLE = "Optimizer Visualizer"
}

val buttonsText = listOf("Brent", "Dichotomy", "Fibonacci", "Golden Section", "Parabolas")
enum class LeftViewType {
METHOD,
FUNCTION
}

val dichotomyInterpolator = DichotomyInterpolator()
val points =
dichotomyInterpolator.makePoints(Constants.L_BOUND.toDouble(), Constants.R_BOUND.toDouble(), Constants.NUM_POINTS) {
it.pow(3.0)
}
val maxFnVal = points.maxByOrNull { it.y }?.y ?: -100f
val minFnVal = points.minByOrNull { it.y }?.y ?: -1000f
enum class MethodType {
BRENT,
DICHOTOMY,
FIBONACCI,
GOLDEN_SECTION,
PARABOLAS,
NONE
}

val methodsButtonsText = listOf(
Pair("Brent", MethodType.BRENT),
Pair("Dichotomy", MethodType.DICHOTOMY),
Pair("Fibonacci", MethodType.FIBONACCI),
Pair("Golden Section", MethodType.GOLDEN_SECTION),
Pair("Parabolas", MethodType.PARABOLAS)
)

val samplePlotData = PlotData(Constants.L_BOUND, Constants.R_BOUND, points, minFnVal, maxFnVal)
val functionsButtonsText = mapOf(
Pair("y = x", fun(x: Double): Double { return x }),
Pair("y = x^2", fun(x: Double): Double { return x.pow(2.0) }),
Pair("y = x^3", fun(x: Double): Double { return x.pow(3.0) }),
Pair("y = sin(x)", fun(x: Double): Double { return sin(x) }),
Pair("y = log2(x)", fun(x: Double): Double { return log2(x) })
)

fun main() = Window {
fun main() = Window(title = Constants.TITLE) {
MaterialTheme {
var leftViewType by remember { mutableStateOf(LeftViewType.METHOD) }
var func by remember { mutableStateOf("none") }
Row(
modifier = Modifier
.background(color = Color(0xff795548))
Expand All @@ -51,23 +75,65 @@ fun main() = Window {
.background(color = Color(0xff4b2c20))
.fillMaxHeight().border(border = BorderStroke(1.dp, color = Color.White))
) {
buttonsText.forEach { buttonInBox(it) }
if (leftViewType == LeftViewType.METHOD) {
methodsButtonsText.forEach {
buttonInBox(it.first) {
leftViewType = it
}
}
} else if (leftViewType == LeftViewType.FUNCTION) {
buttonInBox("Back") {
leftViewType = LeftViewType.METHOD
func = "none"
}
functionsButtonsText.forEach { pair ->
buttonInBox(pair.key) { func = pair.key }
}
}
}
WithConstraints(
modifier = Modifier
.weight(0.8f)
.fillMaxWidth()
) {
val boxWidth = constraints.maxWidth
val boxHeight = constraints.maxHeight
plotView(samplePlotData, boxHeight, boxWidth)
if (func != "none") {
WithConstraints(
modifier = Modifier
.weight(0.8f)
.fillMaxWidth()
) {
val boxWidth = constraints.maxWidth
val boxHeight = constraints.maxHeight
val dichotomyInterpolator = DichotomyInterpolator()
val points =
dichotomyInterpolator.makePoints(
Constants.L_BOUND.toDouble(),
Constants.R_BOUND.toDouble(),
Constants.NUM_POINTS,
functionsButtonsText[func]!!
)
val minFnVal: Float = points.minByOrNull { it.y }?.y ?: -100f
val maxFnVal = points.maxByOrNull { it.y }?.y ?: 100f
val samplePlotData = PlotData(Constants.L_BOUND, Constants.R_BOUND, points, minFnVal, maxFnVal)
plotView(samplePlotData, boxHeight, boxWidth)
}
} else {
Column(
Modifier
.align(alignment = Alignment.CenterVertically)
.weight(0.8f)
) {
Text(
modifier = Modifier
.padding(30.dp),
text = "Something will be drawn here after you chose method and function"
)
}
}
}
}
}

@Composable
fun buttonInBox(text: String) {
fun buttonInBox(
text: String,
onChange: (type: LeftViewType) -> Unit
) {
val active = remember { mutableStateOf(false) }
Box(
modifier = Modifier
Expand All @@ -76,7 +142,7 @@ fun buttonInBox(text: String) {
.fillMaxWidth()
) {
OutlinedButton(
onClick = {},
onClick = { onChange(LeftViewType.FUNCTION) },
shape = RoundedCornerShape(50),
border = BorderStroke(2.dp, Color(0xff64dd17)),
modifier = Modifier
Expand Down

0 comments on commit dd7bd5a

Please sign in to comment.