Cull Points List

Hi, I’m hoping someone can help me.

I’ve got a skirting board profile that I’ve referenced in grasshopper and I’ve exploded to curve to get the list of points.

{623.273156, 1885.035812, 0}
{640.746122, 1856.412398, 0}
{645.746122, 1856.412398, 0}
{645.746122, 1685.035812, 0}
{613.273156, 1685.035812, 0}
{613.273156, 1885.035812, 0}
{623.273156, 1885.035812, 0}

I’d like to keep only the points with the highest X-value for each unique Y-value and cull the rest.

So my new list would be:
{645.746122, 1856.412398, 0}
{645.746122, 1685.035812, 0}
{623.273156, 1885.035812, 0}

Could anyone suggest a good approach to achieve this


Your goal is to obtain all the unique Y-value indexes and then select their respective X-value and sort the Y-value indexes using the highest X-value.

  1. uses Sasquatch/Pancake, perhaps not ideal if you want to keep plug-ins to a minimal.
  2. uses native Grasshopper components.
  3. uses a single GhPython block.

There’s more solutions to your question that aren’t in here. I personally would opt for option 3, but it all comes down to whatever you prefer.

unique_y = set(pt[1] for pt in input)

indices = []
for y in unique_y:
    filtered_points = [i for i, pt in enumerate(input) if pt[1] == y]
    best_index = max(filtered_points, key=lambda i: input[i][0])
    indices.append(best_index)

index = indices
selected_pt = [input[i] for i in indices]

highest_x_val_for_unique_y.gh (17.8 KB)

Amazing, thank you!