reduce Project calls in Front,Back,BoundingRect

This commit is contained in:
Josh Deprez 2021-09-19 15:39:10 +10:00
parent 855f39d9d2
commit c533ee63f7

View file

@ -80,20 +80,20 @@ func (b Box) BoundingRect(π Projector) image.Rectangle {
// Back returns an image.Rectangle representing the back of the box, using // Back returns an image.Rectangle representing the back of the box, using
// the given projection π. // the given projection π.
func (b Box) Back(π Projector) image.Rectangle { func (b Box) Back(π Projector) image.Rectangle {
b.Max.Z = b.Min.Z p := π.Project(Int3{0, 0, b.Min.Z})
return image.Rectangle{ return image.Rectangle{
Min: π.Project(b.Min), Min: b.Min.XY().Add(p),
Max: π.Project(b.Max), Max: b.Max.XY().Add(p),
} }
} }
// Front returns an image.Rectangle representing the front of the box, using // Front returns an image.Rectangle representing the front of the box, using
// the given projection π. // the given projection π.
func (b Box) Front(π Projector) image.Rectangle { func (b Box) Front(π Projector) image.Rectangle {
b.Min.Z = b.Max.Z p := π.Project(Int3{0, 0, b.Max.Z})
return image.Rectangle{ return image.Rectangle{
Min: π.Project(b.Min), Min: b.Min.XY().Add(p),
Max: π.Project(b.Max), Max: b.Max.XY().Add(p),
} }
} }