| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557 |
- //
- // System.Drawing.GraphicsPath unit tests
- //
- // Authors:
- // Sebastien Pouliot <[email protected]>
- //
- // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using SC = System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Security.Permissions;
- using NUnit.Framework;
- namespace MonoTests.System.Drawing.Drawing2D {
- [TestFixture]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- public class GraphicsPathTest {
- private const float Pi4 = (float) (Math.PI / 4);
- // let's tolerate a few differences
- private const float Delta = 0.0003f;
- private void CheckEmpty (string prefix, GraphicsPath gp)
- {
- Assert.AreEqual (0, gp.PathData.Points.Length, "PathData.Points");
- Assert.AreEqual (0, gp.PathData.Types.Length, "PathData.Types");
- Assert.AreEqual (0, gp.PointCount, prefix + "PointCount");
- }
- [Test]
- public void Constructor_InvalidFillMode ()
- {
- GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MinValue);
- Assert.AreEqual (Int32.MinValue, (int) gp.FillMode, "FillMode");
- CheckEmpty ("InvalidFillMode.", gp);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Constructor_Point_Null_Byte ()
- {
- new GraphicsPath ((Point[]) null, new byte[1]);
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void Constructor_Point_Byte_Null ()
- {
- new GraphicsPath (new Point[1], null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void Constructor_Point_Byte_LengthMismatch ()
- {
- new GraphicsPath (new Point[1], new byte [2]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Constructor_PointF_Null_Byte ()
- {
- new GraphicsPath ((PointF[])null, new byte [1]);
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void Constructor_PointF_Byte_Null ()
- {
- new GraphicsPath ( new PointF[1], null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void Constructor_PointF_Byte_LengthMismatch ()
- {
- new GraphicsPath (new PointF[2], new byte [1]);
- }
- [Test]
- public void GraphicsPath_Empty ()
- {
- GraphicsPath gp = new GraphicsPath ();
- Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Empty.FillMode");
- CheckEmpty ("Empty.", gp);
- GraphicsPath clone = (GraphicsPath) gp.Clone ();
- Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Clone.FillMode");
- CheckEmpty ("Clone.", gp);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void GraphicsPath_Empty_PathPoints ()
- {
- Assert.IsNull (new GraphicsPath ().PathPoints);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void GraphicsPath_Empty_PathTypes ()
- {
- Assert.IsNull (new GraphicsPath ().PathTypes);
- }
- [Test]
- [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
- public void FillMode_Invalid ()
- {
- // constructor accept an invalid FillMode
- GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
- Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
- // but you can't set the FillMode property to an invalid value ;-)
- gp.FillMode = (FillMode) Int32.MaxValue;
- }
- [Test]
- public void PathData_CannotChange ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new Rectangle (1, 1, 2, 2));
- Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
- Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
- // now try to change the first point
- gp.PathData.Points[0] = new Point (0, 0);
- // the changes isn't reflected in the property
- Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
- Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
- }
- [Test]
- public void PathPoints_CannotChange ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new Rectangle (1, 1, 2, 2));
- Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
- Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
- // now try to change the first point
- gp.PathPoints[0] = new Point (0, 0);
- // the changes isn't reflected in the property
- Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
- Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
- }
- [Test]
- public void PathTypes_CannotChange ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new Rectangle (1, 1, 2, 2));
- Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
- // now try to change the first type
- gp.PathTypes[0] = 1;
- // the changes isn't reflected in the property
- Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
- }
- private void CheckArc (GraphicsPath path)
- {
- Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (2.999624f, rect.X, "Bounds.X");
- Assert.AreEqual (2.013707f, rect.Y, "Bounds.Y");
- Assert.AreEqual (0f, rect.Width, Delta, "Bounds.Width");
- Assert.AreEqual (0.01370478f, rect.Height, "Bounds.Height");
- Assert.AreEqual (2.999906f, path.PathData.Points[0].X, "Points[0].X");
- Assert.AreEqual (2.013707f, path.PathPoints[0].Y, "Points[0].Y");
- Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
- Assert.AreEqual (2.999843f, path.PathData.Points[1].X, "Points[1].X");
- Assert.AreEqual (2.018276f, path.PathPoints[1].Y, "Points[1].Y");
- Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
- Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, "Points[2].X");
- Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, "Points[2].Y");
- Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
- Assert.AreEqual (2.999624f, path.PathData.Points[3].X, "Points[3].X");
- Assert.AreEqual (2.027412f, path.PathPoints[3].Y, "Points[3].Y");
- Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
- }
- [Test]
- public void AddArc_Rectangle ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
- CheckArc (gp);
- }
- [Test]
- public void AddArc_RectangleF ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
- CheckArc (gp);
- }
- [Test]
- public void AddArc_Int ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
- CheckArc (gp);
- }
- [Test]
- public void AddArc_Float ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
- CheckArc (gp);
- }
- private void CheckBezier (GraphicsPath path)
- {
- Assert.AreEqual (4, path.PointCount, "PointCount");
- Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (1f, rect.X, "Bounds.X");
- Assert.AreEqual (1f, rect.Y, "Bounds.Y");
- Assert.AreEqual (3f, rect.Width, "Bounds.Width");
- Assert.AreEqual (3f, rect.Height, "Bounds.Height");
- Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
- Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
- Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
- Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
- Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
- Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
- Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
- Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
- Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
- Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
- Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
- Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
- }
- [Test]
- public void AddBezier_Point ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
- CheckBezier (gp);
- }
- [Test]
- public void AddBezier_PointF ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
- CheckBezier (gp);
- }
- [Test]
- public void AddBezier_Int ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
- CheckBezier (gp);
- }
- [Test]
- public void AddBezier_Float ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
- CheckBezier (gp);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddBeziers_Point_Null ()
- {
- new GraphicsPath ().AddBeziers ((Point[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddBeziers_3_Points ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
- }
- [Test]
- public void AddBeziers_Point ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
- CheckBezier (gp);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddBeziers_PointF_Null ()
- {
- new GraphicsPath ().AddBeziers ((PointF[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddBeziers_3_PointFs ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
- }
- [Test]
- public void AddBeziers_PointF ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
- CheckBezier (gp);
- }
- private void CheckEllipse (GraphicsPath path)
- {
- Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (1f, rect.X, "Bounds.X");
- Assert.AreEqual (1f, rect.Y, "Bounds.Y");
- Assert.AreEqual (2f, rect.Width, "Bounds.Width");
- Assert.AreEqual (2f, rect.Height, "Bounds.Height");
- Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
- for (int i = 1; i < 12; i++)
- Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
- Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
- }
- [Test]
- public void AddEllipse_Rectangle ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddEllipse (new Rectangle (1, 1, 2, 2));
- CheckEllipse (gp);
- }
- [Test]
- public void AddEllipse_RectangleF ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
- CheckEllipse (gp);
- }
- [Test]
- public void AddEllipse_Int ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddEllipse (1, 1, 2, 2);
- CheckEllipse (gp);
- }
- [Test]
- public void AddEllipse_Float ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddEllipse (1f, 1f, 2f, 2f);
- CheckEllipse (gp);
- }
- private void CheckLine (GraphicsPath path)
- {
- Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (1f, rect.X, "Bounds.X");
- Assert.AreEqual (1f, rect.Y, "Bounds.Y");
- Assert.AreEqual (1f, rect.Width, "Bounds.Width");
- Assert.AreEqual (1f, rect.Height, "Bounds.Height");
- Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
- Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
- Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
- Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
- Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
- Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
- }
- [Test]
- public void AddLine_Point ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLine (new Point (1, 1), new Point (2, 2));
- CheckLine (gp);
- }
- [Test]
- public void AddLine_PointF ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
- CheckLine (gp);
- }
- [Test]
- public void AddLine_Int ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLine (1, 1, 2, 2);
- CheckLine (gp);
- }
- [Test]
- public void AddLine_Float ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLine (1f, 1f, 2f, 2f);
- CheckLine (gp);
- }
- [Test]
- public void AddLine_SamePoint ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLine (new Point (1, 1), new Point (1, 1));
- Assert.AreEqual (2, gp.PointCount, "PointCount");
- Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
- Assert.AreEqual (1, gp.PathTypes[1], "PathTypes[1]");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddLines_Point_Null ()
- {
- new GraphicsPath ().AddLines ((Point[])null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddLines_Point_0 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLines (new Point[0]);
- CheckLine (gp);
- }
- [Test]
- [Category ("NotWorking")]
- public void AddLines_Point_1 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLines (new Point[1] { new Point (1, 1) });
- // Special case - a line with a single point is valid
- Assert.AreEqual (1, gp.PointCount, "PointCount");
- Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
- }
- [Test]
- public void AddLines_Point ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
- CheckLine (gp);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddLines_PointF_Null ()
- {
- new GraphicsPath ().AddLines ((PointF[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddLines_PointF_0 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLines (new PointF[0]);
- CheckLine (gp);
- }
- [Test]
- [Category ("NotWorking")]
- public void AddLines_PointF_1 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
- // Special case - a line with a single point is valid
- Assert.AreEqual (1, gp.PointCount, "PointCount");
- Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
- }
- [Test]
- public void AddLines_PointF ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
- CheckLine (gp);
- }
- private void CheckPie (GraphicsPath path)
- {
- // the number of points generated for a Pie isn't the same between Mono and MS
- #if false
- Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (2f, rect.X, "Bounds.X");
- Assert.AreEqual (2f, rect.Y, "Bounds.Y");
- Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
- Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
- Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
- Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
- Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
- Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
- Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
- Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
- Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
- Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
- Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
- Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
- Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
- Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
- Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
- Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
- Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
- #endif
- }
- [Test]
- public void AddPie_Rect ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
- CheckPie (gp);
- }
- [Test]
- public void AddPie_Int ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
- CheckPie (gp);
- }
- [Test]
- public void AddPie_Float ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
- CheckPie (gp);
- }
- private void CheckPolygon (GraphicsPath path)
- {
- // an extra point is generated by Mono (libgdiplus)
- #if false
- Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
- #endif
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (1f, rect.X, "Bounds.X");
- Assert.AreEqual (1f, rect.Y, "Bounds.Y");
- Assert.AreEqual (2f, rect.Width, "Bounds.Width");
- Assert.AreEqual (2f, rect.Height, "Bounds.Height");
- Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
- Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
- Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
- Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
- Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
- Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
- Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
- Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
- // the extra point change the type of the last point
- #if false
- Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
- #endif
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddPolygon_Point_Null ()
- {
- new GraphicsPath ().AddPolygon ((Point[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddPolygon_Point_Empty ()
- {
- new GraphicsPath ().AddPolygon (new Point[0]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddPolygon_Point_1 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPolygon (new Point[1] { new Point (1, 1) });
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddPolygon_Point_2 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
- }
- [Test]
- public void AddPolygon_Point_3 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
- CheckPolygon (gp);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddPolygon_PointF_Null ()
- {
- new GraphicsPath ().AddPolygon ((PointF[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddPolygon_PointF_Empty ()
- {
- new GraphicsPath ().AddPolygon (new PointF[0]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddPolygon_PointF_1 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddPolygon_PointF_2 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
- }
- [Test]
- public void AddPolygon_PointF_3 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
- CheckPolygon (gp);
- }
- private void CheckRectangle (GraphicsPath path, int count)
- {
- Assert.AreEqual (count, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (count, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (count, path.PathData.Points.Length, "PathData");
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (1f, rect.X, "Bounds.X");
- Assert.AreEqual (1f, rect.Y, "Bounds.Y");
- Assert.AreEqual (2f, rect.Width, "Bounds.Width");
- Assert.AreEqual (2f, rect.Height, "Bounds.Height");
- // check first four points (first rectangle)
- Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
- Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
- Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
- Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
- Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
- Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
- Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
- Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
- Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
- Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
- Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
- Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
- }
- [Test]
- public void AddRectangle_Int ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new Rectangle (1, 1, 2, 2));
- CheckRectangle (gp, 4);
- }
- [Test]
- public void AddRectangle_Float ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
- CheckRectangle (gp, 4);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddRectangles_Int_Null ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangles ((Rectangle[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddRectangles_Int_Empty ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangles (new Rectangle[0]);
- CheckRectangle (gp, 4);
- }
- [Test]
- public void AddRectangles_Int ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
- CheckRectangle (gp, 4);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddRectangles_Float_Null ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangles ((RectangleF[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddRectangles_Float_Empty ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangles ( new RectangleF[0]);
- CheckRectangle (gp, 4);
- }
- [Test]
- public void AddRectangles_Float ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
- CheckRectangle (gp, 4);
- }
- [Test]
- public void AddRectangles_Two ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangles (new RectangleF[2] {
- new RectangleF (1f, 1f, 2f, 2f),
- new RectangleF (2f, 2f, 1f, 1f) } );
- RectangleF rect = gp.GetBounds ();
- Assert.AreEqual (1f, rect.X, "Bounds.X");
- Assert.AreEqual (1f, rect.Y, "Bounds.Y");
- Assert.AreEqual (2f, rect.Width, "Bounds.Width");
- Assert.AreEqual (2f, rect.Height, "Bounds.Height");
- // second rectangle is completely within the first one
- CheckRectangle (gp, 8);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddPath_Null ()
- {
- new GraphicsPath ().AddPath (null, false);
- }
- [Test]
- public void AddPath ()
- {
- GraphicsPath gpr = new GraphicsPath ();
- gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
- GraphicsPath gp = new GraphicsPath ();
- gp.AddPath (gpr, true);
- CheckRectangle (gp, 4);
- }
- private void CheckClosedCurve (GraphicsPath path)
- {
- Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (0.8333333f, rect.X, "Bounds.X");
- Assert.AreEqual (0.8333333f, rect.Y, "Bounds.Y");
- Assert.AreEqual (2.33333278f, rect.Width, "Bounds.Width");
- Assert.AreEqual (2.33333278f, rect.Height, "Bounds.Height");
- Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
- for (int i = 1; i < 9; i++)
- Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
- Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddClosedCurve_Point_Null ()
- {
- new GraphicsPath ().AddClosedCurve ((Point[])null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddClosedCurve_Point_0 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddClosedCurve (new Point [0]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddClosedCurve_Point_1 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddClosedCurve_Point_2 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
- }
- [Test]
- public void AddClosedCurve_Point_3 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
- CheckClosedCurve (gp);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddClosedCurve_PointF_Null ()
- {
- new GraphicsPath ().AddClosedCurve ((PointF[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddClosedCurve_PointF_0 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddClosedCurve (new PointF[0]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddClosedCurve_PointF_1 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddClosedCurve_PointF_2 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
- }
- [Test]
- public void AddClosedCurve_PointF_3 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
- CheckClosedCurve (gp);
- }
- private void CheckCurve (GraphicsPath path)
- {
- Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
- Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
- Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
- // GetBounds (well GdipGetPathWorldBounds) isn't implemented
- RectangleF rect = path.GetBounds ();
- Assert.AreEqual (1.0f, rect.X, "Bounds.X");
- Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
- Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
- Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
- Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
- Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
- Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
- // Mono has wrong? results
- #if false
- Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
- Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
- #endif
- Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
- // Mono has wrong? results
- #if false
- Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
- Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
- #endif
- Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
- Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
- Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
- Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddCurve_Point_Null ()
- {
- new GraphicsPath ().AddCurve ((Point[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddCurve_Point_0 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddCurve (new Point[0]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddCurve_Point_1 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddCurve (new Point[1] { new Point (1, 1) });
- }
- [Test]
- public void AddCurve_Point_2 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
- CheckCurve (gp);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddCurve_PointF_Null ()
- {
- new GraphicsPath ().AddCurve ((PointF[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddCurve_PointF_0 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddCurve (new PointF[0]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AddCurve_PointF_1 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
- }
- [Test]
- public void AddCurve_PointF_2 ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
- CheckCurve (gp);
- }
- [Test]
- public void GetBounds_Empty_Empty ()
- {
- GraphicsPath gp = new GraphicsPath ();
- RectangleF rect = gp.GetBounds ();
- Assert.AreEqual (0.0f, rect.X, "Bounds.X");
- Assert.AreEqual (0.0f, rect.Y, "Bounds.Y");
- Assert.AreEqual (0.0f, rect.Width, "Bounds.Width");
- Assert.AreEqual (0.0f, rect.Height, "Bounds.Height");
- }
- private void CheckRectangleBounds (RectangleF rect)
- {
- Assert.AreEqual (1.0f, rect.X, "Bounds.X");
- Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
- Assert.AreEqual (2.0f, rect.Width, "Bounds.Width");
- Assert.AreEqual (2.0f, rect.Height, "Bounds.Height");
- }
- [Test]
- public void GetBounds_Empty_Rectangle ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new Rectangle (1, 1, 2, 2));
- CheckRectangleBounds (gp.GetBounds ());
- }
- [Test]
- public void GetBounds_Null_Rectangle ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new Rectangle (1, 1, 2, 2));
- CheckRectangleBounds (gp.GetBounds (null));
- }
- [Test]
- public void GetBounds_MatrixEmpty_Rectangle ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new Rectangle (1, 1, 2, 2));
- CheckRectangleBounds (gp.GetBounds (new Matrix ()));
- }
- [Test]
- public void GetBounds_NullNull_Rectangle ()
- {
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (new Rectangle (1, 1, 2, 2));
- CheckRectangleBounds (gp.GetBounds (null, null));
- }
- [Test]
- [Category ("NotWorking")] // bounds+pen support is missing in libgdiplus
- public void GetBounds_WithPen ()
- {
- Rectangle rect = new Rectangle (1, 1, 2, 2);
- Pen p = new Pen (Color.Aqua, 0);
- GraphicsPath gp = new GraphicsPath ();
- gp.AddRectangle (rect);
- RectangleF bounds = gp.GetBounds (null, p);
- Assert.AreEqual (-6.09999943f, bounds.X, "NullMatrix.Bounds.X");
- Assert.AreEqual (-6.09999943f, bounds.Y, "NullMatrix.Bounds.Y");
- Assert.AreEqual (16.1999989f, bounds.Width, "NullMatrix.Bounds.Width");
- Assert.AreEqual (16.1999989f, bounds.Height, "NullMatrix.Bounds.Height");
- Matrix m = new Matrix ();
- // an empty matrix is different than a null matrix
- bounds = gp.GetBounds (m, p);
- Assert.AreEqual (-0.419999957f, bounds.X, "EmptyMatrix.Bounds.X");
- Assert.AreEqual (-0.419999957f, bounds.Y, "EmptyMatrix.Bounds.Y");
- Assert.AreEqual (4.83999968f, bounds.Width, "EmptyMatrix.Bounds.Width");
- Assert.AreEqual (4.83999968f, bounds.Height, "EmptyMatrix.Bounds.Height");
- gp = new GraphicsPath ();
- gp.AddRectangle (rect);
- gp.Widen (p);
- bounds = gp.GetBounds (null);
- Assert.AreEqual (0.499999523f, bounds.X, "WidenNullMatrix.Bounds.X");
- Assert.AreEqual (0.499999523f, bounds.Y, "WidenNullMatrix.Bounds.Y");
- Assert.AreEqual (3.000001f, bounds.Width, "WidenNullMatrix.Bounds.Width");
- Assert.AreEqual (3.000001f, bounds.Height, "WidenNullMatrix.Bounds.Height");
- bounds = gp.GetBounds (m);
- Assert.AreEqual (0.499999523f, bounds.X, "WidenEmptyMatrix.Bounds.X");
- Assert.AreEqual (0.499999523f, bounds.Y, "WidenEmptyMatrix.Bounds.Y");
- Assert.AreEqual (3.000001f, bounds.Width, "WidenEmptyMatrix.Bounds.Width");
- Assert.AreEqual (3.000001f, bounds.Height, "WidenEmptyMatrix.Bounds.Height");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Transform_Null ()
- {
- new GraphicsPath ().Transform (null);
- }
- [Test]
- public void Transform_Empty ()
- {
- // no points in path and no exception
- new GraphicsPath ().Transform (new Matrix ());
- }
- private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
- {
- Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
- for (int i = 0; i < expected.PointCount; i++) {
- Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
- Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
- }
- }
- private void CompareFlats (GraphicsPath flat, GraphicsPath original)
- {
- Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
- for (int i = 0; i < flat.PointCount; i++) {
- Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
- }
- }
- [Test]
- public void Flatten_Empty ()
- {
- GraphicsPath path = new GraphicsPath ();
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- // this is a no-op as there's nothing in the path
- path.Flatten ();
- ComparePaths (path, clone);
- }
- [Test]
- public void Flatten_Null ()
- {
- GraphicsPath path = new GraphicsPath ();
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- // this is a no-op as there's nothing in the path
- // an no matrix to apply
- path.Flatten (null);
- ComparePaths (path, clone);
- }
- [Test]
- public void Flatten_NullFloat ()
- {
- GraphicsPath path = new GraphicsPath ();
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- // this is a no-op as there's nothing in the path
- // an no matrix to apply
- path.Flatten (null, 1f);
- ComparePaths (path, clone);
- }
- [Test]
- public void Flatten_Arc ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddArc (0f, 0f, 100f, 100f, 30, 30);
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- CompareFlats (path, clone);
- }
- [Test]
- public void Flatten_Bezier ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- CompareFlats (path, clone);
- }
- [Test]
- public void Flatten_ClosedCurve ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddClosedCurve (new Point[4] {
- new Point (0, 0), new Point (40, 20),
- new Point (20, 40), new Point (40, 40)
- });
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- CompareFlats (path, clone);
- }
- [Test]
- public void Flatten_Curve ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddCurve (new Point[4] {
- new Point (0, 0), new Point (40, 20),
- new Point (20, 40), new Point (40, 40)
- });
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- CompareFlats (path, clone);
- }
- [Test]
- public void Flatten_Ellipse ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddEllipse (10f, 10f, 100f, 100f);
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- CompareFlats (path, clone);
- }
- [Test]
- public void Flatten_Line ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (10f, 10f, 100f, 100f);
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- ComparePaths (path, clone);
- }
- [Test]
- public void Flatten_Pie ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddPie (0, 0, 100, 100, 30, 30);
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- CompareFlats (path, clone);
- }
- [Test]
- public void Flatten_Polygon ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddPolygon (new Point[4] {
- new Point (0, 0), new Point (10, 10),
- new Point (20, 20), new Point (40, 40)
- });
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- ComparePaths (path, clone);
- }
- [Test]
- public void Flatten_Rectangle ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddRectangle (new Rectangle (0, 0, 100, 100));
- GraphicsPath clone = (GraphicsPath) path.Clone ();
- path.Flatten ();
- ComparePaths (path, clone);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Warp_Null ()
- {
- new GraphicsPath ().Warp (null, new RectangleF ());
- }
- [Test]
- public void SetMarkers_EmptyPath ()
- {
- new GraphicsPath ().SetMarkers ();
- }
- [Test]
- public void ClearMarkers_EmptyPath ()
- {
- new GraphicsPath ().ClearMarkers ();
- }
- [Test]
- public void CloseFigure_EmptyPath ()
- {
- new GraphicsPath ().CloseFigure ();
- }
- [Test]
- public void CloseAllFigures_EmptyPath ()
- {
- new GraphicsPath ().CloseAllFigures ();
- }
- [Test]
- public void StartClose_AddArc ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddArc (10, 10, 100, 100, 90, 180);
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (1, types[2], "start/Arc");
- // check last types
- Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
- }
- [Test]
- public void StartClose_AddBezier ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200);
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (1, types[2], "start/Bezier");
- // check last types
- Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
- }
- [Test]
- public void StartClose_AddBeziers ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddBeziers (new Point[7] { new Point (10, 10),
- new Point (20, 10), new Point (20, 20), new Point (30, 20),
- new Point (40, 40), new Point (50, 40), new Point (50, 50)
- });
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (1, types[2], "start/Bezier");
- // check last types
- Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
- }
- [Test]
- public void StartClose_AddClosedCurve ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (0, types[2], "start/ClosedCurve");
- // check last types
- Assert.AreEqual (131, types[path.PointCount - 3], "end/ClosedCurve");
- Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
- }
- [Test]
- public void StartClose_AddCurve ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (1, types[2], "start/Curve");
- // check last types
- Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
- }
- [Test]
- public void StartClose_AddEllipse ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddEllipse (10, 10, 100, 100);
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (0, types[2], "start/Ellipse");
- // check last types
- Assert.AreEqual (131, types[path.PointCount - 3], "end/Ellipse");
- Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
- }
- [Test]
- public void StartClose_AddLine ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddLine (5, 5, 10, 10);
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (1, types[2], "start/Line2");
- // check last types
- Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
- }
- [Test]
- public void StartClose_AddLines ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddLines (new Point[4] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20) });
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (1, types[2], "start/Lines");
- // check last types
- Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
- }
- [Test]
- public void StartClose_AddPath_Connect ()
- {
- GraphicsPath inner = new GraphicsPath ();
- inner.AddArc (10, 10, 100, 100, 90, 180);
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddPath (inner, true);
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (1, types[2], "start/Path");
- // check last types
- Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
- }
- [Test]
- public void StartClose_AddPath_NoConnect ()
- {
- GraphicsPath inner = new GraphicsPath ();
- inner.AddArc (10, 10, 100, 100, 90, 180);
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddPath (inner, false);
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (0, types[2], "start/Path");
- // check last types
- Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
- }
- [Test]
- public void StartClose_AddPie ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddPie (10, 10, 10, 10, 90, 180);
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (0, types[2], "start/Pie");
- // check last types
- // libgdiplus draws pie by ending with a line (not a curve) section
- Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie");
- Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
- }
- [Test]
- public void StartClose_AddPolygon ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (0, types[2], "start/Polygon");
- // check last types
- Assert.AreEqual (129, types[path.PointCount - 3], "end/Polygon");
- Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
- }
- [Test]
- public void StartClose_AddRectangle ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddRectangle (new RectangleF (10, 10, 20, 20));
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (0, types[2], "start/Rectangle");
- // check last types
- Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangle");
- Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
- }
- [Test]
- public void StartClose_AddRectangles ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddRectangles (new RectangleF[2] {
- new RectangleF (10, 10, 20, 20),
- new RectangleF (20, 20, 10, 10) });
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (0, types[2], "start/Rectangles");
- // check last types
- Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
- Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
- }
- [Test]
- [Category ("NotWorking")]
- public void StartClose_AddString ()
- {
- GraphicsPath path = new GraphicsPath ();
- path.AddLine (1, 1, 2, 2);
- path.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new Point (20,20), StringFormat.GenericDefault);
- path.AddLine (10, 10, 20, 20);
- byte[] types = path.PathTypes;
- // check first types
- Assert.AreEqual (0, types[0], "start/Line");
- Assert.AreEqual (0, types[2], "start/String");
- // check last types
- Assert.AreEqual (163, types[path.PointCount - 3], "end/String");
- Assert.AreEqual (1, types[path.PointCount - 2], "start/Line2");
- Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
- }
- }
- }
|