Added buildings and trees
Overview
- New function
hash
added tojs/math/graph.js
, which returns a JSON string representation of the graph. - New functions added to
js/math/utils.js
:dot
,normalize
,magnitude
, andtranslate
. - New functions added to
js/primitives/polygon.js
:distanceToPoint
,distanceToPoly
andintersectsPoly
. - New functions added to
js/primitives/segment.js
:length
,directionVector
,distanceToPoint
, andprojectPoint
. - New fields and methods added to
js/world.js
:buildingWidth
,buildingMinLength
,spacing
,treeSize
,#generateTrees
,#generateBuildings
, anddraw
.
File wise changes made
index.html
- Old graph hash was being stored in
oldGraphHash
variable. - Now, when graph has changed, the world will be regenerated by calling
world.generate()
function.
js/math/graph.js
- Added
hash()
function to return a hash of the graph.
js/math/utils.js
- Added
dot()
function to calculate the dot product of two points. - Added
normalize()
function to normalize a point. - Added
magnitude()
function to calculate the magnitude of a point.
js/primitives/polygon.js
- Added
distanceToPoint()
function to calculate the minimum distance from a point to the polygon. - Added
distanceToPoly()
function to calculate the minimum distance from a polygon to another polygon. - Added
intersectsPoly()
function to check if the polygon intersects with another polygon.
js/primitives/segment.js
- Added
length()
function to calculate the length of the segment. - Added
directionVector()
function to calculate the direction vector of the segment. - Added
distanceToPoint()
function to calculate the distance from a point to the segment.
js/world.js
- Added constructor parameters for
buildingWidth
,buildingMinLength
,spacing
, andtreeSize
. - Added
#generateBuildings()
function to generate buildings. - Added
#generateTrees()
function to generate trees. - Modified
draw()
function to draw trees and buildings.
Summary
- The
index.html
file was modified to add a check for changes in the graph hash and regenerate the world if the hash has changed. - The
js/math/graph.js
file was modified to add ahash()
method that returns a JSON string representation of the graph. - The
js/math/utils.js
file was modified to add adot()
method that calculates the dot product of two points, anormalize()
method that normalizes a point, amagnitude()
method that calculates the magnitude of a point, and atranslate()
method that translates a point by a given angle and offset. - The
js/primitives/polygon.js
file was modified to add methods for calculating the distance to a point, the distance to another polygon, and to check if it intersects with another polygon. - The
js/primitives/segment.js
file was modified to add methods for calculating the length, the direction vector, the distance to a point, and to project a point onto the segment. - The
js/world.js
file was modified to add new parameters to the constructor for building width, building minimum length, spacing, and tree size. It also adds methods for generating buildings and trees. Thedraw()
method was modified to draw the trees and buildings.