Stack Overflow на русском Asked on August 29, 2021
Есть код на C++:
std::list<PolyEdge> SplitPoly;
struct PolyEdge
{
PolyEdge(const QPointF &startPos, LineSide side) :
StartPos(startPos),
StartSide(side),
Next(nullptr),
Prev(nullptr),
DistOnLine(0.0f),
IsSrcEdge(false),
IsDstEdge(false),
Visited(false)
{
}
QPointF StartPos; // start position on edge
LineSide StartSide; // start position's side of split line
PolyEdge * Next; // next polygon in linked list
PolyEdge * Prev; // previous polygon in linked list
float DistOnLine; // distance relative to first point on split line
bool IsSrcEdge; // for visualization
bool IsDstEdge; // for visualization
bool Visited; // for collecting split polygons
};
...
// connect doubly linked list, except
// first->prev and last->next
// как этот код будет выглядеть на C#
for (auto iter=SplitPoly.begin(); iter!=std::prev(SplitPoly.end()); iter++)
{
auto nextIter = std::next(iter);
iter->Next = &(*nextIter);
nextIter->Prev = &(*iter);
}
// как этот код будет выглядеть на C#
...
У меня код на C#:
public class PolyEdge
{
public Vector2 StartPos; // start position on edge
public LineSide StartSide; // start position's side of split line
public PolyEdge Next; // next polygon in linked list
public PolyEdge Prev; // previous polygon in linked list
public float DistOnLine; // distance relative to first point on split line
public bool IsSrcEdge; // for visualization
public bool IsDstEdge; // for visualization
public bool Visited; // for collecting split polygons
public PolyEdge(Vector2 _startPos, LineSide _side)
{
StartPos = _startPos;
StartSide = _side;
Next = Prev = null;
DistOnLine = 0.0f;
IsSrcEdge = IsDstEdge = Visited = false;
}
};
static public List<ClippingOFArbitraryPolygons.PolyEdge> SplitPoly;
…
Как переписать этот участок на C++:
for (auto iter=SplitPoly.begin(); iter!=std::prev(SplitPoly.end()); iter++)
{
auto nextIter = std::next(iter);
iter->Next = &(*nextIter);
nextIter->Prev = &(*iter);
}
for (int i = 0; i < SplitPoly.Count - 1; i++) {
SplitPoly[i].Next = SplitPoly[i + 1];
SplitPoly[i + 1].Prev = SplitPoly[i];
}
Correct answer by timur on August 29, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP