li:pcb-rnd-conf-v1 {
	ha:overwrite {
		ha:plugins {
			ha:drc_query {
				disable=0

				li:definitions {
					ha:min_copper_clearance {
						type = coord
						legacy = design/bloat
						desc = {minimum gap between copper features of different networks}
					}
					ha:min_copper_overlap {
						type = coord
						legacy = design/shrink
						desc = {minimum overlap between copper features on the same network for reliable connection}
					}
					ha:min_drill {
						type = coord
						legacy = design/min_drill
						desc = {minimum drill diameter}
					}
					ha:hole_overlap_factor {
						type = real
						default = 0.0
						desc = {How much drilled holes may overlap [-1..+1]; 0 means touching holes are reported; positive numbers allow more overlap, negative numbers report non-overlapping but close holes}
					}

					ha:min_copper_thickness {
						type = coord
						default = 0mm
						legacy = design/min_wid
						desc = {Minimum copper object width; anything thinner than this value is a violation}
					}

					ha:min_silk_thickness {
						type = coord
						default = 0mm
						legacy = design/min_slk
						desc = {Minimum silk object width; anything thinner than this value is a violation}
					}


					ha:min_ring {
						type = coord
						default = 0mm
						legacy = design/min_ring
						desc = {Minimum ring thickness of padstacks }
					}
				}

				li:rules {

					ha:hole_dia {
						type = single hole
						title = hole too small
						desc = padstack hole diameter is too small
						query = {(@.hole > 0) && (@.hole < $min_drill)  thus violation(DRCGRP1, @, DRCMEASURE, @.hole, DRCEXPECT, $min_drill)}
					}

					ha:hole_overlap {
						type = pair hole
						title = overlapping holes
						desc = padstack holes overlap
						query = {
rule overlap
let A (@.type==PSTK) && (@.hole > 0)
let B A
assert (A.IID > B.IID) && (distance(A.x, A.y, B.x, B.y) < (A.hole + B.hole)/(2*(1+$hole_overlap_factor))) thus violation(DRCGRP1, A, DRCGRP2, B, DRCMEASURE, coord(distance(A.x, A.y, B.x, B.y)), DRCEXPECT, coord((A.hole + B.hole)/(2*(1+$hole_overlap_factor))))
						}
					}

					ha:net_break {
						type = broken net
						title = insufficient overlap
						desc = the overlap between two objects in the net is insufficient and can lead to broken network during board fabrication
						query = {
rule net brk
let N netlist()
let O netsegs(N)
assert netbreak(O, $min_copper_overlap)
						}
					}

					ha:net_short {
						type = shorted nets
						title = net too close to other net
						desc = insufficient clearance between an object of the network and objects of other networks
						query = {
rule net short
let N netlist()
let O netsegs(N)
assert netshort(O, $min_copper_clearance)
						}
					}

					ha:min_copper_thickness {
						type = thin copper
						title = copper object too thin
						desc = Copper object thickness is below the required value. Copper objects too thin may break or peel off during board fabriaction.
						query = {(@.layer.type == COPPER) && (@.thickness != 0) && (@.thickness < $min_copper_thickness) thus violation(DRCGRP1, @, DRCMEASURE, @.thickness, DRCEXPECT, $min_copper_thickness)}
					}

					ha:min_silk_thickness {
						type = thin silk
						title = silk object too thin
						desc = Silk object thickness is below the required value. Silk objects too thin may disappear during board fabrication.
						query = {(@.layer.type == SILK) && (@.thickness != 0) && (@.thickness < $min_silk_thickness) thus violation(DRCGRP1, @, DRCMEASURE, @.thickness, DRCEXPECT, $min_silk_thickness) }
					}

					ha:beyond_drawing_area {
						type = object beyond drawing area
						title = Objects located outside of the drawing area
						desc = Objects may be omitted from exports or may be outside of the board contour.
						query = { (@.bbox.x2 < 0) || (@.bbox.y2 < 0) || (@.bbox.x1 > $dwg_area_x) || (@.bbox.y1 > $dwg_area_y) }
					}

					ha:min_ring {
						type = padstack ring too thin
						title = Ring of a padstack object is too thin
						desc = The smallest neck of the ring is thinner than the required value - the ring may break during drilling or erode away during etching.
						query = { pstkring(@, $min_ring) > 0 }
					}

					ha:fullpoly {
						type = fullpoly
						title = Multi-island polygon with the fullpoly flag
						desc = Polygon with the fullpoly flag set is cut into multiple islands; there is no guarantee that the islands are connected while pcb-rnd will always think they are, fooling the drc and rats optimizer.
						query = { poly_num_islands(@) > 1 }
					}

					ha:ko_named {
						type = courtyard
						title = Courtyard conflict
						desc = Courtyard objects overlap
						query = {
rule courtyard
let A (@.layer.purpose ~ "^ko.") thus @
let B A
assert (A != B) && (A.IID <= B.IID) && (A.layer.position == B.layer.position) && (A.layer.purpose == B.layer.purpose) && (overlap(A, B)) \\
	thus violation(DRCGRP1, A, DRCGRP2, B, DRCTEXT, "On keepout type ", DRCTEXT, A.layer.purpose, DRCTEXT, " ", DRCTEXT, A.layer.a.drc_desc)
}
					}

					ha:ko_layer {
						type = keepout
						title = Keepout conflict
						desc = Layer object overlap with keepout area
						query = {
rule layer type based keepout
let KOO ((@.layer.purpose ~ "^ko@") && (@.type != SUBC)) thus @
let ALL ((!(@.layer.purpose ~ "^ko@")) && (@.type != SUBC)) thus @
assert layer_ko_match(ALL, KOO) && overlap(KOO, ALL) \\
	thus violation(DRCGRP1, ALL, DRCGRP2, KOO, DRCTEXT, "Red object overlaps with blue keepout object")
}
					}

					ha:invalid_polygons {
						type = polygon
						title = Invalid polygon
						desc = Polygon contour is invalid, most probably self intersecting
						query = {
rule invalidpoly
assert @.type == POLYGON && !poly_is_valid(@)
						}
					}

					ha:invalid_text_chars {
						type = text_char
						title = Invalid character in text
						desc = Text object contains character(s) that will not render with the given font
						query = {
rule invalid_text_chars
assert @.type == TEXT && (text_invalid_chars(@) > 0) \\
	thus violation(DRCGRP1, @, DRCTEXT, "Number of invalid characters:", DRCTEXT, text_invalid_chars(@))
						}
					}

				}
			}
		}
	}
}
