def xor_diff(A, B, precision: float = 1e-4) -> Component: """Given two Devices A and B, performs the layer-by-layer XOR difference between A and B and returns polygons representing the differences between A and B. gdsfactory wrapper for phidl.geometry.xor_diff Args: A: Component(/Reference) or list of Component(/References) B: Component(/Reference) or list of Component(/References) precision: Desired precision for rounding vertex coordinates. Returns Component: containing a polygon(s) defined by the XOR difference result between A and B. """ return gf.read.from_phidl(component=pg.xor_diff(A, B, precision=precision))
#============================================================================== # Comparing two Devices #============================================================================== # Sometimes you want to be able to test whether two Devices are identical or # not (similar to the "diff" of a text file). You can perform this comparison # by using the pg.xor_diff(A, B) function. It will perform a layer-by-layer # XOR difference between the Devices A and B, and returns polygons representing # the differences between A and B. D = Device() E1 = pg.ellipse() E2 = pg.ellipse().rotate(15) E3 = pg.ellipse() # Let's compare two slightly different Devices X1 = pg.xor_diff(A=E1, B=E2) # When we plot the result, we see only the differences between E1 and E2 qp(X1) # Now let's compare two identical Devices X2 = pg.xor_diff(A=E1, B=E3) qp(X2) # In this case X2 is empty -- therefore E1 and E3 are identical! # We can double-check this by computing the area of each device print('E1 != E2 because X1 is not blank: it has total polygon area %s' % X1.area()) print('E1 == E3 because X2 is blank: it has total polygon area %s' % X2.area()) #============================================================================== # Removing geometry #==============================================================================
D.add_ref(O).movex(30) qp(D) # quickplot the geometry create_image(D, 'outline') # example-xor_diff import phidl.geometry as pg from phidl import quickplot as qp from phidl import Device A = Device() A.add_ref(pg.ellipse(radii = [10,5], layer = 1)) A.add_ref(pg.text('A')).move([3,0]) B = Device() B.add_ref(pg.ellipse(radii = [11,4], layer = 1).movex(4)) B.add_ref(pg.text('B')).move([3.2,0]) X = pg.xor_diff(A = A, B = B, precision = 1e-6) # Plot the original geometry and the result # Upper left: A / Upper right: B # Lower left: A and B / Lower right: A xor B "diff" comparison D = Device() D.add_ref(A).move([-15,25]) D.add_ref(B).move([15,25]) D.add_ref(A).movex(-15) D.add_ref(B).movex(-15) D.add_ref(X).movex(15) qp(D) # quickplot the geometry create_image(D, 'xor_diff') # example-union import phidl.geometry as pg