### Author Topic: snapping points  (Read 1864 times)

#### frederic

• Full Member
• Posts: 221
##### snapping points
« on: December 06, 2017, 04:25:20 pm »

Dear specialists

I try to develop a standard procedure for a helping tool in a chart.

The basis is  “ chpointsbasicmaster” : a chart which provides the available data  ( in my test case 60 points).
Then i have standard chpointsLinserie1: achart with evenly distributed zigzag line (20 points here)

The idea is to use to the points of the  zigzag line and then drag them to one of the points  of  the “ chpointsbasicmaster”-line. This dragging should take place in such a way that we keep the sorted character of the zigzag points.
Once we have dragged close to the “chpointsbasicmaster”  the nearest point of the “chpointsbasicmaster”  should be grabbed and its xy values should become the new values of the zigzag point of the chpointsLinserie1.

for the dragging and snapping i try to use following  code:
Quote
procedure TForm1.ctPointsDataPointDragTool1Drag(ASender: TDataPointDragTool;
var AGraphPoint: TDoublePoint);
var  thspoint:integer;
anx,any:double;
AmasterGraphPoint : TDoublePoint;
p: TNearestPointParams;
r: TNearestPointResults;
begin
draggedpoint:= ctPointsDataPointDragTool1.PointIndex ;  // affected series = chpointsLinserie1
if ((AGraphPoint.x >=  minimumX)and(AGraphPoint.x <=  maximumX)) then
begin
RposX[draggedpoint]:=AGraphPoint.x;  //during dragging
RposY[draggedpoint]:= AGraphPoint.y;//during dragging
memo1.Lines.add(' draggedpoint= '+inttostr( draggedpoint)+'   Rx= '+floattostr(RposX[draggedpoint])+' Ry= '+floattostr(RposY[draggedpoint]));
end;

// p.FDistFunc := @PointDistX; // got error when using this
p.FOptimizeX := true;
p.FPoint := chPoints.GraphToImage(aGraphPoint);

if  chpointsbasicmaster.GetNearestPoint(p, r) then
begin
AmasterGraphPoint :=  chpointsbasicmaster.AxisToGraph(r.FValue);
RposX[draggedpoint]:=AmasterGraphPoint.x;  // a detected nearest point
RposY[draggedpoint]:= AmasterGraphPoint.y;
AGraphPoint:=AmasterGraphPoint ; //overriding
anx:=AGraphPoint.x;
any:= AGraphPoint.y;

end else memo1.Lines.add( 'not working') ;
end;

it compiles oke , but "if  chpointsbasicmaster.GetNearestPoint(p, r) then"  is not getting true

// p.FDistFunc := @PointDistX;results in an error
i suspect the "@"which is not recognised in my case ,i do not know what to do with it

i would appriciate some suggestions how to solve this

#### wp

• Hero Member
• Posts: 4911
##### Re: snapping points
« Reply #1 on: December 06, 2017, 04:59:54 pm »
What is "cbpointsbasicmaster"? It "provides the available data" - this means that it should be a ChartSource, but your description reads as if it is a series.

Could you assemble a little demo to play with?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

#### frederic

• Full Member
• Posts: 221
##### Re: snapping points
« Reply #2 on: December 06, 2017, 08:45:52 pm »
wp,
attached the project i was testing

frederic

#### wp

• Hero Member
• Posts: 4911
##### Re: snapping points
« Reply #3 on: December 07, 2017, 12:28:56 am »
Well, I can't say that I understand what you want to achieve. But, at least, the issue with p.FDistFunc := @PointDistX simply is that the unit TAGeometry is missing - this is where these Dist functions are declared.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

#### frederic

• Full Member
• Posts: 221
##### Re: snapping points
« Reply #4 on: December 07, 2017, 09:37:39 am »

thanks wp

it works
why such a tool?
sometimes i get a bunch of arbritrary measuring data(simulated by chpointsbasicmaster) with which you want to do some calculations with).Very often these data were polluted with different kinds of mistakes(known and unknown).This can be handled in two ways:
Careful analysing the deviations and write code for it .This means much work and covering only known deviations.
or the quick and dirty route where this approach can be of help , where you interprete the data and  select the "good"values(the adapted chpointsLinserie1)
You create in this way a filtered input array which you can use for further calculation.

Thats my intension

#### wp

• Hero Member
• Posts: 4911
##### Re: snapping points
« Reply #5 on: December 07, 2017, 10:03:25 am »
it works
Does this mean that this issue is fixed for you? I am asking because I did not see any "snapping" effect in your demo.

Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

#### frederic

• Full Member
• Posts: 221
##### Re: snapping points
« Reply #6 on: December 07, 2017, 10:22:46 am »
wp .
it is solved for me.

not snapping?
my interpretation of "snapping" is that when a point is moved close to fixed other point and it is close enough ,it will be attracted to that  fixed point like a magnet.
That has been achieved.
When that is not "snapping" we should change the title of this thread to..........