initial import
[iDMC.git] / src / java / org / tsho / dmc2 / core / StepperUtil.java
blobd64d7bd3aa17d40f89f24a5b2faba9b334a23336
1 /*
2 * iDMC the interactive Dynamical Model Calculator simulates and performs
3 * graphical and numerical analysis of systems of differential and
4 * difference equations.
6 * Copyright (C) 2004 Marji Lines and Alfredo Medio.
8 * Written by Daniele Pizzoni <auouo@tin.it>.
9 * Extended by Alexei Grigoriev <alexei_grigoriev@libero.it>.
13 * The software program was developed within a research project financed
14 * by the Italian Ministry of Universities, the Universities of Udine and
15 * Ca'Foscari of Venice, the Friuli-Venezia Giulia Region.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or any
20 * later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
27 package org.tsho.dmc2.core;
29 import org.jfree.data.Range;
32 public class StepperUtil {
33 boolean stopped;
35 public interface Range2D {
36 Range getHRange();
37 Range getVRange();
40 Range2D calculateBounds(Stepper stepper, int iterations) {
42 Stepper.Point2D point;
43 double xLower, xUpper;
44 double yLower, yUpper;
46 stopped = false;
47 stepper.initialize();
49 point = stepper.getCurrentPoint2D();
50 xLower = point.getX();
51 xUpper = point.getX();
52 yLower = point.getY();
53 yUpper = point.getY();
55 for (int i = 0; i < iterations; i++) {
56 if (stopped) {
57 break;
60 stepper.step();
61 point = stepper.getCurrentPoint2D();
63 if (xLower > point.getX()) {
64 xLower = point.getX();
66 else if (xUpper < point.getX()) {
67 xUpper = point.getX();
70 if (yLower > point.getY()) {
71 yLower = point.getY();
73 else if (yUpper < point.getY()) {
74 yUpper = point.getY();
78 return new MyRange2D(new Range(xLower, xUpper), new Range(yLower, yUpper));
81 void stop() {
82 stopped = true;
85 private class MyRange2D implements Range2D {
86 private Range horRange, verRange;
88 MyRange2D(Range hRange, Range vRange) {
89 horRange = hRange;
90 verRange = vRange;
93 public Range getHRange() {
94 return horRange;
97 public Range getVRange() {
98 return verRange;