Exemplo n.º 1
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            int curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value : 1st octave
            var signal = Primitive2D.GetValue(x, y);

            // get absolute value of signal (this creates the ridges)
            if (signal < 0.0f)
            {
                signal = -signal;
            }

            // invert and translate (note that "offset" should be ~= 1.0)
            signal = Offset - signal;

            // Square the signal to increase the sharpness of the ridges.
            signal *= signal;

            // Add the signal to the output value.
            var value = signal;

            var weight = 1.0f;

            for (curOctave = 1; weight > 0.001 && curOctave < OctaveCount; curOctave++)
            {
                x *= Lacunarity;
                y *= Lacunarity;

                // Weight successive contributions by the previous signal.
                weight = Libnoise.Clamp01(signal * Gain);

                // Get the coherent-noise value.
                signal = Primitive2D.GetValue(x, y);

                // Make the ridges.
                if (signal < 0.0)
                {
                    signal = -signal;
                }

                signal = Offset - signal;

                // Square the signal to increase the sharpness of the ridges.
                signal *= signal;

                // The weighting from the previous octave is applied to the signal.
                // Larger values have higher weights, producing sharp points along the
                // ridges.
                signal *= weight;

                // Add the signal to the output value.
                value += signal * SpectralWeights[curOctave];
            }

            return(value);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            int curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value
            var value = 1.0f;

            // inner loop of spectral construction, where the fractal is built
            for (curOctave = 0; curOctave < OctaveCount; curOctave++)
            {
                // Get the coherent-noise value.
                var signal = Offset + Primitive2D.GetValue(x, y) * SpectralWeights[curOctave];

                // Add the signal to the output value.
                value *= signal;

                // Go to the next octave.
                x *= Lacunarity;
                y *= Lacunarity;
            }

            //take care of remainder in OctaveCount
            var remainder = OctaveCount - (int)OctaveCount;

            if (remainder > 0.0f)
            {
                value += remainder * Primitive2D.GetValue(x, y) * SpectralWeights[curOctave];
            }

            return(value);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            x *= Frequency;
            y *= Frequency;

            return(Primitive2D.GetValue(x, y));
        }
Exemplo n.º 4
0
        public void TestMapCSSArea()
        {
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, new TagsCollection(
                               Tag.Create("area", "yes")), 1, 2, 3, 1));

            // test closed way.
            string css = "area { " +
                         "   fill-color: black; " +
                         "} ";

            // create the projection and scene objects.
            var     mercator = new WebMercator();
            Scene2D scene    = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the projection and scene objects.
            scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                                                                  new MapCSSDictionaryImageSource());

            interpreter.Translate(scene, mercator, source, source.GetWay(1));

            // test the scene contents.
            Assert.AreEqual(1, scene.Count);
            Primitive2D primitive = scene.Get(0);

            Assert.IsInstanceOf <Polygon2D>(primitive);
        }
Exemplo n.º 5
0
        private bool IsPrimitiveSelected(Primitive2D p)
        {
            PrimitiveRenderData data = p.GetData <PrimitiveRenderData>();

            if (data != null)
            {
                return(data.isSelected);
            }
            return(false);
        }
Exemplo n.º 6
0
        public static PrimitiveRenderData Get(Primitive2D p)
        {
            PrimitiveRenderData data = p.GetData <PrimitiveRenderData>();

            if (data == null)
            {
                data = new PrimitiveRenderData();
                p.SetData(data);
            }
            return(data);
        }
Exemplo n.º 7
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            float signal;
            int   curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value : get first octave of function; later octaves are weighted
            var value  = Primitive2D.GetValue(x, y) + Offset;
            var weight = Gain * value;

            x *= Lacunarity;
            y *= Lacunarity;

            // inner loop of spectral construction, where the fractal is built
            for (curOctave = 1; weight > 0.001 && curOctave < OctaveCount; curOctave++)
            {
                // prevent divergence
                if (weight > 1.0)
                {
                    weight = 1.0f;
                }

                // get next higher frequency
                signal = (Offset + Primitive2D.GetValue(x, y)) * SpectralWeights[curOctave];

                // The weighting from the previous octave is applied to the signal.
                signal *= weight;

                // Add the signal to the output value.
                value += signal;

                // update the (monotonically decreasing) weighting value
                weight *= Gain * signal;

                // Go to the next octave.
                x *= Lacunarity;
                y *= Lacunarity;
            }

            //take care of remainder in OctaveCount
            var remainder = OctaveCount - (int)OctaveCount;

            if (remainder > 0.0f)
            {
                signal  = Primitive2D.GetValue(x, y);
                signal *= SpectralWeights[curOctave];
                signal *= remainder;
                value  += signal;
            }

            return(value);
        }
