Categories
AutoCAD VBA

AutoCAD VBA – завъртане на блокове

Това е VBA скрипт за завъртане на блокове, перпендикулярно на дадена базова линия. Програмата изчертава и линия по перпендикуляра до базовата линия.

Private Sub CommandButton1_Click() 
    HALF_PI = 2 * Atn(1)
    PI = 4 * Atn(1)
    Me.hide
    On Error GoTo ShowForm
    Dim selectedBlockEntity As AcadEntity
    Dim blockSelectionSet As AcadSelectionSet
    Set blockSelectionSet = AddSelectionSet("Blocks")
    blockSelectionSet.Clear
    blockSelectionSet.SelectOnScreen
    For Each selectedBlockEntity In blockSelectionSet
        On Error Resume Next
        If TypeOf selectedBlockEntity Is AcadBlockReference Then
            Dim blockReference As AcadBlockReference
            Set blockReference = selectedBlockEntity
            blockReference.Highlight True
            Dim baseLineStartPoint() As Double
            Dim baseLineEndPoint() As Double
            baseLineStartPoint = ThisDrawing.Utility.GetPoint(, "Select base line start point: ")
            baseLineEndPoint = ThisDrawing.Utility.GetPoint(, "Select base line end point: ")
            Dim baseLine As AcadLine
            Set baseLine = ThisDrawing.ModelSpace.AddLine(baseLineStartPoint, baseLineEndPoint)
            Dim headingAngle As Double
            headingAngle = Atan2(baseLineEndPoint(0) - baseLineStartPoint(0), baseLineEndPoint(1) - baseLineStartPoint(1))
            blockReference.Rotation = headingAngle + PI
            Dim blockReferenceInsertionPoint() As Double
            blockReferenceInsertionPoint = blockReference.InsertionPoint
            Set blockReference = Nothing
            Dim baseLineAngle As Double
            baseLineAngle = baseLine.Angle - HALF_PI
            Dim polarPoint() As Double
            polarPoint = ThisDrawing.Utility.polarPoint(blockReferenceInsertionPoint, baseLineAngle, 10)
            Dim extendedLine As AcadLine
            Set extendedLine = ThisDrawing.ModelSpace.AddLine(blockReferenceInsertionPoint, polarPoint)
            Dim intersectionPoint() As Double
            intersectionPoint = baseLine.IntersectWith(extendedLine, acExtendBoth)
            extendedLine.EndPoint = intersectionPoint
            extendedLine.Linetype = "L175"
            extendedLine.Update
            baseLine.Delete
        End If
    Next selectedBlockEntity
ShowForm:
    Me.show
End Sub
Private Function AddSelectionSet(setName As String) As AcadSelectionSet
    On Error Resume Next
    Set AddSelectionSet = ThisDrawing.SelectionSets.Add(setName)
    If Err.Number <> 0 Then
        Set AddSelectionSet = ThisDrawing.SelectionSets.Item(setName)
    End If
End Function
Private Function Atan2(X As Variant, Y As Variant) As Variant
    PI = 3.14159265358979
    PI_2 = 1.5707963267949
    Select Case X
         Case Is > 0
             Atan2 = Atn(Y / X)
         Case Is < 0             
            Atan2 = Atn(Y / X) + PI * Sgn(Y)             
            If Y = 0 Then 
                ArcTan2 = ArcTan2 + PI         
         Case Is = 0             
            Atan2 = PI_2 * Sgn(Y)     
    End Select 
End Function 
Categories
JavaScript Телерик

Rams and Sheeps – JavaScript Game

Source

Demo

Categories
JavaScript Телерик

JS OOP изпит – сутрешна група

Решение на задачата на сутрешната група на изпита по JavaScript OOP

// item.js
define(function() {
    'use strict';
    var Item;

    Item = (function() {
        var types = ['accessory', 'smart-phone', 'notebook', 'pc', 'tablet'];

        function Item(type, name, price) {
            if (types.indexOf(type) == -1) {
                throw "invalid item type";
            };

            if (name.length < 6 || name.length > 40) {
                throw "invalid item name";
            };

            if (price < 0.0) {
                throw "invalid item price";
            };
            this.type = type;
            this.name = name;
            this.price = price;
        }
        return Item;
    })();
    return Item;
});

// store.js 

