From 856564ec818e7a9719113945020df672b0e0f0ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darko=20Juri=C4=87?= Date: Sat, 17 Oct 2015 18:39:36 +0200 Subject: [PATCH] Updating Primitives2D to reflect changes in .NET 4.6. Comments are also updated. --- Deployment/Setup.NuGet/Build.cmd | 2 +- .../Primitives2D/Imaging.Primitives2D.nuspec | 53 +- README.md | 2 +- Source/Primitives2D/Ellipse/Ellipse.cs | 3 +- Source/Primitives2D/Point/Point.cs | 711 ++++++++---------- Source/Primitives2D/Point/PointF.cs | 523 +++++++------ Source/Primitives2D/Rectangle/Rectangle.cs | 143 ++-- .../Rectangle/RectangleExtensions.cs | 12 +- Source/Primitives2D/Rectangle/RectangleF.cs | 184 ++--- Source/Primitives2D/Size/Size.cs | 344 ++++----- Source/Primitives2D/Size/SizeF.cs | 309 +++----- 11 files changed, 996 insertions(+), 1290 deletions(-) diff --git a/Deployment/Setup.NuGet/Build.cmd b/Deployment/Setup.NuGet/Build.cmd index e61c0a9..fded2e5 100644 --- a/Deployment/Setup.NuGet/Build.cmd +++ b/Deployment/Setup.NuGet/Build.cmd @@ -12,7 +12,7 @@ echo. timeout /T 5 :: Set version info -set version=2.5.5 +set version=2.5.6 set output=%cd%\bin\ :: Create output directory diff --git a/Deployment/Setup.NuGet/Primitives2D/Imaging.Primitives2D.nuspec b/Deployment/Setup.NuGet/Primitives2D/Imaging.Primitives2D.nuspec index 55c8cf7..6691160 100644 --- a/Deployment/Setup.NuGet/Primitives2D/Imaging.Primitives2D.nuspec +++ b/Deployment/Setup.NuGet/Primitives2D/Imaging.Primitives2D.nuspec @@ -1,27 +1,28 @@ - - - - - DotImaging.Primitives2D - $version$ - DotImaging.Primitives2D - Darko Jurić - DotImaging - https://raw.githubusercontent.com/dajuric/dot-imaging/master/Deployment/Licence.txt - https://github.com/dajuric/dot-imaging - https://raw.githubusercontent.com/dajuric/dot-imaging/master/Deployment/Logo/logo-small.png - true - - Provides portable 2D drawing primitives (Point, Size, Rectangle) compatible with System.Drawing structures and some additional ones. - - Point, Size, Rectangle (compatible with System.Drawing) and Circle, Ellipse - imaging geometry structures 2D - - - - - - - - + + + + + DotImaging.Primitives2D + $version$ + DotImaging.Primitives2D + Darko Jurić + DotImaging + https://raw.githubusercontent.com/dajuric/dot-imaging/master/Deployment/Licence.txt + https://github.com/dajuric/dot-imaging + https://raw.githubusercontent.com/dajuric/dot-imaging/master/Deployment/Logo/logo-small.png + true + + Provides portable 2D drawing primitives (Point, Size, Rectangle) compatible with System.Drawing structures. + Additional structures include Circle, Ellipse, Box2D. + + Point, Size, Rectangle (compatible with System.Drawing), Circle, Ellipse, Box2D + imaging geometry structures 2D + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 9beaeb5..961c4e5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

Build passing - NuGet packages version + NuGet packages version

