View previous topic :: View next topic |
Author |
Message |
chronozphere DeleD PRO user
Joined: 20 Jun 2006 Posts: 1010 Location: Netherlands
|
Posted: Thu Jan 28, 2010 5:21 pm Post subject: Edge_IsVertexUsedByEdges? |
|
|
Hey,
I was browsing through the source and I encountered this
Code: |
// determines if a vertex is used by any of the provided edges
function TBasePrimitive.Edge_IsVertexUsedByEdges(edgeList: TEdgeList; vertex: TVertice): boolean;
var i,edgeCounter: integer;
vertexUsedByEdges: boolean;
begin
vertexUsedByEdges := false;
for i := 0 to edgeList.Count-1 do begin
edgeCounter := 0;
repeat
vertexUsedByEdges := Edge_IsVertexUsedByEdge(edgeList[edgeCounter],vertex);
inc(edgeCounter);
until (edgeCounter>=edgeList.Count) or (vertexUsedByEdges);
if not vertexUsedByEdges then
break;
end;
Result := vertexUsedByEdges;
end;
|
I don't understand it. Why 2 nested loops??
Shouldn't this be:
Code: |
// determines if a vertex is used by any of the provided edges
function TBasePrimitive.Edge_IsVertexUsedByEdges(edgeList: TEdgeList; vertex: TVertice): boolean;
var
i: integer;
begin
Result := false;
for i:=0 to edgeList.count-1 do
if Edge_IsVertexUsedByEdge(edgeList[i],vertex) then
begin
Result := true;
Exit;
end;
end;
|
Way easier to understand, and faster too.
I could make a patch with a few improvements, if I encounter more of these. |
|
Back to top |
|
|
Paul-Jan Site Admin
Joined: 08 Aug 2004 Posts: 3066 Location: Lage Zwaluwe
|
Posted: Thu Jan 28, 2010 7:34 pm Post subject: |
|
|
Looks like a bug. Please verify if your new version works as expected and patch it up! |
|
Back to top |
|
|
Jeroen Site Admin
Joined: 07 Aug 2004 Posts: 5332 Location: The Netherlands
|
Posted: Fri Jan 29, 2010 8:23 am Post subject: |
|
|
Yep, code like that should be improved. Go ahead and do so immediately if you encounter any more of these. _________________ Check out Figuro, our online 3D app! More powerful 3D tools for free. |
|
Back to top |
|
|
|