Rectangle
using Autodesk.DesignScript.Interfaces;
using System.Collections.Generic;
using System.Linq;
namespace Autodesk.DesignScript.Geometry
{
public class Rectangle : Polygon
{
internal IRectangleEntity RectangleEntity => HostImpl as IRectangleEntity;
public double Width => RectangleEntity.Width;
public double Height => RectangleEntity.Height;
internal Rectangle(IRectangleEntity host, bool persist)
: base(host, persist)
{
}
public override string ToString()
{
return "Rectangle(Width = " + Width.ToString(GeometryExtension.DoublePrintFormat) + ", Height = " + Height.ToString(GeometryExtension.DoublePrintFormat) + ")";
}
internal new static void InitType()
{
Geometry.RegisterHostType(typeof(IRectangleEntity), (IGeometryEntity host, bool persist) => new Rectangle(host as IRectangleEntity, persist));
}
internal static Rectangle Wrap(IRectangleEntity host, bool persist = true)
{
return Geometry.Wrap(host, false, null) as Rectangle;
}
internal static Rectangle[] Wrap(IRectangleEntity[] hosts, bool persist = true)
{
return (from x in hosts
select Wrap(x, persist)).ToArray();
}
internal static Rectangle[][] Wrap(IRectangleEntity[][] hosts, bool persist = true)
{
return (from x in hosts
select Wrap(x, persist)).ToArray();
}
internal static IRectangleEntity[][] Unwrap(Rectangle[][] o)
{
return (from x in o
select Unwrap(x)).ToArray();
}
internal static IRectangleEntity[] Unwrap(Rectangle[] o)
{
return (from x in o
select Unwrap(x)).ToArray();
}
internal static IRectangleEntity[] Unwrap(IEnumerable<Rectangle> o)
{
return (from x in o
select Unwrap(x)).ToArray();
}
internal static IRectangleEntity Unwrap(Rectangle o)
{
return o.RectangleEntity;
}
public static Rectangle ByCornerPoints(IEnumerable<Point> points)
{
return Wrap(HostFactory.Factory.RectangleByCornerPoints(Point.Unwrap(points)), true);
}
public static Rectangle ByCornerPoints(Point p1, Point p2, Point p3, Point p4)
{
return Wrap(HostFactory.Factory.RectangleByCornerPoints(Point.Unwrap(p1), Point.Unwrap(p2), Point.Unwrap(p3), Point.Unwrap(p4)), true);
}
public static Rectangle ByWidthHeight(double width = 1, double length = 1)
{
return Wrap(HostFactory.Factory.RectangleByWidthHeight(width, length), true);
}
public static Rectangle ByWidthHeight(Plane plane, double width = 1, double length = 1)
{
return Wrap(HostFactory.Factory.RectangleByWidthHeight(Plane.Unwrap(plane), width, length), true);
}
public static Rectangle ByWidthHeight(CoordinateSystem cs, double width = 1, double length = 1)
{
return Wrap(HostFactory.Factory.RectangleByWidthHeight(CoordinateSystem.Unwrap(cs), width, length), true);
}
}
}