|
Yanshof wrote: minimum X, Y value
Yanshof wrote: maximum X, Y value
Yanshof wrote: the best way
first define "minimum" and "maximum" for pairs of numbers: what if the points are (1,100) and (100,1)?
define "best", it is very subjective.
|
|
|
|
|
Lets say i need to find the most left up point as minimum and the most right down point as maximum...
|
|
|
|
|
and which would be which for the list (1,100) and (100,1)??
|
|
|
|
|
I'm not sure that helps: (0, 100) and (100, 0) are both "left up", and they are both equidistant from (0, 0). You need to think about it: Is it more important to be near the left, or near the top? When does it change? If you pick "Left" as most important is (1, 100) less than (2, 0)?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
To visualize Luc's answer, which point is closer to the upper left corner? Is it X or Y?
O O O O O
O O O O O
O O O X O
O O Y O O
O O O O O
X (4, 3):
(4*4) + (3*3) = 16 + 9 = 25
Distance to upperleft corner: 5
Y (3, 4):
(3*3) + (4*4) = 9 + 16 = 25
Distance to upperleft corner: 5
I are Troll
|
|
|
|
|
you cheated and changed my example!
|
|
|
|
|
Luc Pattyn wrote: you cheated and changed my example!
Extended it, adding comments like any student would
I are Troll
|
|
|
|
|
How about something like this
Func<Point, Point, double> distanceToken = new Func<Point, Point, double>((p1, p2) => { return ((p1.X - p2.X) * (p1.X - p2.X)) + ((p1.Y - p2.Y) * (p1.Y - p2.Y)); });
Point TopLeft = new Point() { X = 0, Y = 0 };
Point BottomRight = new Point() { X = 100, Y = 100 };
var t = (from pt in points
select new { p=pt, d= distanceToken (TopLeft, pt) }).OrderBy(a=>a.d);
Console.WriteLine("nearest topleft:" + t.First().ToString());
Console.WriteLine("farthest topleft:" + t.Last().ToString());
var t = (from pt in points
select new { p = pt, DistToA = distanceToken (TopLeft, pt), DistToB = distanceToken(BottomRight, pt) });
modified on Sunday, August 22, 2010 4:46 PM
|
|
|
|
|
cechode wrote: Math.Sqrt(Math.Pow(Math.Abs(p1.X - p2.X), 2) + Math.Pow(Math.Abs(p1.Y - p2.Y), 2))
Ok, no offence, but that's the worst way to do it.
First, never use Math.Pow to calculate trivial powers. It's very slow, and less accurate, compared to doing a couple of multiplications.
Second, that Math.Sqrt is just useless. All it does it take time. It doesn't change the order of the items.
Third, it's a square. What is that Math.Abs for?
If you combine the first two things, you don't even have to use any floating point.
Func distanceSquared = new Func((p1, p2) =>
{
return (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y);
});
|
|
|
|
|
no offence taken. i learn by answering as well
you made some good points
|
|
|
|
|
i'm trying to draw a rectangle with in a panel and move it with in the panel,though i draw it i can't move it, i found the method ControlPaint.DrawReversibleFrame
but it draws in the screen not in the pannel
any idea hw to handle this
thanx in advance
|
|
|
|
|
Firstly, you need to handle the Panel Paint event. That way, each time the panel needs to draw, you will get told to do so. In the handler:
private Rectangle myRect = new Rectangle(0, 0, 40, 30);
private void myPanel_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawRectangle(Pens.Azure, myRect);
}
If you then change the position or size of myRect, just call myPanel.Invalidate() to force the panel to redraw. There is more complex stuff you may want, but that'll get you started on the basics.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
|
Well, i'm sure decorator pattern works in c#, but trying to post this from jave to c#,
no luck so far.
http://java-x.blogspot.com/2007/01/implementing-decorator-pattern-in-java.html
basically this line always gives me trouble, "Decorator decorator = new ConcreteDecorator(comp);"
------------------------------------------------------
import decorator.*;
public class Client {
public static void main(String[] args) {
IComponent comp = new Component();
Decorator decorator = new ConcreteDecorator(comp);
decorator.doStuff();
}
-------------------------------------------------------
BTW, i'm using abstract classes only, no interfaces.
Anyone knows a working example in c# ?
wow
|
|
|
|
|
5883 wrote: Anyone knows a working example in c# ?
Try here[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The decorator pattern is used extensively in the Stream abstract class
and all it's sub classes. Read Here[^]
|
|
|
|
|
I want to know how can I prevent the form resizing when the user double clicks on the titlebar
|
|
|
|
|
You can't prevent it, but you can handle the event and cancel it or resize back the original.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
|
No that is not what I suggested! It is ludicrous to override WndProc when there are perfectly good and valid events for this.
ResizeBegin[^]
Resize[^]
SizeChanged[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
As I said, it's one way - not the way - to implement your suggestion.
In my haste, I was looking for events prefixed with "On ". Given that the events you mentioned exist, subscribing to them would undoubtedly be the way to go.
/ravi
|
|
|
|
|
jrahma wrote: How?
HANDLE THE EVENT !!!
If you still don't understand then give up.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I have a combobox1 and I want to move to another combobox2 (in a different panel).
I tried to put the KeyCode Tab in the KeyDown but it didn't work and when I tried the same in KeyUp it will move immediately to combobox2 when combobox1 gets focused
What can I do if I just need a simple (move to combobox2) when user uses Tab on combobox1
|
|
|
|