Skip to content

Commit

Permalink
ratio ignored fix, detailed incomplete error
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Gilat committed Sep 28, 2017
1 parent 4aede84 commit 7442f48
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type UnrectableError struct {
Errors []error
}

func newIncompleteError(missing []string) *UnrectableError {
return &UnrectableError{Missing: missing}
func newIncompleteError(missing []string, errors []error) *UnrectableError {
return &UnrectableError{Missing: missing, Errors: errors}
}

func (e *UnrectableError) Error() string {
Expand Down
11 changes: 3 additions & 8 deletions pkg/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ func Find(rule *css.Rule) (*Part, error) {
return nil, ErrNonQualified
}

// empty rules are given a shortcut
if len(rule.Declarations) == 0 {
return nil, newIncompleteError(required)
}

// collect properties-of-interest, or any errors extracting them
m := make(map[string]int)
errs := []error{}
Expand Down Expand Up @@ -73,7 +68,7 @@ func Find(rule *css.Rule) (*Part, error) {
}

// check that the map contains a full rectangle representation
err := checkRequired(m)
err := checkRequired(m, errs)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -140,7 +135,7 @@ func bgpos(str string) (int, int, error) {

var required = []string{"x", "y", "w", "h"}

func checkRequired(m map[string]int) error {
func checkRequired(m map[string]int, errs []error) error {
missing := []string{}
for _, prop := range required {
if _, ok := m[prop]; !ok {
Expand All @@ -150,7 +145,7 @@ func checkRequired(m map[string]int) error {

if len(missing) > 0 {
// could not determine one or more of the required rectangle properties
return newIncompleteError(missing)
return newIncompleteError(missing, errs)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Scale(parts []*Part, ratio int) ([]*Part, error) {
x, y := p.Rect.Min.X, p.Rect.Min.Y
diff := p.Rect.Max.Sub(p.Rect.Min)
w, h := diff.X, diff.Y
sr := image.Rect(x, y, x+w, y+h)
sr := image.Rect(x, y, x+(ratio*w), y+(ratio*h))
sp := &Part{Name: p.Name, Rect: &sr}
scaled = append(scaled, sp)
}
Expand Down

0 comments on commit 7442f48

Please sign in to comment.