def AreaOf(twod): name = twod.__class__.__name__ assert issubtype(name, 'twod') if name == "circle": center, radius = twod area = np.pi * radius ** 2 elif issubtype(name, 'polygon'): # http://mathworld.wolfram.com/PolygonArea.html area = area_of_polygon(twod) elif name == 'arc': circle, a, b = twod else: raise Exception() return area
def Is(a, b): if is_number(a) or is_number(b): return Equals(a, b) a_name = a.__class__.__name__ b_name = b.__class__.__name__ if issubtype(a_name , 'polygon') or issubtype(a_name, 'line'): truth = set(a) == set(b) else: truth = a == b if truth: return TruthValue(0) else: return TruthValue(np.inf)
def evaluate(formula, assignment): if not isinstance(formula, Node): return formula if not formula.is_grounded(assignment.keys()): return None if isinstance(formula, SetNode): if issubtype(formula.head.return_type, 'boolean'): out = reduce(operator.__and__, (evaluate(child, assignment) for child in formula.children), True) return out return formula if isinstance(formula.signature, VariableSignature): return assignment[formula.signature.id] elif is_number(formula.signature.id): return float(formula.signature.id) else: evaluated_args = [] for arg in formula.children: if isinstance(arg, FormulaNode): evaluated_args.append(evaluate(arg, assignment)) elif isinstance(arg, SetNode): evaluated_args.append(SetNode([evaluate(arg_arg, assignment) for arg_arg in arg.children])) else: evaluated_args.append(arg) # FIXME : rather than try/catch, check type matching try: out = getattr(this, formula.signature.id)(*evaluated_args) return out except: return TruthValue(np.inf)
def Tangent(line, twod): name = twod.__class__.__name__ if name == "circle": d = perpendicular_distance_between_line_and_point(line, twod.center) return Equals(d, twod.radius) elif issubtype(name, 'polygon'): out = reduce(operator.__or__, (PointLiesOnLine(point, line) for point in twod), False) return out raise Exception()
def IsCenterOf(point, twod): name = twod.__class__.__name__ if name == 'circle': return Equals(point[0], twod.center[0]) & Equals(point[1], twod.center[1]) elif issubtype(name, 'polygon'): distances = [distance_between_points(point, each) for each in twod] reg = IsRegular(twod) out = reduce(operator.__and__, (Equals(distances[index-1], distance) for index, distance in enumerate(distances)), True) return reg & out else: raise Exception()