Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#379 Remake global imports #383

Merged
merged 2 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/lib/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ const config = {
name: 'Miew',
file: packageJson.main,
banner,
sourcemap: true,
globals: {
three: 'THREE',
lodash: '_'
}
sourcemap: true
},
{
format: 'es',
Expand Down
12 changes: 6 additions & 6 deletions packages/lib/src/ComplexVisual.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import _ from 'lodash'
import * as THREE from 'three'
import utils from './utils'
import logger from './utils/logger'
import chem from './chem'
Expand All @@ -13,6 +11,8 @@ import Representation from './gfx/Representation'
import Visual from './Visual'
import ComplexVisualEdit from './ComplexVisualEdit'
import meshutils from './gfx/meshutils'
import { isEmpty, merge } from 'lodash'
import { Group, Mesh } from 'three'

const { selectors } = chem

Expand Down Expand Up @@ -40,7 +40,7 @@ class ComplexVisual extends Visual {
this._reprUsedBits = 0
this._selectionCount = 0

this._selectionGeometry = new THREE.Group()
this._selectionGeometry = new Group()
}

getBoundaries() {
Expand Down Expand Up @@ -198,7 +198,7 @@ class ComplexVisual extends Visual {
)

// something was changed
if (!_.isEmpty(diff)) {
if (!isEmpty(diff)) {
target.needsRebuild = true
for (const key in diff) {
if (diff.hasOwnProperty(key)) {
Expand Down Expand Up @@ -279,7 +279,7 @@ class ComplexVisual extends Visual {

// Fill in default values
const def = settings.now.presets.default[0]
const desc = _.merge(
const desc = merge(
{
selector: def.selector,
mode: def.mode,
Expand Down Expand Up @@ -859,7 +859,7 @@ class ComplexVisual extends Visual {
rep.material.setValues(values)
if (needTraverse) {
rep.geo.traverse((object) => {
if (object instanceof THREE.Mesh) {
if (object instanceof Mesh) {
object.material.setValues(values)

if (process !== undefined) {
Expand Down
26 changes: 13 additions & 13 deletions packages/lib/src/ComplexVisualEdit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as THREE from 'three'
import logger from './utils/logger'
import gfxutils from './gfx/gfxutils'
import './gfx/modes'
import { Group, Matrix4, Object3D, Vector3 } from 'three'

function _traverseComponentGroups(root, component, callback) {
const { children } = root
Expand Down Expand Up @@ -36,7 +36,7 @@ class ComplexComponentEditor extends ComplexEditor {
this._componentTransforms = []
for (let i = 0; i < complex._components.length; ++i) {
const component = complex._components[i]
this._componentTransforms[component._index] = new THREE.Object3D()
this._componentTransforms[component._index] = new Object3D()
}

this._inProgress = true
Expand Down Expand Up @@ -75,7 +75,7 @@ class ComplexComponentEditor extends ComplexEditor {
getAltObj() {
const res = {
objects: [],
pivot: new THREE.Vector3(0, 0, 0)
pivot: new Vector3(0, 0, 0)
}

const visual = this._complexVisual
Expand Down Expand Up @@ -111,12 +111,12 @@ class ComplexComponentEditor extends ComplexEditor {
// add dummy object that stores component transformation
res.objects.push(this._componentTransforms[component._index])

const bbmin = new THREE.Vector3(
const bbmin = new Vector3(
Number.MAX_VALUE,
Number.MAX_VALUE,
Number.MAX_VALUE
)
const bbmax = new THREE.Vector3(
const bbmax = new Vector3(
-Number.MAX_VALUE,
-Number.MAX_VALUE,
-Number.MAX_VALUE
Expand Down Expand Up @@ -235,11 +235,11 @@ class ComplexFragmentEditor extends ComplexEditor {
pivotPos.lerp(atoms[1].position, 0.5)
}

this._fragmentGeo = new THREE.Group()
this._fragmentGeo = new Group()
visual.add(this._fragmentGeo)
this._fragmentGeo.position.copy(pivotPos)

this._fragmentSelectionGeo = new THREE.Group()
this._fragmentSelectionGeo = new Group()
selection.add(this._fragmentSelectionGeo)
this._fragmentSelectionGeo.position.copy(pivotPos)

Expand All @@ -252,10 +252,10 @@ class ComplexFragmentEditor extends ComplexEditor {
continue
}

const vg = new THREE.Group()
const vg = new Group()
this._fragmentGeo.add(vg)

const sg = new THREE.Group()
const sg = new Group()
this._fragmentSelectionGeo.add(sg)

const meshes = g.getSubset(selectionMask, true)
Expand Down Expand Up @@ -289,7 +289,7 @@ class ComplexFragmentEditor extends ComplexEditor {

const p = this._fragmentGeo.position
const m = this._fragmentGeo.matrix.clone()
m.multiply(new THREE.Matrix4().makeTranslation(-p.x, -p.y, -p.z))
m.multiply(new Matrix4().makeTranslation(-p.x, -p.y, -p.z))

this._bakeAtomTransform(m, 1 << selectionBit)

Expand Down Expand Up @@ -334,7 +334,7 @@ class ComplexFragmentEditor extends ComplexEditor {
getAltObj() {
const res = {
objects: [],
pivot: new THREE.Vector3(0, 0, 0)
pivot: new Vector3(0, 0, 0)
}

res.objects.push(this._fragmentGeo, this._fragmentSelectionGeo)
Expand All @@ -344,7 +344,7 @@ class ComplexFragmentEditor extends ComplexEditor {
if (boundAtoms[0].bonds.length === 1) {
// single external bond allows rotation about bond axis
const bond = boundAtoms[0].bonds[0]
res.axis = new THREE.Vector3().subVectors(
res.axis = new Vector3().subVectors(
bond._right.position,
bond._left.position
)
Expand All @@ -353,7 +353,7 @@ class ComplexFragmentEditor extends ComplexEditor {
}
} else if (boundAtoms.length === 2) {
// two bound atoms allow rotation only about axis running through their centers
res.axis = new THREE.Vector3().subVectors(
res.axis = new Vector3().subVectors(
boundAtoms[1].position,
boundAtoms[0].position
)
Expand Down
23 changes: 10 additions & 13 deletions packages/lib/src/Miew-cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import _ from 'lodash'
import Miew from './Miew'
import { parser as parsercli } from './utils/MiewCLIParser'
import clihelp from './utils/MiewCLIHelp'
import logger from './utils/logger'
import utils from './utils'
import { slice, sortBy, get, keys, isUndefined, set, assign } from 'lodash'

const {
chem: { selectors },
Expand Down Expand Up @@ -176,15 +176,15 @@ class CLIUtils {
}

help(path) {
if (_.isUndefined(path)) {
return `${this.joinHelpStr(clihelp.$help)}\n${_.slice(
_.sortBy(_.keys(clihelp)),
if (isUndefined(path)) {
return `${this.joinHelpStr(clihelp.$help)}\n${slice(
sortBy(keys(clihelp)),
1
).join(', ')}\n`
}

const helpItem = _.get(clihelp, path)
return _.isUndefined(helpItem)
const helpItem = get(clihelp, path)
return isUndefined(helpItem)
? this.help()
: `${this.joinHelpStr(helpItem.$help)}\n`
}
Expand Down Expand Up @@ -239,7 +239,7 @@ class CLIUtils {
propagateProp(path, arg) {
if (path !== undefined) {
let argExc = {}
const adapter = options.adapters[typeof _.get(settings.defaults, path)]
const adapter = options.adapters[typeof get(settings.defaults, path)]
if (adapter === undefined) {
const pathExc = { message: `${path} is not existed` }
throw pathExc
Expand Down Expand Up @@ -277,10 +277,7 @@ class CLIUtils {
adapter(arg) !== arg > 0
) {
argExc = {
message: `${path} must be a "${typeof _.get(
settings.defaults,
path
)}"`
message: `${path} must be a "${typeof get(settings.defaults, path)}"`
}
throw argExc
}
Expand Down Expand Up @@ -335,7 +332,7 @@ ArgList.prototype.toJSO = function (cliUtils, cmd, arg) {

const list = this._values
for (let i = 0, n = list.length; i < n; ++i) {
_.set(
set(
res,
list[i].id,
cliUtils.propagateProp(
Expand Down Expand Up @@ -363,7 +360,7 @@ cliutils.echo = null
cliutils.representations = representationsStorage
cliutils.utils = utilFunctions

cliutils._ = _
cliutils.assign = assign
cliutils.CreateObjectPair = CreateObjectPair
cliutils.keyRemap = keyRemap
cliutils.Context = selectors.Context
Expand Down
Loading