Better options checking for TrustRegionMinimizer.

Since the trust region minimizer can use the line search
minimizer when it is solving a box constrained problem,
ensure that the line search options are valid.

Also some minor spacing fixes in the line search code.

Change-Id: Ife04204855cfac389cf980f0a79155d4accc8662
diff --git a/internal/ceres/line_search.cc b/internal/ceres/line_search.cc
index 7ff1164..0d645ac 100644
--- a/internal/ceres/line_search.cc
+++ b/internal/ceres/line_search.cc
@@ -125,14 +125,12 @@
 
   if (g == NULL) {
     return (evaluator_->Evaluate(evaluation_point_.data(),
-                                  f, NULL, NULL, NULL) &&
+                                 f, NULL, NULL, NULL) &&
             IsFinite(*f));
   }
 
   if (!evaluator_->Evaluate(evaluation_point_.data(),
-                            f,
-                            NULL,
-                            gradient_.data(), NULL)) {
+                            f, NULL, gradient_.data(), NULL)) {
     return false;
   }
 
diff --git a/internal/ceres/solver.cc b/internal/ceres/solver.cc
index 3512e15..a1f347f 100644
--- a/internal/ceres/solver.cc
+++ b/internal/ceres/solver.cc
@@ -446,11 +446,16 @@
     return false;
   }
 
-  if (minimizer_type == TRUST_REGION) {
-    return TrustRegionOptionsAreValid(*this, error);
+  if (minimizer_type == TRUST_REGION &&
+      !TrustRegionOptionsAreValid(*this, error)) {
+    return false;
   }
 
-  CHECK_EQ(minimizer_type, LINE_SEARCH);
+  // We do not know if the problem is bounds constrained or not, if it
+  // is then the trust region solver will also use the line search
+  // solver to do a projection onto the box constraints, so make sure
+  // that the line search options are checked independent of what
+  // minimizer algorithm is being used.
   return LineSearchOptionsAreValid(*this, error);
 }
 
diff --git a/internal/ceres/trust_region_minimizer.cc b/internal/ceres/trust_region_minimizer.cc
index c871ae2..7352ac2 100644
--- a/internal/ceres/trust_region_minimizer.cc
+++ b/internal/ceres/trust_region_minimizer.cc
@@ -86,11 +86,10 @@
   line_search_options.function = &line_search_function;
 
   string message;
-  scoped_ptr<LineSearch>
-      line_search(CHECK_NOTNULL(
-                      LineSearch::Create(ceres::ARMIJO,
-                                         line_search_options,
-                                         &message)));
+  scoped_ptr<LineSearch> line_search(
+      CHECK_NOTNULL(LineSearch::Create(ceres::ARMIJO,
+                                       line_search_options,
+                                       &message)));
   LineSearch::Summary summary;
   line_search_function.Init(x, delta);
   // Try the trust region step.
@@ -407,10 +406,10 @@
       double new_cost = std::numeric_limits<double>::max();
       if (evaluator->Plus(x.data(), delta.data(), x_plus_delta.data())) {
         if (!evaluator->Evaluate(x_plus_delta.data(),
-                                &new_cost,
-                                NULL,
-                                NULL,
-                                NULL)) {
+                                 &new_cost,
+                                 NULL,
+                                 NULL,
+                                 NULL)) {
           LOG(WARNING) << "Step failed to evaluate. "
                        << "Treating it as a step with infinite cost";
           new_cost = numeric_limits<double>::max();