GR32_VectorUtils.Reference.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. unit GR32_VectorUtils.Reference;
  2. (* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1 or LGPL 2.1 with linking exception
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * Alternatively, the contents of this file may be used under the terms of the
  16. * Free Pascal modified version of the GNU Lesser General Public License
  17. * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
  18. * of this license are applicable instead of those above.
  19. * Please see the file LICENSE.txt for additional information concerning this
  20. * license.
  21. *
  22. * The Original Code is Polyline builder for Graphics32
  23. *
  24. * The Initial Developer of the Original Code is
  25. * Mattias Andersson <[email protected]>
  26. * Angus Johnson (http://www.angusj.com)
  27. *
  28. * Portions created by the Initial Developer are Copyright (C) 2008-2012
  29. * the Initial Developer. All Rights Reserved.
  30. *
  31. * ***** END LICENSE BLOCK ***** *)
  32. interface
  33. {$include GR32.inc}
  34. {$BOOLEVAL OFF}
  35. uses
  36. GR32,
  37. GR32_VectorUtils,
  38. GR32_Polygons;
  39. //------------------------------------------------------------------------------
  40. //
  41. // PolyLineBuilderReference
  42. //
  43. //------------------------------------------------------------------------------
  44. // Old implementation of the Grow and BuildPoly*line functions.
  45. //------------------------------------------------------------------------------
  46. // Note: Does not currently support JoinStyle=jsSquare; jsBevel is used instead.
  47. //------------------------------------------------------------------------------
  48. type
  49. PolyLineBuilderReference = class(TPolyLineBuilder)
  50. private
  51. class function BuildLineEnd(const P, N: TFloatPoint; const W: TFloat; EndStyle: TEndStyle): TArrayOfFloatPoint; overload; static;
  52. class function BuildLineEnd(const P, N: TFixedPoint; const W: TFixed; EndStyle: TEndStyle): TArrayOfFixedPoint; overload; static;
  53. public
  54. class function SupportedJoinStyles: TJoinStyles; override;
  55. class function SupportedEndStyles: TEndStyles; override;
  56. // Float
  57. class function Grow(const Points: TArrayOfFloatPoint; const Normals: TArrayOfFloatPoint; const Delta: TFloat; JoinStyle: TJoinStyle = jsMiter; Closed: Boolean = True; MiterLimit: TFloat = DEFAULT_MITER_LIMIT): TArrayOfFloatPoint; overload; override;
  58. // Float
  59. class function BuildPolyLine(const Points: TArrayOfFloatPoint; StrokeWidth: TFloat; JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt; MiterLimit: TFloat = DEFAULT_MITER_LIMIT): TArrayOfFloatPoint; overload; override;
  60. class function BuildPolyPolyLine(const Points: TArrayOfArrayOfFloatPoint; Closed: Boolean; StrokeWidth: TFloat; JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt; MiterLimit: TFloat = DEFAULT_MITER_LIMIT): TArrayOfArrayOfFloatPoint; overload; override;
  61. // Fixed
  62. class function BuildPolyLine(const Points: TArrayOfFixedPoint; StrokeWidth: TFixed; JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt; MiterLimit: TFixed = DEFAULT_MITER_LIMIT_FIXED): TArrayOfFixedPoint; overload; override;
  63. class function BuildPolyPolyLine(const Points: TArrayOfArrayOfFixedPoint; Closed: Boolean; StrokeWidth: TFixed; JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt; MiterLimit: TFixed = DEFAULT_MITER_LIMIT_FIXED): TArrayOfArrayOfFixedPoint; overload; override;
  64. end;
  65. //------------------------------------------------------------------------------
  66. //------------------------------------------------------------------------------
  67. //------------------------------------------------------------------------------
  68. implementation
  69. uses
  70. Math,
  71. Types,
  72. GR32_Math,
  73. GR32_Geometry,
  74. GR32_LowLevel;
  75. //------------------------------------------------------------------------------
  76. class function PolyLineBuilderReference.SupportedEndStyles: TEndStyles;
  77. begin
  78. Result := [esButt, esSquare, esRound];
  79. end;
  80. class function PolyLineBuilderReference.SupportedJoinStyles: TJoinStyles;
  81. begin
  82. Result := [jsMiter, jsBevel, jsRound, jsRoundEx];
  83. end;
  84. //------------------------------------------------------------------------------
  85. class function PolyLineBuilderReference.Grow(const Points: TArrayOfFloatPoint; const Normals: TArrayOfFloatPoint;
  86. const Delta: TFloat; JoinStyle: TJoinStyle; Closed: Boolean; MiterLimit: TFloat): TArrayOfFloatPoint;
  87. const
  88. BUFFSIZEINCREMENT = 128;
  89. MINDISTPIXEL = 1.414; // just a little bit smaller than sqrt(2),
  90. // -> set to about 2.5 for a similar output with the previous version
  91. var
  92. I, L, H: Integer;
  93. ResultSize, BufferSize: Integer;
  94. PX, PY: TFloat;
  95. AngleInv, RMin: TFloat;
  96. A, B, Dm: TFloatPoint;
  97. InvMiterLimit: TFloat;
  98. procedure AddPoint(const DeltaX, DeltaY: TFloat); overload;
  99. begin
  100. if (ResultSize = BufferSize) then
  101. begin
  102. Inc(BufferSize, BUFFSIZEINCREMENT);
  103. SetLength(Result, BufferSize);
  104. end;
  105. Result[ResultSize] := FloatPoint(PX + DeltaX, PY + DeltaY);
  106. Inc(ResultSize);
  107. end;
  108. procedure AddPoint(const Delta: TFloatPoint); overload;
  109. begin
  110. if (ResultSize = BufferSize) then
  111. begin
  112. Inc(BufferSize, BUFFSIZEINCREMENT);
  113. SetLength(Result, BufferSize);
  114. end;
  115. Result[ResultSize] := FloatPoint(PX + Delta.X, PY + Delta.Y);
  116. Inc(ResultSize);
  117. end;
  118. procedure AddMitered(const P1, P2: TFloatPoint);
  119. var
  120. R, CX, CY: TFloat;
  121. begin
  122. CX := P1.X + P2.X;
  123. CY := P1.Y + P2.Y;
  124. R := P1.X * CX + P1.Y * CY; //(1 - cos(?)) (range: 0 <= R <= 2)
  125. if (R < RMin) then
  126. begin
  127. AddPoint(Delta * P1.X, Delta * P1.Y);
  128. AddPoint(Delta * P2.X, Delta * P2.Y);
  129. end else
  130. begin
  131. R := Delta / R;
  132. AddPoint(CX * R, CY * R)
  133. end;
  134. end;
  135. procedure AddBevelled(const P1, P2: TFloatPoint);
  136. var
  137. R: TFloat;
  138. begin
  139. R := CrossProduct(P1, P2);
  140. if (R * Delta <= 0) then // ie angle is concave
  141. AddMitered(P1, P2)
  142. else
  143. begin
  144. AddPoint(Delta * P1.X, Delta * P1.Y);
  145. AddPoint(Delta * P2.X, Delta * P2.Y);
  146. end;
  147. end;
  148. procedure AddRoundedJoin(const P1, P2: TFloatPoint);
  149. var
  150. SinA, CosA, A: TFloat;
  151. Steps: Integer;
  152. ii: Integer;
  153. C: TFloatPoint;
  154. d: TFloat;
  155. m,n: Integer;
  156. C2, C3: TFloatPoint;
  157. SignA: Cardinal absolute Delta;
  158. SignB: Cardinal absolute SinA;
  159. begin
  160. SinA := CrossProduct(P1, P2);
  161. CosA := Dot(P1, P2);
  162. A := ArcTan2(SinA, CosA);
  163. Steps := Round(Abs(A * AngleInv));
  164. if (SinA < 0) then
  165. Dm.Y := -Abs(Dm.Y)
  166. else
  167. Dm.Y := Abs(Dm.Y);
  168. //
  169. // (SignA and $80000000) <> (SignB and $80000000) is a fast test for (SinA * Delta < 0).
  170. // It tests if the sign-bit of the two 32-bit Single values are the same.
  171. //
  172. // (SinA * Delta < 0) =>
  173. // Sign(SinA) <> Sign(Delta)
  174. //
  175. if ((SignA and $80000000) <> (SignB and $80000000)) and ((SignB and (not $80000000)) <> 0) then
  176. begin // ie angle is concave
  177. // Compute the inner arc for the jsRoundEx join style (both inner
  178. // and outer vertex rounded).
  179. A := Delta / (CosA +1);
  180. // C = offset pt of concave vertex ...
  181. C.X := PX + (P1.X + P2.X) * A;
  182. C.Y := PY + (P1.Y + P2.Y) * A;
  183. if (I = 0) then
  184. m := H
  185. else
  186. m := I-1;
  187. if (I = H) then
  188. n := 0
  189. else
  190. n := I+1;
  191. A := Min(SqrDistance(Points[m], Points[I]), SqrDistance(Points[n], Points[I]));
  192. if (SqrDistance(C, Points[I]) > A) then
  193. begin
  194. // There's no room to draw anything ...
  195. // This will create a self-intersection but it also ensures that
  196. // the offset will be maintained beyond this intersection ...
  197. AddPoint(Delta * P1.X, Delta * P1.Y);
  198. AddPoint(Delta * P2.X, Delta * P2.Y);
  199. Exit;
  200. end;
  201. A := Sqrt(A);
  202. // Get the points on both edges that's same distance from
  203. // the concave vertex as its closest adjacent vertex.
  204. // nb: using unit normals as unit vectors here ...
  205. C2.X := PX + P1.Y * A;
  206. C2.Y := PY - P1.X * A;
  207. C3.X := PX - P2.Y * A;
  208. C3.Y := PY + P2.X * A;
  209. // Now Delta offset these points ...
  210. C2.X := C2.X + P1.X * Delta;
  211. C2.Y := C2.Y + P1.Y * Delta;
  212. C3.X := C3.X + P2.X * Delta;
  213. C3.Y := C3.Y + P2.Y * Delta;
  214. // This will do Delta/MiterLimit radius rounding of concavities ...
  215. A := SqrDistance(C2, C3);
  216. d := Delta * InvMiterLimit;
  217. if (A < Sqr(d * 3)) then
  218. d := -Sqrt(A) / 3;
  219. // Move point(PX,PY) across the offset path so the
  220. // rounding path will curve around this new point ...
  221. A := (d + Delta) / (CosA +1);
  222. PX := PX + (P1.X + P2.X) * A;
  223. PY := PY + (P1.Y + P2.Y) * A;
  224. // Start of arc
  225. C.X := -P1.X * d;
  226. C.Y := -P1.Y * d;
  227. AddPoint(C);
  228. // Arc
  229. for ii := 1 to Steps -1 do
  230. begin
  231. C := FloatPoint(
  232. C.X * Dm.X - C.Y * Dm.Y,
  233. C.X * Dm.Y + C.Y * Dm.X);
  234. AddPoint(C);
  235. end;
  236. // End of arc
  237. if (P1 <> P2) then
  238. begin
  239. C.X := -P2.X * d;
  240. C.Y := -P2.Y * d;
  241. AddPoint(C);
  242. end;
  243. end else
  244. begin
  245. // Start of arc
  246. C.X := P1.X * Delta;
  247. C.Y := P1.Y * Delta;
  248. AddPoint(C);
  249. // Arc
  250. for ii := 1 to Steps - 1 do
  251. begin
  252. C := FloatPoint(
  253. C.X * Dm.X - C.Y * Dm.Y,
  254. C.Y * Dm.X + C.X * Dm.Y);
  255. AddPoint(C);
  256. end;
  257. // End of arc
  258. if (P1 <> P2) then
  259. begin
  260. C.X := P2.X * Delta;
  261. C.Y := P2.Y * Delta;
  262. AddPoint(C);
  263. end;
  264. end;
  265. end;
  266. procedure AddJoin(const P, PA, PB: TFloatPoint);
  267. begin
  268. PX := P.X;
  269. PY := P.Y;
  270. if (JoinStyle <> jsRoundEx) and (CrossProduct(PA, PB) * Delta < 0) then
  271. begin
  272. // Concave angle
  273. AddPoint(Delta * PA.X, Delta * PA.Y);
  274. AddPoint(0, 0); // Current corner. See #106, #185
  275. AddPoint(Delta * PB.X, Delta * PB.Y);
  276. end else
  277. case JoinStyle of
  278. jsMiter: AddMitered(A, B);
  279. jsSquare,
  280. jsBevel: AddBevelled(A, B);
  281. jsRoundEx,
  282. jsRound: AddRoundedJoin(A, B);
  283. end;
  284. end;
  285. begin
  286. Result := nil;
  287. if (Length(Points) <= 1) then
  288. Exit;
  289. if (IsZero(Delta)) then
  290. Exit(Points);
  291. if (MiterLimit > 0) then
  292. InvMiterLimit := 1 / MiterLimit
  293. else
  294. InvMiterLimit := 0;
  295. RMin := 2 * Sqr(InvMiterLimit);
  296. H := High(Points) - Ord(not Closed);
  297. while (H >= 0) and (Normals[H].X = 0) and (Normals[H].Y = 0) do
  298. Dec(H);
  299. // All normals zeroed => Exit
  300. if H < 0 then
  301. Exit;
  302. L := 0;
  303. while (Normals[L].X = 0) and (Normals[L].Y = 0) do
  304. Inc(L);
  305. ResultSize := 0;
  306. BufferSize := BUFFSIZEINCREMENT;
  307. SetLength(Result, BufferSize);
  308. // prepare
  309. if (JoinStyle in [jsRound, jsRoundEx]) then
  310. begin
  311. Dm.X := 1 - 0.5 * Min(3, Sqr(MINDISTPIXEL / Abs(Delta)));
  312. Dm.Y := Sqrt(1 - Sqr(Dm.X));
  313. AngleInv := 1 / ArcCos(Dm.X);
  314. end;
  315. if Closed then
  316. A := Normals[H]
  317. else
  318. A := Normals[L];
  319. for I := L to H do
  320. begin
  321. B := Normals[I];
  322. if (B.X = 0) and (B.Y = 0) then
  323. Continue;
  324. AddJoin(Points[I], A, B);
  325. A := B;
  326. end;
  327. if (not Closed) then
  328. AddJoin(Points[High(Points)], A, A);
  329. SetLength(Result, ResultSize);
  330. end;
  331. //------------------------------------------------------------------------------
  332. class function PolyLineBuilderReference.BuildLineEnd(const P, N: TFloatPoint; const W: TFloat; EndStyle: TEndStyle): TArrayOfFloatPoint;
  333. var
  334. a1, a2: TFloat;
  335. begin
  336. case EndStyle of
  337. esButt:
  338. begin
  339. Result := nil;
  340. end;
  341. esSquare:
  342. begin
  343. SetLength(Result, 2);
  344. Result[0].X := P.X + (N.X - N.Y) * W;
  345. Result[0].Y := P.Y + (N.Y + N.X) * W;
  346. Result[1].X := P.X - (N.X + N.Y) * W;
  347. Result[1].Y := P.Y - (N.Y - N.X) * W;
  348. end;
  349. esRound:
  350. begin
  351. a1 := ArcTan2(N.Y, N.X);
  352. a2 := ArcTan2(-N.Y, -N.X);
  353. if a2 < a1 then
  354. a2 := a2 + TWOPI;
  355. Result := BuildArc(P, a1, a2, W);
  356. end;
  357. end;
  358. end;
  359. class function PolyLineBuilderReference.BuildLineEnd(const P, N: TFixedPoint; const W: TFixed; EndStyle: TEndStyle): TArrayOfFixedPoint;
  360. var
  361. a1, a2: TFloat;
  362. begin
  363. case EndStyle of
  364. esButt:
  365. begin
  366. Result := nil;
  367. end;
  368. esSquare:
  369. begin
  370. SetLength(Result, 2);
  371. Result[0].X := P.X + (N.X - N.Y) * W;
  372. Result[0].Y := P.Y + (N.Y + N.X) * W;
  373. Result[1].X := P.X - (N.X + N.Y) * W;
  374. Result[1].Y := P.Y - (N.Y - N.X) * W;
  375. end;
  376. esRound:
  377. begin
  378. a1 := ArcTan2(N.Y, N.X);
  379. a2 := ArcTan2(-N.Y, -N.X);
  380. if a2 < a1 then
  381. a2 := a2 + TWOPI;
  382. Result := BuildArc(P, a1, a2, W);
  383. end;
  384. end;
  385. end;
  386. //------------------------------------------------------------------------------
  387. class function PolyLineBuilderReference.BuildPolyLine(const Points: TArrayOfFloatPoint; StrokeWidth: TFloat;
  388. JoinStyle: TJoinStyle; EndStyle: TEndStyle; MiterLimit: TFloat): TArrayOfFloatPoint;
  389. var
  390. L, H: Integer;
  391. Normals: TArrayOfFloatPoint;
  392. P1, P2, E1, E2: TArrayOfFloatPoint;
  393. V: TFloat;
  394. P: PFloatPoint;
  395. begin
  396. Result := nil;
  397. V := StrokeWidth * 0.5;
  398. Normals := BuildNormals(Points);
  399. H := High(Points) - 1;
  400. while (H >= 0) and (Normals[H].X = 0) and (Normals[H].Y = 0) do
  401. Dec(H);
  402. // All normals zeroed => Exit
  403. if H < 0 then
  404. Exit;
  405. L := 0;
  406. while (Normals[L].X = 0) and (Normals[L].Y = 0) do
  407. Inc(L);
  408. P1 := Grow(Points, Normals, V, JoinStyle, False, MiterLimit);
  409. P2 := ReversePolygon(Grow(Points, Normals, -V, JoinStyle, False, MiterLimit));
  410. E1 := BuildLineEnd(Points[0], Normals[L], -V, EndStyle);
  411. E2 := BuildLineEnd(Points[High(Points)], Normals[H], V, EndStyle);
  412. SetLength(Result, Length(P1) + Length(P2) + Length(E1) + Length(E2));
  413. P := @Result[0];
  414. Move(E1[0], P^, Length(E1) * SizeOf(TFloatPoint)); Inc(P, Length(E1));
  415. Move(P1[0], P^, Length(P1) * SizeOf(TFloatPoint)); Inc(P, Length(P1));
  416. Move(E2[0], P^, Length(E2) * SizeOf(TFloatPoint)); Inc(P, Length(E2));
  417. Move(P2[0], P^, Length(P2) * SizeOf(TFloatPoint));
  418. end;
  419. //------------------------------------------------------------------------------
  420. class function PolyLineBuilderReference.BuildPolyPolyLine(const Points: TArrayOfArrayOfFloatPoint;
  421. Closed: Boolean; StrokeWidth: TFloat; JoinStyle: TJoinStyle;
  422. EndStyle: TEndStyle; MiterLimit: TFloat): TArrayOfArrayOfFloatPoint;
  423. var
  424. I: Integer;
  425. P1, P2: TArrayOfFloatPoint;
  426. Dst: TArrayOfArrayOfFloatPoint;
  427. Normals: TArrayOfFloatPoint;
  428. HalfStrokeWidth: TFloat;
  429. begin
  430. if Closed then
  431. begin
  432. SetLength(Dst, Length(Points) * 2);
  433. HalfStrokeWidth := StrokeWidth * 0.5;
  434. for I := 0 to High(Points) do
  435. begin
  436. Normals := BuildNormals(Points[I]);
  437. P1 := Grow(Points[I], Normals, HalfStrokeWidth, JoinStyle, True, MiterLimit);
  438. P2 := Grow(Points[I], Normals, -HalfStrokeWidth, JoinStyle, True, MiterLimit);
  439. Dst[I * 2] := P1;
  440. Dst[I * 2 + 1] := ReversePolygon(P2);
  441. end;
  442. end else
  443. begin
  444. SetLength(Dst, Length(Points));
  445. for I := 0 to High(Points) do
  446. Dst[I] := BuildPolyLine(Points[I], StrokeWidth, JoinStyle, EndStyle, MiterLimit);
  447. end;
  448. Result := Dst;
  449. end;
  450. //------------------------------------------------------------------------------
  451. class function PolyLineBuilderReference.BuildPolyLine(const Points: TArrayOfFixedPoint; StrokeWidth: TFixed;
  452. JoinStyle: TJoinStyle; EndStyle: TEndStyle; MiterLimit: TFixed): TArrayOfFixedPoint;
  453. var
  454. L, H: Integer;
  455. Normals: TArrayOfFixedPoint;
  456. P1, P2, E1, E2: TArrayOfFixedPoint;
  457. V: TFixed;
  458. P: PFixedPoint;
  459. begin
  460. Result := nil;
  461. V := StrokeWidth shr 1;
  462. Normals := BuildNormals(Points);
  463. H := High(Points) - 1;
  464. while (H >= 0) and (Normals[H].X = 0) and (Normals[H].Y = 0) do
  465. Dec(H);
  466. if H < 0 then
  467. Exit;
  468. L := 0;
  469. while (Normals[L].X = 0) and (Normals[L].Y = 0) do
  470. Inc(L);
  471. P1 := Grow(Points, Normals, V, JoinStyle, False, MiterLimit);
  472. P2 := ReversePolygon(Grow(Points, Normals, -V, JoinStyle, False, MiterLimit));
  473. E1 := BuildLineEnd(Points[0], Normals[L], -V, EndStyle);
  474. E2 := BuildLineEnd(Points[High(Points)], Normals[H], V, EndStyle);
  475. SetLength(Result, Length(P1) + Length(P2) + Length(E1) + Length(E2));
  476. P := @Result[0];
  477. Move(E1[0], P^, Length(E1) * SizeOf(TFixedPoint)); Inc(P, Length(E1));
  478. Move(P1[0], P^, Length(P1) * SizeOf(TFixedPoint)); Inc(P, Length(P1));
  479. Move(E2[0], P^, Length(E2) * SizeOf(TFixedPoint)); Inc(P, Length(E2));
  480. Move(P2[0], P^, Length(P2) * SizeOf(TFixedPoint));
  481. end;
  482. //------------------------------------------------------------------------------
  483. class function PolyLineBuilderReference.BuildPolyPolyLine(const Points: TArrayOfArrayOfFixedPoint;
  484. Closed: Boolean; StrokeWidth: TFixed; JoinStyle: TJoinStyle;
  485. EndStyle: TEndStyle; MiterLimit: TFixed): TArrayOfArrayOfFixedPoint;
  486. var
  487. I: Integer;
  488. P1, P2: TArrayOfFixedPoint;
  489. Dst: TArrayOfArrayOfFixedPoint;
  490. Normals: TArrayOfFixedPoint;
  491. HalfStrokeWidth: TFixed;
  492. begin
  493. if Closed then
  494. begin
  495. SetLength(Dst, Length(Points) * 2);
  496. HalfStrokeWidth := StrokeWidth shr 1;
  497. for I := 0 to High(Points) do
  498. begin
  499. Normals := BuildNormals(Points[I]);
  500. P1 := Grow(Points[I], Normals, HalfStrokeWidth, JoinStyle, True, MiterLimit);
  501. P2 := Grow(Points[I], Normals, -HalfStrokeWidth, JoinStyle, True, MiterLimit);
  502. Dst[I * 2] := P1;
  503. Dst[I * 2 + 1] := ReversePolygon(P2);
  504. end;
  505. end else
  506. begin
  507. SetLength(Dst, Length(Points));
  508. for I := 0 to High(Points) do
  509. Dst[I] := BuildPolyLine(Points[I], StrokeWidth, JoinStyle, EndStyle);
  510. end;
  511. Result := Dst;
  512. end;
  513. //------------------------------------------------------------------------------
  514. end.