Polygon

class jwst.skymatch.region.Polygon(rid, vertices, coord_system='Cartesian')[source]

Bases: Region

Represents a 2D polygon region with multiple vertices

Parameters:
  • rid (string) – polygon id

  • vertices (list of (x,y) tuples or lists) – The list is ordered in such a way that when traversed in a counterclockwise direction, the enclosed area is the polygon. The last vertex must coincide with the first vertex, minimum 4 vertices are needed to define a triangle

  • coord_system (string) – coordinate system

Methods Summary

get_edges()

Create a list of Edge objects from vertices

scan(data)

This is the main function which scans the polygon and creates the mask

update_AET(y, AET)

Update the Active Edge Table (AET)

Methods Documentation

get_edges()[source]

Create a list of Edge objects from vertices

scan(data)[source]

This is the main function which scans the polygon and creates the mask

Parameters:
  • data (array) – the mask array it has all zeros initially, elements within a region are set to the region’s ID

  • Algorithm

  • (GET) (- Set the Global Edge Table) –

  • GET (- Set y to be the smallest y coordinate that has an entry in) –

  • empty (- Initialize the Active Edge Table (AET) to be) –

  • line (- For each scan) –

    1. Add edges from GET to AET for which ymin==y

    2. Remove edges from AET fro which ymax==y

    3. Compute the intersection of the current scan line with all edges in the AET

    4. Sort on X of intersection point

    5. Set elements between pairs of X in the AET to the Edge’s ID

update_AET(y, AET)[source]

Update the Active Edge Table (AET)

Add edges from GET to AET for which ymin of the edge is equal to the y of the scan line. Remove edges from AET for which ymax of the edge is equal to y of the scan line.