Esempio n. 1
0
func TestMagnifyHalf(t *testing.T) {
	target := ZoomTarget{}
	target.Xmin = 10
	target.Xmax = 30
	target.Ymin = 20
	target.Ymax = 50

	req := DefaultRequest()
	req.RealMin = "0.5"
	req.RealMax = "0.6"
	req.ImagMin = "0.3"
	req.ImagMax = "0.4"
	req.ImageWidth = 100
	req.ImageHeight = 100
	req.Precision = 53

	expect := []*big.Float{
		big.NewFloat(0.505),
		big.NewFloat(0.565),
		big.NewFloat(0.325),
		big.NewFloat(0.39),
	}

	z := Zoom{ZoomTarget: target}
	prev, conferr := Configure(req)
	if conferr != nil {
		t.Fatal(conferr)
	}
	z.Prev = *prev

	mag, magerr := z.Magnify(0.5)
	if magerr != nil {
		t.Fatal(magerr)
	}
	actual := []*big.Float{
		&mag.RealMin,
		&mag.RealMax,
		&mag.ImagMin,
		&mag.ImagMax,
	}
	for i, ex := range expect {
		ac := actual[i]
		margin := big.NewFloat(0.0)
		margin.Sub(ex, ac)
		margin.Abs(margin)
		if margin.Cmp(big.NewFloat(0.001)) > 0 {
			t.Error("Fail at", i,
				"expected", bigbase.DbgF(*ex), "but received", bigbase.DbgF(*ac))
		}
	}
}
Esempio n. 2
0
func TestMovie(t *testing.T) {
	const framecnt = 2

	target := ZoomTarget{}
	target.Xmin = 10
	target.Xmax = 30
	target.Ymin = 20
	target.Ymax = 50
	target.Frames = framecnt

	req := DefaultRequest()
	req.RealMin = "0.5"
	req.RealMax = "0.6"
	req.ImagMin = "0.3"
	req.ImagMax = "0.4"
	req.ImageWidth = 100
	req.ImageHeight = 100
	req.Precision = 53

	expectations := make([][]*big.Float, framecnt)
	expectations[0] = []*big.Float{
		big.NewFloat(0.505),
		big.NewFloat(0.565),
		big.NewFloat(0.325),
		big.NewFloat(0.39),
	}
	expectations[1] = []*big.Float{
		big.NewFloat(0.51),
		big.NewFloat(0.53),
		big.NewFloat(0.35),
		big.NewFloat(0.38),
	}

	z := Zoom{ZoomTarget: target}
	prev, conferr := Configure(req)
	if conferr != nil {
		t.Fatal(conferr)
	}
	z.Prev = *prev

	frames, magerr := z.Movie()
	if magerr != nil {
		t.Fatal(magerr)
	}
	actualities := make([][]*big.Float, framecnt)
	for i, fr := range frames {
		fract := []*big.Float{
			&fr.RealMin,
			&fr.RealMax,
			&fr.ImagMin,
			&fr.ImagMax,
		}
		actualities[i] = fract
	}
	for i, expectSet := range expectations {
		actualSet := actualities[i]
		for j, ex := range expectSet {
			ac := actualSet[j]
			margin := big.NewFloat(0.0)
			margin.Sub(ex, ac)
			margin.Abs(margin)
			if margin.Cmp(big.NewFloat(0.001)) > 0 {
				t.Error("Fail at frame", i, "bound", j,
					"expected", bigbase.DbgF(*ex), "but received", bigbase.DbgF(*ac))
			}
		}
	}
}
Esempio n. 3
0
func (c *configurator) fixAspect() error {
	if __DEBUG {
		log.Println("Fixing aspect ratio")
	}

	rmin := big.NewFloat(0.0).Copy(&c.RealMin)
	rmax := big.NewFloat(0.0).Copy(&c.RealMax)
	imin := big.NewFloat(0.0).Copy(&c.ImagMin)
	imax := big.NewFloat(0.0).Copy(&c.ImagMax)

	planeWidth := bb.MakeBigFloat(0.0, c.Precision)
	planeHeight := bb.MakeBigFloat(0.0, c.Precision)
	planeAspect := bb.MakeBigFloat(0.0, c.Precision)

	planeWidth.Sub(rmax, rmin)
	planeHeight.Sub(imax, imin)
	planeAspect.Quo(&planeWidth, &planeHeight)

	nativePictureAspect := float64(c.UserRequest.ImageWidth) / float64(c.UserRequest.ImageHeight)
	pictureAspect := bb.MakeBigFloat(nativePictureAspect, c.Precision)
	thindicator := planeAspect.Cmp(&pictureAspect)

	adjustWidth := func() {
		trans := bb.MakeBigFloat(0.0, c.Precision)
		trans.Mul(&planeHeight, &pictureAspect)
		rmax.Add(rmin, &trans)
		c.RealMax = *rmax
	}

	adjustHeight := func() {
		trans := bb.MakeBigFloat(0.0, c.Precision)
		trans.Quo(&planeWidth, &pictureAspect)
		imax.Add(imin, &trans)
		c.ImagMax = *imax
	}

	if __TRACE {
		log.Printf("Old Plane Width: %v", bb.DbgF(planeWidth))
		log.Printf("Old Plane Height: %v", bb.DbgF(planeHeight))
		log.Printf("Old Plane Aspect: %v", bb.DbgF(planeAspect))
		log.Printf("Image Width: %v", c.UserRequest.ImageWidth)
		log.Printf("Image Height: %v", c.UserRequest.ImageHeight)
		log.Printf("Image Aspect: %v", bb.DbgF(pictureAspect))
	}

	var strategy = c.UserRequest.FixAspect

	if strategy == config.Grow {
		// Then the plane is too short, so must be made taller
		if thindicator == 1 {
			if __DEBUG {
				log.Println("Plane becomes taller")
			}
			adjustHeight()
		} else if thindicator == -1 {
			if __DEBUG {
				log.Println("Plane becomes fatter")
			}
			// Then the plane is too thin, and must be made fatter
			adjustWidth()
		}
	} else if strategy == config.Shrink {
		if thindicator == 1 {
			// The plane is too fat, so must be made thinner
			if __DEBUG {
				log.Println("Plane becomes thinner")
			}
			adjustWidth()
		} else if thindicator == -1 {
			if __DEBUG {
				log.Println("Plane becomes shorter")
			}
			// The plane is too tall, so must be made shorter
			adjustHeight()
		}
	}

	if __TRACE && (strategy == config.Shrink || strategy == config.Grow) {
		fixWidth := bb.MakeBigFloat(0.0, c.Precision)
		fixHeight := bb.MakeBigFloat(0.0, c.Precision)
		fixAspect := bb.MakeBigFloat(0.0, c.Precision)

		fixWidth.Sub(rmax, rmin)
		fixHeight.Sub(imax, imin)
		fixAspect.Quo(&fixWidth, &fixHeight)

		log.Printf("New Plane Width: %v", bb.DbgF(fixWidth))
		log.Printf("New Plane Height: %v", bb.DbgF(fixHeight))
		log.Printf("Fixed Aspect: %v", bb.DbgF(fixAspect))
	}

	return nil
}