Skip to content

C arrays for HGEdge::intermediate_points #264

Open

Description

@yakra
  • Use a C array for HGEdge::intermediate_points instead of a list or vector.
  • Include a separate intermediate_count in unused space before format. I'm thinking uint16_t, though could use uint32_t if necessary.
    • What's the largest intermediate_points.size() of any existing edge?
  • Any significant speedup from using raw coords (2 doubles) instead of HGVertex*?
  • Proposed here; referenced here. Carving out a new issue mostly for a good place to leave this code:

    HGEdge collapse ctor

    	// find which endpoints aren't the vertex we're collapsing and set them as our new
    	// endpoints, and at the same time, build up our list of intermediate vertices
    	auto	e1_count = edge1->intermediate_count,
    		e2_count = edge2->intermediate_count;
    	auto	new_p = intermediate_points = new HGVertex*[intermediate_count = e1_count+1+e2_count];
    
    	if (edge1->vertex1 == vertex)
    	     {	vertex1 = edge1->vertex2;
    		auto   old_p = edge1->intermediate_points + e1_count;
    		while (old_p > edge1->intermediate_points) *new_p++ = *--old_p;
    	     }
    	else {	vertex1 = edge1->vertex1;
    		memcpy(new_p , edge1->intermediate_points , e1_count*sizeof(HGVertex*));
    		new_p += e1_count;
    	     }
    
    	*new_p++ = vertex;
    
    	if (edge2->vertex1 == vertex)
    	     {	vertex2 = edge2->vertex2;
    		memcpy(new_p , edge2->intermediate_points , e2_count*sizeof(HGVertex*));
    	     }
    	else {	vertex2 = edge2->vertex1;
    		auto   old_p = edge2->intermediate_points + e2_count;
    		while (old_p > edge2->intermediate_points) *new_p++ = *--old_p;
    	     }
  • We're down 1 line due to deleting 5 lines of debug text.
    Restoring them would make a cleaner commit diff. Do I prefer a clean diff or clean code?
    FWIW, I just now uncommented 4 of them to grep -c them.
  • Consider swapping the 1st if & else for a sense of visual continuity, pattern-spotting, yadda yadda.
  • std::string HGEdge::intermediate_point_string()
    {	if (!intermediate_count) return " None";
    	std::string line;
    	char fstr[56];
    	for (auto p = intermediate_points, end = p+intermediate_count; p < end; p++)
    	{	auto i = *p;
    		sprintf(fstr, "%.15g %.15g", i->lat, i->lng);
    		line += " [" + *i->unique_name + "] " + fstr;
    	}
    	return line;
    }
  • Other functions affected by the change, even if calls are commented out
    • HGEdge::str()
    • Anything else?
  • While I'm in there, readabilty... wall of text -> whitespace, indentation, 1 big cout with a couple ternaries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions