Click here to Skip to main content
15,887,083 members
Home / Discussions / C#
   

C#

 
GeneralRe: Converting Y up to Y down coordinates Pin
SledgeHammer0123-Nov-14 9:08
SledgeHammer0123-Nov-14 9:08 
GeneralRe: Converting Y up to Y down coordinates Pin
SledgeHammer0123-Nov-14 9:14
SledgeHammer0123-Nov-14 9:14 
GeneralRe: Converting Y up to Y down coordinates Pin
SledgeHammer0123-Nov-14 8:10
SledgeHammer0123-Nov-14 8:10 
GeneralRe: Converting Y up to Y down coordinates Pin
SledgeHammer0123-Nov-14 8:11
SledgeHammer0123-Nov-14 8:11 
GeneralRe: Converting Y up to Y down coordinates Pin
Richard MacCutchan23-Nov-14 22:03
mveRichard MacCutchan23-Nov-14 22:03 
GeneralRe: Converting Y up to Y down coordinates Pin
SledgeHammer0123-Nov-14 8:31
SledgeHammer0123-Nov-14 8:31 
GeneralRe: Converting Y up to Y down coordinates Pin
SledgeHammer0123-Nov-14 8:46
SledgeHammer0123-Nov-14 8:46 
AnswerRe: Converting Y up to Y down coordinates Pin
BillWoodruff23-Nov-14 1:00
professionalBillWoodruff23-Nov-14 1:00 
Thank you for my Sunday puzzle !
C#
// version two, passes test of reversing the two sample ranges defined here
private Dictionary<int, int> MapRangeValues(bool flipSign, List<int> sourceRange, List<int> mapToRange)
{
    var dctTransform = new Dictionary<int, int>();

    double ratio = Convert.ToDouble(mapToRange.Max() - mapToRange.Min()) / (sourceRange.Max() - sourceRange.Min());

    int offset = mapToRange[0] - sourceRange[0] + 1;

    foreach (var sInt in sourceRange)
    {
        int val = Convert.ToInt32(ratio*sInt) + offset;
            //(sInt + offset));

        if (flipSign)
        {
            val = mapToRange.Max() - val - 1;
        }
        else
        {
            val--;
        }

        dctTransform.Add(sInt, val);
    }

    return dctTransform;
}

// some test data
private List<int> DataRange = Enumerable.Range(-5, 21).ToList();

private List<int> ControlRange = Enumerable.Range(0, 30).ToList();

// requires two TextBoxes on a Form ...
private void testTheSucker()
{
    textBox1.Clear();
    textBox2.Clear();

    var result1 = MapRangeValues(true, DataRange, ControlRange);

    var result2 = MapRangeValues(false, ControlRange, DataRange);

    foreach (var kvp in result1)
    {
        textBox1.Text += string.Format("{0}\t{1}\r\n", kvp.Key, kvp.Value);
    }

    foreach (var kvp in result2)
    {
        textBox2.Text += string.Format("{0}\t{1}\r\n", kvp.Key, kvp.Value);
    }
}
I am curious to see if this is as general purpose as I intend it to be: so, will test further. I am sure this can be improved (perhaps replaced with a few lines of Linq wizardry ?), and I'd welcome any feedback, corrections, ideas !

// first test results
-5 29
-4 28
-3 26
-2 25
-1 23
0 22
1 21
2 19
3 18
4 16
5 15
6 13
7 12
8 10
9 9
10 8
11 6
12 5
13 3
14 2
15 0

// second test results
0 -5
1 -4
2 -4
3 -3
4 -2
5 -2
6 -1
7 0
8 1
9 1
10 2
11 3
12 3
13 4
14 5
15 5
16 6
17 7
18 7
19 8
20 9
21 9
22 10
23 11
24 12
25 12
26 13
27 14
28 14
29 15
«If you search in Google for 'no-one ever got fired for buying IBM:' the top-hit is the Wikipedia article on 'Fear, uncertainty and doubt'»  What does that tell you about sanity in these times?


modified 23-Nov-14 7:51am.

GeneralRe: Converting Y up to Y down coordinates Pin
SledgeHammer0123-Nov-14 8:13
SledgeHammer0123-Nov-14 8:13 
QuestionLooking for books recommendations to learn specifically about DB using .NET and C# Pin
Member 1000166322-Nov-14 8:04
Member 1000166322-Nov-14 8:04 
AnswerRe: Looking for books recommendations to learn specifically about DB using .NET and C# Pin
BillWoodruff22-Nov-14 8:33
professionalBillWoodruff22-Nov-14 8:33 
QuestionIBM - ILog Diagram: Find node position in pixel Pin
hassan faghihi21-Nov-14 22:20
professionalhassan faghihi21-Nov-14 22:20 
QuestionPocketSphinx Pin
Member 1001593821-Nov-14 7:54
Member 1001593821-Nov-14 7:54 
AnswerRe: PocketSphinx Pin
Dave Kreskowiak21-Nov-14 8:39
mveDave Kreskowiak21-Nov-14 8:39 
AnswerRe: PocketSphinx Pin
BillWoodruff21-Nov-14 9:31
professionalBillWoodruff21-Nov-14 9:31 
Questionhow to solve System.OutOf Memory Exception was thrown Pin
cicill21-Nov-14 5:24
cicill21-Nov-14 5:24 
AnswerRe: how to solve System.OutOf Memory Exception was thrown Pin
Eddy Vluggen21-Nov-14 5:35
professionalEddy Vluggen21-Nov-14 5:35 
AnswerRe: how to solve System.OutOf Memory Exception was thrown Pin
OriginalGriff21-Nov-14 5:50
mveOriginalGriff21-Nov-14 5:50 
AnswerRe: how to solve System.OutOf Memory Exception was thrown Pin
hassan faghihi21-Nov-14 22:27
professionalhassan faghihi21-Nov-14 22:27 
QuestionApplication has stopped working error in C# .NET application Pin
eljainc21-Nov-14 4:51
eljainc21-Nov-14 4:51 
AnswerRe: Application has stopped working error in C# .NET application Pin
OriginalGriff21-Nov-14 5:10
mveOriginalGriff21-Nov-14 5:10 
AnswerRe: Application has stopped working error in C# .NET application Pin
Redgum21-Nov-14 5:11
professionalRedgum21-Nov-14 5:11 
AnswerRe: Application has stopped working error in C# .NET application Pin
Richard MacCutchan21-Nov-14 5:12
mveRichard MacCutchan21-Nov-14 5:12 
QuestionRaise RowCommand event of GridView with asynchronous postback Pin
Miroslav Georgiev20-Nov-14 22:33
Miroslav Georgiev20-Nov-14 22:33 
QuestionSentimental analysis and plotting charts with C# Pin
sachidanandgowda20-Nov-14 21:54
sachidanandgowda20-Nov-14 21:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.