Commit f91edf82 authored by Moritz's avatar Moritz

test push

parent fc2de57b
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testestest : MonoBehaviour
{
public bool start = false;
public bool start2 = false;
// Update is called once per frame
void Update()
{
if(start) {
start = false;
test();
}
if(start2) {
start2 = false;
test2();
}
}
private void test2() {
float gridStepSize = 0.7f;
float neighborhoodRange = gridStepSize;
float getFloorGridPoint(float value) {
if (0 != 0) {
for (int i = 0; i < gridStepSize * 400; i++) {
if (value > i * gridStepSize)
return i;
}
return 0;
}
value -= neighborhoodRange;
value = Mathf.Ceil(value / gridStepSize);
return value < 0 ? 0 : value;
}
float getCeilGridPoint(float value, int gridDimensionMax) {
if (0 != 0) {
for (int i = 0; i < gridDimensionMax - 1; i++) {
if (value < i * gridStepSize)
return i;
}
return gridDimensionMax - 1;
}
value += neighborhoodRange;
value = Mathf.Floor(value / gridStepSize);
return value > gridDimensionMax -1 ? gridDimensionMax - 1 : value;
}
void getMinMaxPoint(float value) {
float min = getFloorGridPoint(value);
float max = getCeilGridPoint(value, 9);
Debug.Log("for value " + value + " min index is " + min + " and max index is " + max);
}
getMinMaxPoint(0.5f); //0, 1 jo
getMinMaxPoint(0f); //0, 1 jo
getMinMaxPoint(-0.5f); // kp sollte nicht sein -> is 0, 0 (super?)
getMinMaxPoint(1f); //1, 2 jo
getMinMaxPoint(2.7f); //3, 4 jo
getMinMaxPoint(6.7f); //9?, 8 leider ja
getMinMaxPoint(3.5f); //5, 5, nein ist 4, 6 (leider)
getMinMaxPoint(4.5f); //6, 7 jo
getMinMaxPoint(6f); //8, 8 nein 8, 9
getMinMaxPoint(-1f); //sollte 0, 0, ist 0, -1
}
private void test() {
float aLow = -5;
float aHigh = 5;
float bLow = 0;
float bHigh = 10;
void print(float value) {
float normal = Mathf.InverseLerp(aLow, aHigh, value);
float bValue = Mathf.Lerp(bLow, bHigh, normal);
Debug.Log(bValue);
}
void print2(float x) {
float x1 = aLow;
float x2 = aHigh;
float y1 = bLow;
float y2 = bHigh;
var m = (y2 - y1) / (x2 - x1);
var c = y1 - m * x1; // point of interest: c is also equal to y2 - m * x2, though float math might lead to slightly different results.
Debug.Log(m * x + c);
}
print(0f);
print(-3f);
print(1f);
print(5f);
print2(0f);
print2(-3f);
print2(1f);
print2(5f);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment