Skip to content

Commit

Permalink
version 4.1.5 (VCL+FMX)
Browse files Browse the repository at this point in the history
- Fixed TSVGIconImageListBase.Assign
- Fixed TSVGIconImageCollection registration for FMX projects
- Aligned to Image32 version of 14 May 2024
  • Loading branch information
carloBarazzetta committed May 22, 2024
1 parent 3c8d406 commit 310214f
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 163 deletions.
100 changes: 68 additions & 32 deletions Image32/source/Clipper.Core.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(*******************************************************************************
* Author : Angus Johnson *
* Date : 14 February 2024 *
* Date : 3 May 2024 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Purpose : Core Clipper Library module *
Expand Down Expand Up @@ -154,7 +154,8 @@ function IsPositive(const path: TPath64): Boolean; overload;
function IsPositive(const path: TPathD): Boolean; overload;
{$IFDEF INLINING} inline; {$ENDIF}

function __Trunc(val: double): Int64; {$IFDEF INLINE} inline; {$ENDIF}
function IsCollinear(const pt1, pt2, pt3: TPoint64): Boolean;
{$IFDEF INLINING} inline; {$ENDIF}

function CrossProduct(const pt1, pt2, pt3: TPoint64): double; overload;
{$IFDEF INLINING} inline; {$ENDIF}
Expand Down Expand Up @@ -829,6 +830,9 @@ function ScalePath(const path: TPath64; sx, sy: double): TPath64;
begin
result[i].X := Round(path[i].X * sx);
result[i].Y := Round(path[i].Y * sy);
{$IFDEF USINGZ}
result[i].Z := path[i].Z;
{$ENDIF}
end;
end;
//------------------------------------------------------------------------------
Expand All @@ -845,10 +849,16 @@ function ScalePath(const path: TPathD; sx, sy: double): TPath64;
j := 1;
result[0].X := Round(path[0].X * sx);
result[0].Y := Round(path[0].Y * sy);
{$IFDEF USINGZ}
result[0].Z := path[0].Z;
{$ENDIF}
for i := 1 to len -1 do
begin
result[j].X := Round(path[i].X * sx);
result[j].Y := Round(path[i].Y * sy);
{$IFDEF USINGZ}
result[j].Z := path[i].Z;
{$ENDIF}
if (result[j].X <> result[j-1].X) or
(result[j].Y <> result[j-1].Y) then inc(j);
end;
Expand All @@ -866,10 +876,16 @@ function ScalePath(const path: TPath64; scale: double): TPath64;
j := 1;
result[0].X := Round(path[0].X * scale);
result[0].Y := Round(path[0].Y * scale);
{$IFDEF USINGZ}
result[0].Z := path[0].Z;
{$ENDIF}
for i := 1 to len -1 do
begin
result[j].X := Round(path[i].X * scale);
result[j].Y := Round(path[i].Y * scale);
{$IFDEF USINGZ}
result[j].Z := path[i].Z;
{$ENDIF}
if (result[j].X <> result[j-1].X) or
(result[j].Y <> result[j-1].Y) then inc(j);
end;
Expand All @@ -887,6 +903,9 @@ function ScalePath(const path: TPathD; scale: double): TPath64;
begin
result[i].X := Round(path[i].X * scale);
result[i].Y := Round(path[i].Y * scale);
{$IFDEF USINGZ}
result[i].Z := path[i].Z;
{$ENDIF}
end;
end;
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -926,6 +945,9 @@ function ScalePathD(const path: TPath64; sx, sy: double): TPathD;
begin
result[i].X := path[i].X * sx;
result[i].Y := path[i].Y * sy;
{$IFDEF USINGZ}
result[i].Z := path[i].Z;
{$ENDIF}
end;
end;
//------------------------------------------------------------------------------
Expand All @@ -939,6 +961,9 @@ function ScalePathD(const path: TPathD; sx, sy: double): TPathD;
begin
result[i].X := path[i].X * sx;
result[i].Y := path[i].Y * sy;
{$IFDEF USINGZ}
result[i].Z := path[i].Z;
{$ENDIF}
end;
end;
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -989,6 +1014,9 @@ function ScalePathsD(const paths: TPaths64; sx, sy: double): TPathsD;
begin
result[i][j].X := (paths[i][j].X * sx);
result[i][j].Y := (paths[i][j].Y * sy);
{$IFDEF USINGZ}
result[i][j].Z := paths[i][j].Z;
{$ENDIF}
end;
end;
end;
Expand All @@ -1008,6 +1036,9 @@ function ScalePathsD(const paths: TPathsD; sx, sy: double): TPathsD;
begin
result[i][j].X := paths[i][j].X * sx;
result[i][j].Y := paths[i][j].Y * sy;
{$IFDEF USINGZ}
result[i][j].Z := paths[i][j].Z;
{$ENDIF}
end;
end;
end;
Expand Down Expand Up @@ -1103,6 +1134,9 @@ function Path64(const pathD: TPathD): TPath64;
begin
Result[i].X := Round(pathD[i].X);
Result[i].Y := Round(pathD[i].Y);
{$IFDEF USINGZ}
Result[i].Z := pathD[i].Z;
{$ENDIF}
end;
end;
//------------------------------------------------------------------------------
Expand All @@ -1117,6 +1151,9 @@ function PathD(const path: TPath64): TPathD;
begin
Result[i].X := path[i].X;
Result[i].Y := path[i].Y;
{$IFDEF USINGZ}
Result[i].Z := path[i].Z;
{$ENDIF}
end;
end;
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1827,6 +1864,18 @@ function IsPositive(const path: TPathD): Boolean;
end;
//------------------------------------------------------------------------------

{$OVERFLOWCHECKS OFF}
function IsCollinear(const pt1, pt2, pt3: TPoint64): Boolean;
var
a,b: Int64;
begin
a := (pt2.X - pt1.X) * (pt3.Y - pt2.Y);
b := (pt2.Y - pt1.Y) * (pt3.X - pt2.X);
result := a = b;
end;
{$OVERFLOWCHECKS ON}
//------------------------------------------------------------------------------

function CrossProduct(const pt1, pt2, pt3: TPoint64): double;
begin
result := CrossProduct(
Expand Down Expand Up @@ -1925,14 +1974,14 @@ function CleanPath(const path: TPath64): TPath64;
Result := nil;
len := Length(path);
while (len > 2) and
(CrossProduct(path[len-2], path[len-1], path[0]) = 0) do dec(len);
(IsCollinear(path[len-2], path[len-1], path[0])) do dec(len);
SetLength(Result, len);
if (len < 2) then Exit;
prev := path[len -1];
j := 0;
for i := 0 to len -2 do
begin
if CrossProduct(prev, path[i], path[i+1]) = 0 then Continue;
if IsCollinear(prev, path[i], path[i+1]) then Continue;
Result[j] := path[i];
inc(j);
prev := path[i];
Expand All @@ -1942,6 +1991,14 @@ function CleanPath(const path: TPath64): TPath64;
end;
//------------------------------------------------------------------------------

function GetSign(const val: double): integer; {$IFDEF INLINING} inline; {$ENDIF}
begin
if val = 0 then Result := 0
else if val < 0 then Result := -1
else Result := 1;
end;
//------------------------------------------------------------------------------

function SegmentsIntersect(const s1a, s1b, s2a, s2b: TPoint64;
inclusive: Boolean): boolean;
var
Expand All @@ -1961,38 +2018,14 @@ function SegmentsIntersect(const s1a, s1b, s2a, s2b: TPoint64;
(res3 <> 0) or (res4 <> 0); // ensures not collinear
end else
begin
result := (CrossProduct(s1a, s2a, s2b) * CrossProduct(s1b, s2a, s2b) < 0) and
(CrossProduct(s2a, s1a, s1b) * CrossProduct(s2b, s1a, s1b) < 0);
result := (GetSign(CrossProduct(s1a, s2a, s2b)) *
GetSign(CrossProduct(s1b, s2a, s2b)) < 0) and
(GetSign(CrossProduct(s2a, s1a, s1b)) *
GetSign(CrossProduct(s2b, s1a, s1b)) < 0);
end;
end;
//------------------------------------------------------------------------------

function __Trunc(val: double): Int64; {$IFDEF INLINE} inline; {$ENDIF}
var
exp: integer;
i64: UInt64 absolute val;
const
shl51: UInt64 = UInt64(1) shl 51;
begin
Result := 0;
if i64 = 0 then Exit;
exp := Integer(Cardinal(i64 shr 52) and $7FF) - 1023;
//nb: when exp == 1024 then val == INF or NAN.
if exp < 0 then
Exit
else if exp > 52 then
begin
Result := ((i64 and $1FFFFFFFFFFFFF) shl (exp - 52)) or (UInt64(1) shl exp)
end else
begin
Result := ((i64 and $1FFFFFFFFFFFFF) shr (52 - exp)) or (UInt64(1) shl exp);
//the following line will round
//if (i64 and (shl51 shr (exp)) <> 0) then inc(Result);
end;
if val < 0 then Result := -Result;
end;
//------------------------------------------------------------------------------

function GetSegmentIntersectPt(const ln1a, ln1b, ln2a, ln2b: TPoint64;
out ip: TPoint64): Boolean;
var
Expand All @@ -2011,6 +2044,9 @@ function GetSegmentIntersectPt(const ln1a, ln1b, ln2a, ln2b: TPoint64;
else if t >= 1.0 then ip := ln1b;
ip.X := Trunc(ln1a.X + t * dx1);
ip.Y := Trunc(ln1a.Y + t * dy1);
{$IFDEF USINGZ}
ip.Z := 0;
{$ENDIF}
end;
//------------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit 310214f

Please sign in to comment.