Exemplo n.º 8
0
        internal void TogglePrimitive(Primitive2D p)
        {
            int idx = primitives.IndexOf(p);

            if (idx != -1)
            {
                PrimitiveRenderData.Get(primitives[idx]).isSelected = false;
                primitives.RemoveAt(idx);
            }
            else
            {
                Add(p);
            }
        }
Exemplo n.º 9
0
        public void Append(Primitive2D primitive)
        {
            primitive.Transform(_shift);
            _primitives.Add(primitive);

            _canvas.BeginDraw();
            try
            {
                primitive.Render(_canvas);
            }
            finally
            {
                _canvas.EndDraw();
            }
        }
Exemplo n.º 10
0
        private Color GetColor(Primitive2D p, Colors.ColorPair defaultColors)
        {
            if (!isActive)
            {
                return(defaultColors.Inactive);
            }

            PrimitiveRenderData data = p.GetData <PrimitiveRenderData>();

            if (data != null)
            {
                return(data.isSelected ? defaultColors.Selected : data.GetColor(defaultColors.Active));
            }
            return(defaultColors.Active);
        }
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            float signal;
            int   curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value : first unscaled octave of function; later octaves are scaled
            var value = Offset + Primitive2D.GetValue(x, y);

            x *= Lacunarity;
            y *= Lacunarity;

            // inner loop of spectral construction, where the fractal is built
            for (curOctave = 1; curOctave < OctaveCount; curOctave++)
            {
                // obtain displaced noise value.
                signal = Offset + Primitive2D.GetValue(x, y);

                //scale amplitude appropriately for this frequency
                signal *= SpectralWeights[curOctave];

                // scale increment by current altitude of function
                signal *= value;

                // Add the signal to the output value.
                value += signal;

                // Go to the next octave.
                x *= Lacunarity;
                y *= Lacunarity;
            }

            //take care of remainder in OctaveCount
            var remainder = OctaveCount - (int)OctaveCount;

            if (remainder > 0.0f)
            {
                signal  = Offset + Primitive2D.GetValue(x, y);
                signal *= SpectralWeights[curOctave];
                signal *= value;
                signal *= remainder;
                value  += signal;
            }

            return(value);
        }
Exemplo n.º 12
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            float signal;
            float value;
            int   curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value, fBM starts with 0
            value = 0;

            // Inner loop of spectral construction, where the fractal is built

            for (curOctave = 0; curOctave < OctaveCount; curOctave++)
            {
                // Get the coherent-noise value.
                signal = Primitive2D.GetValue(x, y) * SpectralWeights[curOctave];

                if (signal < 0.0f)
                {
                    signal = -signal;
                }

                // Add the signal to the output value.
                value += signal * PScale + PBias;

                // Go to the next octave.
                x *= Lacunarity;
                y *= Lacunarity;
            }

            //take care of remainder in OctaveCount
            var remainder = OctaveCount - (int)OctaveCount;

            if (remainder > 0)
            {
                value += PScale * remainder * Primitive2D.GetValue(x, y) * SpectralWeights[curOctave] + PBias;
            }

            return(value);
        }
Exemplo n.º 13
0
        public bool TryAppend(Primitive2D primitive)
        {
            if (!_primitives.Any())
            {
                _primitives.Add(primitive);
                return(true);
            }

            foreach (var primitive2D in _primitives)
            {
                var intersection = _intersectionFactory.CreateBehaviour(primitive2D, primitive);
                if (intersection.Intersects())
                {
                    _primitives.Add(primitive);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 14
0
        public void TestMapCSSSimpleEval()
        {
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, new TagsCollection(
                               Tag.Create("width", "10")), 1, 2, 3, 1));

            // test closed way.
            string css = "way { " +
                         "   width:  eval(\"tag('width')\"); " +
                         "   color: green; " +
                         "} ";

            // create the projection and scene objects.
            var     mercator = new WebMercator();
            Scene2D scene    = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the projection and scene objects.
            scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                                                                  new MapCSSDictionaryImageSource());

            interpreter.Translate(scene, mercator, source, source.GetWay(1));

            // test the scene contents.
            Assert.AreEqual(1, scene.Count);
            Primitive2D primitive = scene.Get(0);

            Assert.IsInstanceOf <Line2D>(primitive);
            Line2D line = (primitive as Line2D);

            Assert.AreEqual(10, line.Width);
        }
Exemplo n.º 15
0
        public IIntersectionBehaviour CreateBehaviour(Primitive2D primitive1, Primitive2D primitive2)
        {
            if (primitive1 is Point2D point1 && primitive2 is Point2D point2)
            {
                return(new PointToPointIntersection(point1, point2));
            }

            if (primitive1 is Triangle2D triangle1 && primitive2 is Triangle2D trinagle2)
            {
                return(new TriangleToTriangleIntersection(triangle1, trinagle2));
            }

            if (primitive1 is Triangle2D triangle2 && primitive2 is Point2D point)
            {
                return(new PointToTriangleIntersection(triangle2, point));
            }

            if (primitive1 is Point2D point2D && primitive2 is Triangle2D triangle2D)
            {
                return(new PointToTriangleIntersection(triangle2D, point2D));
            }

            throw new System.NotImplementedException();
        }
Exemplo n.º 16
0
 public float GetValue(float x, float y)
 {
     return(Primitive2D.GetValue(x * XScale, y * ZScale));
 }
Exemplo n.º 17
0
        public void TestCanvasJOSMSettingsCSS()
        {
            // create CSS.
            string css = "canvas { " +
                         "background-color: white; " +
                         "default-points: true; " + // adds default points for every node (color: black, size: 2).
                         "default-lines: true; " +  // adds default lines for every way (color: red, width: 1).
                         "} ";

            // create 'test' objects.
            Node node1 = new Node();

            node1.Id        = 1;
            node1.Latitude  = 1;
            node1.Longitude = 1;

            Node node2 = new Node();

            node2.Id        = 2;
            node2.Latitude  = 2;
            node2.Longitude = 2;

            Way way = new Way();

            way.Id    = 1;
            way.Nodes = new List <long>();
            way.Nodes.Add(1);
            way.Nodes.Add(2);

            // create the datasource.
            MemoryDataSource dataSource = new MemoryDataSource();

            dataSource.AddNode(node1);
            dataSource.AddNode(node2);
            dataSource.AddWay(way);

            // create the projection and scene objects.
            var     mercator = new WebMercator();
            Scene2D scene    = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                                                                  new MapCSSDictionaryImageSource());

            interpreter.Translate(scene, mercator, dataSource, node1);
            interpreter.Translate(scene, mercator, dataSource, node2);
            interpreter.Translate(scene, mercator, dataSource, way);

            // test the scene contents.
            Assert.AreEqual(3, scene.Count);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.White).Value, scene.BackColor);

            // test the scene point 1.
            Primitive2D primitive = scene.Get(0);

            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf <Primitive2D>(primitive);
            Point2D pointObject = primitive as Point2D;

            Assert.AreEqual(2, pointObject.Size);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color);
            Assert.AreEqual(mercator.LongitudeToX(1), pointObject.X);
            Assert.AreEqual(mercator.LatitudeToY(1), pointObject.Y);

            // test the scene point 2.
            primitive = scene.Get(1);
            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf <Point2D>(primitive);
            pointObject = primitive as Point2D;
            Assert.AreEqual(2, pointObject.Size);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color);
            Assert.AreEqual(mercator.LongitudeToX(2), pointObject.X);
            Assert.AreEqual(mercator.LatitudeToY(2), pointObject.Y);

            // test the scene line 2.
            primitive = scene.Get(2);
            Assert.IsNotNull(primitive);
            Assert.IsInstanceOf <Line2D>(primitive);
            Line2D line = primitive as Line2D;

            Assert.AreEqual(1, line.Width);
            Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Red).Value, line.Color);
            Assert.IsNotNull(line.X);
            Assert.IsNotNull(line.Y);
            Assert.AreEqual(2, line.X.Length);
            Assert.AreEqual(2, line.Y.Length);
            Assert.AreEqual(mercator.LongitudeToX(1), line.X[0]);
            Assert.AreEqual(mercator.LatitudeToY(1), line.Y[0]);
            Assert.AreEqual(mercator.LongitudeToX(2), line.X[1]);
            Assert.AreEqual(mercator.LatitudeToY(2), line.Y[1]);
        }
Exemplo n.º 18
0
 public void Add(Primitive2D p)
 {
     primitives.Add(p);
 }
Exemplo n.º 19
0
 internal void Add(Primitive2D p)
 {
     PrimitiveRenderData.Get(p).isSelected = true;
     primitives.Add(p);
 }