Skip to content

Commit

Permalink
Add point property
Browse files Browse the repository at this point in the history
  • Loading branch information
Sedictious committed Jul 26, 2019
1 parent 2d579c3 commit 7e8f7dd
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 3 deletions.
128 changes: 128 additions & 0 deletions src/czml3/properties.py
Expand Up @@ -989,6 +989,134 @@ def material(self):
return self._material


class Point(BaseCZMLObject):
"""A point, or viewport-aligned circle."""

KNOWN_PROPERTIES = [
"show",
"pixelSize",
"heightReference",
"color",
"outlineColor",
"outlineWidth",
"scaleByDistance",
"translucencyByDistance",
"distanceDisplayCondition",
"disableDepthTestDistance",
]

def __init__(
self,
*,
show=None,
pixelSize=None,
heightReference=None,
color=None,
outlineColor=None,
outlineWidth=None,
scaleByDistance=None,
translucencyByDistance=None,
distanceDisplayCondition=None,
disableDepthTestDistance=None,
):
self._show = show
self._pixel_size = pixelSize
self._height_reference = heightReference
self._color = color
self._outline_color = outlineColor
self._outline_width = outlineWidth
self._scale_by_distance = scaleByDistance
self._translucency_by_distance = translucencyByDistance
self._distance_display_condition = distanceDisplayCondition
self._disable_depth_test_distance = disableDepthTestDistance

@property
def show(self):
"""Whether or not the point is shown."""
return self._show

@property
def pixelSize(self):
"""The size of the point, in pixels."""
return self._pixel_size

@property
def heightReference(self):
"""The height reference of the point, which indicates if the position is relative to terrain or not."""
return self._height_reference

@property
def color(self):
"""The color of the point."""
return self._color

@property
def outlineColor(self):
"""The color of the outline of the point."""
return self._outline_color

@property
def outlineWidth(self):
"""The width of the outline of the point."""
return self._outline_width

@property
def scaleByDistance(self):
""" How the point's scale should change based on the point's distance from the camera.
This scalar value will be multiplied by pixelSize.
"""
return self._scale_by_distance

@property
def translucencyByDistance(self):
""" How the point's translucency should change based on the point's distance from the camera.
This scalar value should range from 0 to 1.
"""
return self._translucency_by_distance

@property
def distanceDisplayCondition(self):
"""The display condition specifying the distance from the camera at which this point will be displayed."""
return self._distance_display_condition

@property
def disableDepthTestDistance(self):
""" The distance from the camera at which to disable the depth test. This can be used to prevent clipping
against terrain, for example. When set to zero, the depth test is always applied.
When set to Infinity, the depth test is never applied.
"""
return self._disable_depth_test_distance


class NearFarScalar(BaseCZMLObject, Interpolatable, Deletable):
""" A numeric value which will be linearly interpolated between two values based on an object's distance from the
camera, in eye coordinates.
The computed value will interpolate between the near value and the far value while the camera distance falls
between the near distance and the far distance, and will be clamped to the near or far value while the distance is
less than the near distance or greater than the far distance, respectively.
"""

KNOWN_PROPERTIES = ["nearFarScalar", "reference"]

def __init__(self, *, nearFarScalar=None, reference=None):
self._near_far_scalar = nearFarScalar
self._reference = reference

@property
def nearFarScalar(self):
""" The value specified as four values [NearDistance, NearValue, FarDistance, FarValue], with distances in eye
coordinates in meters.
"""
return self._near_far_scalar

@property
def reference(self):
"""The value specified as a reference to another property."""
return self._reference


# noinspection PyPep8Naming
class Label(BaseCZMLObject, HasAlignment):
"""A string of text."""
Expand Down
31 changes: 28 additions & 3 deletions src/czml3/types.py
Expand Up @@ -80,7 +80,7 @@ def values(self):
return self._values

def to_json(self):
return list(self.values)
return list(self._values)


class RgbaValue(BaseCZMLObject):
Expand Down Expand Up @@ -121,7 +121,7 @@ def values(self):
return self._values

def to_json(self):
return list(self.values)
return list(self._values)


class ReferenceValue(BaseCZMLObject):
Expand Down Expand Up @@ -175,7 +175,7 @@ def values(self):
return self._values

def to_json(self):
return list(self.values)
return list(self._values)


class StringValue(BaseCZMLObject, Deletable):
Expand Down Expand Up @@ -320,6 +320,31 @@ def to_json(self):
return list(self._values)


class NearFarScalarValue(BaseCZMLObject, Deletable):
"""A near-far scalar value specified as four values [NearDistance, NearValue, FarDistance, FarValue].
If the array has four elements, the value is constant. If it has five or more elements, they are time-tagged
samples arranged as [Time, NearDistance, NearValue, FarDistance, FarValue, Time, NearDistance, NearValue,
FarDistance, FarValue, ...], where Time is an ISO 8601 date and time string or seconds since epoch.
"""

def __init__(self, *, values=None):
if not (len(values) == 4 or len(values) % 5 == 0):
raise ValueError(
"Input values must have either 4 or N * 5 values, "
"where N is the number of time-tagged samples."
)

self._values = values

@property
def values(self):
return self._values

def to_json(self):
return list(self._values)


class Uri(BaseCZMLObject, Deletable):
"""A URI value.
Expand Down
29 changes: 29 additions & 0 deletions tests/test_properties.py
Expand Up @@ -10,6 +10,8 @@
HeightReference,
ImageMaterial,
Material,
NearFarScalar,
Point,
Polyline,
PolylineMaterial,
Position,
Expand All @@ -26,12 +28,39 @@
DistanceDisplayConditionValue,
HeightReferenceValue,
IntervalValue,
NearFarScalarValue,
Sequence,
ShadowModeValue,
Uri,
)


def test_point():
expected_result = """{
"show": true,
"pixelSize": 10,
"scaleByDistance": {
"nearFarScalar": [
150,
2.0,
15000000,
0.5
]
},
"disableDepthTestDistance": 1.2
}"""

pnt = Point(
show=True,
pixelSize=10,
scaleByDistance=NearFarScalar(
nearFarScalar=NearFarScalarValue(values=[150, 2.0, 15000000, 0.5])
),
disableDepthTestDistance=1.2,
)
assert repr(pnt) == expected_result


def test_arc_type():
expected_result = """{
"arcType": "NONE"
Expand Down

0 comments on commit 7e8f7dd

Please sign in to comment.