 # Problem with offset a rectangle

Hello everybody,
I have a problem when I try to offset a rectangle.

I use the following method:

``````Curve curvaOffset = ((Curve)geometria).Offset(Plane.WorldXY, herramientaCorte.Diametro / 2, 0.01,CurveOffsetCornerStyle.Sharp);
``````

Geometria contains a rectangle. After doing this, I want to explode curvaOffset with the following method:

``````curvaOffset .TryGetPolyline(out polylinea)
``````

But polylinea has 12 segments instead 4 because each increment of the offset is a segment.

Are there any way to offset a rectangle and get a polyline of 4 segments?

Yes, this is on the list to fix. To work around this, you can clean up the offset curve by doing something like this:

``````protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var src_points = new Point3d;
src_points = new Point3d(1, 1, 0);
src_points = new Point3d(9, 1, 0);
src_points = new Point3d(9, 9, 0);
src_points = new Point3d(1, 9, 0);
src_points = new Point3d(1, 1, 0);

var src_curve = new PolylineCurve(src_points);

var offsets = src_curve.Offset(Plane.WorldXY, 1.0, doc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.Sharp);
if (null == offsets || 0 == offsets.Length)
return Result.Failure;

for (var i = 0; i < offsets.Length; i++)
{
var curve = offsets[i];
if (null != curve)
{
if (curve.IsPolyline())
{
var polyline = new Polyline();
var dom = curve.Domain;
var t = dom.Min;
while (curve.GetNextDiscontinuity(Continuity.G1_continuous, t, dom.Max, out t))

if (curve.IsClosed)
{
var p0 = polyline;
var pn = polyline[polyline.Count - 1];
var v = pn - p0;
if (v.Length > Rhino.RhinoMath.SqrtEpsilon)
}

if (curve.IsValid)
curve = new PolylineCurve(polyline);
}