A method of building CAD models based on algebraic optimisation of geometric constraints