-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
dEllipsoid.java
135 lines (104 loc) · 3.55 KB
/
dEllipsoid.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package net.aufdemrand.denizen.objects;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.objects.properties.PropertyParser;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import java.util.List;
public class dEllipsoid implements dObject {
//////////////////
// OBJECT FETCHER
////////////////
/**
* Gets an Ellipsoid Object from a string form.
*
* @param string the string
*
*/
@Fetchable("ellipsoid")
public static dEllipsoid valueOf(String string) {
string = string.substring("ellipsoid@".length());
List<String> split = CoreUtilities.Split(string, ',');
if (split.size() != 7)
return null;
dLocation location = new dLocation(dWorld.valueOf(split.get(3)).getWorld(),
aH.getDoubleFrom(split.get(0)), aH.getDoubleFrom(split.get(1)), aH.getDoubleFrom(split.get(2)));
dLocation size = new dLocation(null, aH.getDoubleFrom(split.get(4)),
aH.getDoubleFrom(split.get(5)), aH.getDoubleFrom(split.get(6)));
return new dEllipsoid(location, size);
}
/**
* Determines whether a string is a valid ellipsoid.
*
* @param arg the string
* @return true if matched, otherwise false
*
*/
public static boolean matches(String arg) {
return arg.startsWith("ellipsoid@");
}
///////////////
// Constructors
/////////////
public dEllipsoid(dLocation loc, dLocation size) {
this.loc = loc;
this.size = size;
}
/////////////////////
// INSTANCE FIELDS/METHODS
/////////////////
private dLocation loc;
private dLocation size;
public boolean contains(dLocation test) {
double xbase = test.getX() - loc.getX();
double ybase = test.getY() - loc.getY();
double zbase = test.getZ() - loc.getZ();
return ((xbase * xbase) / (size.getX() * size.getX())
+ (ybase * ybase) / (size.getY() * size.getY())
+ (zbase * zbase) / (size.getZ() * size.getZ()) < 1);
}
String prefix = "ellipsoid";
@Override
public String getPrefix() {
return prefix;
}
@Override
public String debug() {
return (prefix + "='<A>" + identify() + "<G>' ");
}
@Override
public boolean isUnique() {
return false;
}
@Override
public String getObjectType() {
return "Ellipsoid";
}
@Override
public String identify() {
return "ellipsoid@" + loc.getX() + "," + loc.getY() + "," + loc.getZ() + "," + loc.getWorld().getName()
+ "," + size.getX() + "," + size.getY() + "," + size.getZ();
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String toString() {
return identify();
}
@Override
public dObject setPrefix(String prefix) {
if (prefix != null)
this.prefix = prefix;
return this;
}
@Override
public String getAttribute(Attribute attribute) {
// Iterate through this object's properties' attributes
for (Property property : PropertyParser.getProperties(this)) {
String returned = property.getAttribute(attribute);
if (returned != null) return returned;
}
return new Element(identify()).getAttribute(attribute);
}
}