2023-09-12 23:00:04 -04:00
SVGElement . prototype . getTransformToElement = SVGElement . prototype . getTransformToElement || function ( toElement ) {
return toElement . getScreenCTM ( ) . inverse ( ) . multiply ( this . getScreenCTM ( ) ) ;
} ;
2023-09-09 12:04:55 -04:00
function ns _elem ( ) { if ( typeof arguments [ 0 ] === "undefined" ) { console . log ( 'There was an error in the element assist function. Called with no valid tag name!' ) ; } var elem ; if ( typeof arguments [ 1 ] === "string" ) { elem = document . createElementNS ( arguments [ 1 ] , arguments [ 0 ] ) ; for ( var i = 2 ; i < arguments . length ; i += 2 ) { if ( typeof arguments [ i + 1 ] === "undefined" ) { for ( var key in arguments [ i ] ) { elem . setAttribute ( key , arguments [ i ] [ key ] ) ; } break ; } else { for ( var key in arguments [ i ] ) { elem . setAttributeNS ( arguments [ i + 1 ] , key , arguments [ i ] [ key ] ) ; } } } } else { elem = document . createElement ( arguments [ 0 ] ) ; for ( var i = 1 ; i < arguments . length ; i += 2 ) { if ( typeof arguments [ i + 1 ] === "undefined" ) { for ( var key in arguments [ i ] ) { elem . setAttribute ( key , arguments [ i ] [ key ] ) ; } break ; } else { for ( var key in arguments [ i ] ) { elem . setAttributeNS ( arguments [ i + 1 ] , key , arguments [ i ] [ key ] ) ; } } } } return elem ; }
var svg _ns = "http://www.w3.org/2000/svg" ;
var xlink _ns = "http://www.w3.org/1999/xlink" ;
function norm ( vector ) {
var norm = Math . sqrt ( vector . x * vector . x + vector . y * vector . y ) ;
return { x : vector . x / norm , y : vector . y / norm } ;
}
function len ( vector ) {
return Math . sqrt ( vector . x * vector . x + vector . y * vector . y ) ;
}
function sub ( a , b ) { return { x : a . x - b . x , y : a . y - b . y } ; }
function add ( a , b ) { return { x : a . x + b . x , y : a . y + b . y } ; }
function mul ( a , b ) {
if ( "x" in a ) { return { x : a . x * b , y : a . y * b } ; }
return a * b ;
}
function remove _class ( element , classname ) {
var classlist = $ ( element ) . attr ( "class" ) ;
if ( classlist ) {
classlist = classlist . split ( " " ) ;
}
var newclasslist = "" ;
for ( const x in classlist ) {
newclasslist += ( classname != classlist [ x ] ) ? " " + classlist [ x ] : "" ;
}
$ ( element ) . attr ( "class" , newclasslist ) ;
}
function add _class ( element , classname ) {
const classlist = $ ( element ) . attr ( "class" ) ;
$ ( element ) . attr ( "class" , classlist + " " + classname ) ;
}
function svg _from _dom ( point , svg ) {
const pt = svg . createSVGPoint ( ) ;
pt . x = point . x ;
pt . y = point . y ;
return pt . matrixTransform ( svg . getScreenCTM ( ) . inverse ( ) ) ;
}
function dom _from _svg ( point , svg ) {
const pt = svg . createSVGPoint ( ) ;
pt . x = point . x ;
pt . y = point . y ;
return pt . matrixTransform ( svg . getScreenCTM ( ) ) ;
}
function point _from _circle ( circle ) {
return { x : parseFloat ( circle . attr ( 'cx' ) ) , y : parseFloat ( circle . attr ( 'cy' ) ) } ;
}
var previous _mouse _position = { x : 0 , y : 0 } ;
function set _transform ( element , point , rotation ) {
const transform _string = ` translate( ${ point . x } , ${ point . y } ) rotate( ${ 180 * rotation / Math . PI } ) ` ;
return $ ( element ) . attr ( "transform" , transform _string ) ;
}
function remove ( list , element ) {
const index = list . indexOf ( element ) ;
if ( index > - 1 ) { // only splice array when item is found
list . splice ( index , 1 ) ; // 2nd parameter means remove one item only
}
}
function appropriate _angle ( point ) {
return - Math . atan2 ( point . x , point . y ) ;
2023-09-12 23:00:04 -04:00
}
function newsvg ( element ) {
document . createElementNS ( svg _ns , element ) ;
}
function set _loc ( elem , point ) { return $ ( elem ) . attr ( "cx" , point . x ) . attr ( "cy" , point . y ) }
function get _global _point _at _length ( svg , path , distance ) {
return path . getPointAtLength ( distance ) . matrixTransform ( path . getTransformToElement ( svg ) ) ;
2023-09-09 12:04:55 -04:00
}