Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // data point it TRectF
- // all y values are >= 0
- // http://stackoverflow.com/questions/17641308
- // very generic framework - suboptimal in many many senses.
- // in other words - no "premature optimization" :-)
- // and not testing - just drafting
- type
- PropagationConfig = record
- x_delta, y_delta: single;
- poly_coeff: array of single; // p[0]*x^0 + p[1]*x^2 + p[2]*x^4 + ...
- end;
- // the programmer should fill those values to his tastes of what is beautiful or purposeful
- function EnrichData(const Input: any stream of TRectF): same as input stream of TRectF;
- begin
- for every pair of data points in Input
- do emit into Result ( EnrichPair( datapoint 1, datapoint 2, propagation config ) );
- end;
- function EnrichPair( dp1, dp2: TRectF; const config: propagationconfig): array of TRectF;
- var tempDP: TRectF;
- begin
- if dp1.x = dp2.x then begin
- SetLength(Result,1);
- Result[0].x := dp1.x;
- Result[0].y := Max(dp1.y, dp2.y);
- Exit;
- end;
- if dp1.x > dp2.x then begin
- tempDP := dp1; dp1 := dp2; dp2 := tempDP;
- end;
- if dp2.x - dp1.x <= config.x_delta then begin
- SetLength(Result,2);
- Result[0] := dp1;
- Result[1] := dp2;
- Exit;
- end;
- SetLength(Result, 1 + Ceil(dp2.x - dp1.x) );
- Result[Low(Result)] := dp1; Result[High(Result)] := dp2;
- for i := Low(Result) + 1 to High(Result) - 1 do begin
- Result[i].x := Result [i-1].x + config.x_delta;
- Result[i].y := 0;
- end;
- for i := Low(Result) + 1 to High(Result) - 1 do begin
- Result[i].y := Estimate(dp1, Result[i].x, config);
- if Result[i].y < config.y_delta then break; // too far from peak - no more traces
- end;
- for i := High(Result) - 1 downto Low(Result) + 1 do begin
- y := Estimate(dp2, Result[i].x, config);
- if Result[i].y > y then break; // adjacent peak has more influence here
- Result[i].y := y;
- if Result[i].y < config.y_delta then break; // too far from peak - no more traces
- end;
- end;
- function Estimate(const peak: TRectF; const place: single; const config: PropagationConfig): single;
- var delta: single; i: integer;
- begin
- delta := abs(place - peak.x);
- if delta = 0 then Exit(peak.y);
- Result := 0;
- for i := Low(config.poly_coeff) to High(config.poly_coeff) do
- Result := Result + config.poly_coeff[i - Low(config.poly_coeff)] *
- Power(1 + delta , 2 * ( i - Low(config.poly_coeff) ) );
- Result := peak.y / Result; // fall down from peak to the sides
- end;
Add Comment
Please, Sign In to add comment