# The data structure of ON\_SimpleArray

**URL:** <https://discourse.mcneel.com/t/the-data-structure-of-on-simplearray/153246>\
**Category:** Rhino Developer\
**Tags:** windows, c\
**Created:** [January 12, 2023, 6:01pm UTC](https://discourse.mcneel.com/t/the-data-structure-of-on-simplearray/153246 "2023-01-12T18:01:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qingxiang](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/qingxiang/32/485566_2.png) [@Qingxiang](https://discourse.mcneel.com/u/Qingxiang)\
**Post date:** [January 12, 2023, 6:01pm UTC](https://discourse.mcneel.com/t/the-data-structure-of-on-simplearray/153246/1 "2023-01-12T18:01:15Z")

</div>

Dear Sir/Madam:

I have just test a C++ sample SampleSplitCurve and it runs well. But I am very confused about the data structure of ON\_SimpleArray crv\_t. After adding a line in the code, the output result is the same. For example I spilt a line for (1,1,0) to (1,11,0). The output is 0,2,4. Would you please explain me the problem and how to print the correct result of crv\_t?

Many Thanks,  
Meng

// The one and only CCommandSampleSplitCurve object  
static class CCommandSampleSplitCurve theSampleSplitCurveCommand;

CRhinoCommand::result CCommandSampleSplitCurve::RunCommand(const CRhinoCommandContext& context)  
{  
CRhinoGetObject go;  
go.SetCommandPrompt(L"Select curve to split");  
go.SetGeometryFilter(CRhinoGetObject::curve\_object);  
go.GetObjects(1, 1);  
if (go.CommandResult() != CRhinoCommand::success)  
return go.CommandResult();

const CRhinoObjRef& crv\_obj\_ref = go.Object(0);  
const CRhinoObject\* crv\_obj = crv\_obj\_ref.Object();  
const ON\_Curve\* crv = crv\_obj\_ref.Curve();  
if (0 == crv\_obj || 0 == crv)  
return CRhinoCommand::failure;

ON\_SimpleArray crv\_t;  
CRhinoCommand::result rc = PickCurveParameters(context.m\_doc, \*crv, crv\_t);  
if (rc != CRhinoCommand::success)  
return rc;

ON\_3dmObjectAttributes atts(crv\_obj-\>Attributes());

int i;  
for (i = 0; i \< crv\_t.Count() - 1; i++)  
{  
RhinoApp().Print(L"Point = %f,%f,%f\n", crv\_t[i,0], crv\_t[i,1], crv\_t[i,2]);  
ON\_Interval interval(crv\_t[i], crv\_t[i + 1]);  
if (crv-\>Domain().Includes(interval))  
{  
ON\_Curve\* new\_crv = ON\_TrimCurve(_crv, interval);  
if (new\_crv)  
{  
CRhinoCurveObject_ new\_crv\_obj = new CRhinoCurveObject(atts);  
new\_crv\_obj-\>SetCurve(new\_crv);  
context.m\_doc.AddObject(new\_crv\_obj);  
}  
}  
}

context.m\_doc.DeleteObject(crv\_obj\_ref);  
context.m\_doc.Redraw();

return CRhinoCommand::success;  
}

CRhinoCommand::result CCommandSampleSplitCurve::PickCurveParameters(CRhinoDoc& doc, const ON\_Curve& crv, ON\_SimpleArray& crv\_t)  
{  
crv\_t.Empty();

CRhinoGetCurvePoints gp;  
gp.Constrain(crv);  
int l\_option = gp.AddCommandOption(RHCMDOPTNAME(L"Length"));  
/_int s\_option =_/ gp.AddCommandOption(RHCMDOPTNAME(L"Segments"));  
CRhinoGet::result res = gp.GetPoints();  
if (res == CRhinoGet::option)  
{  
const CRhinoCommandOption\* option = gp.Option();  
if (0 == option)  
return CRhinoCommand::failure;  
if (option-\>m\_option\_index == l\_option)  
return DivideCurveLength(doc, crv, crv\_t);  
else  
return DivideCurveSegments(doc, crv, crv\_t);  
}  
else if (res != CRhinoGet::point)  
return CRhinoCommand::cancel;

ON\_3dPointArray points;  
int i, point\_count = gp.Points(points);  
for (i = 0; i \< point\_count; i++)  
{  
double t = 0;  
if (crv.GetClosestPoint(points[i], &t))  
crv\_t.Append(t);  
}

crv\_t.Append(crv.Domain().Min());  
crv\_t.Append(crv.Domain().Max());  
crv\_t.QuickSort(&ON\_CompareIncreasing);

return CRhinoCommand::success;  
}

 ![3](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/0/e/30e7f236616fed2af643f4f727a2f24199ee2975.png)  
 ![2](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/1/0/010d35fb94a66d21baf2e66fda4c3ebc4579dc87.png)  
 ![1](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/f/d/a/fdaff8daa9daa5bb449cd9862f1cf00d5ce17da4.png)

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/772741_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [January 12, 2023, 6:30pm UTC](https://discourse.mcneel.com/t/the-data-structure-of-on-simplearray/153246/2 "2023-01-12T18:30:56Z")

</div>

For others reading this, here is a link to the SDK sample.

[cmdSampleSplitCurve.cpp](https://github.com/mcneel/rhino-developer-samples/blob/7/cpp/SampleCommands/cmdSampleSplitCurve.cpp)

@Qingxiang - if you review this block of code:

```auto
ON_SimpleArray<double> crv_t;
CRhinoCommand::result rc = PickCurveParameters(context.m_doc, *crv, crv_t);
if (rc != CRhinoCommand::success)
  return rc;

```

Here, the command is declaring a simple array of doubles (crv\_t). The array is passed to the `PickCurveParameters` function, which fills in the array with curve parameters (think parametric equation).

Because the array contains doubles, and not points, your print function should look like this:

```auto
int i;
for (i = 0; i < crv_t.Count() - 1; i++)
{
  RhinoApp().Print(L"Curve parameter = %f\n", crv_t[i]);

```

Hope this helps.

– Dale

---

<div class="post-metadata">

**Author:** ![Qingxiang](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/qingxiang/32/485566_2.png) [@Qingxiang](https://discourse.mcneel.com/u/Qingxiang)\
**Post date:** [January 13, 2023, 9:26am UTC](https://discourse.mcneel.com/t/the-data-structure-of-on-simplearray/153246/3 "2023-01-13T09:26:14Z")

</div>

@dale Thanks for your help. I find the crv\_t is an array of the accumulated length of the curve.

I have another question. Can If I get the coordinates (x,y,z) of the segment points. Can the ON\_SimpleArray be used store the coordinates?

I just use ON\_3dPointArray to store the point array. Do you have any better suggestion.

Thanks for your help again!  
Qinxiang

---

<div class="post-metadata">

**Author:** ![Qingxiang](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/qingxiang/32/485566_2.png) [@Qingxiang](https://discourse.mcneel.com/u/Qingxiang)\
**Post date:** [January 13, 2023, 1:10pm UTC](https://discourse.mcneel.com/t/the-data-structure-of-on-simplearray/153246/4 "2023-01-13T13:10:57Z")

</div>

@dale I have tested the ON\_SimpleArray\<ON\_3dPoint\> m\_my\_array, it solve my problem perfactly.

Many thanks,  
Qingxiang

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/772741_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [January 13, 2023, 4:23pm UTC](https://discourse.mcneel.com/t/the-data-structure-of-on-simplearray/153246/5 "2023-01-13T16:23:22Z")

</div>

> [@Qingxiang](#):
>
> I find the crv\_t is an array of the accumulated length of the curve.

No, “crv\_t” is an array of curve parameters.

[Parametric equation - Wikipedia](https://en.wikipedia.org/wiki/Parametric_equation)

– Dale
