Custom Asteroids  1.0.0
A mod for Kerbal Space Program that lets users control where asteroids appear
 All Classes Namespaces Files Functions Variables Enumerations Properties Pages
Population.ValueRange Class Reference

Represents the set of values an orbital element may assume. More...

+ Inheritance diagram for Population.ValueRange:

Protected Member Functions

virtual void parseAll ()
 Ensures that any abstract entries in the config file are properly interpreted. More...
 

Static Protected Member Functions

static double parseOrbitalElement (string rawValue)
 Converts an arbitrary string representation of an orbital element to a specific value. More...
 
static double getPlanetProperty (string planet, string property)
 Returns the desired property of a known celestial body. More...
 

Protected Attributes

const string planetFormat = "(?<planet>.+)"
 Parse format for planet names. More...
 
const string propFormat = "(?<prop>rad|soi|sma|per|apo|ecc|inc|(a|l)pe|lan|mn(a|l)0)"
 Parse format for planet properties. More...
 
const string planetProp = planetFormat + "\\s*\\.\\s*" + propFormat
 Parse format for planets, with properties. More...
 
Distribution dist
 The probability distribution from which the value is drawn.
 
string rawMin
 Abstract string representation of min.
 
double min
 The minimum allowed value (not always used)
 
string rawMax
 Abstract string representation of max.
 
double max
 The maximum allowed value (not always used)
 
string rawAvg
 Abstract string representation of avg.
 
double avg
 The average value (not always used)
 
string rawStdDev
 Abstract string representation of stdDev.
 
double stdDev
 The standard deviation of the values (not always used)
 

Package Types

enum  Distribution {
  Uniform, LogUniform, Gaussian, Normal,
  Rayleigh, Exponential, Isotropic
}
 Defines the type of probability distribution from which the value is drawn.
 

Package Functions

 ValueRange (Distribution dist, double min=0.0, double max=1.0, double avg=0.0, double stdDev=0.0)
 Assigns situation-specific default values to the ValueRange. More...
 
double draw ()
 Generates a random number consistent with the distribution. More...
 

Private Member Functions

void IPersistenceLoad. PersistenceLoad ()
 Callback used by ConfigNode.LoadObjectFromConfig()
 

Static Private Attributes

static Regex ratioDecl
 Defines the syntax for a Ratio declaration. More...
 
static Regex sumDecl
 Defines the syntax for an Offset declaration. More...
 

Detailed Description

Represents the set of values an orbital element may assume.

The same consistency caveats as for Population apply here.

Constructor & Destructor Documentation

ValueRange ( Distribution  dist,
double  min = 0.0,
double  max = 1.0,
double  avg = 0.0,
double  stdDev = 0.0 
)
package

Assigns situation-specific default values to the ValueRange.

Parameters
[in]distThe distribution from which the value will be drawn
[in]min,maxThe minimum and maximum values allowed for distributions. May be unused.
[in]avgThe mean value returned. May be unused.
[in]stdDevThe standard deviation of values returned. May be unused.
Postcondition
The given values will be used by draw() unless they are specifically overridden by a ConfigNode.
Exception Safety
Does not throw exceptions

Member Function Documentation

double draw ( )
package

Generates a random number consistent with the distribution.

Returns
The desired random variate. The distribution depends on this object's internal data.
Exceptions
System.InvalidOperationExceptionThrown if the parameters are inappropriate for the distribution, or if the distribution is invalid.
Exception Safety
This method is atomic
static double getPlanetProperty ( string  planet,
string  property 
)
staticprotected

Returns the desired property of a known celestial body.

Parameters
[in]planetThe exact, case-sensitive name of the celestial body
[in]propertyThe short name of the property to recover. Must be one of ("rad", "soi", "sma", "per", "apo", "ecc", "inc", "ape", "lan", "mna0", or "mnl0").
Returns
The value of property appropriate for planet. Distances are given in meters, angles are given in degrees.
Precondition
All loaded celestial bodies have unique names
Exceptions
ArgumentExceptionThrown if no planet named name exists, or if property does not have one of the allowed values
Note
The only properties supported for Sun are "rad" and "soi"
Exception Safety
This method is atomic
virtual void parseAll ( )
protectedvirtual

Ensures that any abstract entries in the config file are properly interpreted.

Precondition
this.rawMin, this.rawMax, this.rawAvg, and this.rawStdDev contain a representation of the desired object value
Warning
Class invariant should not be assumed to hold true prior to calling parseAll()
Exceptions
TypeInitializationExceptionThrown if the ConfigNode could not be interpreted as a set of floating-point values
Exception Safety
The program is in a consistent state in the event of an exception

Reimplemented in Population.SizeRange.

static double parseOrbitalElement ( string  rawValue)
staticprotected

Converts an arbitrary string representation of an orbital element to a specific value.

Parameters
[in]rawValueA string representing the value.
Returns
The value represented by rawValue.
Precondition
rawValue has one of the following formats:
  • a string representation of a floating-point number
  • a string of the format "Ratio(<Planet>.<stat>, <value>)", where <Planet> is the name of a loaded celestial body, <stat> is one of (rad, soi, sma, per, apo, ecc, inc, ape, lpe, lan, mna0, mnl0), and <value> is a string representation of a floating-point number
  • a string of the format "Offset(<Planet>.<stat>, <value>)", where <Planet>, <stat>, and <value> are as above.
Exceptions
ArgumentExceptionThrown if rawValue could not be interpreted as a floating-point value
Exception Safety
This method is atomic.

Member Data Documentation

const string planetFormat = "(?<planet>.+)"
protected

Parse format for planet names.

const string planetProp = planetFormat + "\\s*\\.\\s*" + propFormat
protected

Parse format for planets, with properties.

const string propFormat = "(?<prop>rad|soi|sma|per|apo|ecc|inc|(a|l)pe|lan|mn(a|l)0)"
protected

Parse format for planet properties.

Regex ratioDecl
staticprivate
Initial value:
= new Regex("Ratio\\(\\s*" + planetProp + "\\s*,"
+ "\\s*(?<ratio>[-+.e\\d]+)\\s*\\)",
RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture)

Defines the syntax for a Ratio declaration.

Regex sumDecl
staticprivate
Initial value:
= new Regex("Offset\\(\\s*" + planetProp + "\\s*,"
+ "\\s*(?<incr>[-+.e\\d]+)\\s*\\)",
RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture)

Defines the syntax for an Offset declaration.


The documentation for this class was generated from the following file: