diff --git a/core/src/net/sf/openrocket/rocketcomponent/EllipticalFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/EllipticalFinSet.java index 59f8ca330..7d6ed096f 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/EllipticalFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/EllipticalFinSet.java @@ -71,7 +71,7 @@ public class EllipticalFinSet extends FinSet { if (MathUtil.equals(this.length, length)) return; this.length = length; - validateFinTab(); + validateFinTabLength(); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index 931bf7760..13314e81c 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -274,7 +274,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona } tabHeight = newTabHeight; - + validateFinTabHeight(); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } @@ -293,9 +293,15 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona tabLength = lengthRequest; + setTabPosition(); + fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } + protected void setTabPosition(){ + this.tabPosition = this.tabOffsetMethod.getAsPosition(tabOffset, tabLength, length); + } + /** * internally, set the internal offset and optionally validate tab * @@ -303,7 +309,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona */ public void setTabOffset( final double offsetRequest) { tabOffset = offsetRequest; - tabPosition = tabOffsetMethod.getAsPosition( tabOffset, tabLength, length); + setTabPosition(); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } @@ -318,7 +324,8 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona */ public void setTabOffsetMethod(final AxialMethod newPositionMethod) { this.tabOffsetMethod = newPositionMethod; - this.tabOffset = tabOffsetMethod.getAsOffset( tabPosition, tabLength, length); + this.tabOffset = this.tabOffsetMethod.getAsOffset(tabPosition, tabLength, length); + fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } @@ -340,25 +347,32 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona return tabPosition + tabLength; } - public void validateFinTab(){ - this.tabPosition = this.tabOffsetMethod.getAsPosition(tabOffset, tabLength, length); - + public void validateFinTabPosition() { //check front bounds: - if( tabPosition < 0){ + if (tabPosition < 0) { this.tabPosition = 0; } //check tail bounds: - if (this.length < tabPosition ) { + if (this.length < tabPosition) { this.tabPosition = length; } + } + + public void validateFinTabLength() { + //System.err.println(String.format(" >> Fin Tab Length: %.6f @ %.6f", tabLength, tabOffset)); + final double xTabBack = getTabTrailingEdge(); - if( this.length < xTabBack ){ + if (this.length < xTabBack) { this.tabLength -= (xTabBack - this.length); } - + tabLength = Math.max(0, tabLength); - + + //System.err.println(String.format(" << Fin Tab Length: %.6f @ %.6f", tabLength, tabOffset)); + } + + public void validateFinTabHeight(){ // check tab height if( null != getParent() ){ // pulls the parent-body radius at the fin-tab reference point. @@ -792,7 +806,6 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona this.centerOfMass = Coordinate.NaN; this.totalVolume = Double.NaN; this.cantRotation = null; - validateFinTab(); } super.componentChanged(e); diff --git a/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java index 62bd26067..14e4e6d40 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java @@ -319,7 +319,7 @@ public class FreeformFinSet extends FinSet { clampLastPoint(); if (oldLength != this.length) - validateFinTab(); + validateFinTabLength(); } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/TrapezoidFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/TrapezoidFinSet.java index 57f72a0e4..34b29525b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/TrapezoidFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/TrapezoidFinSet.java @@ -77,8 +77,9 @@ public class TrapezoidFinSet extends FinSet { if (length == r) return; length = Math.max(r, 0); - validateFinTab(); - fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); + setTabPosition(); + + fireComponentChangeEvent(ComponentChangeEvent.AEROMASS_CHANGE); } public double getTipChord() { diff --git a/core/test/net/sf/openrocket/rocketcomponent/FinSetTest.java b/core/test/net/sf/openrocket/rocketcomponent/FinSetTest.java index dd18c900b..03d7613e1 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FinSetTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FinSetTest.java @@ -93,7 +93,7 @@ public class FinSetTest extends BaseTestCase { fins.setTabOffsetMethod( methods[caseIndex]); //query - double actShift = fins.getTabOffset(); + final double actShift = fins.getTabOffset(); assertEquals(String.format("Offset doesn't match for: %s \n", methods[caseIndex].name()), expShift[caseIndex], actShift, EPSILON); } } @@ -148,7 +148,11 @@ public class FinSetTest extends BaseTestCase { { // MIDDLE -> native fins.setTabOffsetMethod(AxialMethod.MIDDLE); fins.setTabOffset(0.0); - fins.setTabHeight(0.02); + + assertEquals("Setting by MIDDLE method failed!", 0.015, fins.getTabFrontEdge(), EPSILON); + assertEquals("Setting by MIDDLE method failed!", 0.0, fins.getTabOffset(), EPSILON); + assertEquals("Setting by MIDDLE method failed!", 0.02, fins.getTabLength(), EPSILON); + fins.setTabLength(0.04); assertEquals("Setting by MIDDLE method failed!", 0.005, fins.getTabFrontEdge(), EPSILON); @@ -171,9 +175,9 @@ public class FinSetTest extends BaseTestCase { assertEquals("Setting by TOP method failed!", 0.02, fins.getTabFrontEdge(), EPSILON); ((TrapezoidFinSet)fins).setRootChord(0.08); - - assertEquals("Front edge doesn't match after adjusting root chord...", 0.03, fins.getTabFrontEdge(), EPSILON); + assertEquals("Offset doesn't match after adjusting root chord....", 0.0, fins.getTabOffset(), EPSILON); + assertEquals("Front edge doesn't match after adjusting root chord...", 0.03, fins.getTabFrontEdge(), EPSILON); } @Test