Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
AnswerRe: Creating & writing to a text file from two different forms Pin
Richard MacCutchan3-Nov-18 10:07
mveRichard MacCutchan3-Nov-18 10:07 
AnswerRe: Creating & writing to a text file from two different forms Pin
OriginalGriff3-Nov-18 20:28
mveOriginalGriff3-Nov-18 20:28 
AnswerRe: Creating & writing to a text file from two different forms Pin
BillWoodruff4-Nov-18 6:47
professionalBillWoodruff4-Nov-18 6:47 
Questionbest mothod for save file database C# Pin
arman02-Nov-18 4:40
arman02-Nov-18 4:40 
AnswerRe: best mothod for save file database C# Pin
OriginalGriff2-Nov-18 5:16
mveOriginalGriff2-Nov-18 5:16 
AnswerRe: best mothod for save file database C# Pin
Gerry Schmitz2-Nov-18 6:06
mveGerry Schmitz2-Nov-18 6:06 
AnswerRe: best mothod for save file database C# Pin
Eddy Vluggen3-Nov-18 2:07
professionalEddy Vluggen3-Nov-18 2:07 
QuestionList of surrounding points Pin
Bernhard Hiller2-Nov-18 3:16
Bernhard Hiller2-Nov-18 3:16 
I have a list of System.Drawing.Point, e.g. selected pixels in a bitmap. Now I'd like to get a list of points which are nearby, say less than 10 pixels (simply the sum of distances in x and y direction) away from the former points.
When the number of points is small, that's easy. But when more than 1000 pixels are selected, the performance becomes important. Can you suggest some algorithms for this task?

Currently, I use a simple method:
public static IReadOnlyList<Point> GetSurroundingCloud(this IEnumerable<Point> _points, int _maximumDistance)
{
    ISet<Point> result = new HashSet<Point>();
    foreach (Point p in _points)
    {
        for (int x = 0; x <= _maximumDistance; x++)
        {
            for (int y = 0; y + x <= _maximumDistance; y++)
            {
                result.Add(new Point(p.X - x, p.Y - y));
                result.Add(new Point(p.X - x, p.Y + y));
                result.Add(new Point(p.X + x, p.Y - y));
                result.Add(new Point(p.X + x, p.Y + y));
            }
        }
    }
    return result.ToList();
}
As you can see, there are some features which won't scale well:
- the iteration over the input list (though O(n) could be acceptable)
- the loops with maximumDistance parameter - O(n^2) with that parameter
- HashSet.Add - the larger the list gets, the more points it has to look up for preventing duplicates, so something like O(n^2) or worse.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!


modified 5-Nov-18 3:50am.

AnswerRe: List of surrounding points Pin
Dar Brett2-Nov-18 5:15
Dar Brett2-Nov-18 5:15 
GeneralRe: List of surrounding points Pin
Bernhard Hiller4-Nov-18 21:44
Bernhard Hiller4-Nov-18 21:44 
AnswerRe: List of surrounding points Pin
Gerry Schmitz2-Nov-18 5:50
mveGerry Schmitz2-Nov-18 5:50 
GeneralRe: List of surrounding points Pin
BillWoodruff9-Nov-18 13:28
professionalBillWoodruff9-Nov-18 13:28 
AnswerRe: List of surrounding points Pin
Daniel Pfeffer4-Nov-18 23:53
professionalDaniel Pfeffer4-Nov-18 23:53 
AnswerRe: List of surrounding points Pin
BillWoodruff9-Nov-18 13:26
professionalBillWoodruff9-Nov-18 13:26 
GeneralRe: List of surrounding points Pin
Bernhard Hiller11-Nov-18 21:33
Bernhard Hiller11-Nov-18 21:33 
GeneralRe: List of surrounding points Pin
BillWoodruff11-Nov-18 22:26
professionalBillWoodruff11-Nov-18 22:26 
GeneralRe: List of surrounding points Pin
Bernhard Hiller13-Nov-18 21:57
Bernhard Hiller13-Nov-18 21:57 
GeneralRe: List of surrounding points Pin
BillWoodruff13-Nov-18 22:05
professionalBillWoodruff13-Nov-18 22:05 
GeneralRe: List of surrounding points Pin
Bernhard Hiller13-Nov-18 22:22
Bernhard Hiller13-Nov-18 22:22 
Question[SOLVED] I need help with NIM GAME IN C# Pin
RES7B4-Nov-18 5:23
RES7B4-Nov-18 5:23 
AnswerRe: I need help with NIM GAME IN C# Pin
OriginalGriff1-Nov-18 21:07
mveOriginalGriff1-Nov-18 21:07 
AnswerRe: I need help with NIM GAME IN C# Pin
Eddy Vluggen4-Nov-18 3:48
professionalEddy Vluggen4-Nov-18 3:48 
AnswerRe: [SOLVED] I need help with NIM GAME IN C# Pin
F-ES Sitecore5-Nov-18 2:32
professionalF-ES Sitecore5-Nov-18 2:32 
QuestionHow to update data to existing PDF using Itextsharp library Pin
pondurelakshman30-Oct-18 19:27
pondurelakshman30-Oct-18 19:27 
AnswerRe: How to update data to existing PDF using Itextsharp library Pin
Richard MacCutchan31-Oct-18 3:09
mveRichard MacCutchan31-Oct-18 3:09 

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.