define(function() {
    'use strict';
    var Store;
    Store = (function() {
        function Store(storeName) {
            if (storeName.length < 6 || storeName.length > 40) {
                throw "invalid store name";
            }

            this._name = storeName;
            this._items = [];
        };

        Store.prototype.addItem = function(item) {
            if (item.constructor.name !== "Item") {
                throw "invalid item type";
            }

            this._items.push(item);

            return this;
        };

        Store.prototype.getAll = function() {
            var sortedItems = compareBy(this._items, "name");

            return sortedItems;
        };

        Store.prototype.getSmartPhones = function() {
            var items = [];

            this._items.forEach(function(item) {
                if (item.type === 'smart-phone') {
                    items.push(item);
                }
            });

            var sortedItems = compareBy(items, "name");

            return sortedItems;
        };

        Store.prototype.getMobiles = function() {
            var items = [];

            this._items.forEach(function(item) {
                if (item.type === 'smart-phone' || item.type === 'tablet') {
                    items.push(item);
                }
            });

            var sortedItems = compareBy(items, "name");

            return sortedItems;
        };

        Store.prototype.getComputers = function() {
            var items = [];

            this._items.forEach(function(item) {
                if (item.type === 'pc' || item.type === 'notebook') {
                    items.push(item);
                }
            });

            var sortedItems = compareBy(items, "name");

            return sortedItems;
        };

        Store.prototype.filterItemsByType = function(type) {
            var items = [];

            this._items.forEach(function(item) {
                if (item.type === type) {
                    items.push(item);
                }
            });

            var sortedItems = compareBy(items, "name");

            return sortedItems;
        };

        Store.prototype.filterItemsByPrice = function(options) {
            var minPrice = 0;
            var maxPrice = 999999999.99;
            var items = [];

            if (options) {
                minPrice = options.min || minPrice;
                maxPrice = options.max || maxPrice;
            }

            this._items.forEach(function(item) {
                if (item.price >= minPrice && item.price <= maxPrice) {
                    items.push(item);
                }
            });
            var sortedItems = compareBy(items, "price");
            return sortedItems;
        };
        Store.prototype.countItemsByType = function() {
            var itemTypes = [];
            for (var i = 0; i < this._items.length; i++) {
                if (itemTypes[this._items[i].type]) {
                    itemTypes[this._items[i].type]++;
                } else {
                    itemTypes[this._items[i].type] = 1;
                }
            }
            return itemTypes;
        };
        Store.prototype.filterItemsByName = function(part) {
            var items = [];
            this._items.forEach(function(item) {
                if (item.name.toLowerCase().indexOf(part.toLowerCase()) >= 0) {
                    items.push(item);
                }
            });

            var sortedItems = compareBy(items, "name");

            return sortedItems;
        };

        function compareBy(data, field) {
            data.sort(function(a, b) {
                if (a[field] < b[field]) return -1;
                if (a[field] > b[field])
                    return 1;
                return 0;
            });

            return data;
        };

        return Store;
    })();

    return Store;
});
Categories
JavaScript

JavaScript OOP подготовка за изпит

Решение на задачата с курсове и студенти

course.js

define(function() {
    var Course;

    Course = (function() {
        function Course(title, totalScoreFormula) {
            this.title = title;
            this._totalScoreFormula = totalScoreFormula;
            this._students = [];
        }

        Course.prototype.addStudent = function(student) {
            this._students.push(student);
        };

        Course.prototype.calculateResults = function() {
            for (var i = 0; i < this._students.length; i++) {
                this._students[i].totalScore = this._totalScoreFormula(this._students[i]);
            }
        };
        Course.prototype.getTopStudentsByExam = function(number) {
            var sortedStudents = compareBy(this._students, 'exam');
            var topStudents = sortedStudents.slice(0, number);
            return topStudents;
        };
        Course.prototype.getTopStudentsByTotalScore = function(number) {
            var sortedStudents = compareBy(this._students, 'totalScore');
            var topStudents = sortedStudents.slice(0, number);
            return topStudents;
        };

        function compareBy(data, field) {
            data.sort(function(a, b) {
                if (a[field] < b[field]) return 1;
                if (a[field] > b[field])
                    return -1;
                return 0;
            });

            return data;
        };

        return Course;
    })();

    return Course;
});

student.js

define(function() {
    var Student;

    Student = (function() {
        function Student(data) {
            this.name = data.name;
            this.exam = data.exam;
            this.homework = data.homework;
            this.attendance = data.attendance;
            this.teamwork = data.teamwork;
            this.bonus = data.bonus;
        }

        return Student;
    })();

    return Student;
});
Categories
JavaScript

JavaScript OOP – подготовка

Задача 1:

//container.js

define(function() {
    'use strict';
    var Container;

    Container = (function() {
        function Container() {
            this.container = [];
        }

        Container.prototype.add = function(section) {
            this.container.push(section);
        };

        Container.prototype.getData = function() {
            return this.container;
        };

        return Container;
    }());

    return Container;
});

//section.js

define(function() {
    'use strict';
    var Section;

    Section = (function() {
        function Section(title) {
            this.title = title;
            this.content = [];
        }

        Section.prototype.add = function(item) {
            this.content.push(item);
        };

        Section.prototype.getData = function() {
            return {
                title: this.title,
                content: this.content
            };
        };

        return Section;
    }());

    return Section;
});

//item.js

define(function() {
    'use strict';
    var Item;

    Item = (function() {
        function Item(content) {
            this.content = content;
        }

        Item.prototype.getData = function() {
            return {
                content: this.content
            };
        };

        return Item;
    })();

    return Item;
});
Categories
Visual C# Геодезия

Програма за изравнение на мрежи

Програма за изравнение на планови мрежи

Изравнение на планови мрежи по метода на най-малките квадрати.

Изравнение на засечки – ъглови, линейни, ъглово-линейни, геодезически мрежи, полигони.

Въвеждане на измервания и координати

adjustment-dpi-file-open
adjustment-kor-file-open

Изчисляване на ориентировъчните ъгли на дадените точки

adjustment-orientation-angles-calculation

Изчисляване на несъвпаденията в триъгълниците

adjustment-triangles-misclosures-calculation

Изчисляване на приблизителни координати на новите точки

adjustment-approximate-coordinates-calculation

Изравнение на мрежата (измервания и нови точки)

adjustment-adjusted-observations
adjustment-adjusted-points

Други