**DotImaging** - .NET array as imaging object diff --git a/Source/Primitives2D/Ellipse/Ellipse.cs b/Source/Primitives2D/Ellipse/Ellipse.cs index b06cf56..9d6097a 100644 --- a/Source/Primitives2D/Ellipse/Ellipse.cs +++ b/Source/Primitives2D/Ellipse/Ellipse.cs @@ -26,8 +26,7 @@ namespace DotImaging.Primitives2D { /// - /// Ellipse structure. - /// See also. + /// Ellipse structure containing center and ellipse size. /// [StructLayout(LayoutKind.Sequential)] public struct Ellipse diff --git a/Source/Primitives2D/Point/Point.cs b/Source/Primitives2D/Point/Point.cs index df53cf7..5376983 100644 --- a/Source/Primitives2D/Point/Point.cs +++ b/Source/Primitives2D/Point/Point.cs @@ -1,396 +1,315 @@ -// -// System.Drawing.Point.cs -// -// Author: -// Mike Kestner (mkestner@speakeasy.net) -// -// Copyright (C) 2001 Mike Kestner -// Copyright (C) 2004 Novell, Inc. http://www.novell.com -// - -// -// Copyright (C) 2004 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 System.Globalization; -//using System.ComponentModel; - -namespace DotImaging.Primitives2D -{ - /// - /// Represents the 2D (X, Y) pair. - /// - public struct Point - { - // Private x and y coordinate fields. - private int x, y; - - // ----------------------- - // Public Shared Members - // ----------------------- - - /// - /// Empty Shared Field - /// - /// - /// - /// An uninitialized Point Structure. - /// - - public static readonly Point Empty; - - /// - /// Ceiling Shared Method - /// - /// - /// - /// Produces a Point structure from a PointF structure by - /// taking the ceiling of the X and Y properties. - /// - - public static Point Ceiling(PointF value) - { - int x, y; - checked - { - x = (int)Math.Ceiling(value.X); - y = (int)Math.Ceiling(value.Y); - } - - return new Point(x, y); - } - - /// - /// Round Shared Method - /// - /// - /// - /// Produces a Point structure from a PointF structure by - /// rounding the X and Y properties. - /// - - public static Point Round(PointF value) - { - int x, y; - checked - { - x = (int)Math.Round(value.X); - y = (int)Math.Round(value.Y); - } - - return new Point(x, y); - } - - /// - /// Truncate Shared Method - /// - /// - /// - /// Produces a Point structure from a PointF structure by - /// truncating the X and Y properties. - /// - - // LAMESPEC: Should this be floor, or a pure cast to int? - - public static Point Truncate(PointF value) - { - int x, y; - checked - { - x = (int)value.X; - y = (int)value.Y; - } - - return new Point(x, y); - } - - /// - /// Addition Operator - /// - /// - /// - /// Translates a Point using the Width and Height - /// properties of the given Size. - /// - - public static Point operator +(Point pt, Size sz) - { - return new Point(pt.X + sz.Width, pt.Y + sz.Height); - } - - /// - /// Equality Operator - /// - /// - /// - /// Compares two Point objects. The return value is - /// based on the equivalence of the X and Y properties - /// of the two points. - /// - - public static bool operator ==(Point left, Point right) - { - return ((left.X == right.X) && (left.Y == right.Y)); - } - - /// - /// Inequality Operator - /// - /// - /// - /// Compares two Point objects. The return value is - /// based on the equivalence of the X and Y properties - /// of the two points. - /// - - public static bool operator !=(Point left, Point right) - { - return ((left.X != right.X) || (left.Y != right.Y)); - } - - /// - /// Subtraction Operator - /// - /// - /// - /// Translates a Point using the negation of the Width - /// and Height properties of the given Size. - /// - - public static Point operator -(Point pt, Size sz) - { - return new Point(pt.X - sz.Width, pt.Y - sz.Height); - } - - /// - /// Point to Size Conversion - /// - /// - /// - /// Returns a Size based on the Coordinates of a given - /// Point. Requires explicit cast. - /// - - public static explicit operator Size(Point p) - { - return new Size(p.X, p.Y); - } - - /// - /// Point to PointF Conversion - /// - /// - /// - /// Creates a PointF based on the coordinates of a given - /// Point. No explicit cast is required. - /// - - public static implicit operator PointF(Point p) - { - return new PointF(p.X, p.Y); - } - - - // ----------------------- - // Public Constructors - // ----------------------- - - /// - /// Point Constructor - /// - /// - /// - /// Creates a Point from an integer which holds the Y - /// coordinate in the high order 16 bits and the X - /// coordinate in the low order 16 bits. - /// - - public Point(int dw) - { - y = dw >> 16; - x = dw & 0xffff; - } - - /// - /// Point Constructor - /// - /// - /// - /// Creates a Point from a Size value. - /// - - public Point(Size sz) - { - x = sz.Width; - y = sz.Height; - } - - /// - /// Point Constructor - /// - /// - /// - /// Creates a Point from a specified x,y coordinate pair. - /// - - public Point(int x, int y) - { - this.x = x; - this.y = y; - } - - // ----------------------- - // Public Instance Members - // ----------------------- - - /// - /// IsEmpty Property - /// - /// - /// - /// Indicates if both X and Y are zero. - /// - - public bool IsEmpty - { - get - { - return ((x == 0) && (y == 0)); - } - } - - /// - /// X Property - /// - /// - /// - /// The X coordinate of the Point. - /// - - public int X - { - get - { - return x; - } - set - { - x = value; - } - } - - /// - /// Y Property - /// - /// - /// - /// The Y coordinate of the Point. - /// - - public int Y - { - get - { - return y; - } - set - { - y = value; - } - } - - /// - /// Equals Method - /// - /// - /// - /// Checks equivalence of this Point and another object. - /// - - public override bool Equals(object obj) - { - if (!(obj is Point)) - return false; - - return (this == (Point)obj); - } - - /// - /// GetHashCode Method - /// - /// - /// - /// Calculates a hashing value. - /// - - public override int GetHashCode() - { - return x ^ y; - } - - /// - /// Offset Method - /// - /// - /// - /// Moves the Point a specified distance. - /// - - public void Offset(int dx, int dy) - { - x += dx; - y += dy; - } - - /// - /// ToString Method - /// - /// - /// - /// Formats the Point as a string in coordinate notation. - /// - - public override string ToString() - { - return string.Format("{{X={0},Y={1}}}", x.ToString(CultureInfo.InvariantCulture), - y.ToString(CultureInfo.InvariantCulture)); - } -#if NET_2_0 - public static Point Add (Point pt, Size sz) - { - return new Point (pt.X + sz.Width, pt.Y + sz.Height); - } - - public void Offset (Point p) - { - Offset (p.X, p.Y); - } - - public static Point Subtract (Point pt, Size sz) - { - return new Point (pt.X - sz.Width, pt.Y - sz.Height); - } -#endif - - } -} +#region Licence and Terms +// DotImaging Framework +// https://github.com/dajuric/dot-imaging +// +// Copyright © Darko Jurić, 2014-2015-2015 +// darko.juric2@gmail.com +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +//---------------------- original----------------------- +// Author: +// Mike Kestner (mkestner@speakeasy.net) +// +// Copyright (C) 2001 Mike Kestner +// Copyright (C) 2004, 2007 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. +#endregion + +using System; +using System.Globalization; + +namespace DotImaging.Primitives2D +{ + /// + /// Represents the 2D (X, Y) pair. + /// + public struct Point + { + private int x, y; + + /// + /// An uninitialized Point structure. + /// + public static readonly Point Empty; + + /// + /// Produces a Point structure from a PointF structure by + /// taking the ceiling of the X and Y properties. + /// + /// Floating-point coordinate pair. + /// Integer coordinate pair. + public static Point Ceiling(PointF value) + { + int x, y; + checked + { + x = (int)Math.Ceiling(value.X); + y = (int)Math.Ceiling(value.Y); + } + + return new Point(x, y); + } + + /// + /// Produces a Point structure from a PointF structure by + /// rounding the X and Y properties. + /// + /// Floating-point coordinate pair. + /// Integer coordinate pair. + public static Point Round(PointF value) + { + int x, y; + checked + { + x = (int)Math.Round(value.X); + y = (int)Math.Round(value.Y); + } + + return new Point(x, y); + } + + /// + /// Produces a Point structure from a PointF structure by + /// truncating the X and Y properties. + /// + /// Floating-point coordinate pair. + /// Integer coordinate pair. + public static Point Truncate(PointF value) + { + int x, y; + checked + { + x = (int)value.X; + y = (int)value.Y; + } + + return new Point(x, y); + } + + /// + /// Translates a Point by the positive of a specified size. + /// + /// Point. + /// Offset. + /// PointF structure. + public static Point Add(Point pt, Size sz) + { + return new Point(pt.X + sz.Width, pt.Y + sz.Height); + } + + /// + /// Translates a Point by the negative of a specified size. + /// + /// Point. + /// Offset. + /// PointF structure. + public static Point Subtract(Point pt, Size sz) + { + return new Point(pt.X - sz.Width, pt.Y - sz.Height); + } + + /// + /// Translates a Point by the positive of a specified size. + /// + /// Point. + /// Offset. + /// Translated point. + public static Point operator +(Point pt, Size sz) + { + return Add(pt, sz); + } + + /// + /// Translates a Point by the negative of a specified size. + /// + /// Point. + /// Offset. + /// Translated point. + public static Point operator -(Point pt, Size sz) + { + return Subtract(pt, sz); + } + + /// + /// Compares two Point objects. The return value is + /// based on the equivalence of the X and Y properties + /// of the two points. + /// + /// First structure. + /// Second structure. + /// Point structure. + public static bool operator ==(Point left, Point right) + { + return ((left.X == right.X) && (left.Y == right.Y)); + } + + /// + /// Compares two Point objects. The return value is + /// based on the equivalence of the X and Y properties + /// of the two points. + /// + /// First structure. + /// Second structure. + /// Point structure. + public static bool operator !=(Point left, Point right) + { + return ((left.X != right.X) || (left.Y != right.Y)); + } + + /// + /// Returns a Size based on the Coordinates of a given + /// Point. Requires explicit cast. + /// + /// Point. + public static explicit operator Size(Point p) + { + return new Size(p.X, p.Y); + } + + /// + /// Creates a PointF based on the coordinates of a given + /// Point. No explicit cast is required. + /// + /// Point. + public static implicit operator PointF(Point p) + { + return new PointF(p.X, p.Y); + } + + /// + /// Creates a Point from an integer which holds the Y + /// coordinate in the high order 16 bits and the X + /// coordinate in the low order 16 bits. + /// + /// An integer-packed point. + public Point(int dw) + { + y = dw >> 16; + x = dw & 0xffff; + } + + /// + /// Creates a Point from a Size value. + /// + /// Size. + public Point(Size sz) + { + x = sz.Width; + y = sz.Height; + } + + /// + /// Creates a PointF from a specified x,y coordinate pair. + /// + /// X. + /// Y. + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + + /// + /// Indicates if both X and Y are zero. + /// + public bool IsEmpty + { + get + { + return ((x == 0) && (y == 0)); + } + } + + /// + /// Gets or sets X value. + /// + public int X + { + get { return x; } + set { x = value; } + } + + /// + /// Gets or sets Y value. + /// + public int Y + { + get { return y; } + set { y = value; } + } + + /// + /// Checks equivalence of this PointF and another object. + /// + /// Other object. + /// True if the provided object is equal to this structure, false otherwise. + public override bool Equals(object obj) + { + if (!(obj is Point)) + return false; + + return (this == (Point)obj); + } + + /// + /// Calculates a hash value of the object. + /// + /// Hash code. + public override int GetHashCode() + { + return x ^ y; + } + + /// + /// Moves the Point a specified distance. + /// + /// Horizontal offset. + /// Vertical offset. + public void Offset(int dx, int dy) + { + x += dx; + y += dy; + } + + /// + /// Formats the structure as a string in coordinate notation. + /// + /// Structure represented as a string. + public override string ToString() + { + return string.Format("{X={0},Y={1}}", x.ToString(CultureInfo.InvariantCulture), + y.ToString(CultureInfo.InvariantCulture)); + } + } +} diff --git a/Source/Primitives2D/Point/PointF.cs b/Source/Primitives2D/Point/PointF.cs index 30c1b3d..c4cbb2c 100644 --- a/Source/Primitives2D/Point/PointF.cs +++ b/Source/Primitives2D/Point/PointF.cs @@ -1,273 +1,252 @@ -// -// System.Drawing.PointF.cs -// -// Author: -// Mike Kestner (mkestner@speakeasy.net) -// -// Copyright (C) 2001 Mike Kestner -// Copyright (C) 2004,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 System.Globalization; -using System.Runtime.InteropServices; -//using System.ComponentModel; - -namespace DotImaging.Primitives2D -{ - /// - /// Represents the 2D (X, Y) pair. - /// - public struct PointF - { - // Private x and y coordinate fields. - private float x, y; - - // ----------------------- - // Public Shared Members - // ----------------------- - - /// - /// Empty Shared Field - /// - /// - /// - /// An uninitialized PointF Structure. - /// - - public static readonly PointF Empty; - - /// - /// Addition Operator - /// - /// - /// - /// Translates a PointF using the Width and Height - /// properties of the given Size. - /// - - public static PointF operator +(PointF pt, Size sz) - { - return new PointF(pt.X + sz.Width, pt.Y + sz.Height); - } -#if NET_2_0 - public static PointF operator + (PointF pt, SizeF sz) - { - return new PointF (pt.X + sz.Width, pt.Y + sz.Height); - } -#endif - - /// - /// Equality Operator - /// - /// - /// - /// Compares two PointF objects. The return value is - /// based on the equivalence of the X and Y properties - /// of the two points. - /// - - public static bool operator ==(PointF left, PointF right) - { - return ((left.X == right.X) && (left.Y == right.Y)); - } - - /// - /// Inequality Operator - /// - /// - /// - /// Compares two PointF objects. The return value is - /// based on the equivalence of the X and Y properties - /// of the two points. - /// - - public static bool operator !=(PointF left, PointF right) - { - return ((left.X != right.X) || (left.Y != right.Y)); - } - - /// - /// Subtraction Operator - /// - /// - /// - /// Translates a PointF using the negation of the Width - /// and Height properties of the given Size. - /// - - public static PointF operator -(PointF pt, Size sz) - { - return new PointF(pt.X - sz.Width, pt.Y - sz.Height); - } -#if NET_2_0 - public static PointF operator - (PointF pt, SizeF sz) - { - return new PointF (pt.X - sz.Width, pt.Y - sz.Height); - } -#endif - - // ----------------------- - // Public Constructor - // ----------------------- - - /// - /// PointF Constructor - /// - /// - /// - /// Creates a PointF from a specified x,y coordinate pair. - /// - - public PointF(float x, float y) - { - this.x = x; - this.y = y; - } - - // ----------------------- - // Public Instance Members - // ----------------------- - - /// - /// IsEmpty Property - /// - /// - /// - /// Indicates if both X and Y are zero. - /// - - public bool IsEmpty - { - get - { - return ((x == 0.0) && (y == 0.0)); - } - } - - /// - /// X Property - /// - /// - /// - /// The X coordinate of the PointF. - /// - - public float X - { - get - { - return x; - } - set - { - x = value; - } - } - - /// - /// Y Property - /// - /// - /// - /// The Y coordinate of the PointF. - /// - - public float Y - { - get - { - return y; - } - set - { - y = value; - } - } - - /// - /// Equals Method - /// - /// - /// - /// Checks equivalence of this PointF and another object. - /// - - public override bool Equals(object obj) - { - if (!(obj is PointF)) - return false; - - return (this == (PointF)obj); - } - - /// - /// GetHashCode Method - /// - /// - /// - /// Calculates a hashing value. - /// - - public override int GetHashCode() - { - return (int)x ^ (int)y; - } - - /// - /// ToString Method - /// - /// - /// - /// Formats the PointF as a string in coordinate notation. - /// - - public override string ToString() - { - return String.Format("{{X={0}, Y={1}}}", x.ToString(CultureInfo.CurrentCulture), - y.ToString(CultureInfo.CurrentCulture)); - } - -#if NET_2_0 - public static PointF Add (PointF pt, Size sz) - { - return new PointF (pt.X + sz.Width, pt.Y + sz.Height); - } - - public static PointF Add (PointF pt, SizeF sz) - { - return new PointF (pt.X + sz.Width, pt.Y + sz.Height); - } - - public static PointF Subtract (PointF pt, Size sz) - { - return new PointF (pt.X - sz.Width, pt.Y - sz.Height); - } - - public static PointF Subtract (PointF pt, SizeF sz) - { - return new PointF (pt.X - sz.Width, pt.Y - sz.Height); - } -#endif - - } +#region Licence and Terms +// DotImaging Framework +// https://github.com/dajuric/dot-imaging +// +// Copyright © Darko Jurić, 2014-2015-2015 +// darko.juric2@gmail.com +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +//---------------------- original----------------------- +// Author: +// Mike Kestner (mkestner@speakeasy.net) +// +// Copyright (C) 2001 Mike Kestner +// Copyright (C) 2004, 2007 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. +#endregion + +using System; +using System.Globalization; + +namespace DotImaging.Primitives2D +{ + /// + /// Represents the 2D (X, Y) pair. + /// + public struct PointF + { + private float x, y; + + /// + /// An uninitialized PointF structure. + /// + public static readonly PointF Empty; + + /// + /// Translates a PointF by the positive of a specified size. + /// + /// Point. + /// Offset. + /// PointF structure. + public static PointF Add(PointF pt, SizeF sz) + { + return new PointF(pt.X + sz.Width, pt.Y + sz.Height); + } + + /// + /// Translates a PointF by the negative of a specified size. + /// + /// Point. + /// Offset. + /// PointF structure. + public static PointF Subtract(PointF pt, SizeF sz) + { + return new PointF(pt.X - sz.Width, pt.Y - sz.Height); + } + + /// + /// Translates a PointF by the positive of a specified size. + /// + /// Point. + /// Offset. + /// PointF structure. + public static PointF Add(PointF pt, Size sz) + { + return new PointF(pt.X + sz.Width, pt.Y + sz.Height); + } + + /// + /// Translates a PointF by the negative of a specified size. + /// + /// Point. + /// Offset. + /// PointF structure. + public static PointF Subtract(PointF pt, Size sz) + { + return new PointF(pt.X - sz.Width, pt.Y - sz.Height); + } + + /// + /// Translates a PointF by the positive of a specified size. + /// + /// Point. + /// Offset. + /// Translated point. + public static PointF operator +(PointF pt, SizeF sz) + { + return Add(pt, sz); + } + + /// + /// Translates a PointF by the negative of a specified size. + /// + /// Point. + /// Offset. + /// Translated point. + public static PointF operator -(PointF pt, SizeF sz) + { + return Subtract(pt, sz); + } + + /// + /// Translates a PointF by the positive of a specified size. + /// + /// Point. + /// Offset. + /// Translated point. + public static PointF operator +(PointF pt, Size sz) + { + return Add(pt, sz); + } + + /// + /// Translates a PointF by the negative of a specified size. + /// + /// Point. + /// Offset. + /// Translated point. + public static PointF operator -(PointF pt, Size sz) + { + return Subtract(pt, sz); + } + + /// + /// Compares two PointF objects. The return value is + /// based on the equivalence of the X and Y properties + /// of the two points. + /// + /// First structure. + /// Second structure. + /// PointF structure. + public static bool operator ==(PointF left, PointF right) + { + return ((left.X == right.X) && (left.Y == right.Y)); + } + + /// + /// Compares two PointF objects. The return value is + /// based on the equivalence of the X and Y properties + /// of the two points. + /// + /// First structure. + /// Second structure. + /// PointF structure. + public static bool operator !=(PointF left, PointF right) + { + return ((left.X != right.X) || (left.Y != right.Y)); + } + + /// + /// Creates a PointF from a specified x,y coordinate pair. + /// + /// X. + /// Y. + public PointF(float x, float y) + { + this.x = x; + this.y = y; + } + + /// + /// Indicates if both X and Y are zero. + /// + public bool IsEmpty + { + get + { + return ((x == 0.0) && (y == 0.0)); + } + } + + /// + /// Gets or sets X value. + /// + public float X + { + get { return x; } + set { x = value; } + } + + /// + /// Gets or sets Y value. + /// + public float Y + { + get { return y; } + set { y = value; } + } + + /// + /// Checks equivalence of this PointF and another object. + /// + /// Other object. + /// True if the provided object is equal to this structure, false otherwise. + public override bool Equals(object obj) + { + if (!(obj is PointF)) + return false; + + return (this == (PointF)obj); + } + + /// + /// Calculates a hash value of the object. + /// + /// Hash code. + public override int GetHashCode() + { + return (int)x ^ (int)y; + } + + /// + /// Formats the structure as a string in coordinate notation. + /// + /// Structure represented as a string. + public override string ToString() + { + return String.Format("{X={0}, Y={1}}", x.ToString(CultureInfo.CurrentCulture), + y.ToString(CultureInfo.CurrentCulture)); + } + } } \ No newline at end of file diff --git a/Source/Primitives2D/Rectangle/Rectangle.cs b/Source/Primitives2D/Rectangle/Rectangle.cs index 55474ba..3d57d47 100644 --- a/Source/Primitives2D/Rectangle/Rectangle.cs +++ b/Source/Primitives2D/Rectangle/Rectangle.cs @@ -19,6 +19,7 @@ // along with this program. If not, see . // +//---------------------- original----------------------- // Author: // Mike Kestner (mkestner@speakeasy.net) // @@ -144,6 +145,23 @@ public void Intersect(Rectangle rect) this = Rectangle.Intersect(this, rect); } + /// + /// Determines if this rectangle intersects with . + /// + /// The rectangle to test. + /// This method returns true if there is any intersection, otherwise false. + public bool IntersectsWith(Rectangle rect) + { + return !((Left >= rect.Right) || (Right <= rect.Left) || + (Top >= rect.Bottom) || (Bottom <= rect.Top)); + } + + private bool intersectsWithInclusive(Rectangle r) + { + return !((Left > r.Right) || (Right < r.Left) || + (Top > r.Bottom) || (Bottom < r.Top)); + } + /// /// Gets a Rectangle structure that contains the union of two Rectangle structures. /// @@ -274,77 +292,88 @@ public Rectangle(int x, int y, int width, int height) } /// - /// Gets the y-coordinate that is the sum of the Y and Height property values of this Rectangle structure. + /// Tests whether all numeric properties of this Rectangle have values of zero. /// - public int Bottom + public bool IsEmpty { get { - return y + height; + return ((x == 0) && (y == 0) && (width == 0) && (height == 0)); } } /// - /// Gets or sets the height of this Rectangle structure. + /// Gets the x-coordinate of the left edge of this Rectangle structure. /// - public int Height + public int Left { get { - return height; + return X; } - set + } + + /// + /// Gets the x-coordinate that is the sum of X and Width property values of this Rectangle structure. + /// + public int Right + { + get { - height = value; + return X + Width; } } /// - /// Tests whether all numeric properties of this Rectangle have values of zero. + /// Gets the y-coordinate of the top edge of this Rectangle structure. /// - public bool IsEmpty + public int Top { get { - return ((x == 0) && (y == 0) && (width == 0) && (height == 0)); + return y; } } /// - /// Gets the x-coordinate of the left edge of this Rectangle structure. + /// Gets the y-coordinate that is the sum of the Y and Height property values of this Rectangle structure. /// - public int Left + public int Bottom { get { - return X; + return y + height; } } /// - /// Gets or sets the coordinates of the upper-left corner of this Rectangle structure. + /// Gets or sets the height of this Rectangle structure. /// - public Point Location + public int Height { get { - return new Point(x, y); + return height; } set { - x = value.X; - y = value.Y; + height = value; } } /// - /// Gets the x-coordinate that is the sum of X and Width property values of this Rectangle structure. + /// Gets or sets the coordinates of the upper-left corner of this Rectangle structure. /// - public int Right + public Point Location { get { - return X + Width; + return new Point(x, y); + } + set + { + x = value.X; + y = value.Y; } } @@ -364,17 +393,6 @@ public Size Size } } - /// - /// Gets the y-coordinate of the top edge of this Rectangle structure. - /// - public int Top - { - get - { - return y; - } - } - /// /// Gets or sets the width of this Rectangle structure. /// @@ -452,6 +470,27 @@ public bool Contains(Rectangle rect) return (rect == Intersect(this, rect)); } + /// + /// Adjusts the location of this rectangle by the specified amount. + /// + /// The horizontal offset. + /// The vertical offset. + public void Offset(int x, int y) + { + this.x += x; + this.y += y; + } + + /// + /// Adjusts the location of this rectangle by the specified amount. + /// + /// Amount to offset the location. + public void Offset(Point pos) + { + x += pos.X; + y += pos.Y; + } + /// /// Tests whether obj is a Rectangle structure with the same location and size of this Rectangle structure. /// @@ -474,44 +513,6 @@ public override int GetHashCode() return (height + width) ^ x + y; } - /// - /// Determines if this rectangle intersects with . - /// - /// The rectangle to test. - /// This method returns true if there is any intersection, otherwise false. - public bool IntersectsWith(Rectangle rect) - { - return !((Left >= rect.Right) || (Right <= rect.Left) || - (Top >= rect.Bottom) || (Bottom <= rect.Top)); - } - - private bool intersectsWithInclusive(Rectangle r) - { - return !((Left > r.Right) || (Right < r.Left) || - (Top > r.Bottom) || (Bottom < r.Top)); - } - - /// - /// Adjusts the location of this rectangle by the specified amount. - /// - /// The horizontal offset. - /// The vertical offset. - public void Offset(int x, int y) - { - this.x += x; - this.y += y; - } - - /// - /// Adjusts the location of this rectangle by the specified amount. - /// - /// Amount to offset the location. - public void Offset(Point pos) - { - x += pos.X; - y += pos.Y; - } - /// /// Converts the attributes of this System.Drawing.Rectangle to a human-readable string. /// diff --git a/Source/Primitives2D/Rectangle/RectangleExtensions.cs b/Source/Primitives2D/Rectangle/RectangleExtensions.cs index 6a5f02b..2fe160d 100644 --- a/Source/Primitives2D/Rectangle/RectangleExtensions.cs +++ b/Source/Primitives2D/Rectangle/RectangleExtensions.cs @@ -110,10 +110,10 @@ public static Point Center(this Rectangle rect) } /// - /// Gets rectangle vertices in clock-wise order staring from left-upper corner. + /// Gets rectangle vertexes in clock-wise order staring from left-upper corner. /// /// Rectangle. - /// Vertices. + /// Vertexes. public static Point[] Vertices(this Rectangle rect) { return new Point[] @@ -218,7 +218,7 @@ public static bool MoveToFit(this Rectangle rect, Size area, out Rectangle trans /// /// Defined functions can be used as object extensions. - /// Provides extension methods for . + /// Provides extension methods for rectangle structure. /// public static class RectangleFExtensions { @@ -290,10 +290,10 @@ public static PointF Center(this RectangleF rect) } /// - /// Gets rectangle vertices in clock-wise order staring from left-upper corner. + /// Gets rectangle vertexes in clock-wise order staring from left-upper corner. /// /// Rectangle. - /// Vertices. + /// Vertexes. public static PointF[] Vertices(this RectangleF rect) { return new PointF[] @@ -383,7 +383,7 @@ public static RectangleF Inflate(this RectangleF rect, double widthScale, double /// Scales rectangles by the specified amount. /// /// Rectangle. - /// Multiplication factor for vertices coordinates. + /// Multiplication factor for vertexes coordinates. /// Scaled rectangle. public static RectangleF Scale(this RectangleF rect, float scaleFactor) { diff --git a/Source/Primitives2D/Rectangle/RectangleF.cs b/Source/Primitives2D/Rectangle/RectangleF.cs index ee20b99..2022adf 100644 --- a/Source/Primitives2D/Rectangle/RectangleF.cs +++ b/Source/Primitives2D/Rectangle/RectangleF.cs @@ -19,6 +19,7 @@ // along with this program. If not, see . // +//---------------------- original----------------------- // Author: // Mike Kestner (mkestner@speakeasy.net) // @@ -143,6 +144,23 @@ public void Intersect(RectangleF rect) this = RectangleF.Intersect(this, rect); } + /// + /// Determines if this rectangle intersects with . + /// + /// The rectangle to test. + /// This method returns true if there is any intersection, otherwise false. + public bool IntersectsWith(RectangleF rect) + { + return !((Left >= rect.Right) || (Right <= rect.Left) || + (Top >= rect.Bottom) || (Bottom <= rect.Top)); + } + + private bool intersectsWithInclusive(RectangleF r) + { + return !((Left > r.Right) || (Right < r.Left) || + (Top > r.Bottom) || (Bottom < r.Top)); + } + /// /// Gets a RectangleF structure that contains the union of two RectangleF structures. /// @@ -195,11 +213,6 @@ public static RectangleF Union(RectangleF a, RectangleF b) return new RectangleF(r.X, r.Y, r.Width, r.Height); } - - // ----------------------- - // Public Constructors - // ----------------------- - /// /// Creates a RectangleF from PointF and SizeF values. /// @@ -229,53 +242,44 @@ public RectangleF(float x, float y, float width, float height) this.height = height; } + /// + /// Tests whether all numeric properties of this RectangleF have values of zero. + /// + public bool IsEmpty + { + get { return (width <= 0 || height <= 0); } + } /// - /// Gets the y-coordinate that is the sum of the Y and Height property values of this RectangleF structure. + /// Gets the x-coordinate of the left edge of this RectangleF structure. /// - public float Bottom + public float Left { - get - { - return Y + Height; - } + get { return X; } } /// - /// Gets or sets the height of this RectangleF structure. + /// Gets the x-coordinate that is the sum of X and Width property values of this RectangleF structure. /// - public float Height + public float Right { - get - { - return height; - } - set - { - height = value; - } + get { return X + Width; } } /// - /// Tests whether all numeric properties of this RectangleF have values of zero. + /// Gets the y-coordinate of the top edge of this RectangleF structure. /// - public bool IsEmpty + public float Top { - get - { - return (width <= 0 || height <= 0); - } + get { return Y; } } /// - /// Gets the x-coordinate of the left edge of this RectangleF structure. + /// Gets the y-coordinate that is the sum of the Y and Height property values of this RectangleF structure. /// - public float Left + public float Bottom { - get - { - return X; - } + get { return Y + Height; } } /// @@ -294,17 +298,6 @@ public PointF Location } } - /// - /// Gets the x-coordinate that is the sum of X and Width property values of this RectangleF structure. - /// - public float Right - { - get - { - return X + Width; - } - } - /// /// Gets or sets the size of this rectangle. /// @@ -322,29 +315,21 @@ public SizeF Size } /// - /// Gets the y-coordinate of the top edge of this RectangleF structure. + /// Gets or sets the width of this RectangleF structure. /// - public float Top + public float Width { - get - { - return Y; - } + get { return width; } + set { width = value; } } /// - /// Gets or sets the width of this RectangleF structure. + /// Gets or sets the height of this RectangleF structure. /// - public float Width + public float Height { - get - { - return width; - } - set - { - width = value; - } + get { return height; } + set { height = value; } } /// @@ -352,14 +337,8 @@ public float Width /// public float X { - get - { - return x; - } - set - { - x = value; - } + get { return x; } + set { x = value; } } /// @@ -367,14 +346,8 @@ public float X /// public float Y { - get - { - return y; - } - set - { - y = value; - } + get { return y; } + set { y = value; } } /// @@ -409,6 +382,26 @@ public bool Contains(RectangleF rect) return (rect == Intersect(this, rect)); } + /// + /// Adjusts the location of this rectangle by the specified amount. + /// + /// The horizontal offset. + /// The vertical offset. + public void Offset(float x, float y) + { + X += x; + Y += y; + } + + /// + /// Adjusts the location of this rectangle by the specified amount. + /// + /// Amount to offset the location. + public void Offset(PointF pos) + { + Offset(pos.X, pos.Y); + } + /// /// Tests whether obj is a RectangleF structure with the same location and size of this RectangleF structure. /// @@ -431,50 +424,13 @@ public override int GetHashCode() return (int)(x + y + width + height); } - /// - /// Determines if this rectangle intersects with . - /// - /// The rectangle to test. - /// This method returns true if there is any intersection, otherwise false. - public bool IntersectsWith(RectangleF rect) - { - return !((Left >= rect.Right) || (Right <= rect.Left) || - (Top >= rect.Bottom) || (Bottom <= rect.Top)); - } - - private bool intersectsWithInclusive(RectangleF r) - { - return !((Left > r.Right) || (Right < r.Left) || - (Top > r.Bottom) || (Bottom < r.Top)); - } - - /// - /// Adjusts the location of this rectangle by the specified amount. - /// - /// The horizontal offset. - /// The vertical offset. - public void Offset(float x, float y) - { - X += x; - Y += y; - } - - /// - /// Adjusts the location of this rectangle by the specified amount. - /// - /// Amount to offset the location. - public void Offset(PointF pos) - { - Offset(pos.X, pos.Y); - } - /// /// Converts the attributes of this System.Drawing.Rectangle to a human-readable string. /// /// A string in (x,y,w,h) notation public override string ToString() { - return String.Format("{{X={0},Y={1},Width={2},Height={3}}}", + return String.Format("{X={0},Y={1},Width={2},Height={3}}", x, y, width, height); } } diff --git a/Source/Primitives2D/Size/Size.cs b/Source/Primitives2D/Size/Size.cs index 213cf5e..92a8a1f 100644 --- a/Source/Primitives2D/Size/Size.cs +++ b/Source/Primitives2D/Size/Size.cs @@ -18,76 +18,106 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // + +//---------------------- original----------------------- +// Author: +// Mike Kestner (mkestner@speakeasy.net) +// +// Copyright (C) 2001 Mike Kestner +// Copyright (C) 2004 Novell, Inc. http://www.novell.com +// + +// +// Copyright (C) 2004 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. #endregion using System; -//using System.ComponentModel; -using System.Runtime.InteropServices; namespace DotImaging.Primitives2D { - // Author: - // Mike Kestner (mkestner@speakeasy.net) - // - // Copyright (C) 2001 Mike Kestner - // Copyright (C) 2004 Novell, Inc. http://www.novell.com - // - - // - // Copyright (C) 2004 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. - // - /// - /// Stores an ordered pair of integer numbers, which specify a Height and Width and defines related functions. + /// Stores an ordered pair of integer numbers, which specify height and width and defines related functions. /// public struct Size { - - // Private Height and width fields. private int width, height; - // ----------------------- - // Public Shared Members - // ----------------------- + /// + /// An uninitialized Size structure. + /// + public static readonly Size Empty; /// - /// Empty Shared Field + /// Adds two Size structures. /// - /// - /// - /// An uninitialized Size Structure. - /// + /// First structure. + /// Second structure. + /// Size structure. + public static Size Add(Size sz1, Size sz2) + { + return new Size(sz1.Width + sz2.Width, + sz1.Height + sz2.Height); + } - public static readonly Size Empty; + /// + /// Subtracts two Size structures. + /// + /// First structure. + /// Second structure. + /// Size structure. + public static Size Subtract(Size sz1, Size sz2) + { + return new Size(sz1.Width - sz2.Width, + sz1.Height - sz2.Height); + } /// - /// Ceiling Shared Method + /// Addition of two Size structures. /// - /// - /// - /// Produces a Size structure from a SizeF structure by - /// taking the ceiling of the Width and Height properties. - /// + /// First structure. + /// Second structure. + /// Size structure. + public static Size operator +(Size sz1, Size sz2) + { + return Add(sz1, sz2); + } + + /// + /// Subtracts two Size structures. + /// + /// First structure. + /// Second structure. + /// Size structure. + public static Size operator -(Size sz1, Size sz2) + { + return Subtract(sz1, sz2); + } + /// + /// Produces a Size structure from a SizeF structure by + /// taking the ceiling of the Width and Height properties. + /// + /// Floating-point size structure. + /// Integer size structure. public static Size Ceiling(SizeF value) { int w, h; @@ -101,14 +131,11 @@ public static Size Ceiling(SizeF value) } /// - /// Round Shared Method - /// - /// - /// - /// Produces a Size structure from a SizeF structure by + /// Produces a Size structure from a SizeF structure by /// rounding the Width and Height properties. - /// - + /// + /// Floating-point size structure. + /// Integer size structure. public static Size Round(SizeF value) { int w, h; @@ -122,14 +149,11 @@ public static Size Round(SizeF value) } /// - /// Truncate Shared Method - /// - /// - /// - /// Produces a Size structure from a SizeF structure by + /// Produces a Size structure from a SizeF structure by /// truncating the Width and Height properties. - /// - + /// + /// Floating-point size structure. + /// Integer size structure. public static Size Truncate(SizeF value) { int w, h; @@ -143,29 +167,13 @@ public static Size Truncate(SizeF value) } /// - /// Addition Operator - /// - /// - /// - /// Addition of two Size structures. - /// - - public static Size operator +(Size sz1, Size sz2) - { - return new Size(sz1.Width + sz2.Width, - sz1.Height + sz2.Height); - } - - /// - /// Equality Operator - /// - /// - /// - /// Compares two Size objects. The return value is + /// Compares two Size objects. The return value is /// based on the equivalence of the Width and Height - /// properties of the two Sizes. - /// - + /// properties of the two Size structures. + /// + /// First structure. + /// Second structure. + /// Size structure. public static bool operator ==(Size sz1, Size sz2) { return ((sz1.Width == sz2.Width) && @@ -173,15 +181,13 @@ public static Size Truncate(SizeF value) } /// - /// Inequality Operator - /// - /// - /// - /// Compares two Size objects. The return value is + /// Compares two Size objects. The return value is /// based on the equivalence of the Width and Height - /// properties of the two Sizes. - /// - + /// properties of the two Size structures. + /// + /// First structure. + /// Second structure. + /// Size structure. public static bool operator !=(Size sz1, Size sz2) { return ((sz1.Width != sz2.Width) || @@ -189,60 +195,29 @@ public static Size Truncate(SizeF value) } /// - /// Subtraction Operator - /// - /// - /// - /// Subtracts two Size structures. - /// - - public static Size operator -(Size sz1, Size sz2) - { - return new Size(sz1.Width - sz2.Width, - sz1.Height - sz2.Height); - } - - /// - /// Size to Point Conversion - /// - /// - /// - /// Returns a Point based on the dimensions of a given + /// Returns a Point based on the dimensions of a given /// Size. Requires explicit cast. - /// - + /// + /// Size structure. public static explicit operator Point(Size size) { return new Point(size.Width, size.Height); } /// - /// Size to SizeF Conversion - /// - /// - /// - /// Creates a SizeF based on the dimensions of a given + /// Creates a SizeF based on the dimensions of a given /// Size. No explicit cast is required. - /// - + /// + /// public static implicit operator SizeF(Size p) { return new SizeF(p.Width, p.Height); } - - // ----------------------- - // Public Constructors - // ----------------------- - /// - /// Size Constructor + /// Creates a Size from a Point value. /// - /// - /// - /// Creates a Size from a Point value. - /// - + /// Point. public Size(Point pt) { width = pt.X; @@ -250,88 +225,47 @@ public Size(Point pt) } /// - /// Size Constructor + /// Creates a Size from specified dimensions. /// - /// - /// - /// Creates a Size from specified dimensions. - /// - + /// Width. + /// Height. public Size(int width, int height) { this.width = width; this.height = height; } - // ----------------------- - // Public Instance Members - // ----------------------- - /// - /// IsEmpty Property + /// Indicates if both width and height are zero. /// - /// - /// - /// Indicates if both Width and Height are zero. - /// - - //[Browsable(false)] public bool IsEmpty { - get - { - return ((width == 0) && (height == 0)); - } + get { return ((width == 0) && (height == 0)); } } /// - /// Width Property + /// Gets or sets width value. /// - /// - /// - /// The Width coordinate of the Size. - /// - public int Width { - get - { - return width; - } - set - { - width = value; - } + get { return width; } + set { width = value; } } /// - /// Height Property + /// Gets or sets height value. /// - /// - /// - /// The Height coordinate of the Size. - /// - public int Height { - get - { - return height; - } - set - { - height = value; - } + get { return height; } + set { height = value; } } /// - /// Equals Method + /// Checks equivalence of this Size and another object. /// - /// - /// - /// Checks equivalence of this Size and another object. - /// - + /// Other object. + /// True if the provided object is equal to this structure, false otherwise. public override bool Equals(object obj) { if (!(obj is Size)) @@ -341,45 +275,21 @@ public override bool Equals(object obj) } /// - /// GetHashCode Method + /// Calculates a hash value of the object. /// - /// - /// - /// Calculates a hashing value. - /// - + /// Hash code. public override int GetHashCode() { return width ^ height; } /// - /// ToString Method + /// Formats the structure as a string in coordinate notation. /// - /// - /// - /// Formats the Size as a string in coordinate notation. - /// - + /// Structure represented as a string. public override string ToString() { - return String.Format("{{Width={0}, Height={1}}}", width, height); + return String.Format("{Width={0}, Height={1}}", width, height); } - -#if NET_2_0 - public static Size Add (Size sz1, Size sz2) - { - return new Size (sz1.Width + sz2.Width, - sz1.Height + sz2.Height); - - } - - public static Size Subtract (Size sz1, Size sz2) - { - return new Size (sz1.Width - sz2.Width, - sz1.Height - sz2.Height); - } -#endif - } } diff --git a/Source/Primitives2D/Size/SizeF.cs b/Source/Primitives2D/Size/SizeF.cs index eb84680..4949fd3 100644 --- a/Source/Primitives2D/Size/SizeF.cs +++ b/Source/Primitives2D/Size/SizeF.cs @@ -18,91 +18,126 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // + +//---------------------- original----------------------- +// Author: +// Mike Kestner (mkestner@speakeasy.net) +// +// Copyright (C) 2001 Mike Kestner +// Copyright (C) 2004 Novell, Inc. http://www.novell.com +// + +// +// Copyright (C) 2004 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. #endregion -using System; -//using System.ComponentModel; using System.Globalization; -using System.Runtime.InteropServices; namespace DotImaging.Primitives2D { - // Author: - // Mike Kestner (mkestner@speakeasy.net) - // - // Copyright (C) 2001 Mike Kestner - // Copyright (C) 2004 Novell, Inc. http://www.novell.com - // - - // - // Copyright (C) 2004 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. - // - /// - /// Stores an ordered pair of floating-point numbers, which specify a Height and Width and defines related functions. + /// Stores an ordered pair of floating-point numbers, which specify height and width and defines related functions. /// public struct SizeF { - // Private height and width fields. private float width, height; - // ----------------------- - // Public Shared Members - // ----------------------- + /// + /// An uninitialized Size structure. + /// + public static readonly SizeF Empty; /// - /// Empty Shared Field + /// Adds two SizeF structures. /// - /// - /// - /// An uninitialized SizeF Structure. - /// + /// First structure. + /// Second structure. + /// SizeF structure. + public static SizeF Add(SizeF sz1, SizeF sz2) + { + return new SizeF(sz1.Width + sz2.Width, + sz1.Height + sz2.Height); + } - public static readonly SizeF Empty; + /// + /// Subtracts two SizeF structures. + /// + /// First structure. + /// Second structure. + /// SizeF structure. + public static SizeF Subtract(SizeF sz1, SizeF sz2) + { + return new SizeF(sz1.Width - sz2.Width, + sz1.Height - sz2.Height); + } + + /// + /// Converts the structure to PointF representation. + /// + /// PointF. + public PointF ToPointF() + { + return (PointF)this; + } /// - /// Addition Operator + /// Converts the structure to Size representation. /// - /// - /// - /// Addition of two SizeF structures. - /// + /// Size. + public Size ToSize() + { + return (Size)this; + } + /// + /// Adds two SizeF structures. + /// + /// First structure. + /// Second structure. + /// Size structure. public static SizeF operator +(SizeF sz1, SizeF sz2) { - return new SizeF(sz1.Width + sz2.Width, - sz1.Height + sz2.Height); + return Add(sz1, sz2); } /// - /// Equality Operator + /// Subtracts two Size structures. /// - /// - /// - /// Compares two SizeF objects. The return value is - /// based on the equivalence of the Width and Height - /// properties of the two Sizes. - /// + /// First structure. + /// Second structure. + /// Size structure. + public static SizeF operator -(SizeF sz1, SizeF sz2) + { + return Subtract(sz1, sz2); + } + /// + /// Compares two SizeF objects. The return value is + /// based on the equivalence of the Width and Height + /// properties of the two SizeF structures. + /// + /// First structure. + /// Second structure. + /// SizeF structure. public static bool operator ==(SizeF sz1, SizeF sz2) { return ((sz1.Width == sz2.Width) && @@ -110,15 +145,13 @@ public struct SizeF } /// - /// Inequality Operator - /// - /// - /// - /// Compares two SizeF objects. The return value is + /// Compares two SizeF objects. The return value is /// based on the equivalence of the Width and Height - /// properties of the two Sizes. - /// - + /// properties of the two SizeF structures. + /// + /// First structure. + /// Second structure. + /// SizeF structure. public static bool operator !=(SizeF sz1, SizeF sz2) { return ((sz1.Width != sz2.Width) || @@ -126,46 +159,18 @@ public struct SizeF } /// - /// Subtraction Operator - /// - /// - /// - /// Subtracts two SizeF structures. - /// - - public static SizeF operator -(SizeF sz1, SizeF sz2) - { - return new SizeF(sz1.Width - sz2.Width, - sz1.Height - sz2.Height); - } - - /// - /// SizeF to PointF Conversion - /// - /// - /// - /// Returns a PointF based on the dimensions of a given + /// Returns a PointF based on the dimensions of a given /// SizeF. Requires explicit cast. - /// - + /// public static explicit operator PointF(SizeF size) { return new PointF(size.Width, size.Height); } - - // ----------------------- - // Public Constructors - // ----------------------- - /// - /// SizeF Constructor + /// Creates a SizeF from a PointF value. /// - /// - /// - /// Creates a SizeF from a PointF value. - /// - + /// PointF. public SizeF(PointF pt) { width = pt.X; @@ -173,46 +178,29 @@ public SizeF(PointF pt) } /// - /// SizeF Constructor + /// Creates a SizeF from an existing SizeF value. /// - /// - /// - /// Creates a SizeF from an existing SizeF value. - /// - - public SizeF(SizeF size) + /// Size. + public SizeF(SizeF sz) { - width = size.Width; - height = size.Height; + width = sz.Width; + height = sz.Height; } /// - /// SizeF Constructor + /// Creates a SizeF from specified dimensions. /// - /// - /// - /// Creates a SizeF from specified dimensions. - /// - + /// Width. + /// Height. public SizeF(float width, float height) { this.width = width; this.height = height; } - // ----------------------- - // Public Instance Members - // ----------------------- - /// - /// IsEmpty Property + /// Indicates if both width and height are zero. /// - /// - /// - /// Indicates if both Width and Height are zero. - /// - - //[Browsable(false)] public bool IsEmpty { get @@ -222,53 +210,28 @@ public bool IsEmpty } /// - /// Width Property + /// Gets or sets width value. /// - /// - /// - /// The Width coordinate of the SizeF. - /// - public float Width { - get - { - return width; - } - set - { - width = value; - } + get { return width; } + set { width = value; } } /// - /// Height Property + /// Gets or sets height value. /// - /// - /// - /// The Height coordinate of the SizeF. - /// - public float Height { - get - { - return height; - } - set - { - height = value; - } + get { return height; } + set { height = value; } } /// - /// Equals Method + /// Checks equivalence of this SizeF and another object. /// - /// - /// - /// Checks equivalence of this SizeF and another object. - /// - + /// Other object. + /// True if the provided object is equal to this structure, false otherwise. public override bool Equals(object obj) { if (!(obj is SizeF)) @@ -278,13 +241,9 @@ public override bool Equals(object obj) } /// - /// GetHashCode Method + /// Calculates a hash value of the object. /// - /// - /// - /// Calculates a hashing value. - /// - + /// Hash code. public override int GetHashCode() { return (int)width ^ (int)height; @@ -301,31 +260,13 @@ public override int GetHashCode() } /// - /// ToString Method + /// Formats the structure as a string in coordinate notation. /// - /// - /// - /// Formats the SizeF as a string in coordinate notation. - /// - + /// Structure represented as a string. public override string ToString() { return string.Format("{{Width={0}, Height={1}}}", width.ToString(CultureInfo.CurrentCulture), height.ToString(CultureInfo.CurrentCulture)); } - -#if NET_2_0 - public static SizeF Add (SizeF sz1, SizeF sz2) - { - return new SizeF (sz1.Width + sz2.Width, - sz1.Height + sz2.Height); - } - - public static SizeF Subtract (SizeF sz1, SizeF sz2) - { - return new SizeF (sz1.Width - sz2.Width, - sz1.Height - sz2.Height); - } -#endif } }