endpoint logic fixed

main
Howard DaCosta 2021-12-21 11:53:03 -05:00
rodzic 912e54327a
commit e49be2df0e
1 zmienionych plików z 31 dodań i 37 usunięć

Wyświetl plik

@ -80,6 +80,8 @@ class CombineGrids(InkstitchExtension):
else: else:
right_wire, left_wire = self.wires right_wire, left_wire = self.wires
if left_wire.get_num_endpoints(is_horizontal=True) % 2 == 1:
left_wire.set_flipped_points(is_horizontal=True)
union_wire_points = self.union_wires(left_wire, right_wire, is_horizontal=True) union_wire_points = self.union_wires(left_wire, right_wire, is_horizontal=True)
left_wire.wire.getparent().remove(left_wire.wire) left_wire.wire.getparent().remove(left_wire.wire)
right_wire.wire.getparent().remove(right_wire.wire) right_wire.wire.getparent().remove(right_wire.wire)
@ -95,7 +97,9 @@ class CombineGrids(InkstitchExtension):
top_wire, bottom_wire = self.wires top_wire, bottom_wire = self.wires
else: else:
bottom_wire, top_wire = self.wires bottom_wire, top_wire = self.wires
if top_wire.get_num_endpoints(is_horizontal=False) % 2 == 1:
top_wire.set_flipped_points(is_horizontal=False)
union_wire_points = self.union_wires(top_wire, bottom_wire, is_horizontal=False) union_wire_points = self.union_wires(top_wire, bottom_wire, is_horizontal=False)
top_wire.wire.getparent().remove(top_wire.wire) top_wire.wire.getparent().remove(top_wire.wire)
bottom_wire.wire.getparent().remove(bottom_wire.wire) bottom_wire.wire.getparent().remove(bottom_wire.wire)
@ -211,7 +215,7 @@ class CombineGrids(InkstitchExtension):
inkex.errormsg([type(i) for i in wires]) inkex.errormsg([type(i) for i in wires])
union_wire_points, union_wire_sections = self.combine_wires(wires, is_horizontal) # map sections of unionized wire to each component wire multiplier union_wire_points, union_wire_sections = self.combine_wires(wires, is_horizontal) # map sections of unionized wire to each component wire multiplier
inkex.errormsg("NUM WIRES HERE:{}".format(wires[0].get_num_endpoints(is_horizontal)))
# now we splice in connector to union wire # now we splice in connector to union wire
connection_points = [] connection_points = []
wire_point_idx = 0 wire_point_idx = 0
@ -258,28 +262,17 @@ class CombineGrids(InkstitchExtension):
connection_points.extend(max_points) connection_points.extend(max_points)
else: else:
endpoints = wires[-1].get_num_endpoints(is_horizontal) endpoints = wires[-1].get_num_endpoints(is_horizontal)
connect_last_wire = False if endpoints % 2 == 1:
# TODO: this logic needs work if has_connector:
# if endpoints % 2 == 1: connector_pins = self.connector.connect_pins()
# if is_horizontal and reversed_connection: connector_points = ['{},{}'.format(p.x,p.y) for p in connector_pins]
# connect_last_wire = True connection_points.extend(connector_points)
# else: else:
# if reversed_connection: max_multiplier = max_wire.get_num_wire_joins(is_horizontal)
# connect_last_wire = True max_wire_splice_length = min(4 * max_multiplier, len(max_wire_points) - max_wire_idx)
# elif endpoints % 2 == 0: max_points = ['{},{}'.format(p.x,p.y) for p in max_wire_points[max_wire_idx: max_wire_idx + max_wire_splice_length]]
# if reversed_connection: max_wire_idx += max_wire_splice_length
# connect_last_wire = True connection_points.extend(max_points)
# if connect_last_wire:
# if has_connector:
# connector_pins = self.connector.connect_pins()
# connector_points = ['{},{}'.format(p.x,p.y) for p in connector_pins]
# connection_points.extend(connector_points)
# else:
# max_multiplier = max_wire.get_num_wire_joins(is_horizontal)
# max_wire_splice_length = min(4 * max_multiplier, len(max_wire_points) - max_wire_idx)
# max_points = ['{},{}'.format(p.x,p.y) for p in max_wire_points[max_wire_idx: max_wire_idx + max_wire_splice_length]]
# max_wire_idx += max_wire_splice_length
# connection_points.extend(max_points)
# return union_wire_points # to debug wire unions # return union_wire_points # to debug wire unions
if not has_connector: if not has_connector:
@ -321,7 +314,6 @@ class CombineGrids(InkstitchExtension):
if len(self.wires) == 2 and self.connector is None: if len(self.wires) == 2 and self.connector is None:
self.pair_wires_horizontally() if self.is_horizontal_connection else self.pair_wires_vertically() self.pair_wires_horizontally() if self.is_horizontal_connection else self.pair_wires_vertically()
else: else:
inkex.errormsg("COMING")
self.horizontal_grid_union() if self.is_horizontal_connection else self.vertical_grid_union() self.horizontal_grid_union() if self.is_horizontal_connection else self.vertical_grid_union()
@ -352,18 +344,20 @@ class Wire():
return self.points return self.points
def get_num_endpoints(self, is_horizontal): def get_num_endpoints(self, is_horizontal):
def count_bdry_points(bdry): num_wires = 0
wire_sum = 0 for p1 in self.points:
for p in self.points: counter = 1
if is_horizontal and p.x == bdry: for p2 in self.points:
wire_sum += 1 if p1 != p2:
elif not is_horizontal and p.y == bdry: if is_horizontal:
wire_sum += 1 if p1.x == p2.x:
return wire_sum counter += 1
if is_horizontal: else:
return max(count_bdry_points(self.bbox.right), count_bdry_points(self.bbox.left)) if p1.y == p2.y:
else: counter += 1
return max(count_bdry_points(self.bbox.top), count_bdry_points(self.bbox.bottom)) if counter > num_wires:
num_wires = counter
return num_wires
def set_flipped_points(self, is_horizontal): def set_flipped_points(self, is_horizontal):
self.points = self.get_flipped_points(is_horizontal) self.points = self.get_flipped_points(is_horizontal)