GraphicsPathTest.cs 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449
  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 very precise with curves
  726. RectangleF rect = path.GetBounds ();
  727. Assert.AreEqual (0.8333333f, rect.X, 0.2f, "Bounds.X");
  728. Assert.AreEqual (0.8333333f, rect.Y, 0.2f, "Bounds.Y");
  729. Assert.AreEqual (2.33333278f, rect.Width, 0.4f, "Bounds.Width");
  730. Assert.AreEqual (2.33333278f, rect.Height, 0.4f, "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. // note: GdipAddPathCurveI allows adding a "curve" with only 2 points (a.k.a. a line ;-)
  861. gp.Dispose ();
  862. }
  863. [Test]
  864. public void AddCurve_Point_2_Tension ()
  865. {
  866. GraphicsPath gp = new GraphicsPath ();
  867. gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) }, 1.0f);
  868. CheckCurve (gp);
  869. // note: GdipAddPathCurve2I allows adding a "curve" with only 2 points (a.k.a. a line ;-)
  870. gp.Dispose ();
  871. }
  872. [Test]
  873. [ExpectedException (typeof (ArgumentException))]
  874. public void AddCurve3_Point_2 ()
  875. {
  876. GraphicsPath gp = new GraphicsPath ();
  877. gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) }, 0, 2, 0.5f);
  878. // adding only two points isn't supported by GdipAddCurve3I
  879. }
  880. [Test]
  881. [ExpectedException (typeof (ArgumentNullException))]
  882. public void AddCurve_PointF_Null ()
  883. {
  884. new GraphicsPath ().AddCurve ((PointF[]) null);
  885. }
  886. [Test]
  887. [ExpectedException (typeof (ArgumentException))]
  888. public void AddCurve_PointF_0 ()
  889. {
  890. GraphicsPath gp = new GraphicsPath ();
  891. gp.AddCurve (new PointF[0]);
  892. }
  893. [Test]
  894. [ExpectedException (typeof (ArgumentException))]
  895. public void AddCurve_PointF_1 ()
  896. {
  897. GraphicsPath gp = new GraphicsPath ();
  898. gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
  899. }
  900. [Test]
  901. public void AddCurve_PointF_2 ()
  902. {
  903. GraphicsPath gp = new GraphicsPath ();
  904. gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  905. CheckCurve (gp);
  906. // note: GdipAddPathCurve allows adding a "curve" with only 2 points (a.k.a. a line ;-)
  907. gp.Dispose ();
  908. }
  909. [Test]
  910. public void AddCurve_PoinFt_2_Tension ()
  911. {
  912. GraphicsPath gp = new GraphicsPath ();
  913. gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 1.0f);
  914. CheckCurve (gp);
  915. // note: GdipAddPathCurve2 allows adding a "curve" with only 2 points (a.k.a. a line ;-)
  916. gp.Dispose ();
  917. }
  918. [Test]
  919. [ExpectedException (typeof (ArgumentException))]
  920. public void AddCurve3_PointF_2 ()
  921. {
  922. GraphicsPath gp = new GraphicsPath ();
  923. gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, 2, 0.5f);
  924. // adding only two points isn't supported by GdipAddCurve3
  925. }
  926. [Test]
  927. public void AddCurve_LargeTension ()
  928. {
  929. GraphicsPath gp = new GraphicsPath ();
  930. gp.AddCurve (new PointF[3] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f) }, 0, 2, Single.MaxValue);
  931. Assert.AreEqual (7, gp.PointCount, "PointCount");
  932. gp.Dispose ();
  933. }
  934. [Test]
  935. [ExpectedException (typeof (ArgumentException))]
  936. public void AddCurve_ZeroSegments ()
  937. {
  938. GraphicsPath gp = new GraphicsPath ();
  939. gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, 0, 0.5f);
  940. }
  941. [Test]
  942. [ExpectedException (typeof (ArgumentException))]
  943. public void AddCurve_NegativeSegments ()
  944. {
  945. GraphicsPath gp = new GraphicsPath ();
  946. gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, -1, 0.5f);
  947. }
  948. [Test]
  949. [ExpectedException (typeof (ArgumentException))]
  950. public void AddCurve_OffsetTooLarge ()
  951. {
  952. GraphicsPath gp = new GraphicsPath ();
  953. gp.AddCurve (new PointF[3] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f) }, 1, 2, 0.5f);
  954. }
  955. [Test]
  956. public void AddCurve_Offset ()
  957. {
  958. GraphicsPath gp = new GraphicsPath ();
  959. gp.AddCurve (new PointF[4] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f), new PointF (0f, 10f) }, 1, 2, 0.5f);
  960. Assert.AreEqual (7, gp.PointCount, "PointCount");
  961. gp.Dispose ();
  962. }
  963. private FontFamily GetFontFamily ()
  964. {
  965. try {
  966. return FontFamily.GenericMonospace;
  967. }
  968. catch (ArgumentException) {
  969. Assert.Ignore ("GenericMonospace FontFamily couldn't be found");
  970. return null;
  971. }
  972. }
  973. [Test]
  974. [ExpectedException (typeof (NullReferenceException))]
  975. public void AddString_NullString ()
  976. {
  977. GraphicsPath gp = new GraphicsPath ();
  978. FontFamily ff = GetFontFamily ();
  979. gp.AddString (null, ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
  980. }
  981. [Test]
  982. public void AddString_EmptyString ()
  983. {
  984. GraphicsPath gp = new GraphicsPath ();
  985. FontFamily ff = GetFontFamily ();
  986. gp.AddString (String.Empty, ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
  987. Assert.AreEqual (0, gp.PointCount, "PointCount");
  988. }
  989. [Test]
  990. [ExpectedException (typeof (ArgumentException))]
  991. public void AddString_NullFontFamily ()
  992. {
  993. GraphicsPath gp = new GraphicsPath ();
  994. gp.AddString ("mono", null, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
  995. }
  996. [Test]
  997. public void AddString_NegativeSize ()
  998. {
  999. GraphicsPath gp = new GraphicsPath ();
  1000. FontFamily ff = GetFontFamily ();
  1001. gp.AddString ("mono", ff, 0, -10, new Point (10, 10), StringFormat.GenericDefault);
  1002. Assert.IsTrue (gp.PointCount > 0, "PointCount");
  1003. }
  1004. [Test]
  1005. [Category ("NotWorking")] // StringFormat not yet supported in libgdiplus
  1006. public void AddString_StringFormat ()
  1007. {
  1008. FontFamily ff = GetFontFamily ();
  1009. // null maps to ?
  1010. GraphicsPath gp1 = new GraphicsPath ();
  1011. gp1.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), null);
  1012. // StringFormat.GenericDefault
  1013. GraphicsPath gp2 = new GraphicsPath ();
  1014. gp2.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericDefault);
  1015. Assert.AreEqual (gp1.PointCount, gp2.PointCount, "GenericDefault");
  1016. // StringFormat.GenericTypographic
  1017. GraphicsPath gp3 = new GraphicsPath ();
  1018. gp3.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericTypographic);
  1019. Assert.IsFalse (gp1.PointCount == gp3.PointCount, "GenericTypographic");
  1020. }
  1021. [Test]
  1022. public void GetBounds_Empty_Empty ()
  1023. {
  1024. GraphicsPath gp = new GraphicsPath ();
  1025. RectangleF rect = gp.GetBounds ();
  1026. Assert.AreEqual (0.0f, rect.X, "Bounds.X");
  1027. Assert.AreEqual (0.0f, rect.Y, "Bounds.Y");
  1028. Assert.AreEqual (0.0f, rect.Width, "Bounds.Width");
  1029. Assert.AreEqual (0.0f, rect.Height, "Bounds.Height");
  1030. }
  1031. private void CheckRectangleBounds (RectangleF rect)
  1032. {
  1033. Assert.AreEqual (1.0f, rect.X, "Bounds.X");
  1034. Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
  1035. Assert.AreEqual (2.0f, rect.Width, "Bounds.Width");
  1036. Assert.AreEqual (2.0f, rect.Height, "Bounds.Height");
  1037. }
  1038. [Test]
  1039. public void GetBounds_Empty_Rectangle ()
  1040. {
  1041. GraphicsPath gp = new GraphicsPath ();
  1042. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  1043. CheckRectangleBounds (gp.GetBounds ());
  1044. }
  1045. [Test]
  1046. public void GetBounds_Null_Rectangle ()
  1047. {
  1048. GraphicsPath gp = new GraphicsPath ();
  1049. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  1050. CheckRectangleBounds (gp.GetBounds (null));
  1051. }
  1052. [Test]
  1053. public void GetBounds_MatrixEmpty_Rectangle ()
  1054. {
  1055. GraphicsPath gp = new GraphicsPath ();
  1056. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  1057. CheckRectangleBounds (gp.GetBounds (new Matrix ()));
  1058. }
  1059. [Test]
  1060. public void GetBounds_NullNull_Rectangle ()
  1061. {
  1062. GraphicsPath gp = new GraphicsPath ();
  1063. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  1064. CheckRectangleBounds (gp.GetBounds (null, null));
  1065. }
  1066. [Test]
  1067. [Category ("NotWorking")] // can't/wont duplicate the lack of precision
  1068. public void GetBounds_WithPen ()
  1069. {
  1070. Rectangle rect = new Rectangle (1, 1, 2, 2);
  1071. Pen p = new Pen (Color.Aqua, 0);
  1072. GraphicsPath gp = new GraphicsPath ();
  1073. gp.AddRectangle (rect);
  1074. RectangleF bounds = gp.GetBounds (null, p);
  1075. // those bounds doesn't make any sense (even visually)
  1076. // probably null gets mis-interpreted ???
  1077. Assert.AreEqual (-6.09999943f, bounds.X, "NullMatrix.Bounds.X");
  1078. Assert.AreEqual (-6.09999943f, bounds.Y, "NullMatrix.Bounds.Y");
  1079. Assert.AreEqual (16.1999989f, bounds.Width, "NullMatrix.Bounds.Width");
  1080. Assert.AreEqual (16.1999989f, bounds.Height, "NullMatrix.Bounds.Height");
  1081. Matrix m = new Matrix ();
  1082. bounds = gp.GetBounds (m, p);
  1083. Assert.AreEqual (-0.419999957f, bounds.X, "EmptyMatrix.Bounds.X");
  1084. Assert.AreEqual (-0.419999957f, bounds.Y, "EmptyMatrix.Bounds.Y");
  1085. Assert.AreEqual (4.83999968f, bounds.Width, "EmptyMatrix.Bounds.Width");
  1086. Assert.AreEqual (4.83999968f, bounds.Height, "EmptyMatrix.Bounds.Height");
  1087. // visually we can see the bounds just a pixel bigger than the rectangle
  1088. gp = new GraphicsPath ();
  1089. gp.AddRectangle (rect);
  1090. gp.Widen (p);
  1091. bounds = gp.GetBounds (null);
  1092. Assert.AreEqual (0.499999523f, bounds.X, "WidenNullMatrix.Bounds.X");
  1093. Assert.AreEqual (0.499999523f, bounds.Y, "WidenNullMatrix.Bounds.Y");
  1094. Assert.AreEqual (3.000001f, bounds.Width, "WidenNullMatrix.Bounds.Width");
  1095. Assert.AreEqual (3.000001f, bounds.Height, "WidenNullMatrix.Bounds.Height");
  1096. bounds = gp.GetBounds (m);
  1097. Assert.AreEqual (0.499999523f, bounds.X, "WidenEmptyMatrix.Bounds.X");
  1098. Assert.AreEqual (0.499999523f, bounds.Y, "WidenEmptyMatrix.Bounds.Y");
  1099. Assert.AreEqual (3.000001f, bounds.Width, "WidenEmptyMatrix.Bounds.Width");
  1100. Assert.AreEqual (3.000001f, bounds.Height, "WidenEmptyMatrix.Bounds.Height");
  1101. }
  1102. private void CheckPieBounds (RectangleF rect)
  1103. {
  1104. Assert.AreEqual (60.0f, rect.X, 1, "Bounds.X");
  1105. Assert.AreEqual (60.0f, rect.Y, 1, "Bounds.Y");
  1106. Assert.AreEqual (43.3f, rect.Width, 1, "Bounds.Width");
  1107. Assert.AreEqual (48.3f, rect.Height, 1, "Bounds.Height");
  1108. }
  1109. [Test]
  1110. public void GetBounds_Empty_Pie ()
  1111. {
  1112. GraphicsPath gp = new GraphicsPath ();
  1113. gp.AddPie (10, 10, 100, 100, 30, 45);
  1114. CheckPieBounds (gp.GetBounds ());
  1115. gp.Dispose ();
  1116. }
  1117. [Test]
  1118. public void GetBounds_Null_Pie ()
  1119. {
  1120. GraphicsPath gp = new GraphicsPath ();
  1121. gp.AddPie (10, 10, 100, 100, 30, 45);
  1122. CheckPieBounds (gp.GetBounds (null));
  1123. gp.Dispose ();
  1124. }
  1125. [Test]
  1126. public void GetBounds_MatrixEmpty_Pie ()
  1127. {
  1128. GraphicsPath gp = new GraphicsPath ();
  1129. gp.AddPie (10, 10, 100, 100, 30, 45);
  1130. CheckPieBounds (gp.GetBounds (new Matrix ()));
  1131. gp.Dispose ();
  1132. }
  1133. [Test]
  1134. public void GetBounds_NullNull_Pie ()
  1135. {
  1136. GraphicsPath gp = new GraphicsPath ();
  1137. gp.AddPie (10, 10, 100, 100, 30, 45);
  1138. CheckPieBounds (gp.GetBounds (null, null));
  1139. gp.Dispose ();
  1140. }
  1141. [Test]
  1142. public void GetBounds_Empty_ClosedCurve ()
  1143. {
  1144. GraphicsPath gp = new GraphicsPath ();
  1145. gp.AddClosedCurve (new Point[4] { new Point (20, 100), new Point (70, 10),
  1146. new Point (130, 200), new Point (180, 100) });
  1147. #if false
  1148. // so far from reality that it's totally useless
  1149. Assert.AreEqual (1.666666f, rect.X, 0.00001, "Bounds.X");
  1150. Assert.AreEqual (-6.66666f, rect.Y, 1, "Bounds.Y");
  1151. Assert.AreEqual (196.6666f, rect.Width, 1, "Bounds.Width");
  1152. Assert.AreEqual (221.6666f, rect.Height, 1, "Bounds.Height");
  1153. #endif
  1154. gp.Dispose ();
  1155. }
  1156. [Test]
  1157. [ExpectedException (typeof (ArgumentNullException))]
  1158. public void Transform_Null ()
  1159. {
  1160. new GraphicsPath ().Transform (null);
  1161. }
  1162. [Test]
  1163. public void Transform_Empty ()
  1164. {
  1165. // no points in path and no exception
  1166. new GraphicsPath ().Transform (new Matrix ());
  1167. }
  1168. private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
  1169. {
  1170. Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
  1171. for (int i = 0; i < expected.PointCount; i++) {
  1172. Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
  1173. Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
  1174. }
  1175. }
  1176. private void CompareFlats (GraphicsPath flat, GraphicsPath original)
  1177. {
  1178. Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
  1179. for (int i = 0; i < flat.PointCount; i++) {
  1180. Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
  1181. }
  1182. }
  1183. [Test]
  1184. public void Flatten_Empty ()
  1185. {
  1186. GraphicsPath path = new GraphicsPath ();
  1187. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1188. // this is a no-op as there's nothing in the path
  1189. path.Flatten ();
  1190. ComparePaths (path, clone);
  1191. }
  1192. [Test]
  1193. public void Flatten_Null ()
  1194. {
  1195. GraphicsPath path = new GraphicsPath ();
  1196. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1197. // this is a no-op as there's nothing in the path
  1198. // an no matrix to apply
  1199. path.Flatten (null);
  1200. ComparePaths (path, clone);
  1201. }
  1202. [Test]
  1203. public void Flatten_NullFloat ()
  1204. {
  1205. GraphicsPath path = new GraphicsPath ();
  1206. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1207. // this is a no-op as there's nothing in the path
  1208. // an no matrix to apply
  1209. path.Flatten (null, 1f);
  1210. ComparePaths (path, clone);
  1211. }
  1212. [Test]
  1213. public void Flatten_Arc ()
  1214. {
  1215. GraphicsPath path = new GraphicsPath ();
  1216. path.AddArc (0f, 0f, 100f, 100f, 30, 30);
  1217. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1218. path.Flatten ();
  1219. CompareFlats (path, clone);
  1220. }
  1221. [Test]
  1222. public void Flatten_Bezier ()
  1223. {
  1224. GraphicsPath path = new GraphicsPath ();
  1225. path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
  1226. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1227. path.Flatten ();
  1228. CompareFlats (path, clone);
  1229. }
  1230. [Test]
  1231. public void Flatten_ClosedCurve ()
  1232. {
  1233. GraphicsPath path = new GraphicsPath ();
  1234. path.AddClosedCurve (new Point[4] {
  1235. new Point (0, 0), new Point (40, 20),
  1236. new Point (20, 40), new Point (40, 40)
  1237. });
  1238. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1239. path.Flatten ();
  1240. CompareFlats (path, clone);
  1241. }
  1242. [Test]
  1243. public void Flatten_Curve ()
  1244. {
  1245. GraphicsPath path = new GraphicsPath ();
  1246. path.AddCurve (new Point[4] {
  1247. new Point (0, 0), new Point (40, 20),
  1248. new Point (20, 40), new Point (40, 40)
  1249. });
  1250. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1251. path.Flatten ();
  1252. CompareFlats (path, clone);
  1253. }
  1254. [Test]
  1255. public void Flatten_Ellipse ()
  1256. {
  1257. GraphicsPath path = new GraphicsPath ();
  1258. path.AddEllipse (10f, 10f, 100f, 100f);
  1259. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1260. path.Flatten ();
  1261. CompareFlats (path, clone);
  1262. }
  1263. [Test]
  1264. public void Flatten_Line ()
  1265. {
  1266. GraphicsPath path = new GraphicsPath ();
  1267. path.AddLine (10f, 10f, 100f, 100f);
  1268. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1269. path.Flatten ();
  1270. ComparePaths (path, clone);
  1271. }
  1272. [Test]
  1273. public void Flatten_Pie ()
  1274. {
  1275. GraphicsPath path = new GraphicsPath ();
  1276. path.AddPie (0, 0, 100, 100, 30, 30);
  1277. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1278. path.Flatten ();
  1279. CompareFlats (path, clone);
  1280. }
  1281. [Test]
  1282. public void Flatten_Polygon ()
  1283. {
  1284. GraphicsPath path = new GraphicsPath ();
  1285. path.AddPolygon (new Point[4] {
  1286. new Point (0, 0), new Point (10, 10),
  1287. new Point (20, 20), new Point (40, 40)
  1288. });
  1289. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1290. path.Flatten ();
  1291. ComparePaths (path, clone);
  1292. }
  1293. [Test]
  1294. public void Flatten_Rectangle ()
  1295. {
  1296. GraphicsPath path = new GraphicsPath ();
  1297. path.AddRectangle (new Rectangle (0, 0, 100, 100));
  1298. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1299. path.Flatten ();
  1300. ComparePaths (path, clone);
  1301. }
  1302. private void CheckWrap (GraphicsPath path)
  1303. {
  1304. Assert.AreEqual (3, path.PointCount, "Count");
  1305. PointF[] pts = path.PathPoints;
  1306. Assert.AreEqual (0, pts[0].X, 1e-30, "0.X");
  1307. Assert.AreEqual (0, pts[0].Y, 1e-30, "0.Y");
  1308. Assert.AreEqual (0, pts[1].X, 1e-30, "1.X");
  1309. Assert.AreEqual (0, pts[1].Y, 1e-30, "1.Y");
  1310. Assert.AreEqual (0, pts[2].X, 1e-30, "2.X");
  1311. Assert.AreEqual (0, pts[2].Y, 1e-30, "2.Y");
  1312. byte[] types = path.PathTypes;
  1313. Assert.AreEqual (0, types[0], "0");
  1314. Assert.AreEqual (1, types[1], "1");
  1315. Assert.AreEqual (129, types[2], "2");
  1316. }
  1317. private void CheckWrapNaN (GraphicsPath path, bool closed)
  1318. {
  1319. Assert.AreEqual (3, path.PointCount, "Count");
  1320. PointF[] pts = path.PathPoints;
  1321. Assert.AreEqual (Single.NaN, pts[0].X, "0.X");
  1322. Assert.AreEqual (Single.NaN, pts[0].Y, "0.Y");
  1323. Assert.AreEqual (Single.NaN, pts[1].X, "1.X");
  1324. Assert.AreEqual (Single.NaN, pts[1].Y, "1.Y");
  1325. Assert.AreEqual (Single.NaN, pts[2].X, "2.X");
  1326. Assert.AreEqual (Single.NaN, pts[2].Y, "2.Y");
  1327. byte[] types = path.PathTypes;
  1328. Assert.AreEqual (0, types[0], "0");
  1329. Assert.AreEqual (1, types[1], "1");
  1330. Assert.AreEqual (closed ? 129 : 1, types[2], "2");
  1331. }
  1332. [Test]
  1333. [ExpectedException (typeof (ArgumentNullException))]
  1334. public void Warp_Null ()
  1335. {
  1336. new GraphicsPath ().Warp (null, new RectangleF ());
  1337. }
  1338. [Test]
  1339. [ExpectedException (typeof (ArgumentException))]
  1340. public void Warp_NoPoints ()
  1341. {
  1342. new GraphicsPath ().Warp (new PointF[0], new RectangleF ());
  1343. }
  1344. [Test]
  1345. public void Wrap_NoPoint ()
  1346. {
  1347. using (GraphicsPath gp = new GraphicsPath ()) {
  1348. Assert.AreEqual (0, gp.PointCount, "PointCount-1");
  1349. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1350. RectangleF r = new RectangleF (10, 20, 30, 40);
  1351. gp.Warp (pts, r, new Matrix ());
  1352. Assert.AreEqual (0, gp.PointCount, "PointCount-2");
  1353. }
  1354. }
  1355. [Test]
  1356. [Category ("NotWorking")]
  1357. public void Wrap_SinglePoint ()
  1358. {
  1359. using (GraphicsPath gp = new GraphicsPath ()) {
  1360. gp.AddLines (new Point[1] { new Point (1, 1) });
  1361. // Special case - a line with a single point is valid
  1362. Assert.AreEqual (1, gp.PointCount, "PointCount-1");
  1363. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1364. RectangleF r = new RectangleF (10, 20, 30, 40);
  1365. gp.Warp (pts, r, new Matrix ());
  1366. Assert.AreEqual (0, gp.PointCount, "PointCount-2");
  1367. }
  1368. }
  1369. [Test]
  1370. [Category ("NotWorking")]
  1371. public void Wrap_Line ()
  1372. {
  1373. using (GraphicsPath gp = new GraphicsPath ()) {
  1374. gp.AddLine (new Point (1, 1), new Point (20, 20));
  1375. Assert.AreEqual (2, gp.PointCount, "PointCount-1");
  1376. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1377. RectangleF r = new RectangleF (10, 20, 30, 40);
  1378. gp.Warp (pts, r, new Matrix ());
  1379. Assert.AreEqual (2, gp.PointCount, "PointCount-2");
  1380. }
  1381. }
  1382. [Test]
  1383. [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
  1384. public void Warp_NullMatrix ()
  1385. {
  1386. PointF[] pts = new PointF[1] { new PointF (0,0) };
  1387. GraphicsPath path = new GraphicsPath ();
  1388. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1389. RectangleF r = new RectangleF (10, 20, 30, 40);
  1390. path.Warp (pts, r, null);
  1391. CheckWrap (path);
  1392. }
  1393. [Test]
  1394. [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
  1395. public void Warp_EmptyMatrix ()
  1396. {
  1397. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1398. GraphicsPath path = new GraphicsPath ();
  1399. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1400. RectangleF r = new RectangleF (10, 20, 30, 40);
  1401. path.Warp (pts, r, new Matrix ());
  1402. CheckWrap (path);
  1403. }
  1404. [Test]
  1405. [Category ("NotWorking")]
  1406. public void Warp_Rectangle_Empty ()
  1407. {
  1408. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1409. GraphicsPath path = new GraphicsPath ();
  1410. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1411. path.Warp (pts, new RectangleF (), null);
  1412. CheckWrapNaN (path, true);
  1413. }
  1414. [Test]
  1415. [Category ("NotWorking")]
  1416. public void Warp_Rectangle_NegativeWidthHeight ()
  1417. {
  1418. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1419. GraphicsPath path = new GraphicsPath ();
  1420. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1421. RectangleF r = new RectangleF (10, 20, -30, -40);
  1422. path.Warp (pts, r, null);
  1423. Assert.AreEqual (3, path.PointCount, "Count");
  1424. pts = path.PathPoints;
  1425. Assert.AreEqual (1.131355e-39, pts[0].X, 1e40, "0.X");
  1426. Assert.AreEqual (-2.0240637E-33, pts[0].Y, 1e40, "0.Y");
  1427. Assert.AreEqual (1.070131E-39, pts[1].X, 1e40, "1.X");
  1428. Assert.AreEqual (-2.02406389E-33, pts[1].Y, 1e40, "1.Y");
  1429. Assert.AreEqual (3.669146E-40, pts[2].X, 1e40, "2.X");
  1430. Assert.AreEqual (-6.746879E-34, pts[2].Y, 1e40, "2.Y");
  1431. byte[] types = path.PathTypes;
  1432. Assert.AreEqual (0, types[0], "0");
  1433. Assert.AreEqual (1, types[1], "1");
  1434. Assert.AreEqual (129, types[2], "2");
  1435. }
  1436. [Test]
  1437. [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
  1438. public void Warp_Matrix_NonInvertible ()
  1439. {
  1440. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  1441. Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
  1442. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1443. GraphicsPath path = new GraphicsPath ();
  1444. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1445. RectangleF r = new RectangleF (10, 20, 30, 40);
  1446. path.Warp (pts, r, matrix);
  1447. Assert.AreEqual (3, path.PointCount, "Count");
  1448. pts = path.PathPoints;
  1449. Assert.AreEqual (47, pts[0].X, "0.X");
  1450. Assert.AreEqual (30, pts[0].Y, "0.Y");
  1451. Assert.AreEqual (47, pts[1].X, "1.X");
  1452. Assert.AreEqual (30, pts[1].Y, "1.Y");
  1453. Assert.AreEqual (47, pts[2].X, "2.X");
  1454. Assert.AreEqual (30, pts[2].Y, "2.Y");
  1455. byte[] types = path.PathTypes;
  1456. Assert.AreEqual (0, types[0], "0");
  1457. Assert.AreEqual (1, types[1], "1");
  1458. Assert.AreEqual (129, types[2], "2");
  1459. }
  1460. [Test]
  1461. [Category ("NotWorking")]
  1462. public void Warp_Bilinear ()
  1463. {
  1464. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1465. GraphicsPath path = new GraphicsPath ();
  1466. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1467. RectangleF r = new RectangleF (10, 20, 30, 40);
  1468. path.Warp (pts, r, new Matrix (), WarpMode.Bilinear);
  1469. // note that the last point is no more closed
  1470. CheckWrapNaN (path, false);
  1471. }
  1472. [Test]
  1473. [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
  1474. public void Warp_Perspective ()
  1475. {
  1476. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1477. GraphicsPath path = new GraphicsPath ();
  1478. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1479. RectangleF r = new RectangleF (10, 20, 30, 40);
  1480. path.Warp (pts, r, new Matrix (), WarpMode.Perspective);
  1481. CheckWrap (path);
  1482. }
  1483. [Test]
  1484. public void Warp_Invalid ()
  1485. {
  1486. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1487. GraphicsPath path = new GraphicsPath ();
  1488. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1489. RectangleF r = new RectangleF (10, 20, 30, 40);
  1490. path.Warp (pts, r, new Matrix (), (WarpMode) Int32.MinValue);
  1491. Assert.AreEqual (0, path.PointCount, "Count");
  1492. }
  1493. [Test]
  1494. [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
  1495. public void Warp_Flatness_Negative ()
  1496. {
  1497. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1498. GraphicsPath path = new GraphicsPath ();
  1499. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1500. RectangleF r = new RectangleF (10, 20, 30, 40);
  1501. path.Warp (pts, r, new Matrix (), WarpMode.Perspective, -1f);
  1502. CheckWrap (path);
  1503. }
  1504. [Test]
  1505. [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
  1506. public void Warp_Flatness_OverOne ()
  1507. {
  1508. PointF[] pts = new PointF[1] { new PointF (0, 0) };
  1509. GraphicsPath path = new GraphicsPath ();
  1510. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1511. RectangleF r = new RectangleF (10, 20, 30, 40);
  1512. path.Warp (pts, r, new Matrix (), WarpMode.Perspective, 2.0f);
  1513. CheckWrap (path);
  1514. }
  1515. [Test]
  1516. public void SetMarkers_EmptyPath ()
  1517. {
  1518. new GraphicsPath ().SetMarkers ();
  1519. }
  1520. [Test]
  1521. public void ClearMarkers_EmptyPath ()
  1522. {
  1523. new GraphicsPath ().ClearMarkers ();
  1524. }
  1525. [Test]
  1526. public void CloseFigure_EmptyPath ()
  1527. {
  1528. new GraphicsPath ().CloseFigure ();
  1529. }
  1530. [Test]
  1531. public void CloseAllFigures_EmptyPath ()
  1532. {
  1533. new GraphicsPath ().CloseAllFigures ();
  1534. }
  1535. [Test]
  1536. public void StartClose_AddArc ()
  1537. {
  1538. GraphicsPath path = new GraphicsPath ();
  1539. path.AddLine (1, 1, 2, 2);
  1540. path.AddArc (10, 10, 100, 100, 90, 180);
  1541. path.AddLine (10, 10, 20, 20);
  1542. byte[] types = path.PathTypes;
  1543. // check first types
  1544. Assert.AreEqual (0, types[0], "start/Line");
  1545. Assert.AreEqual (1, types[2], "start/Arc");
  1546. // check last types
  1547. Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
  1548. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1549. }
  1550. [Test]
  1551. public void StartClose_AddBezier ()
  1552. {
  1553. GraphicsPath path = new GraphicsPath ();
  1554. path.AddLine (1, 1, 2, 2);
  1555. path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200);
  1556. path.AddLine (10, 10, 20, 20);
  1557. byte[] types = path.PathTypes;
  1558. // check first types
  1559. Assert.AreEqual (0, types[0], "start/Line");
  1560. Assert.AreEqual (1, types[2], "start/Bezier");
  1561. // check last types
  1562. Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
  1563. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1564. }
  1565. [Test]
  1566. public void StartClose_AddBeziers ()
  1567. {
  1568. GraphicsPath path = new GraphicsPath ();
  1569. path.AddLine (1, 1, 2, 2);
  1570. path.AddBeziers (new Point[7] { new Point (10, 10),
  1571. new Point (20, 10), new Point (20, 20), new Point (30, 20),
  1572. new Point (40, 40), new Point (50, 40), new Point (50, 50)
  1573. });
  1574. path.AddLine (10, 10, 20, 20);
  1575. byte[] types = path.PathTypes;
  1576. // check first types
  1577. Assert.AreEqual (0, types[0], "start/Line");
  1578. Assert.AreEqual (1, types[2], "start/Bezier");
  1579. // check last types
  1580. Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
  1581. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1582. }
  1583. [Test]
  1584. public void StartClose_AddClosedCurve ()
  1585. {
  1586. GraphicsPath path = new GraphicsPath ();
  1587. path.AddLine (1, 1, 2, 2);
  1588. path.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1589. path.AddLine (10, 10, 20, 20);
  1590. byte[] types = path.PathTypes;
  1591. // check first types
  1592. Assert.AreEqual (0, types[0], "start/Line");
  1593. Assert.AreEqual (0, types[2], "start/ClosedCurve");
  1594. // check last types
  1595. Assert.AreEqual (131, types[path.PointCount - 3], "end/ClosedCurve");
  1596. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
  1597. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
  1598. }
  1599. [Test]
  1600. public void StartClose_AddCurve ()
  1601. {
  1602. GraphicsPath path = new GraphicsPath ();
  1603. path.AddLine (1, 1, 2, 2);
  1604. path.AddCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1605. path.AddLine (10, 10, 20, 20);
  1606. byte[] types = path.PathTypes;
  1607. // check first types
  1608. Assert.AreEqual (0, types[0], "start/Line");
  1609. Assert.AreEqual (1, types[2], "start/Curve");
  1610. // check last types
  1611. Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
  1612. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1613. }
  1614. [Test]
  1615. public void StartClose_AddEllipse ()
  1616. {
  1617. GraphicsPath path = new GraphicsPath ();
  1618. path.AddLine (1, 1, 2, 2);
  1619. path.AddEllipse (10, 10, 100, 100);
  1620. path.AddLine (10, 10, 20, 20);
  1621. byte[] types = path.PathTypes;
  1622. // check first types
  1623. Assert.AreEqual (0, types[0], "start/Line");
  1624. Assert.AreEqual (0, types[2], "start/Ellipse");
  1625. // check last types
  1626. Assert.AreEqual (131, types[path.PointCount - 3], "end/Ellipse");
  1627. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
  1628. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
  1629. }
  1630. [Test]
  1631. public void StartClose_AddLine ()
  1632. {
  1633. GraphicsPath path = new GraphicsPath ();
  1634. path.AddLine (1, 1, 2, 2);
  1635. path.AddLine (5, 5, 10, 10);
  1636. path.AddLine (10, 10, 20, 20);
  1637. byte[] types = path.PathTypes;
  1638. // check first types
  1639. Assert.AreEqual (0, types[0], "start/Line");
  1640. Assert.AreEqual (1, types[2], "start/Line2");
  1641. // check last types
  1642. Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
  1643. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1644. }
  1645. [Test]
  1646. public void StartClose_AddLines ()
  1647. {
  1648. GraphicsPath path = new GraphicsPath ();
  1649. path.AddLine (1, 1, 2, 2);
  1650. path.AddLines (new Point[4] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20) });
  1651. path.AddLine (10, 10, 20, 20);
  1652. byte[] types = path.PathTypes;
  1653. // check first types
  1654. Assert.AreEqual (0, types[0], "start/Line");
  1655. Assert.AreEqual (1, types[2], "start/Lines");
  1656. // check last types
  1657. Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
  1658. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1659. }
  1660. [Test]
  1661. public void StartClose_AddPath_Connect ()
  1662. {
  1663. GraphicsPath inner = new GraphicsPath ();
  1664. inner.AddArc (10, 10, 100, 100, 90, 180);
  1665. GraphicsPath path = new GraphicsPath ();
  1666. path.AddLine (1, 1, 2, 2);
  1667. path.AddPath (inner, true);
  1668. path.AddLine (10, 10, 20, 20);
  1669. byte[] types = path.PathTypes;
  1670. // check first types
  1671. Assert.AreEqual (0, types[0], "start/Line");
  1672. Assert.AreEqual (1, types[2], "start/Path");
  1673. // check last types
  1674. Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
  1675. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1676. }
  1677. [Test]
  1678. public void StartClose_AddPath_NoConnect ()
  1679. {
  1680. GraphicsPath inner = new GraphicsPath ();
  1681. inner.AddArc (10, 10, 100, 100, 90, 180);
  1682. GraphicsPath path = new GraphicsPath ();
  1683. path.AddLine (1, 1, 2, 2);
  1684. path.AddPath (inner, false);
  1685. path.AddLine (10, 10, 20, 20);
  1686. byte[] types = path.PathTypes;
  1687. // check first types
  1688. Assert.AreEqual (0, types[0], "start/Line");
  1689. Assert.AreEqual (0, types[2], "start/Path");
  1690. // check last types
  1691. Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
  1692. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1693. }
  1694. [Test]
  1695. public void StartClose_AddPie ()
  1696. {
  1697. GraphicsPath path = new GraphicsPath ();
  1698. path.AddLine (1, 1, 2, 2);
  1699. path.AddPie (10, 10, 10, 10, 90, 180);
  1700. path.AddLine (10, 10, 20, 20);
  1701. byte[] types = path.PathTypes;
  1702. // check first types
  1703. Assert.AreEqual (0, types[0], "start/Line");
  1704. Assert.AreEqual (0, types[2], "start/Pie");
  1705. // check last types
  1706. // libgdiplus draws pie by ending with a line (not a curve) section
  1707. Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie");
  1708. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1709. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1710. }
  1711. [Test]
  1712. public void StartClose_AddPolygon ()
  1713. {
  1714. GraphicsPath path = new GraphicsPath ();
  1715. path.AddLine (1, 1, 2, 2);
  1716. path.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1717. path.AddLine (10, 10, 20, 20);
  1718. byte[] types = path.PathTypes;
  1719. // check first types
  1720. Assert.AreEqual (0, types[0], "start/Line");
  1721. Assert.AreEqual (0, types[2], "start/Polygon");
  1722. // check last types
  1723. Assert.AreEqual (129, types[path.PointCount - 3], "end/Polygon");
  1724. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1725. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1726. }
  1727. [Test]
  1728. public void StartClose_AddRectangle ()
  1729. {
  1730. GraphicsPath path = new GraphicsPath ();
  1731. path.AddLine (1, 1, 2, 2);
  1732. path.AddRectangle (new RectangleF (10, 10, 20, 20));
  1733. path.AddLine (10, 10, 20, 20);
  1734. byte[] types = path.PathTypes;
  1735. // check first types
  1736. Assert.AreEqual (0, types[0], "start/Line");
  1737. Assert.AreEqual (0, types[2], "start/Rectangle");
  1738. // check last types
  1739. Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangle");
  1740. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1741. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1742. }
  1743. [Test]
  1744. public void StartClose_AddRectangles ()
  1745. {
  1746. GraphicsPath path = new GraphicsPath ();
  1747. path.AddLine (1, 1, 2, 2);
  1748. path.AddRectangles (new RectangleF[2] {
  1749. new RectangleF (10, 10, 20, 20),
  1750. new RectangleF (20, 20, 10, 10) });
  1751. path.AddLine (10, 10, 20, 20);
  1752. byte[] types = path.PathTypes;
  1753. // check first types
  1754. Assert.AreEqual (0, types[0], "start/Line");
  1755. Assert.AreEqual (0, types[2], "start/Rectangles");
  1756. // check last types
  1757. Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
  1758. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1759. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1760. }
  1761. [Test]
  1762. [Category ("NotWorking")]
  1763. public void StartClose_AddString ()
  1764. {
  1765. GraphicsPath path = new GraphicsPath ();
  1766. path.AddLine (1, 1, 2, 2);
  1767. path.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new Point (20,20), StringFormat.GenericDefault);
  1768. path.AddLine (10, 10, 20, 20);
  1769. byte[] types = path.PathTypes;
  1770. // check first types
  1771. Assert.AreEqual (0, types[0], "start/Line");
  1772. Assert.AreEqual (0, types[2], "start/String");
  1773. // check last types
  1774. Assert.AreEqual (163, types[path.PointCount - 3], "end/String");
  1775. Assert.AreEqual (1, types[path.PointCount - 2], "start/Line2");
  1776. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1777. }
  1778. [Test]
  1779. [ExpectedException (typeof (ArgumentNullException))]
  1780. public void Widen_Pen_Null ()
  1781. {
  1782. new GraphicsPath ().Widen (null);
  1783. }
  1784. [Test]
  1785. [Category ("NotWorking")]
  1786. public void Widen_Pen ()
  1787. {
  1788. Pen pen = new Pen (Color.Blue);
  1789. GraphicsPath path = new GraphicsPath ();
  1790. path.AddRectangle (new Rectangle (1, 1, 2, 2));
  1791. Assert.AreEqual (4, path.PointCount, "Count-1");
  1792. path.Widen (pen);
  1793. Assert.AreEqual (12, path.PointCount, "Count-2");
  1794. PointF[] pts = path.PathPoints;
  1795. Assert.AreEqual (0.5, pts[0].X, 0.25, "0.X");
  1796. Assert.AreEqual (0.5, pts[0].Y, 0.25, "0.Y");
  1797. Assert.AreEqual (3.5, pts[1].X, 0.25, "1.X");
  1798. Assert.AreEqual (0.5, pts[1].Y, 0.25, "1.Y");
  1799. Assert.AreEqual (3.5, pts[2].X, 0.25, "2.X");
  1800. Assert.AreEqual (3.5, pts[2].Y, 0.25, "2.Y");
  1801. Assert.AreEqual (0.5, pts[3].X, 0.25, "3.X");
  1802. Assert.AreEqual (3.5, pts[3].Y, 0.25, "3.Y");
  1803. Assert.AreEqual (1.5, pts[4].X, 0.25, "4.X");
  1804. Assert.AreEqual (3.0, pts[4].Y, 0.25, "4.Y");
  1805. Assert.AreEqual (1.0, pts[5].X, 0.25, "5.X");
  1806. Assert.AreEqual (2.5, pts[5].Y, 0.25, "5.Y");
  1807. Assert.AreEqual (3.0, pts[6].X, 0.25, "6.X");
  1808. Assert.AreEqual (2.5, pts[6].Y, 0.25, "6.Y");
  1809. Assert.AreEqual (2.5, pts[7].X, 0.25, "7.X");
  1810. Assert.AreEqual (3.0, pts[7].Y, 0.25, "7.Y");
  1811. Assert.AreEqual (2.5, pts[8].X, 0.25, "8.X");
  1812. Assert.AreEqual (1.0, pts[8].Y, 0.25, "8.Y");
  1813. Assert.AreEqual (3.0, pts[9].X, 0.25, "9.X");
  1814. Assert.AreEqual (1.5, pts[9].Y, 0.25, "9.Y");
  1815. Assert.AreEqual (1.0, pts[10].X, 0.25, "10.X");
  1816. Assert.AreEqual (1.5, pts[10].Y, 0.25, "10.Y");
  1817. Assert.AreEqual (1.5, pts[11].X, 0.25, "11.X");
  1818. Assert.AreEqual (1.0, pts[11].Y, 0.25, "11.Y");
  1819. byte[] types = path.PathTypes;
  1820. Assert.AreEqual (0, types[0], "0");
  1821. Assert.AreEqual (1, types[1], "1");
  1822. Assert.AreEqual (1, types[2], "2");
  1823. Assert.AreEqual (129, types[3], "3");
  1824. Assert.AreEqual (0, types[4], "4");
  1825. Assert.AreEqual (1, types[5], "5");
  1826. Assert.AreEqual (1, types[6], "6");
  1827. Assert.AreEqual (1, types[7], "7");
  1828. Assert.AreEqual (1, types[8], "8");
  1829. Assert.AreEqual (1, types[9], "9");
  1830. Assert.AreEqual (1, types[10], "10");
  1831. Assert.AreEqual (129, types[11], "11");
  1832. }
  1833. [Test]
  1834. [ExpectedException (typeof (ArgumentNullException))]
  1835. public void Widen_Pen_Null_Matrix ()
  1836. {
  1837. new GraphicsPath ().Widen (null, new Matrix ());
  1838. }
  1839. [Test]
  1840. #if ONLY_1_1
  1841. [ExpectedException (typeof (OutOfMemoryException))]
  1842. #endif
  1843. public void Widen_NoPoint ()
  1844. {
  1845. using (GraphicsPath gp = new GraphicsPath ()) {
  1846. Assert.AreEqual (0, gp.PointCount, "PointCount-1");
  1847. Pen pen = new Pen (Color.Blue);
  1848. gp.Widen (pen);
  1849. Assert.AreEqual (0, gp.PointCount, "PointCount-2");
  1850. }
  1851. }
  1852. [Test]
  1853. [ExpectedException (typeof (OutOfMemoryException))]
  1854. public void Widen_SinglePoint ()
  1855. {
  1856. using (GraphicsPath gp = new GraphicsPath ()) {
  1857. gp.AddLines (new Point[1] { new Point (1, 1) });
  1858. // Special case - a line with a single point is valid
  1859. Assert.AreEqual (1, gp.PointCount, "PointCount");
  1860. gp.Widen (Pens.Red);
  1861. // oops ;-)
  1862. }
  1863. }
  1864. private void CheckWiden3 (GraphicsPath path)
  1865. {
  1866. PointF[] pts = path.PathPoints;
  1867. Assert.AreEqual (4.2, pts[0].X, 0.25, "0.X");
  1868. Assert.AreEqual (4.5, pts[0].Y, 0.25, "0.Y");
  1869. Assert.AreEqual (15.8, pts[1].X, 0.25, "1.X");
  1870. Assert.AreEqual (4.5, pts[1].Y, 0.25, "1.Y");
  1871. Assert.AreEqual (10.0, pts[2].X, 0.25, "2.X");
  1872. Assert.AreEqual (16.1, pts[2].Y, 0.25, "2.Y");
  1873. Assert.AreEqual (10.4, pts[3].X, 0.25, "3.X");
  1874. Assert.AreEqual (14.8, pts[3].Y, 0.25, "3.Y");
  1875. Assert.AreEqual (9.6, pts[4].X, 0.25, "4.X");
  1876. Assert.AreEqual (14.8, pts[4].Y, 0.25, "4.Y");
  1877. Assert.AreEqual (14.6, pts[5].X, 0.25, "7.X");
  1878. Assert.AreEqual (4.8, pts[5].Y, 0.25, "7.Y");
  1879. Assert.AreEqual (15.0, pts[6].X, 0.25, "5.X");
  1880. Assert.AreEqual (5.5, pts[6].Y, 0.25, "5.Y");
  1881. Assert.AreEqual (5.0, pts[7].X, 0.25, "6.X");
  1882. Assert.AreEqual (5.5, pts[7].Y, 0.25, "6.Y");
  1883. Assert.AreEqual (5.4, pts[8].X, 0.25, "8.X");
  1884. Assert.AreEqual (4.8, pts[8].Y, 0.25, "8.Y");
  1885. byte[] types = path.PathTypes;
  1886. Assert.AreEqual (0, types[0], "0");
  1887. Assert.AreEqual (1, types[1], "1");
  1888. Assert.AreEqual (129, types[2], "2");
  1889. Assert.AreEqual (0, types[3], "3");
  1890. Assert.AreEqual (1, types[4], "4");
  1891. Assert.AreEqual (1, types[5], "5");
  1892. Assert.AreEqual (1, types[6], "6");
  1893. Assert.AreEqual (1, types[7], "7");
  1894. Assert.AreEqual (129, types[8], "8");
  1895. }
  1896. [Test]
  1897. [Category ("NotWorking")]
  1898. public void Widen_Pen_Matrix_Null ()
  1899. {
  1900. Pen pen = new Pen (Color.Blue);
  1901. GraphicsPath path = new GraphicsPath ();
  1902. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1903. path.Widen (pen, null);
  1904. Assert.AreEqual (9, path.PointCount, "Count");
  1905. CheckWiden3 (path);
  1906. }
  1907. [Test]
  1908. [Category ("NotWorking")]
  1909. public void Widen_Pen_Matrix_Empty ()
  1910. {
  1911. Pen pen = new Pen (Color.Blue);
  1912. GraphicsPath path = new GraphicsPath ();
  1913. path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
  1914. path.Widen (pen, new Matrix ());
  1915. Assert.AreEqual (9, path.PointCount, "Count");
  1916. CheckWiden3 (path);
  1917. }
  1918. [Test]
  1919. [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
  1920. public void Widen_Pen_Matrix_NonInvertible ()
  1921. {
  1922. Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
  1923. Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
  1924. GraphicsPath path = new GraphicsPath ();
  1925. path.Widen (new Pen (Color.Blue), matrix);
  1926. Assert.AreEqual (0, path.PointCount, "Points");
  1927. }
  1928. private void CheckWidenedBounds (string message, GraphicsPath gp, Matrix m)
  1929. {
  1930. RectangleF bounds = gp.GetBounds (m);
  1931. Assert.AreEqual (0.5f, bounds.X, 0.00001f, message + ".Bounds.X");
  1932. Assert.AreEqual (0.5f, bounds.Y, 0.00001f, message + ".Bounds.Y");
  1933. Assert.AreEqual (3.0f, bounds.Width, 0.00001f, message + ".Bounds.Width");
  1934. Assert.AreEqual (3.0f, bounds.Height, 0.00001f, message + ".Bounds.Height");
  1935. }
  1936. [Test]
  1937. [Category ("NotWorking")]
  1938. public void Widen_Pen_SmallWidth ()
  1939. {
  1940. Matrix m = new Matrix ();
  1941. Rectangle rect = new Rectangle (1, 1, 2, 2);
  1942. // pen's smaller than 1.0 (width) are "promoted" to 1
  1943. Pen p = new Pen (Color.Aqua, 0);
  1944. GraphicsPath gp = new GraphicsPath ();
  1945. gp.AddRectangle (rect);
  1946. gp.Widen (p);
  1947. CheckWidenedBounds ("Width == 0, Null matrix", gp, null);
  1948. CheckWidenedBounds ("Width == 0, Empty matrix", gp, m);
  1949. p.Width = 0.5f;
  1950. gp = new GraphicsPath ();
  1951. gp.AddRectangle (rect);
  1952. gp.Widen (p);
  1953. CheckWidenedBounds ("Width == 0.5, Null matrix", gp, null);
  1954. CheckWidenedBounds ("Width == 0.5, Empty matrix", gp, m);
  1955. p.Width = 1.0f;
  1956. gp = new GraphicsPath ();
  1957. gp.AddRectangle (rect);
  1958. gp.Widen (p);
  1959. CheckWidenedBounds ("Width == 1.0, Null matrix", gp, null);
  1960. CheckWidenedBounds ("Width == 1.0, Empty matrix", gp, m);
  1961. p.Width = 1.1f;
  1962. gp = new GraphicsPath ();
  1963. gp.AddRectangle (rect);
  1964. gp.Widen (p);
  1965. RectangleF bounds = gp.GetBounds (m);
  1966. Assert.AreEqual (0.45f, bounds.X, 0.00001f, "1.1.Bounds.X");
  1967. Assert.AreEqual (0.45f, bounds.Y, 0.00001f, "1.1.Bounds.Y");
  1968. Assert.AreEqual (3.10f, bounds.Width, 0.00001f, "1.1.Bounds.Width");
  1969. Assert.AreEqual (3.10f, bounds.Height, 0.00001f, "1.1.Bounds.Height");
  1970. }
  1971. [Test]
  1972. [ExpectedException (typeof (ArgumentNullException))]
  1973. public void IsOutlineVisible_IntNull ()
  1974. {
  1975. new GraphicsPath ().IsOutlineVisible (1, 1, null);
  1976. }
  1977. [Test]
  1978. [ExpectedException (typeof (ArgumentNullException))]
  1979. public void IsOutlineVisible_FloatNull ()
  1980. {
  1981. new GraphicsPath ().IsOutlineVisible (1.0f, 1.0f, null);
  1982. }
  1983. [Test]
  1984. [ExpectedException (typeof (ArgumentNullException))]
  1985. public void IsOutlineVisible_PointNull ()
  1986. {
  1987. new GraphicsPath ().IsOutlineVisible (new Point (), null);
  1988. }
  1989. [Test]
  1990. [ExpectedException (typeof (ArgumentNullException))]
  1991. public void IsOutlineVisible_PointFNull ()
  1992. {
  1993. new GraphicsPath ().IsOutlineVisible (new PointF (), null);
  1994. }
  1995. private void IsOutlineVisible_Line (Graphics graphics)
  1996. {
  1997. Pen p2 = new Pen (Color.Red, 3.0f);
  1998. using (GraphicsPath gp = new GraphicsPath ()) {
  1999. gp.AddLine (10, 1, 14, 1);
  2000. Assert.IsTrue (gp.IsOutlineVisible (10, 1, Pens.Red, graphics), "Int1");
  2001. Assert.IsTrue (gp.IsOutlineVisible (10, 2, p2, graphics), "Int2");
  2002. Assert.IsFalse (gp.IsOutlineVisible (10, 2, Pens.Red, graphics), "Int3");
  2003. Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, Pens.Red, graphics), "Float1");
  2004. Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, p2, graphics), "Float2");
  2005. Assert.IsFalse (gp.IsOutlineVisible (11.0f, 2.0f, Pens.Red, graphics), "Float3");
  2006. Point pt = new Point (12, 2);
  2007. Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
  2008. Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
  2009. pt.Y = 1;
  2010. Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
  2011. PointF pf = new PointF (13.0f, 2.0f);
  2012. Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
  2013. Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
  2014. pf.Y = 1;
  2015. Assert.IsTrue (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF3");
  2016. }
  2017. p2.Dispose ();
  2018. }
  2019. [Test]
  2020. public void IsOutlineVisible_Line_WithoutGraphics ()
  2021. {
  2022. IsOutlineVisible_Line (null);
  2023. }
  2024. [Test]
  2025. public void IsOutlineVisible_Line_WithGraphics_Inside ()
  2026. {
  2027. using (Bitmap bitmap = new Bitmap (20, 20)) {
  2028. using (Graphics g = Graphics.FromImage (bitmap)) {
  2029. IsOutlineVisible_Line (g);
  2030. }
  2031. }
  2032. }
  2033. [Test]
  2034. public void IsOutlineVisible_Line_WithGraphics_Outside ()
  2035. {
  2036. using (Bitmap bitmap = new Bitmap (5, 5)) {
  2037. using (Graphics g = Graphics.FromImage (bitmap)) {
  2038. IsOutlineVisible_Line (g);
  2039. }
  2040. // graphics "seems" ignored as the line is outside the bitmap!
  2041. }
  2042. }
  2043. // docs ways the point is in world coordinates and that the graphics transform
  2044. // should be applied
  2045. [Test]
  2046. public void IsOutlineVisible_Line_WithGraphics_Transform ()
  2047. {
  2048. using (Bitmap bitmap = new Bitmap (20, 20)) {
  2049. using (Graphics g = Graphics.FromImage (bitmap)) {
  2050. g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
  2051. IsOutlineVisible_Line (g);
  2052. }
  2053. // graphics still "seems" ignored (Transform)
  2054. }
  2055. }
  2056. [Test]
  2057. public void IsOutlineVisible_Line_WithGraphics_PageUnit ()
  2058. {
  2059. using (Bitmap bitmap = new Bitmap (20, 20)) {
  2060. using (Graphics g = Graphics.FromImage (bitmap)) {
  2061. g.PageUnit = GraphicsUnit.Millimeter;
  2062. IsOutlineVisible_Line (g);
  2063. }
  2064. // graphics still "seems" ignored (PageUnit)
  2065. }
  2066. }
  2067. [Test]
  2068. public void IsOutlineVisible_Line_WithGraphics_PageScale ()
  2069. {
  2070. using (Bitmap bitmap = new Bitmap (20, 20)) {
  2071. using (Graphics g = Graphics.FromImage (bitmap)) {
  2072. g.PageScale = 2.0f;
  2073. IsOutlineVisible_Line (g);
  2074. }
  2075. // graphics still "seems" ignored (PageScale)
  2076. }
  2077. }
  2078. [Test]
  2079. [Category ("NotWorking")]
  2080. public void IsOutlineVisible_Line_WithGraphics ()
  2081. {
  2082. using (Bitmap bitmap = new Bitmap (20, 20)) {
  2083. using (Graphics g = Graphics.FromImage (bitmap)) {
  2084. g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
  2085. g.PageUnit = GraphicsUnit.Millimeter;
  2086. g.PageScale = 2.0f;
  2087. using (GraphicsPath gp = new GraphicsPath ()) {
  2088. gp.AddLine (10, 1, 14, 1);
  2089. Assert.IsFalse (gp.IsOutlineVisible (10, 1, Pens.Red, g), "Int1");
  2090. }
  2091. }
  2092. // graphics ISN'T ignored (Transform+PageUnit+PageScale)
  2093. }
  2094. }
  2095. [Test]
  2096. [Category ("NotWorking")] // looks buggy - reported to MS as FDBK50868
  2097. public void IsOutlineVisible_Line_End ()
  2098. {
  2099. // horizontal line
  2100. using (GraphicsPath gp = new GraphicsPath ()) {
  2101. gp.AddLine (10, 1, 14, 1);
  2102. Assert.IsFalse (gp.IsOutlineVisible (14, 1, Pens.Red, null), "Int1h");
  2103. Assert.IsFalse (gp.IsOutlineVisible (13.5f, 1.0f, Pens.Red, null), "Float1h");
  2104. Assert.IsTrue (gp.IsOutlineVisible (13.4f, 1.0f, Pens.Red, null), "Float2h");
  2105. Assert.IsFalse (gp.IsOutlineVisible (new Point (14, 1), Pens.Red, null), "Point1h");
  2106. Assert.IsFalse (gp.IsOutlineVisible (new PointF (13.5f, 1.0f), Pens.Red, null), "PointF1h");
  2107. Assert.IsTrue (gp.IsOutlineVisible (new PointF (13.49f, 1.0f), Pens.Red, null), "PointF2h");
  2108. }
  2109. // vertical line
  2110. using (GraphicsPath gp = new GraphicsPath ()) {
  2111. gp.AddLine (1, 10, 1, 14);
  2112. Assert.IsFalse (gp.IsOutlineVisible (1, 14, Pens.Red, null), "Int1v");
  2113. Assert.IsFalse (gp.IsOutlineVisible (1.0f, 13.5f, Pens.Red, null), "Float1v");
  2114. Assert.IsTrue (gp.IsOutlineVisible (1.0f, 13.4f, Pens.Red, null), "Float2v");
  2115. Assert.IsFalse (gp.IsOutlineVisible (new Point (1, 14), Pens.Red, null), "Point1v");
  2116. Assert.IsFalse (gp.IsOutlineVisible (new PointF (1.0f, 13.5f), Pens.Red, null), "PointF1v");
  2117. Assert.IsTrue (gp.IsOutlineVisible (new PointF (1.0f, 13.49f), Pens.Red, null), "PointF2v");
  2118. }
  2119. }
  2120. private void IsOutlineVisible_Rectangle (Graphics graphics)
  2121. {
  2122. Pen p2 = new Pen (Color.Red, 3.0f);
  2123. using (GraphicsPath gp = new GraphicsPath ()) {
  2124. gp.AddRectangle (new Rectangle (10, 10, 20, 20));
  2125. Assert.IsTrue (gp.IsOutlineVisible (10, 10, Pens.Red, graphics), "Int1");
  2126. Assert.IsTrue (gp.IsOutlineVisible (10, 11, p2, graphics), "Int2");
  2127. Assert.IsFalse (gp.IsOutlineVisible (11, 11, Pens.Red, graphics), "Int3");
  2128. Assert.IsTrue (gp.IsOutlineVisible (11.0f, 10.0f, Pens.Red, graphics), "Float1");
  2129. Assert.IsTrue (gp.IsOutlineVisible (11.0f, 11.0f, p2, graphics), "Float2");
  2130. Assert.IsFalse (gp.IsOutlineVisible (11.0f, 11.0f, Pens.Red, graphics), "Float3");
  2131. Point pt = new Point (15, 10);
  2132. Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
  2133. Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
  2134. pt.Y = 15;
  2135. Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
  2136. PointF pf = new PointF (29.0f, 29.0f);
  2137. Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
  2138. Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
  2139. pf.Y = 31.0f;
  2140. Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF3");
  2141. }
  2142. p2.Dispose ();
  2143. }
  2144. [Test]
  2145. public void IsOutlineVisible_Rectangle_WithoutGraphics ()
  2146. {
  2147. IsOutlineVisible_Rectangle (null);
  2148. }
  2149. private void IsVisible_Rectangle (Graphics graphics)
  2150. {
  2151. using (GraphicsPath gp = new GraphicsPath ()) {
  2152. gp.AddRectangle (new Rectangle (10, 10, 20, 20));
  2153. Assert.IsFalse (gp.IsVisible (9, 9, graphics), "Int0");
  2154. Assert.IsTrue (gp.IsVisible (10, 10, graphics), "Int1");
  2155. Assert.IsTrue (gp.IsVisible (20, 20, graphics), "Int2");
  2156. Assert.IsTrue (gp.IsVisible (29, 29, graphics), "Int3");
  2157. Assert.IsFalse (gp.IsVisible (30, 29, graphics), "Int4");
  2158. Assert.IsFalse (gp.IsVisible (29, 30, graphics), "Int5");
  2159. Assert.IsFalse (gp.IsVisible (30, 30, graphics), "Int6");
  2160. Assert.IsFalse (gp.IsVisible (9.4f, 9.4f, graphics), "Float0");
  2161. Assert.IsTrue (gp.IsVisible (9.5f, 9.5f, graphics), "Float1");
  2162. Assert.IsTrue (gp.IsVisible (10f, 10f, graphics), "Float2");
  2163. Assert.IsTrue (gp.IsVisible (20f, 20f, graphics), "Float3");
  2164. Assert.IsTrue (gp.IsVisible (29.4f, 29.4f, graphics), "Float4");
  2165. Assert.IsFalse (gp.IsVisible (29.5f, 29.5f, graphics), "Float5");
  2166. Assert.IsFalse (gp.IsVisible (29.5f, 29.4f, graphics), "Float6");
  2167. Assert.IsFalse (gp.IsVisible (29.4f, 29.5f, graphics), "Float7");
  2168. }
  2169. }
  2170. [Test]
  2171. public void IsVisible_Rectangle_WithoutGraphics ()
  2172. {
  2173. IsVisible_Rectangle (null);
  2174. }
  2175. [Test]
  2176. public void IsVisible_Rectangle_WithGraphics ()
  2177. {
  2178. using (Bitmap bitmap = new Bitmap (40, 40)) {
  2179. using (Graphics g = Graphics.FromImage (bitmap)) {
  2180. IsVisible_Rectangle (g);
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }