Exemplo n.º 1
0
        public void ZeroDimensions()
        {
            ObjectDimensions dimensions = new ObjectDimensions();
            float            scale      = dimensions.AutoScale(10f);

            Assert.AreEqual(1f, scale);
        }
Exemplo n.º 2
0
        public void NoScale()
        {
            ObjectDimensions dimensions = new ObjectDimensions();

            dimensions.Initialize(new TestDimensions(10f, 10f, 10f));
            float scale = dimensions.AutoScale(10f);

            Assert.AreEqual(1f, scale);
        }
Exemplo n.º 3
0
        public GCodeExporter(Model model, SlicerOptions options, Vector2 offset)
        {
            Model   = model ?? throw new ArgumentNullException("model");
            Options = options ?? throw new ArgumentNullException("options");
            ObjectDimensions dimensions = model.Dimensions;

            Position = new Vector3(offset.X - (dimensions.Size.X / 2 + dimensions.MinPoint.X),
                                   offset.Y - (dimensions.Size.Y / 2 + dimensions.MinPoint.Y), -dimensions.MinPoint.Z);
        }
 //private readonly LayerMask _defaultLayerMask = LayerMask.NameToLayer("Default");
 public AdvancedMovementStrategy(IContext context, float optimalDistance = 10f, float moveAroundFactor = 0f, float accelerationTime = 1.5f,
     float maxAcceleration = 0.1f, float maxAngularAcceleration = 3f, float turningTime = 1f,
     ObjectDimensions objectDimensions = default)
     : base(context, optimalDistance, accelerationTime, maxAcceleration, maxAngularAcceleration, turningTime)
 {
     this._objectDimensions = objectDimensions;
     this._moveAroundFactor = moveAroundFactor;
     this._initialMoveAroundFactor = moveAroundFactor;
 }
Exemplo n.º 5
0
        public void ZComponentScale()
        {
            ObjectDimensions dimensions = new ObjectDimensions();

            dimensions.Initialize(new TestDimensions(1f, 1f, 10f));
            float scale = dimensions.AutoScale(5f);

            Assert.AreEqual(0.5f, scale);
        }
Exemplo n.º 6
0
        public void GetDimensionsTest()
        {
            part.AddSection(Vector3.Zero, Vector3.UnitX);
            part.AddSection(Vector3.UnitX, Vector3.UnitY);
            part.AddSection(Vector3.UnitY, Vector3.Zero);

            ObjectDimensions dimensions = part.GetDimensions();

            Assert.IsNotNull(dimensions);
            Assert.AreEqual(Vector3.Zero, dimensions.MinPoint);
            Assert.AreEqual(new Vector3(1f, 1f, 0f), dimensions.MaxPoint);
        }
Exemplo n.º 7
0
 public void Transform(Matrix3 matrix)
 {
     if (Facets.Count < FacetCountThreshold)
     {
         Facets.ForEach(x => x.Transform(matrix));
     }
     else
     {
         Facets.AsParallel().ForAll(x => x.Transform(matrix));
     }
     dimensions = null;
 }
Exemplo n.º 8
0
        private void UpdateView()
        {
            Vector2 offset = new Vector2(
                (float)edPositionX.Value - options.Printer.BuildAreaWidth / 2,
                (float)edPositionY.Value - options.Printer.BuildAreaDepth / 2);
            ObjectDimensions dimensions = model.Dimensions;

            position.X = offset.X - (dimensions.Size.X / 2 + dimensions.MinPoint.X) * scale.X;
            position.Y = offset.Y - (dimensions.Size.Y / 2 + dimensions.MinPoint.Y) * scale.Y;
            position.Z = -dimensions.MinPoint.Z * scale.Z;
            UpdateScalingUI();
            glControl1.Invalidate();
        }
Exemplo n.º 9
0
        public ObjectDimensions GetDimensions()
        {
            if (Parts.Count == 0)
            {
                throw new InvalidOperationException("Get dimensions from empty slice.");
            }
            ObjectDimensions result = Parts[0].GetDimensions();

            for (int i = 1; i < Parts.Count; i++)
            {
                result.Aggregate(Parts[i].GetDimensions());
            }
            return(result);
        }
Exemplo n.º 10
0
        public ObjectDimensions GetDimensions()
        {
            if (Points.Count == 0)
            {
                throw new InvalidOperationException("Get dimensions from empty slice part.");
            }
            ObjectDimensions result = new ObjectDimensions();

            result.Initialize(Points[0]);
            for (int i = 1; i < Points.Count; i++)
            {
                result.Aggregate(Points[i]);
            }
            return(result);
        }
Exemplo n.º 11
0
        public void GetDimensionsTest()
        {
            slice.AddSection(Vector3.UnitX * -1, Vector3.UnitX);
            slice.AddSection(Vector3.UnitX, Vector3.UnitY);
            slice.AddSection(Vector3.UnitY, Vector3.UnitX * -1);

            slice.AddSection(Vector3.Zero, Vector3.UnitX);
            slice.AddSection(Vector3.UnitX * 2, Vector3.UnitY * 3);

            ObjectDimensions dimensions = slice.GetDimensions();

            Assert.IsNotNull(dimensions);
            Assert.AreEqual(new Vector3(-1f, 0f, 0f), dimensions.MinPoint);
            Assert.AreEqual(new Vector3(2f, 3f, 0f), dimensions.MaxPoint);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Расчитать коэффициент масштабирования и позицию модели
        /// </summary>
        private void SetupAutoScaleAndPosition()
        {
            ResetPositionUI();
            float minSize = Math.Min(options.Printer.BuildAreaWidth,
                                     Math.Min(options.Printer.BuildAreaDepth, options.Printer.BuildAreaHeight));
            ObjectDimensions dimensions = model.Dimensions;
            // Auto scale to 50% of printer build area
            float autoScale = dimensions.AutoScale(minSize * 50f / 100f);

            scale = new Vector3(autoScale);
            // Расположить модель посередине стола
            position.X = -(dimensions.Size.X / 2 + dimensions.MinPoint.X) * scale.X;
            position.Y = -(dimensions.Size.Y / 2 + dimensions.MinPoint.Y) * scale.Y;
            position.Z = -dimensions.MinPoint.Z * scale.Z;
            UpdateScalingUI();
        }
Exemplo n.º 13
0
        // Start is called before the first frame update
        // Start should only be used as is or extended to prefer another strategy
        protected virtual void Start()
        {
            player             = GameObject.FindWithTag("Player");
            _playerRigidbody2D = player.GetComponent <Rigidbody2D>();

            _rigidbody2D = GetComponent <Rigidbody2D>();
            _section     = GetComponent <Section>();

            objectDimensions = _section.CalculateShipDimensions(); // Get dimensions from section for strategies

            // Send the MonoBehaviour to strategy through the specific IContext
            // It would be catastrophic for strategies to access a MonoBehaviour directly
            // If there is a preferred strategy for enemy, override it in child
            movementStrategy ??= new MovementStrategy(this);
            shootingStrategy ??= new ShootingStrategy(this);

            Invoke(nameof(EnableFighting), shootingEnabledTimer);
        }
Exemplo n.º 14
0
        protected override void GenerateFill(Fill fill, Slice slice, float step)
        {
            ObjectDimensions dimensions = slice.GetDimensions();
            int minIndex = (int)Math.Truncate(dimensions.MinPoint.X / step);
            int maxIndex = (int)Math.Truncate(dimensions.MaxPoint.X / step);

            if ((minIndex * step) <= dimensions.MinPoint.X)
            {
                minIndex++;
            }
            if ((maxIndex * step) >= dimensions.MaxPoint.X)
            {
                maxIndex--;
            }
            for (int i = minIndex; i <= maxIndex; i++)
            {
                GenerateParts(fill, slice, i * step, i % 2 != 0);
            }
        }
Exemplo n.º 15
0
        private void SetupInitialScaleAndPosition()
        {
            ObjectDimensions dimensions    = model.Dimensions;
            Vector3          size          = dimensions.Size;
            Vector3          buildAreaSize = options.Printer.GetBuildAreaSize();

            if (size.X > buildAreaSize.X || size.Y > buildAreaSize.Y || size.Z > buildAreaSize.Z)
            {
                SetupAutoScaleAndPosition();
            }
            else
            {
                ResetPositionUI();
                scale      = Vector3.One;
                position.X = -(dimensions.Size.X / 2 + dimensions.MinPoint.X) * scale.X;
                position.Y = -(dimensions.Size.Y / 2 + dimensions.MinPoint.Y) * scale.Y;
                position.Z = -dimensions.MinPoint.Z * scale.Z;
                UpdateScalingUI();
            }
        }
Exemplo n.º 16
0
        private ObjectDimensions CalcDimensions()
        {
            ObjectDimensions result = new ObjectDimensions();

            if (Facets.Count > 0)
            {
                result.Initialize(Facets[0]);
                if (Facets.Count < FacetCountThreshold)
                {
                    for (int i = 1; i < Facets.Count; i++)
                    {
                        result.Aggregate(Facets[i]);
                    }
                }
                else
                {
                    result = Facets.AsParallel().Aggregate(result,
                                                           (acc, item) => { acc.Aggregate(item); return(acc); });
                }
            }
            return(result);
        }
Exemplo n.º 17
0
 public void Cleanup()
 {
     dimensions = null;
 }
Exemplo n.º 18
0
 public void Initialize()
 {
     dimensions = new ObjectDimensions();
 }
Exemplo n.º 19
0
 public void Clear()
 {
     Name = string.Empty;
     Facets.Clear();
     dimensions = null;
 }