Re: [Lazarus] ComparePoints func

2017-07-26 Thread Michael Van Canneyt via Lazarus



On Wed, 26 Jul 2017, Reimar Grabowski via Lazarus wrote:


On Wed, 26 Jul 2017 18:53:34 +0100
Graeme Geldenhuys via Lazarus  wrote:


On 2017-07-26 17:27, Alexey via Lazarus wrote:
> Hm, in my app Int makes sense: i need to compare Points in binary
> search, and see: >, <, =. 

Ever heard of Manhatten Length? That would be a more logical approach. 

If a metric would be more logical (I don't know why exactly it should be but 
whatever) the euclidean metric would be even more logical, wouldn't it?


It is a commonly used length calculation for points.

That sounds horrible.
Is length really used like this?
The length of two points???
Metrics are distance functions.


   http://en.wikipedia.org/wiki/Taxicab_geometry

Any 2 dimensional metric can be used.
But it may totally not be the thing the TC needs as the metric conditions may 
not be desirable in his context.

The point is (and Michael made it already) that there is no definition of how 
to compare points. You have quite a lot of options and the current problem 
determines which function to use.
Therefore it makes no sense to introduce a general ComparePoints-function.


Exactly.

Michael.
--
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Sven Barth via Lazarus
Am 26.07.2017 19:51 schrieb "Graeme Geldenhuys via Lazarus" <
lazarus@lists.lazarus-ide.org>:
>> If "equals" is needed, why not simply use p1=p2 ?
>
>
> If operator overload exists for the types then sure, but as you know I
like OOP approaches to things.
>
> Also is TPoint a record or a object or a class?

It's an advanced record with methods and operator overloads:
https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/inc/typshrdh.inc?revision=33062=markup

> In fpGUI the equivalent of TPoint and TRect are object types and has many
related methods defined inside them. I don't believe p1 = p2 is going to
work with the object data type.

For object types you'll need to declare global operator overloads to use
e.g. the = operator (which have the disadvantage that they don't work with
generics... at least not yet :/ ).

Regards,
Sven
-- 
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Alexey via Lazarus
First start by defining what ComparePoints is supposed to measure or 
compare.


yes, of course: compare source editor x/y positions. Ie, it  is 
CompareCoords.


--
Regards,
Alexey

-- 
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Graeme Geldenhuys via Lazarus

On 2017-07-26 17:27, Alexey via Lazarus wrote:

Hm, in my app Int makes sense: i need to compare Points in binary
search, and see: >, <, =.


Ever heard of Manhatten Length? That would be a more logical approach. 
It is a commonly used length calculation for points.


  http://en.wikipedia.org/wiki/Taxicab_geometry


The interface as in fpGUI's TfpgPoint:


https://github.com/graemeg/fpGUI/blob/develop/src/corelib/fpg_base.pas#L164..L165


The implementations:


https://github.com/graemeg/fpGUI/blob/develop/src/corelib/fpg_base.pas#L2021..L2029



Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
--
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Graeme Geldenhuys via Lazarus

On 2017-07-26 16:22, Michael Van Canneyt via Lazarus wrote:

First start by defining what ComparePoints is supposed to measure or compare.


If "compare" doesn't mean "equals", then a better name should be used, 
otherwise that too is up for incorrect interpretation.





If "equals" is needed, why not simply use p1=p2 ?


If operator overload exists for the types then sure, but as you know I 
like OOP approaches to things.


Also is TPoint a record or a object or a class?

In fpGUI the equivalent of TPoint and TRect are object types and has 
many related methods defined inside them. I don't believe p1 = p2 is 
going to work with the object data type.


https://github.com/graemeg/fpGUI/blob/develop/src/corelib/fpg_base.pas#L160..L191



Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
--
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Sandro Cumerlato via Lazarus
IMHO you should consider 5 cases: P1 = P2 and the four quadrants

https://en.m.wikipedia.org/wiki/Quadrant_(plane_geometry)

- Quadrant I should correspond to >
- Quadrant III should correspond to <
- What about quadrants II and IV? You could compare your point to Y = -X
line to reduce your study to 3 cases.

Best regards

Sandro Cumerlato


On Jul 26, 2017 6:27 PM, "Alexey via Lazarus" 
wrote:

On 26.07.2017 18:11, Graeme Geldenhuys via Lazarus wrote:

> ComparePoints() returning a Integer is not a very friendly return type
> either,
>

Hm, in my app Int makes sense: i need to compare Points in binary search,
and see: >, <, =.

-- 
Regards,
Alexey


-- 
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus
-- 
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Michael Van Canneyt via Lazarus



On Wed, 26 Jul 2017, Alexey via Lazarus wrote:


On 26.07.2017 18:11, Graeme Geldenhuys via Lazarus wrote:
ComparePoints() returning a Integer is not a very friendly return type 
either,


Hm, in my app Int makes sense: i need to compare Points in binary 
search, and see: >, <, =.


This compare is very specific to your application.

I don't think it would be a good idea to generalize this.

Michael.
--
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Alexey via Lazarus

On 26.07.2017 18:11, Graeme Geldenhuys via Lazarus wrote:
ComparePoints() returning a Integer is not a very friendly return type 
either,


Hm, in my app Int makes sense: i need to compare Points in binary 
search, and see: >, <, =.


--
Regards,
Alexey

--
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Michael Van Canneyt via Lazarus



On Wed, 26 Jul 2017, Graeme Geldenhuys via Lazarus wrote:


On 2017-07-26 14:54, Alexey via Lazarus wrote:

I think LCL has many Compare funcs, but misses func for TPoint. Here
it's comparing x/y screen coordinates


Why not extend TPoint with an IsEquals() method, so you can do something 
like



var
  p1: TPoint;
  p2: TPoint;
begin
  // ... populate p1 & p2
  if p1.IsEquals(p2) then
// do something.


ComparePoints() returning a Integer is not a very friendly return type 
either, whereas Boolean makes more sense.


First start by defining what ComparePoints is supposed to measure or compare.

If "equals" is needed, why not simply use p1=p2 ?

Michael.
--
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] ComparePoints func

2017-07-26 Thread Sandro Cumerlato via Lazarus
What do you think about:

function ComparePoints(P1, P2: TPoint): TPoint;
begin
  Result.X := (P1.X - P2.X);
  Result.Y := (P1.Y - P2.Y);
end;

Best regards.

Sandro Cumerlato


On Jul 26, 2017 3:56 PM, "Alexey via Lazarus" 
wrote:

I think LCL has many Compare funcs, but misses func for TPoint. Here
it's comparing x/y screen coordinates

function ComparePoints(P1, P2: TPoint): integer;
begin
  if (P1.X=P2.X) and (P1.Y=P2.Y) then exit(0);
  if (P1.Y>P2.Y) then exit(1);
  if (P1.YP2.X) then exit(1) else exit(-1);
end;


-- 
Regards,
Alexey

-- 
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus
-- 
___
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus