GraphicsPathTest.cs 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. //
  2. // System.Drawing.GraphicsPath unit tests
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using SC = System.ComponentModel;
  30. using System.Drawing;
  31. using System.Drawing.Drawing2D;
  32. using System.Security.Permissions;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Drawing.Drawing2D {
  35. [TestFixture]
  36. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  37. public class GraphicsPathTest {
  38. private const float Pi4 = (float) (Math.PI / 4);
  39. // let's tolerate a few differences
  40. private const float Delta = 0.0003f;
  41. private void CheckEmpty (string prefix, GraphicsPath gp)
  42. {
  43. Assert.AreEqual (0, gp.PathData.Points.Length, "PathData.Points");
  44. Assert.AreEqual (0, gp.PathData.Types.Length, "PathData.Types");
  45. Assert.AreEqual (0, gp.PointCount, prefix + "PointCount");
  46. }
  47. [Test]
  48. public void Constructor_InvalidFillMode ()
  49. {
  50. GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MinValue);
  51. Assert.AreEqual (Int32.MinValue, (int) gp.FillMode, "FillMode");
  52. CheckEmpty ("InvalidFillMode.", gp);
  53. }
  54. [Test]
  55. [ExpectedException (typeof (ArgumentNullException))]
  56. public void Constructor_Point_Null_Byte ()
  57. {
  58. new GraphicsPath ((Point[]) null, new byte[1]);
  59. }
  60. [Test]
  61. [ExpectedException (typeof (NullReferenceException))]
  62. public void Constructor_Point_Byte_Null ()
  63. {
  64. new GraphicsPath (new Point[1], null);
  65. }
  66. [Test]
  67. [ExpectedException (typeof (ArgumentException))]
  68. public void Constructor_Point_Byte_LengthMismatch ()
  69. {
  70. new GraphicsPath (new Point[1], new byte [2]);
  71. }
  72. [Test]
  73. [ExpectedException (typeof (ArgumentNullException))]
  74. public void Constructor_PointF_Null_Byte ()
  75. {
  76. new GraphicsPath ((PointF[])null, new byte [1]);
  77. }
  78. [Test]
  79. [ExpectedException (typeof (NullReferenceException))]
  80. public void Constructor_PointF_Byte_Null ()
  81. {
  82. new GraphicsPath ( new PointF[1], null);
  83. }
  84. [Test]
  85. [ExpectedException (typeof (ArgumentException))]
  86. public void Constructor_PointF_Byte_LengthMismatch ()
  87. {
  88. new GraphicsPath (new PointF[2], new byte [1]);
  89. }
  90. [Test]
  91. public void GraphicsPath_Empty ()
  92. {
  93. GraphicsPath gp = new GraphicsPath ();
  94. Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Empty.FillMode");
  95. CheckEmpty ("Empty.", gp);
  96. GraphicsPath clone = (GraphicsPath) gp.Clone ();
  97. Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Clone.FillMode");
  98. CheckEmpty ("Clone.", gp);
  99. }
  100. [Test]
  101. [ExpectedException (typeof (ArgumentException))]
  102. public void GraphicsPath_Empty_PathPoints ()
  103. {
  104. Assert.IsNull (new GraphicsPath ().PathPoints);
  105. }
  106. [Test]
  107. [ExpectedException (typeof (ArgumentException))]
  108. public void GraphicsPath_Empty_PathTypes ()
  109. {
  110. Assert.IsNull (new GraphicsPath ().PathTypes);
  111. }
  112. [Test]
  113. [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
  114. public void FillMode_Invalid ()
  115. {
  116. // constructor accept an invalid FillMode
  117. GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
  118. Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
  119. // but you can't set the FillMode property to an invalid value ;-)
  120. gp.FillMode = (FillMode) Int32.MaxValue;
  121. }
  122. [Test]
  123. public void PathData_CannotChange ()
  124. {
  125. GraphicsPath gp = new GraphicsPath ();
  126. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  127. Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
  128. Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
  129. // now try to change the first point
  130. gp.PathData.Points[0] = new Point (0, 0);
  131. // the changes isn't reflected in the property
  132. Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
  133. Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
  134. }
  135. [Test]
  136. public void PathPoints_CannotChange ()
  137. {
  138. GraphicsPath gp = new GraphicsPath ();
  139. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  140. Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
  141. Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
  142. // now try to change the first point
  143. gp.PathPoints[0] = new Point (0, 0);
  144. // the changes isn't reflected in the property
  145. Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
  146. Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
  147. }
  148. [Test]
  149. public void PathTypes_CannotChange ()
  150. {
  151. GraphicsPath gp = new GraphicsPath ();
  152. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  153. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
  154. // now try to change the first type
  155. gp.PathTypes[0] = 1;
  156. // the changes isn't reflected in the property
  157. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
  158. }
  159. private void CheckArc (GraphicsPath path)
  160. {
  161. Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
  162. Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
  163. Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
  164. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  165. RectangleF rect = path.GetBounds ();
  166. Assert.AreEqual (2.999624f, rect.X, "Bounds.X");
  167. Assert.AreEqual (2.013707f, rect.Y, "Bounds.Y");
  168. Assert.AreEqual (0f, rect.Width, Delta, "Bounds.Width");
  169. Assert.AreEqual (0.01370478f, rect.Height, "Bounds.Height");
  170. Assert.AreEqual (2.999906f, path.PathData.Points[0].X, "Points[0].X");
  171. Assert.AreEqual (2.013707f, path.PathPoints[0].Y, "Points[0].Y");
  172. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  173. Assert.AreEqual (2.999843f, path.PathData.Points[1].X, "Points[1].X");
  174. Assert.AreEqual (2.018276f, path.PathPoints[1].Y, "Points[1].Y");
  175. Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
  176. Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, "Points[2].X");
  177. Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, "Points[2].Y");
  178. Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
  179. Assert.AreEqual (2.999624f, path.PathData.Points[3].X, "Points[3].X");
  180. Assert.AreEqual (2.027412f, path.PathPoints[3].Y, "Points[3].Y");
  181. Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
  182. }
  183. [Test]
  184. public void AddArc_Rectangle ()
  185. {
  186. GraphicsPath gp = new GraphicsPath ();
  187. gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
  188. CheckArc (gp);
  189. }
  190. [Test]
  191. public void AddArc_RectangleF ()
  192. {
  193. GraphicsPath gp = new GraphicsPath ();
  194. gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
  195. CheckArc (gp);
  196. }
  197. [Test]
  198. public void AddArc_Int ()
  199. {
  200. GraphicsPath gp = new GraphicsPath ();
  201. gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
  202. CheckArc (gp);
  203. }
  204. [Test]
  205. public void AddArc_Float ()
  206. {
  207. GraphicsPath gp = new GraphicsPath ();
  208. gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
  209. CheckArc (gp);
  210. }
  211. private void CheckBezier (GraphicsPath path)
  212. {
  213. Assert.AreEqual (4, path.PointCount, "PointCount");
  214. Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
  215. Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
  216. Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
  217. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  218. RectangleF rect = path.GetBounds ();
  219. Assert.AreEqual (1f, rect.X, "Bounds.X");
  220. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  221. Assert.AreEqual (3f, rect.Width, "Bounds.Width");
  222. Assert.AreEqual (3f, rect.Height, "Bounds.Height");
  223. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  224. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  225. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  226. Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
  227. Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
  228. Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
  229. Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
  230. Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
  231. Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
  232. Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
  233. Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
  234. Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
  235. }
  236. [Test]
  237. public void AddBezier_Point ()
  238. {
  239. GraphicsPath gp = new GraphicsPath ();
  240. gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
  241. CheckBezier (gp);
  242. }
  243. [Test]
  244. public void AddBezier_PointF ()
  245. {
  246. GraphicsPath gp = new GraphicsPath ();
  247. gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
  248. CheckBezier (gp);
  249. }
  250. [Test]
  251. public void AddBezier_Int ()
  252. {
  253. GraphicsPath gp = new GraphicsPath ();
  254. gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
  255. CheckBezier (gp);
  256. }
  257. [Test]
  258. public void AddBezier_Float ()
  259. {
  260. GraphicsPath gp = new GraphicsPath ();
  261. gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
  262. CheckBezier (gp);
  263. }
  264. [Test]
  265. [ExpectedException (typeof (ArgumentNullException))]
  266. public void AddBeziers_Point_Null ()
  267. {
  268. new GraphicsPath ().AddBeziers ((Point[]) null);
  269. }
  270. [Test]
  271. [ExpectedException (typeof (ArgumentException))]
  272. public void AddBeziers_3_Points ()
  273. {
  274. GraphicsPath gp = new GraphicsPath ();
  275. gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  276. }
  277. [Test]
  278. public void AddBeziers_Point ()
  279. {
  280. GraphicsPath gp = new GraphicsPath ();
  281. gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
  282. CheckBezier (gp);
  283. }
  284. [Test]
  285. [ExpectedException (typeof (ArgumentNullException))]
  286. public void AddBeziers_PointF_Null ()
  287. {
  288. new GraphicsPath ().AddBeziers ((PointF[]) null);
  289. }
  290. [Test]
  291. [ExpectedException (typeof (ArgumentException))]
  292. public void AddBeziers_3_PointFs ()
  293. {
  294. GraphicsPath gp = new GraphicsPath ();
  295. gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
  296. }
  297. [Test]
  298. public void AddBeziers_PointF ()
  299. {
  300. GraphicsPath gp = new GraphicsPath ();
  301. gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
  302. CheckBezier (gp);
  303. }
  304. private void CheckEllipse (GraphicsPath path)
  305. {
  306. Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
  307. Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
  308. Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
  309. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  310. RectangleF rect = path.GetBounds ();
  311. Assert.AreEqual (1f, rect.X, "Bounds.X");
  312. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  313. Assert.AreEqual (2f, rect.Width, "Bounds.Width");
  314. Assert.AreEqual (2f, rect.Height, "Bounds.Height");
  315. Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
  316. for (int i = 1; i < 12; i++)
  317. Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
  318. Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
  319. }
  320. [Test]
  321. public void AddEllipse_Rectangle ()
  322. {
  323. GraphicsPath gp = new GraphicsPath ();
  324. gp.AddEllipse (new Rectangle (1, 1, 2, 2));
  325. CheckEllipse (gp);
  326. }
  327. [Test]
  328. public void AddEllipse_RectangleF ()
  329. {
  330. GraphicsPath gp = new GraphicsPath ();
  331. gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
  332. CheckEllipse (gp);
  333. }
  334. [Test]
  335. public void AddEllipse_Int ()
  336. {
  337. GraphicsPath gp = new GraphicsPath ();
  338. gp.AddEllipse (1, 1, 2, 2);
  339. CheckEllipse (gp);
  340. }
  341. [Test]
  342. public void AddEllipse_Float ()
  343. {
  344. GraphicsPath gp = new GraphicsPath ();
  345. gp.AddEllipse (1f, 1f, 2f, 2f);
  346. CheckEllipse (gp);
  347. }
  348. private void CheckLine (GraphicsPath path)
  349. {
  350. Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
  351. Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
  352. Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
  353. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  354. RectangleF rect = path.GetBounds ();
  355. Assert.AreEqual (1f, rect.X, "Bounds.X");
  356. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  357. Assert.AreEqual (1f, rect.Width, "Bounds.Width");
  358. Assert.AreEqual (1f, rect.Height, "Bounds.Height");
  359. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  360. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  361. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  362. Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
  363. Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
  364. Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
  365. }
  366. [Test]
  367. public void AddLine_Point ()
  368. {
  369. GraphicsPath gp = new GraphicsPath ();
  370. gp.AddLine (new Point (1, 1), new Point (2, 2));
  371. CheckLine (gp);
  372. }
  373. [Test]
  374. public void AddLine_PointF ()
  375. {
  376. GraphicsPath gp = new GraphicsPath ();
  377. gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
  378. CheckLine (gp);
  379. }
  380. [Test]
  381. public void AddLine_Int ()
  382. {
  383. GraphicsPath gp = new GraphicsPath ();
  384. gp.AddLine (1, 1, 2, 2);
  385. CheckLine (gp);
  386. }
  387. [Test]
  388. public void AddLine_Float ()
  389. {
  390. GraphicsPath gp = new GraphicsPath ();
  391. gp.AddLine (1f, 1f, 2f, 2f);
  392. CheckLine (gp);
  393. }
  394. [Test]
  395. public void AddLine_SamePoint ()
  396. {
  397. GraphicsPath gp = new GraphicsPath ();
  398. gp.AddLine (new Point (1, 1), new Point (1, 1));
  399. Assert.AreEqual (2, gp.PointCount, "PointCount");
  400. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
  401. Assert.AreEqual (1, gp.PathTypes[1], "PathTypes[1]");
  402. }
  403. [Test]
  404. [ExpectedException (typeof (ArgumentNullException))]
  405. public void AddLines_Point_Null ()
  406. {
  407. new GraphicsPath ().AddLines ((Point[])null);
  408. }
  409. [Test]
  410. [ExpectedException (typeof (ArgumentException))]
  411. public void AddLines_Point_0 ()
  412. {
  413. GraphicsPath gp = new GraphicsPath ();
  414. gp.AddLines (new Point[0]);
  415. CheckLine (gp);
  416. }
  417. [Test]
  418. public void AddLines_Point_1 ()
  419. {
  420. GraphicsPath gp = new GraphicsPath ();
  421. gp.AddLines (new Point[1] { new Point (1, 1) });
  422. // Special case - a line with a single point is valid
  423. Assert.AreEqual (1, gp.PointCount, "PointCount");
  424. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
  425. }
  426. [Test]
  427. public void AddLines_Point ()
  428. {
  429. GraphicsPath gp = new GraphicsPath ();
  430. gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
  431. CheckLine (gp);
  432. }
  433. [Test]
  434. [ExpectedException (typeof (ArgumentNullException))]
  435. public void AddLines_PointF_Null ()
  436. {
  437. new GraphicsPath ().AddLines ((PointF[]) null);
  438. }
  439. [Test]
  440. [ExpectedException (typeof (ArgumentException))]
  441. public void AddLines_PointF_0 ()
  442. {
  443. GraphicsPath gp = new GraphicsPath ();
  444. gp.AddLines (new PointF[0]);
  445. CheckLine (gp);
  446. }
  447. [Test]
  448. public void AddLines_PointF_1 ()
  449. {
  450. GraphicsPath gp = new GraphicsPath ();
  451. gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
  452. // Special case - a line with a single point is valid
  453. Assert.AreEqual (1, gp.PointCount, "PointCount");
  454. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
  455. }
  456. [Test]
  457. public void AddLines_PointF ()
  458. {
  459. GraphicsPath gp = new GraphicsPath ();
  460. gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  461. CheckLine (gp);
  462. }
  463. private void CheckPie (GraphicsPath path)
  464. {
  465. // the number of points generated for a Pie isn't the same between Mono and MS
  466. #if false
  467. Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
  468. Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
  469. Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
  470. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  471. RectangleF rect = path.GetBounds ();
  472. Assert.AreEqual (2f, rect.X, "Bounds.X");
  473. Assert.AreEqual (2f, rect.Y, "Bounds.Y");
  474. Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
  475. Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
  476. Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
  477. Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
  478. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  479. Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
  480. Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
  481. Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
  482. Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
  483. Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
  484. Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
  485. Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
  486. Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
  487. Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
  488. Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
  489. Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
  490. Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
  491. #endif
  492. }
  493. [Test]
  494. public void AddPie_Rect ()
  495. {
  496. GraphicsPath gp = new GraphicsPath ();
  497. gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
  498. CheckPie (gp);
  499. }
  500. [Test]
  501. public void AddPie_Int ()
  502. {
  503. GraphicsPath gp = new GraphicsPath ();
  504. gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
  505. CheckPie (gp);
  506. }
  507. [Test]
  508. public void AddPie_Float ()
  509. {
  510. GraphicsPath gp = new GraphicsPath ();
  511. gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
  512. CheckPie (gp);
  513. }
  514. private void CheckPolygon (GraphicsPath path)
  515. {
  516. // an extra point is generated by Mono (libgdiplus)
  517. #if false
  518. Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
  519. Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
  520. Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
  521. #endif
  522. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  523. RectangleF rect = path.GetBounds ();
  524. Assert.AreEqual (1f, rect.X, "Bounds.X");
  525. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  526. Assert.AreEqual (2f, rect.Width, "Bounds.Width");
  527. Assert.AreEqual (2f, rect.Height, "Bounds.Height");
  528. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  529. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  530. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  531. Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
  532. Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
  533. Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
  534. Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
  535. Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
  536. // the extra point change the type of the last point
  537. #if false
  538. Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
  539. #endif
  540. }
  541. [Test]
  542. [ExpectedException (typeof (ArgumentNullException))]
  543. public void AddPolygon_Point_Null ()
  544. {
  545. new GraphicsPath ().AddPolygon ((Point[]) null);
  546. }
  547. [Test]
  548. [ExpectedException (typeof (ArgumentException))]
  549. public void AddPolygon_Point_Empty ()
  550. {
  551. new GraphicsPath ().AddPolygon (new Point[0]);
  552. }
  553. [Test]
  554. [ExpectedException (typeof (ArgumentException))]
  555. public void AddPolygon_Point_1 ()
  556. {
  557. GraphicsPath gp = new GraphicsPath ();
  558. gp.AddPolygon (new Point[1] { new Point (1, 1) });
  559. }
  560. [Test]
  561. [ExpectedException (typeof (ArgumentException))]
  562. public void AddPolygon_Point_2 ()
  563. {
  564. GraphicsPath gp = new GraphicsPath ();
  565. gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
  566. }
  567. [Test]
  568. public void AddPolygon_Point_3 ()
  569. {
  570. GraphicsPath gp = new GraphicsPath ();
  571. gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  572. CheckPolygon (gp);
  573. }
  574. [Test]
  575. [ExpectedException (typeof (ArgumentNullException))]
  576. public void AddPolygon_PointF_Null ()
  577. {
  578. new GraphicsPath ().AddPolygon ((PointF[]) null);
  579. }
  580. [Test]
  581. [ExpectedException (typeof (ArgumentException))]
  582. public void AddPolygon_PointF_Empty ()
  583. {
  584. new GraphicsPath ().AddPolygon (new PointF[0]);
  585. }
  586. [Test]
  587. [ExpectedException (typeof (ArgumentException))]
  588. public void AddPolygon_PointF_1 ()
  589. {
  590. GraphicsPath gp = new GraphicsPath ();
  591. gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
  592. }
  593. [Test]
  594. [ExpectedException (typeof (ArgumentException))]
  595. public void AddPolygon_PointF_2 ()
  596. {
  597. GraphicsPath gp = new GraphicsPath ();
  598. gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  599. }
  600. [Test]
  601. public void AddPolygon_PointF_3 ()
  602. {
  603. GraphicsPath gp = new GraphicsPath ();
  604. gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
  605. CheckPolygon (gp);
  606. }
  607. private void CheckRectangle (GraphicsPath path, int count)
  608. {
  609. Assert.AreEqual (count, path.PathPoints.Length, "PathPoints");
  610. Assert.AreEqual (count, path.PathTypes.Length, "PathPoints");
  611. Assert.AreEqual (count, path.PathData.Points.Length, "PathData");
  612. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  613. RectangleF rect = path.GetBounds ();
  614. Assert.AreEqual (1f, rect.X, "Bounds.X");
  615. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  616. Assert.AreEqual (2f, rect.Width, "Bounds.Width");
  617. Assert.AreEqual (2f, rect.Height, "Bounds.Height");
  618. // check first four points (first rectangle)
  619. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  620. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  621. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  622. Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
  623. Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
  624. Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
  625. Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
  626. Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
  627. Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
  628. Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
  629. Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
  630. Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
  631. }
  632. [Test]
  633. public void AddRectangle_Int ()
  634. {
  635. GraphicsPath gp = new GraphicsPath ();
  636. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  637. CheckRectangle (gp, 4);
  638. }
  639. [Test]
  640. public void AddRectangle_Float ()
  641. {
  642. GraphicsPath gp = new GraphicsPath ();
  643. gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
  644. CheckRectangle (gp, 4);
  645. }
  646. [Test]
  647. [ExpectedException (typeof (ArgumentNullException))]
  648. public void AddRectangles_Int_Null ()
  649. {
  650. GraphicsPath gp = new GraphicsPath ();
  651. gp.AddRectangles ((Rectangle[]) null);
  652. }
  653. [Test]
  654. [ExpectedException (typeof (ArgumentException))]
  655. public void AddRectangles_Int_Empty ()
  656. {
  657. GraphicsPath gp = new GraphicsPath ();
  658. gp.AddRectangles (new Rectangle[0]);
  659. CheckRectangle (gp, 4);
  660. }
  661. [Test]
  662. public void AddRectangles_Int ()
  663. {
  664. GraphicsPath gp = new GraphicsPath ();
  665. gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
  666. CheckRectangle (gp, 4);
  667. }
  668. [Test]
  669. [ExpectedException (typeof (ArgumentNullException))]
  670. public void AddRectangles_Float_Null ()
  671. {
  672. GraphicsPath gp = new GraphicsPath ();
  673. gp.AddRectangles ((RectangleF[]) null);
  674. }
  675. [Test]
  676. [ExpectedException (typeof (ArgumentException))]
  677. public void AddRectangles_Float_Empty ()
  678. {
  679. GraphicsPath gp = new GraphicsPath ();
  680. gp.AddRectangles ( new RectangleF[0]);
  681. CheckRectangle (gp, 4);
  682. }
  683. [Test]
  684. public void AddRectangles_Float ()
  685. {
  686. GraphicsPath gp = new GraphicsPath ();
  687. gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
  688. CheckRectangle (gp, 4);
  689. }
  690. [Test]
  691. public void AddRectangles_Two ()
  692. {
  693. GraphicsPath gp = new GraphicsPath ();
  694. gp.AddRectangles (new RectangleF[2] {
  695. new RectangleF (1f, 1f, 2f, 2f),
  696. new RectangleF (2f, 2f, 1f, 1f) } );
  697. RectangleF rect = gp.GetBounds ();
  698. Assert.AreEqual (1f, rect.X, "Bounds.X");
  699. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  700. Assert.AreEqual (2f, rect.Width, "Bounds.Width");
  701. Assert.AreEqual (2f, rect.Height, "Bounds.Height");
  702. // second rectangle is completely within the first one
  703. CheckRectangle (gp, 8);
  704. }
  705. [Test]
  706. [ExpectedException (typeof (ArgumentNullException))]
  707. public void AddPath_Null ()
  708. {
  709. new GraphicsPath ().AddPath (null, false);
  710. }
  711. [Test]
  712. public void AddPath ()
  713. {
  714. GraphicsPath gpr = new GraphicsPath ();
  715. gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
  716. GraphicsPath gp = new GraphicsPath ();
  717. gp.AddPath (gpr, true);
  718. CheckRectangle (gp, 4);
  719. }
  720. private void CheckClosedCurve (GraphicsPath path)
  721. {
  722. Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
  723. Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
  724. Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
  725. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  726. RectangleF rect = path.GetBounds ();
  727. Assert.AreEqual (0.8333333f, rect.X, "Bounds.X");
  728. Assert.AreEqual (0.8333333f, rect.Y, "Bounds.Y");
  729. Assert.AreEqual (2.33333278f, rect.Width, "Bounds.Width");
  730. Assert.AreEqual (2.33333278f, rect.Height, "Bounds.Height");
  731. Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
  732. for (int i = 1; i < 9; i++)
  733. Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
  734. Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
  735. }
  736. [Test]
  737. [ExpectedException (typeof (ArgumentNullException))]
  738. public void AddClosedCurve_Point_Null ()
  739. {
  740. new GraphicsPath ().AddClosedCurve ((Point[])null);
  741. }
  742. [Test]
  743. [ExpectedException (typeof (ArgumentException))]
  744. public void AddClosedCurve_Point_0 ()
  745. {
  746. GraphicsPath gp = new GraphicsPath ();
  747. gp.AddClosedCurve (new Point [0]);
  748. }
  749. [Test]
  750. [ExpectedException (typeof (ArgumentException))]
  751. public void AddClosedCurve_Point_1 ()
  752. {
  753. GraphicsPath gp = new GraphicsPath ();
  754. gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
  755. }
  756. [Test]
  757. [ExpectedException (typeof (ArgumentException))]
  758. public void AddClosedCurve_Point_2 ()
  759. {
  760. GraphicsPath gp = new GraphicsPath ();
  761. gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
  762. }
  763. [Test]
  764. public void AddClosedCurve_Point_3 ()
  765. {
  766. GraphicsPath gp = new GraphicsPath ();
  767. gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  768. CheckClosedCurve (gp);
  769. }
  770. [Test]
  771. [ExpectedException (typeof (ArgumentNullException))]
  772. public void AddClosedCurve_PointF_Null ()
  773. {
  774. new GraphicsPath ().AddClosedCurve ((PointF[]) null);
  775. }
  776. [Test]
  777. [ExpectedException (typeof (ArgumentException))]
  778. public void AddClosedCurve_PointF_0 ()
  779. {
  780. GraphicsPath gp = new GraphicsPath ();
  781. gp.AddClosedCurve (new PointF[0]);
  782. }
  783. [Test]
  784. [ExpectedException (typeof (ArgumentException))]
  785. public void AddClosedCurve_PointF_1 ()
  786. {
  787. GraphicsPath gp = new GraphicsPath ();
  788. gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
  789. }
  790. [Test]
  791. [ExpectedException (typeof (ArgumentException))]
  792. public void AddClosedCurve_PointF_2 ()
  793. {
  794. GraphicsPath gp = new GraphicsPath ();
  795. gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  796. }
  797. [Test]
  798. public void AddClosedCurve_PointF_3 ()
  799. {
  800. GraphicsPath gp = new GraphicsPath ();
  801. gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
  802. CheckClosedCurve (gp);
  803. }
  804. private void CheckCurve (GraphicsPath path)
  805. {
  806. Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
  807. Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
  808. Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
  809. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  810. RectangleF rect = path.GetBounds ();
  811. Assert.AreEqual (1.0f, rect.X, "Bounds.X");
  812. Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
  813. Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
  814. Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
  815. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  816. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  817. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  818. // Mono has wrong? results
  819. #if false
  820. Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
  821. Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
  822. #endif
  823. Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
  824. // Mono has wrong? results
  825. #if false
  826. Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
  827. Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
  828. #endif
  829. Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
  830. Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
  831. Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
  832. Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
  833. }
  834. [Test]
  835. [ExpectedException (typeof (ArgumentNullException))]
  836. public void AddCurve_Point_Null ()
  837. {
  838. new GraphicsPath ().AddCurve ((Point[]) null);
  839. }
  840. [Test]
  841. [ExpectedException (typeof (ArgumentException))]
  842. public void AddCurve_Point_0 ()
  843. {
  844. GraphicsPath gp = new GraphicsPath ();
  845. gp.AddCurve (new Point[0]);
  846. }
  847. [Test]
  848. [ExpectedException (typeof (ArgumentException))]
  849. public void AddCurve_Point_1 ()
  850. {
  851. GraphicsPath gp = new GraphicsPath ();
  852. gp.AddCurve (new Point[1] { new Point (1, 1) });
  853. }
  854. [Test]
  855. public void AddCurve_Point_2 ()
  856. {
  857. GraphicsPath gp = new GraphicsPath ();
  858. gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
  859. CheckCurve (gp);
  860. }
  861. [Test]
  862. [ExpectedException (typeof (ArgumentNullException))]
  863. public void AddCurve_PointF_Null ()
  864. {
  865. new GraphicsPath ().AddCurve ((PointF[]) null);
  866. }
  867. [Test]
  868. [ExpectedException (typeof (ArgumentException))]
  869. public void AddCurve_PointF_0 ()
  870. {
  871. GraphicsPath gp = new GraphicsPath ();
  872. gp.AddCurve (new PointF[0]);
  873. }
  874. [Test]
  875. [ExpectedException (typeof (ArgumentException))]
  876. public void AddCurve_PointF_1 ()
  877. {
  878. GraphicsPath gp = new GraphicsPath ();
  879. gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
  880. }
  881. [Test]
  882. public void AddCurve_PointF_2 ()
  883. {
  884. GraphicsPath gp = new GraphicsPath ();
  885. gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  886. CheckCurve (gp);
  887. }
  888. [Test]
  889. [ExpectedException (typeof (NullReferenceException))]
  890. public void AddString_NullString ()
  891. {
  892. GraphicsPath gp = new GraphicsPath ();
  893. gp.AddString (null, FontFamily.GenericMonospace, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
  894. }
  895. [Test]
  896. public void AddString_EmptyString ()
  897. {
  898. GraphicsPath gp = new GraphicsPath ();
  899. gp.AddString (String.Empty, FontFamily.GenericMonospace, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
  900. Assert.AreEqual (0, gp.PointCount, "PointCount");
  901. }
  902. [Test]
  903. [ExpectedException (typeof (ArgumentException))]
  904. public void AddString_NullFontFamily ()
  905. {
  906. GraphicsPath gp = new GraphicsPath ();
  907. gp.AddString ("mono", null, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
  908. }
  909. [Test]
  910. public void AddString_NegativeSize ()
  911. {
  912. GraphicsPath gp = new GraphicsPath ();
  913. gp.AddString ("mono", FontFamily.GenericMonospace, 0, -10, new Point (10, 10), StringFormat.GenericDefault);
  914. Assert.IsTrue (gp.PointCount > 0, "PointCount");
  915. }
  916. [Test]
  917. [Category ("NotWorking")] // StringFormat not yet supported in libgdiplus
  918. public void AddString_StringFormat ()
  919. {
  920. // null maps to ?
  921. GraphicsPath gp1 = new GraphicsPath ();
  922. gp1.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new RectangleF (10, 10, 10, 10), null);
  923. // StringFormat.GenericDefault
  924. GraphicsPath gp2 = new GraphicsPath ();
  925. gp2.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericDefault);
  926. Assert.AreEqual (gp1.PointCount, gp2.PointCount, "GenericDefault");
  927. // StringFormat.GenericTypographic
  928. GraphicsPath gp3 = new GraphicsPath ();
  929. gp3.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericTypographic);
  930. Assert.IsFalse (gp1.PointCount == gp3.PointCount, "GenericTypographic");
  931. }
  932. [Test]
  933. public void GetBounds_Empty_Empty ()
  934. {
  935. GraphicsPath gp = new GraphicsPath ();
  936. RectangleF rect = gp.GetBounds ();
  937. Assert.AreEqual (0.0f, rect.X, "Bounds.X");
  938. Assert.AreEqual (0.0f, rect.Y, "Bounds.Y");
  939. Assert.AreEqual (0.0f, rect.Width, "Bounds.Width");
  940. Assert.AreEqual (0.0f, rect.Height, "Bounds.Height");
  941. }
  942. private void CheckRectangleBounds (RectangleF rect)
  943. {
  944. Assert.AreEqual (1.0f, rect.X, "Bounds.X");
  945. Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
  946. Assert.AreEqual (2.0f, rect.Width, "Bounds.Width");
  947. Assert.AreEqual (2.0f, rect.Height, "Bounds.Height");
  948. }
  949. [Test]
  950. public void GetBounds_Empty_Rectangle ()
  951. {
  952. GraphicsPath gp = new GraphicsPath ();
  953. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  954. CheckRectangleBounds (gp.GetBounds ());
  955. }
  956. [Test]
  957. public void GetBounds_Null_Rectangle ()
  958. {
  959. GraphicsPath gp = new GraphicsPath ();
  960. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  961. CheckRectangleBounds (gp.GetBounds (null));
  962. }
  963. [Test]
  964. public void GetBounds_MatrixEmpty_Rectangle ()
  965. {
  966. GraphicsPath gp = new GraphicsPath ();
  967. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  968. CheckRectangleBounds (gp.GetBounds (new Matrix ()));
  969. }
  970. [Test]
  971. public void GetBounds_NullNull_Rectangle ()
  972. {
  973. GraphicsPath gp = new GraphicsPath ();
  974. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  975. CheckRectangleBounds (gp.GetBounds (null, null));
  976. }
  977. [Test]
  978. [Category ("NotWorking")] // bounds+pen support is missing in libgdiplus
  979. public void GetBounds_WithPen ()
  980. {
  981. Rectangle rect = new Rectangle (1, 1, 2, 2);
  982. Pen p = new Pen (Color.Aqua, 0);
  983. GraphicsPath gp = new GraphicsPath ();
  984. gp.AddRectangle (rect);
  985. RectangleF bounds = gp.GetBounds (null, p);
  986. Assert.AreEqual (-6.09999943f, bounds.X, "NullMatrix.Bounds.X");
  987. Assert.AreEqual (-6.09999943f, bounds.Y, "NullMatrix.Bounds.Y");
  988. Assert.AreEqual (16.1999989f, bounds.Width, "NullMatrix.Bounds.Width");
  989. Assert.AreEqual (16.1999989f, bounds.Height, "NullMatrix.Bounds.Height");
  990. Matrix m = new Matrix ();
  991. // an empty matrix is different than a null matrix
  992. bounds = gp.GetBounds (m, p);
  993. Assert.AreEqual (-0.419999957f, bounds.X, "EmptyMatrix.Bounds.X");
  994. Assert.AreEqual (-0.419999957f, bounds.Y, "EmptyMatrix.Bounds.Y");
  995. Assert.AreEqual (4.83999968f, bounds.Width, "EmptyMatrix.Bounds.Width");
  996. Assert.AreEqual (4.83999968f, bounds.Height, "EmptyMatrix.Bounds.Height");
  997. gp = new GraphicsPath ();
  998. gp.AddRectangle (rect);
  999. gp.Widen (p);
  1000. bounds = gp.GetBounds (null);
  1001. Assert.AreEqual (0.499999523f, bounds.X, "WidenNullMatrix.Bounds.X");
  1002. Assert.AreEqual (0.499999523f, bounds.Y, "WidenNullMatrix.Bounds.Y");
  1003. Assert.AreEqual (3.000001f, bounds.Width, "WidenNullMatrix.Bounds.Width");
  1004. Assert.AreEqual (3.000001f, bounds.Height, "WidenNullMatrix.Bounds.Height");
  1005. bounds = gp.GetBounds (m);
  1006. Assert.AreEqual (0.499999523f, bounds.X, "WidenEmptyMatrix.Bounds.X");
  1007. Assert.AreEqual (0.499999523f, bounds.Y, "WidenEmptyMatrix.Bounds.Y");
  1008. Assert.AreEqual (3.000001f, bounds.Width, "WidenEmptyMatrix.Bounds.Width");
  1009. Assert.AreEqual (3.000001f, bounds.Height, "WidenEmptyMatrix.Bounds.Height");
  1010. }
  1011. [Test]
  1012. [ExpectedException (typeof (ArgumentNullException))]
  1013. public void Transform_Null ()
  1014. {
  1015. new GraphicsPath ().Transform (null);
  1016. }
  1017. [Test]
  1018. public void Transform_Empty ()
  1019. {
  1020. // no points in path and no exception
  1021. new GraphicsPath ().Transform (new Matrix ());
  1022. }
  1023. private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
  1024. {
  1025. Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
  1026. for (int i = 0; i < expected.PointCount; i++) {
  1027. Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
  1028. Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
  1029. }
  1030. }
  1031. private void CompareFlats (GraphicsPath flat, GraphicsPath original)
  1032. {
  1033. Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
  1034. for (int i = 0; i < flat.PointCount; i++) {
  1035. Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
  1036. }
  1037. }
  1038. [Test]
  1039. public void Flatten_Empty ()
  1040. {
  1041. GraphicsPath path = new GraphicsPath ();
  1042. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1043. // this is a no-op as there's nothing in the path
  1044. path.Flatten ();
  1045. ComparePaths (path, clone);
  1046. }
  1047. [Test]
  1048. public void Flatten_Null ()
  1049. {
  1050. GraphicsPath path = new GraphicsPath ();
  1051. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1052. // this is a no-op as there's nothing in the path
  1053. // an no matrix to apply
  1054. path.Flatten (null);
  1055. ComparePaths (path, clone);
  1056. }
  1057. [Test]
  1058. public void Flatten_NullFloat ()
  1059. {
  1060. GraphicsPath path = new GraphicsPath ();
  1061. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1062. // this is a no-op as there's nothing in the path
  1063. // an no matrix to apply
  1064. path.Flatten (null, 1f);
  1065. ComparePaths (path, clone);
  1066. }
  1067. [Test]
  1068. public void Flatten_Arc ()
  1069. {
  1070. GraphicsPath path = new GraphicsPath ();
  1071. path.AddArc (0f, 0f, 100f, 100f, 30, 30);
  1072. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1073. path.Flatten ();
  1074. CompareFlats (path, clone);
  1075. }
  1076. [Test]
  1077. public void Flatten_Bezier ()
  1078. {
  1079. GraphicsPath path = new GraphicsPath ();
  1080. path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
  1081. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1082. path.Flatten ();
  1083. CompareFlats (path, clone);
  1084. }
  1085. [Test]
  1086. public void Flatten_ClosedCurve ()
  1087. {
  1088. GraphicsPath path = new GraphicsPath ();
  1089. path.AddClosedCurve (new Point[4] {
  1090. new Point (0, 0), new Point (40, 20),
  1091. new Point (20, 40), new Point (40, 40)
  1092. });
  1093. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1094. path.Flatten ();
  1095. CompareFlats (path, clone);
  1096. }
  1097. [Test]
  1098. public void Flatten_Curve ()
  1099. {
  1100. GraphicsPath path = new GraphicsPath ();
  1101. path.AddCurve (new Point[4] {
  1102. new Point (0, 0), new Point (40, 20),
  1103. new Point (20, 40), new Point (40, 40)
  1104. });
  1105. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1106. path.Flatten ();
  1107. CompareFlats (path, clone);
  1108. }
  1109. [Test]
  1110. public void Flatten_Ellipse ()
  1111. {
  1112. GraphicsPath path = new GraphicsPath ();
  1113. path.AddEllipse (10f, 10f, 100f, 100f);
  1114. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1115. path.Flatten ();
  1116. CompareFlats (path, clone);
  1117. }
  1118. [Test]
  1119. public void Flatten_Line ()
  1120. {
  1121. GraphicsPath path = new GraphicsPath ();
  1122. path.AddLine (10f, 10f, 100f, 100f);
  1123. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1124. path.Flatten ();
  1125. ComparePaths (path, clone);
  1126. }
  1127. [Test]
  1128. public void Flatten_Pie ()
  1129. {
  1130. GraphicsPath path = new GraphicsPath ();
  1131. path.AddPie (0, 0, 100, 100, 30, 30);
  1132. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1133. path.Flatten ();
  1134. CompareFlats (path, clone);
  1135. }
  1136. [Test]
  1137. public void Flatten_Polygon ()
  1138. {
  1139. GraphicsPath path = new GraphicsPath ();
  1140. path.AddPolygon (new Point[4] {
  1141. new Point (0, 0), new Point (10, 10),
  1142. new Point (20, 20), new Point (40, 40)
  1143. });
  1144. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1145. path.Flatten ();
  1146. ComparePaths (path, clone);
  1147. }
  1148. [Test]
  1149. public void Flatten_Rectangle ()
  1150. {
  1151. GraphicsPath path = new GraphicsPath ();
  1152. path.AddRectangle (new Rectangle (0, 0, 100, 100));
  1153. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1154. path.Flatten ();
  1155. ComparePaths (path, clone);
  1156. }
  1157. private void CheckWrap (GraphicsPath path)
  1158. {
  1159. Assert.AreEqual (3, path.PointCount, "Count");
  1160. PointF[] pts = path.PathPoints;
  1161. Assert.AreEqual (0, pts[0].X, 1e-30, "0.X");
  1162. Assert.AreEqual (0, pts[0].Y, 1e-30, "0.Y");
  1163. Assert.AreEqual (0, pts[1].X, 1e-30, "1.X");
  1164. Assert.AreEqual (0, pts[1].Y, 1e-30, "1.Y");
  1165. Assert.AreEqual (0, pts[2].X, 1e-30, "2.X");
  1166. Assert.AreEqual (0, pts[2].Y, 1e-30, "2.Y");
  1167. byte[] types = path.PathTypes;
  1168. Assert.AreEqual (0, types[0], "0");
  1169. Assert.AreEqual (1, types[1], "1");
  1170. Assert.AreEqual (129, types[2], "2");
  1171. }
  1172. private void CheckWrapNaN (GraphicsPath path, bool closed)
  1173. {
  1174. Assert.AreEqual (3, path.PointCount, "Count");
  1175. PointF[] pts = path.PathPoints;
  1176. Assert.AreEqual (Single.NaN, pts[0].X, "0.X");
  1177. Assert.AreEqual (Single.NaN, pts[0].Y, "0.Y");
  1178. Assert.AreEqual (Single.NaN, pts[1].X, "1.X");
  1179. Assert.AreEqual (Single.NaN, pts[1].Y, "1.Y");
  1180. Assert.AreEqual (Single.NaN, pts[2].X, "2.X");
  1181. Assert.AreEqual (Single.NaN, pts[2].Y, "2.Y");
  1182. byte[] types = path.PathTypes;
  1183. Assert.AreEqual (0, types[0], "0");
  1184. Assert.AreEqual (1, types[1], "1");
  1185. Assert.AreEqual (closed ? 129 : 1, types[2], "2");
  1186. }
  1187. [Test]
  1188. [ExpectedException (typeof (ArgumentNullException))]
  1189. public void Warp_Null ()
  1190. {
  1191. new GraphicsPath ().Warp (null, new RectangleF ());
  1192. }
  1193. [Test]
  1194. [ExpectedException (typeof (ArgumentException))]
  1195. public void Warp_NoPoints ()
  1196. {
  1197. new GraphicsPath ().Warp (new PointF[0], new RectangleF ());
  1198. }
  1199. [Test]
  1200. [Category ("NotWorking")]
  1201. public void Warp_NullMatrix ()
  1202. {
  1203. PointF[] pts = new PointF[1] { new PointF (0,0) };
  1204. GraphicsPath path = new GraphicsPath ();
  1205. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1206. RectangleF r = new RectangleF (10, 20, 30, 40);
  1207. path.Warp (pts, r, null);
  1208. CheckWrap (path);
  1209. }
  1210. [Test]
  1211. [Category ("NotWorking")]
  1212. public void Warp_EmptyMatrix ()
  1213. {
  1214. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1215. GraphicsPath path = new GraphicsPath ();
  1216. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1217. RectangleF r = new RectangleF (10, 20, 30, 40);
  1218. path.Warp (pts, r, new Matrix ());
  1219. CheckWrap (path);
  1220. }
  1221. [Test]
  1222. [Category ("NotWorking")]
  1223. public void Warp_Rectangle_Empty ()
  1224. {
  1225. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1226. GraphicsPath path = new GraphicsPath ();
  1227. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1228. path.Warp (pts, new RectangleF (), null);
  1229. CheckWrapNaN (path, true);
  1230. }
  1231. [Test]
  1232. [Category ("NotWorking")]
  1233. public void Warp_Rectangle_NegativeWidthHeight ()
  1234. {
  1235. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1236. GraphicsPath path = new GraphicsPath ();
  1237. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1238. RectangleF r = new RectangleF (10, 20, -30, -40);
  1239. path.Warp (pts, r, null);
  1240. Assert.AreEqual (3, path.PointCount, "Count");
  1241. pts = path.PathPoints;
  1242. Assert.AreEqual (1.131355e-39, pts[0].X, 1e40, "0.X");
  1243. Assert.AreEqual (-2.0240637E-33, pts[0].Y, 1e40, "0.Y");
  1244. Assert.AreEqual (1.070131E-39, pts[1].X, 1e40, "1.X");
  1245. Assert.AreEqual (-2.02406389E-33, pts[1].Y, 1e40, "1.Y");
  1246. Assert.AreEqual (3.669146E-40, pts[2].X, 1e40, "2.X");
  1247. Assert.AreEqual (-6.746879E-34, pts[2].Y, 1e40, "2.Y");
  1248. byte[] types = path.PathTypes;
  1249. Assert.AreEqual (0, types[0], "0");
  1250. Assert.AreEqual (1, types[1], "1");
  1251. Assert.AreEqual (129, types[2], "2");
  1252. }
  1253. [Test]
  1254. [Category ("NotWorking")]
  1255. public void Warp_Matrix_NonInvertible ()
  1256. {
  1257. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  1258. Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
  1259. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1260. GraphicsPath path = new GraphicsPath ();
  1261. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1262. RectangleF r = new RectangleF (10, 20, 30, 40);
  1263. path.Warp (pts, r, matrix);
  1264. Assert.AreEqual (3, path.PointCount, "Count");
  1265. pts = path.PathPoints;
  1266. Assert.AreEqual (47, pts[0].X, "0.X");
  1267. Assert.AreEqual (30, pts[0].Y, "0.Y");
  1268. Assert.AreEqual (47, pts[1].X, "1.X");
  1269. Assert.AreEqual (30, pts[1].Y, "1.Y");
  1270. Assert.AreEqual (47, pts[2].X, "2.X");
  1271. Assert.AreEqual (30, pts[2].Y, "2.Y");
  1272. byte[] types = path.PathTypes;
  1273. Assert.AreEqual (0, types[0], "0");
  1274. Assert.AreEqual (1, types[1], "1");
  1275. Assert.AreEqual (129, types[2], "2");
  1276. }
  1277. [Test]
  1278. [Category ("NotWorking")]
  1279. public void Warp_Bilinear ()
  1280. {
  1281. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1282. GraphicsPath path = new GraphicsPath ();
  1283. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1284. RectangleF r = new RectangleF (10, 20, 30, 40);
  1285. path.Warp (pts, r, new Matrix (), WarpMode.Bilinear);
  1286. // note that the last point is no more closed
  1287. CheckWrapNaN (path, false);
  1288. }
  1289. [Test]
  1290. [Category ("NotWorking")]
  1291. public void Warp_Perspective ()
  1292. {
  1293. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1294. GraphicsPath path = new GraphicsPath ();
  1295. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1296. RectangleF r = new RectangleF (10, 20, 30, 40);
  1297. path.Warp (pts, r, new Matrix (), WarpMode.Perspective);
  1298. CheckWrap (path);
  1299. }
  1300. [Test]
  1301. public void Warp_Invalid ()
  1302. {
  1303. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1304. GraphicsPath path = new GraphicsPath ();
  1305. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1306. RectangleF r = new RectangleF (10, 20, 30, 40);
  1307. path.Warp (pts, r, new Matrix (), (WarpMode) Int32.MinValue);
  1308. Assert.AreEqual (0, path.PointCount, "Count");
  1309. }
  1310. [Test]
  1311. [Category ("NotWorking")]
  1312. public void Warp_Flatness_Negative ()
  1313. {
  1314. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1315. GraphicsPath path = new GraphicsPath ();
  1316. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1317. RectangleF r = new RectangleF (10, 20, 30, 40);
  1318. path.Warp (pts, r, new Matrix (), WarpMode.Perspective, -1f);
  1319. CheckWrap (path);
  1320. }
  1321. [Test]
  1322. [Category ("NotWorking")]
  1323. public void Warp_Flatness_OverOne ()
  1324. {
  1325. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1326. GraphicsPath path = new GraphicsPath ();
  1327. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1328. RectangleF r = new RectangleF (10, 20, 30, 40);
  1329. path.Warp (pts, r, new Matrix (), WarpMode.Perspective, 2.0f);
  1330. CheckWrap (path);
  1331. }
  1332. [Test]
  1333. public void SetMarkers_EmptyPath ()
  1334. {
  1335. new GraphicsPath ().SetMarkers ();
  1336. }
  1337. [Test]
  1338. public void ClearMarkers_EmptyPath ()
  1339. {
  1340. new GraphicsPath ().ClearMarkers ();
  1341. }
  1342. [Test]
  1343. public void CloseFigure_EmptyPath ()
  1344. {
  1345. new GraphicsPath ().CloseFigure ();
  1346. }
  1347. [Test]
  1348. public void CloseAllFigures_EmptyPath ()
  1349. {
  1350. new GraphicsPath ().CloseAllFigures ();
  1351. }
  1352. [Test]
  1353. public void StartClose_AddArc ()
  1354. {
  1355. GraphicsPath path = new GraphicsPath ();
  1356. path.AddLine (1, 1, 2, 2);
  1357. path.AddArc (10, 10, 100, 100, 90, 180);
  1358. path.AddLine (10, 10, 20, 20);
  1359. byte[] types = path.PathTypes;
  1360. // check first types
  1361. Assert.AreEqual (0, types[0], "start/Line");
  1362. Assert.AreEqual (1, types[2], "start/Arc");
  1363. // check last types
  1364. Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
  1365. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1366. }
  1367. [Test]
  1368. public void StartClose_AddBezier ()
  1369. {
  1370. GraphicsPath path = new GraphicsPath ();
  1371. path.AddLine (1, 1, 2, 2);
  1372. path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200);
  1373. path.AddLine (10, 10, 20, 20);
  1374. byte[] types = path.PathTypes;
  1375. // check first types
  1376. Assert.AreEqual (0, types[0], "start/Line");
  1377. Assert.AreEqual (1, types[2], "start/Bezier");
  1378. // check last types
  1379. Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
  1380. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1381. }
  1382. [Test]
  1383. public void StartClose_AddBeziers ()
  1384. {
  1385. GraphicsPath path = new GraphicsPath ();
  1386. path.AddLine (1, 1, 2, 2);
  1387. path.AddBeziers (new Point[7] { new Point (10, 10),
  1388. new Point (20, 10), new Point (20, 20), new Point (30, 20),
  1389. new Point (40, 40), new Point (50, 40), new Point (50, 50)
  1390. });
  1391. path.AddLine (10, 10, 20, 20);
  1392. byte[] types = path.PathTypes;
  1393. // check first types
  1394. Assert.AreEqual (0, types[0], "start/Line");
  1395. Assert.AreEqual (1, types[2], "start/Bezier");
  1396. // check last types
  1397. Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
  1398. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1399. }
  1400. [Test]
  1401. public void StartClose_AddClosedCurve ()
  1402. {
  1403. GraphicsPath path = new GraphicsPath ();
  1404. path.AddLine (1, 1, 2, 2);
  1405. path.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1406. path.AddLine (10, 10, 20, 20);
  1407. byte[] types = path.PathTypes;
  1408. // check first types
  1409. Assert.AreEqual (0, types[0], "start/Line");
  1410. Assert.AreEqual (0, types[2], "start/ClosedCurve");
  1411. // check last types
  1412. Assert.AreEqual (131, types[path.PointCount - 3], "end/ClosedCurve");
  1413. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
  1414. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
  1415. }
  1416. [Test]
  1417. public void StartClose_AddCurve ()
  1418. {
  1419. GraphicsPath path = new GraphicsPath ();
  1420. path.AddLine (1, 1, 2, 2);
  1421. path.AddCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1422. path.AddLine (10, 10, 20, 20);
  1423. byte[] types = path.PathTypes;
  1424. // check first types
  1425. Assert.AreEqual (0, types[0], "start/Line");
  1426. Assert.AreEqual (1, types[2], "start/Curve");
  1427. // check last types
  1428. Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
  1429. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1430. }
  1431. [Test]
  1432. public void StartClose_AddEllipse ()
  1433. {
  1434. GraphicsPath path = new GraphicsPath ();
  1435. path.AddLine (1, 1, 2, 2);
  1436. path.AddEllipse (10, 10, 100, 100);
  1437. path.AddLine (10, 10, 20, 20);
  1438. byte[] types = path.PathTypes;
  1439. // check first types
  1440. Assert.AreEqual (0, types[0], "start/Line");
  1441. Assert.AreEqual (0, types[2], "start/Ellipse");
  1442. // check last types
  1443. Assert.AreEqual (131, types[path.PointCount - 3], "end/Ellipse");
  1444. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
  1445. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
  1446. }
  1447. [Test]
  1448. public void StartClose_AddLine ()
  1449. {
  1450. GraphicsPath path = new GraphicsPath ();
  1451. path.AddLine (1, 1, 2, 2);
  1452. path.AddLine (5, 5, 10, 10);
  1453. path.AddLine (10, 10, 20, 20);
  1454. byte[] types = path.PathTypes;
  1455. // check first types
  1456. Assert.AreEqual (0, types[0], "start/Line");
  1457. Assert.AreEqual (1, types[2], "start/Line2");
  1458. // check last types
  1459. Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
  1460. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1461. }
  1462. [Test]
  1463. public void StartClose_AddLines ()
  1464. {
  1465. GraphicsPath path = new GraphicsPath ();
  1466. path.AddLine (1, 1, 2, 2);
  1467. path.AddLines (new Point[4] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20) });
  1468. path.AddLine (10, 10, 20, 20);
  1469. byte[] types = path.PathTypes;
  1470. // check first types
  1471. Assert.AreEqual (0, types[0], "start/Line");
  1472. Assert.AreEqual (1, types[2], "start/Lines");
  1473. // check last types
  1474. Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
  1475. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1476. }
  1477. [Test]
  1478. public void StartClose_AddPath_Connect ()
  1479. {
  1480. GraphicsPath inner = new GraphicsPath ();
  1481. inner.AddArc (10, 10, 100, 100, 90, 180);
  1482. GraphicsPath path = new GraphicsPath ();
  1483. path.AddLine (1, 1, 2, 2);
  1484. path.AddPath (inner, true);
  1485. path.AddLine (10, 10, 20, 20);
  1486. byte[] types = path.PathTypes;
  1487. // check first types
  1488. Assert.AreEqual (0, types[0], "start/Line");
  1489. Assert.AreEqual (1, types[2], "start/Path");
  1490. // check last types
  1491. Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
  1492. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1493. }
  1494. [Test]
  1495. public void StartClose_AddPath_NoConnect ()
  1496. {
  1497. GraphicsPath inner = new GraphicsPath ();
  1498. inner.AddArc (10, 10, 100, 100, 90, 180);
  1499. GraphicsPath path = new GraphicsPath ();
  1500. path.AddLine (1, 1, 2, 2);
  1501. path.AddPath (inner, false);
  1502. path.AddLine (10, 10, 20, 20);
  1503. byte[] types = path.PathTypes;
  1504. // check first types
  1505. Assert.AreEqual (0, types[0], "start/Line");
  1506. Assert.AreEqual (0, types[2], "start/Path");
  1507. // check last types
  1508. Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
  1509. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1510. }
  1511. [Test]
  1512. public void StartClose_AddPie ()
  1513. {
  1514. GraphicsPath path = new GraphicsPath ();
  1515. path.AddLine (1, 1, 2, 2);
  1516. path.AddPie (10, 10, 10, 10, 90, 180);
  1517. path.AddLine (10, 10, 20, 20);
  1518. byte[] types = path.PathTypes;
  1519. // check first types
  1520. Assert.AreEqual (0, types[0], "start/Line");
  1521. Assert.AreEqual (0, types[2], "start/Pie");
  1522. // check last types
  1523. // libgdiplus draws pie by ending with a line (not a curve) section
  1524. Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie");
  1525. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1526. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1527. }
  1528. [Test]
  1529. public void StartClose_AddPolygon ()
  1530. {
  1531. GraphicsPath path = new GraphicsPath ();
  1532. path.AddLine (1, 1, 2, 2);
  1533. path.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1534. path.AddLine (10, 10, 20, 20);
  1535. byte[] types = path.PathTypes;
  1536. // check first types
  1537. Assert.AreEqual (0, types[0], "start/Line");
  1538. Assert.AreEqual (0, types[2], "start/Polygon");
  1539. // check last types
  1540. Assert.AreEqual (129, types[path.PointCount - 3], "end/Polygon");
  1541. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1542. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1543. }
  1544. [Test]
  1545. public void StartClose_AddRectangle ()
  1546. {
  1547. GraphicsPath path = new GraphicsPath ();
  1548. path.AddLine (1, 1, 2, 2);
  1549. path.AddRectangle (new RectangleF (10, 10, 20, 20));
  1550. path.AddLine (10, 10, 20, 20);
  1551. byte[] types = path.PathTypes;
  1552. // check first types
  1553. Assert.AreEqual (0, types[0], "start/Line");
  1554. Assert.AreEqual (0, types[2], "start/Rectangle");
  1555. // check last types
  1556. Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangle");
  1557. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1558. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1559. }
  1560. [Test]
  1561. public void StartClose_AddRectangles ()
  1562. {
  1563. GraphicsPath path = new GraphicsPath ();
  1564. path.AddLine (1, 1, 2, 2);
  1565. path.AddRectangles (new RectangleF[2] {
  1566. new RectangleF (10, 10, 20, 20),
  1567. new RectangleF (20, 20, 10, 10) });
  1568. path.AddLine (10, 10, 20, 20);
  1569. byte[] types = path.PathTypes;
  1570. // check first types
  1571. Assert.AreEqual (0, types[0], "start/Line");
  1572. Assert.AreEqual (0, types[2], "start/Rectangles");
  1573. // check last types
  1574. Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
  1575. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1576. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1577. }
  1578. [Test]
  1579. [Category ("NotWorking")]
  1580. public void StartClose_AddString ()
  1581. {
  1582. GraphicsPath path = new GraphicsPath ();
  1583. path.AddLine (1, 1, 2, 2);
  1584. path.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new Point (20,20), StringFormat.GenericDefault);
  1585. path.AddLine (10, 10, 20, 20);
  1586. byte[] types = path.PathTypes;
  1587. // check first types
  1588. Assert.AreEqual (0, types[0], "start/Line");
  1589. Assert.AreEqual (0, types[2], "start/String");
  1590. // check last types
  1591. Assert.AreEqual (163, types[path.PointCount - 3], "end/String");
  1592. Assert.AreEqual (1, types[path.PointCount - 2], "start/Line2");
  1593. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1594. }
  1595. [Test]
  1596. [ExpectedException (typeof (ArgumentNullException))]
  1597. public void Widen_Pen_Null ()
  1598. {
  1599. new GraphicsPath ().Widen (null);
  1600. }
  1601. [Test]
  1602. [Category ("NotWorking")]
  1603. public void Widen_Pen ()
  1604. {
  1605. Pen pen = new Pen (Color.Blue);
  1606. GraphicsPath path = new GraphicsPath ();
  1607. path.AddRectangle (new Rectangle (1, 1, 2, 2));
  1608. Assert.AreEqual (4, path.PointCount, "Count-1");
  1609. path.Widen (pen);
  1610. Assert.AreEqual (12, path.PointCount, "Count-2");
  1611. PointF[] pts = path.PathPoints;
  1612. Assert.AreEqual (0.5, pts[0].X, 0.25, "0.X");
  1613. Assert.AreEqual (0.5, pts[0].Y, 0.25, "0.Y");
  1614. Assert.AreEqual (3.5, pts[1].X, 0.25, "1.X");
  1615. Assert.AreEqual (0.5, pts[1].Y, 0.25, "1.Y");
  1616. Assert.AreEqual (3.5, pts[2].X, 0.25, "2.X");
  1617. Assert.AreEqual (3.5, pts[2].Y, 0.25, "2.Y");
  1618. Assert.AreEqual (0.5, pts[3].X, 0.25, "3.X");
  1619. Assert.AreEqual (3.5, pts[3].Y, 0.25, "3.Y");
  1620. Assert.AreEqual (1.5, pts[4].X, 0.25, "4.X");
  1621. Assert.AreEqual (3.0, pts[4].Y, 0.25, "4.Y");
  1622. Assert.AreEqual (1.0, pts[5].X, 0.25, "5.X");
  1623. Assert.AreEqual (2.5, pts[5].Y, 0.25, "5.Y");
  1624. Assert.AreEqual (3.0, pts[6].X, 0.25, "6.X");
  1625. Assert.AreEqual (2.5, pts[6].Y, 0.25, "6.Y");
  1626. Assert.AreEqual (2.5, pts[7].X, 0.25, "7.X");
  1627. Assert.AreEqual (3.0, pts[7].Y, 0.25, "7.Y");
  1628. Assert.AreEqual (2.5, pts[8].X, 0.25, "8.X");
  1629. Assert.AreEqual (1.0, pts[8].Y, 0.25, "8.Y");
  1630. Assert.AreEqual (3.0, pts[9].X, 0.25, "9.X");
  1631. Assert.AreEqual (1.5, pts[9].Y, 0.25, "9.Y");
  1632. Assert.AreEqual (1.0, pts[10].X, 0.25, "10.X");
  1633. Assert.AreEqual (1.5, pts[10].Y, 0.25, "10.Y");
  1634. Assert.AreEqual (1.5, pts[11].X, 0.25, "11.X");
  1635. Assert.AreEqual (1.0, pts[11].Y, 0.25, "11.Y");
  1636. byte[] types = path.PathTypes;
  1637. Assert.AreEqual (0, types[0], "0");
  1638. Assert.AreEqual (1, types[1], "1");
  1639. Assert.AreEqual (1, types[2], "2");
  1640. Assert.AreEqual (129, types[3], "3");
  1641. Assert.AreEqual (0, types[4], "4");
  1642. Assert.AreEqual (1, types[5], "5");
  1643. Assert.AreEqual (1, types[6], "6");
  1644. Assert.AreEqual (1, types[7], "7");
  1645. Assert.AreEqual (1, types[8], "8");
  1646. Assert.AreEqual (1, types[9], "9");
  1647. Assert.AreEqual (1, types[10], "10");
  1648. Assert.AreEqual (129, types[11], "11");
  1649. }
  1650. [Test]
  1651. [ExpectedException (typeof (ArgumentNullException))]
  1652. public void Widen_Pen_Null_Matrix ()
  1653. {
  1654. new GraphicsPath ().Widen (null, new Matrix ());
  1655. }
  1656. private void CheckWiden3 (GraphicsPath path)
  1657. {
  1658. PointF[] pts = path.PathPoints;
  1659. Assert.AreEqual (4.2, pts[0].X, 0.25, "0.X");
  1660. Assert.AreEqual (4.5, pts[0].Y, 0.25, "0.Y");
  1661. Assert.AreEqual (15.8, pts[1].X, 0.25, "1.X");
  1662. Assert.AreEqual (4.5, pts[1].Y, 0.25, "1.Y");
  1663. Assert.AreEqual (10.0, pts[2].X, 0.25, "2.X");
  1664. Assert.AreEqual (16.1, pts[2].Y, 0.25, "2.Y");
  1665. Assert.AreEqual (10.4, pts[3].X, 0.25, "3.X");
  1666. Assert.AreEqual (14.8, pts[3].Y, 0.25, "3.Y");
  1667. Assert.AreEqual (9.6, pts[4].X, 0.25, "4.X");
  1668. Assert.AreEqual (14.8, pts[4].Y, 0.25, "4.Y");
  1669. Assert.AreEqual (14.6, pts[5].X, 0.25, "7.X");
  1670. Assert.AreEqual (4.8, pts[5].Y, 0.25, "7.Y");
  1671. Assert.AreEqual (15.0, pts[6].X, 0.25, "5.X");
  1672. Assert.AreEqual (5.5, pts[6].Y, 0.25, "5.Y");
  1673. Assert.AreEqual (5.0, pts[7].X, 0.25, "6.X");
  1674. Assert.AreEqual (5.5, pts[7].Y, 0.25, "6.Y");
  1675. Assert.AreEqual (5.4, pts[8].X, 0.25, "8.X");
  1676. Assert.AreEqual (4.8, pts[8].Y, 0.25, "8.Y");
  1677. byte[] types = path.PathTypes;
  1678. Assert.AreEqual (0, types[0], "0");
  1679. Assert.AreEqual (1, types[1], "1");
  1680. Assert.AreEqual (129, types[2], "2");
  1681. Assert.AreEqual (0, types[3], "3");
  1682. Assert.AreEqual (1, types[4], "4");
  1683. Assert.AreEqual (1, types[5], "5");
  1684. Assert.AreEqual (1, types[6], "6");
  1685. Assert.AreEqual (1, types[7], "7");
  1686. Assert.AreEqual (129, types[8], "8");
  1687. }
  1688. [Test]
  1689. [Category ("NotWorking")]
  1690. public void Widen_Pen_Matrix_Null ()
  1691. {
  1692. Pen pen = new Pen (Color.Blue);
  1693. GraphicsPath path = new GraphicsPath ();
  1694. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1695. path.Widen (pen, null);
  1696. Assert.AreEqual (9, path.PointCount, "Count");
  1697. CheckWiden3 (path);
  1698. }
  1699. [Test]
  1700. [Category ("NotWorking")]
  1701. public void Widen_Pen_Matrix_Empty ()
  1702. {
  1703. Pen pen = new Pen (Color.Blue);
  1704. GraphicsPath path = new GraphicsPath ();
  1705. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1706. path.Widen (pen, new Matrix ());
  1707. Assert.AreEqual (9, path.PointCount, "Count");
  1708. CheckWiden3 (path);
  1709. }
  1710. [Test]
  1711. public void Widen_Pen_Matrix_NonInvertible ()
  1712. {
  1713. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  1714. Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
  1715. GraphicsPath path = new GraphicsPath ();
  1716. path.Widen (new Pen (Color.Blue), matrix);
  1717. Assert.AreEqual (0, path.PointCount, "Points");
  1718. }
  1719. }
  1720. }