1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 * @short_description: Angular dimensions
25 * The #AdgADim entity defines an angular dimension.
31 * All fields are privates and should not be used directly.
32 * Use its public methods instead.
37 #include "adg-adim-private.h"
38 #include "adg-dim-private.h"
41 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_adim_parent_class)
42 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_adim_parent_class)
54 static void dispose (GObject
*object
);
55 static void get_property (GObject
*object
,
59 static void set_property (GObject
*object
,
63 static void local_changed (AdgEntity
*entity
);
64 static void invalidate (AdgEntity
*entity
);
65 static void arrange (AdgEntity
*entity
);
66 static void render (AdgEntity
*entity
,
68 static gchar
* default_value (AdgDim
*dim
);
69 static void update_geometry (AdgADim
*adim
);
70 static void update_entities (AdgADim
*adim
);
71 static void unset_trail (AdgADim
*adim
);
72 static void dispose_markers (AdgADim
*adim
);
73 static gboolean
get_info (AdgADim
*adim
,
77 static CpmlPath
* trail_callback (AdgTrail
*trail
,
81 G_DEFINE_TYPE(AdgADim
, adg_adim
, ADG_TYPE_DIM
);
85 adg_adim_class_init(AdgADimClass
*klass
)
87 GObjectClass
*gobject_class
;
88 AdgEntityClass
*entity_class
;
89 AdgDimClass
*dim_class
;
92 gobject_class
= (GObjectClass
*) klass
;
93 entity_class
= (AdgEntityClass
*) klass
;
94 dim_class
= (AdgDimClass
*) klass
;
96 g_type_class_add_private(klass
, sizeof(AdgADimPrivate
));
98 gobject_class
->dispose
= dispose
;
99 gobject_class
->get_property
= get_property
;
100 gobject_class
->set_property
= set_property
;
102 entity_class
->local_changed
= local_changed
;
103 entity_class
->invalidate
= invalidate
;
104 entity_class
->arrange
= arrange
;
105 entity_class
->render
= render
;
107 dim_class
->default_value
= default_value
;
109 param
= g_param_spec_boxed("org1",
111 P_("Where the first line comes from: this point is used toghether with \"ref1\" to align the first extension line"),
114 g_object_class_install_property(gobject_class
, PROP_ORG1
, param
);
116 param
= g_param_spec_boxed("org2",
118 P_("Where the second line comes from: this point is used toghether with \"ref2\" to align the second extension line"),
121 g_object_class_install_property(gobject_class
, PROP_ORG2
, param
);
125 adg_adim_init(AdgADim
*adim
)
127 AdgADimPrivate
*data
;
128 cairo_path_data_t move_to
, line_to
, arc_to
;
130 data
= G_TYPE_INSTANCE_GET_PRIVATE(adim
, ADG_TYPE_ADIM
, AdgADimPrivate
);
131 move_to
.header
.type
= CAIRO_PATH_MOVE_TO
;
132 move_to
.header
.length
= 2;
133 line_to
.header
.type
= CAIRO_PATH_LINE_TO
;
134 line_to
.header
.length
= 2;
135 arc_to
.header
.type
= CAIRO_PATH_ARC_TO
;
136 arc_to
.header
.length
= 3;
140 data
->has_extension1
= TRUE
;
141 data
->has_extension2
= TRUE
;
143 data
->cpml
.path
.status
= CAIRO_STATUS_INVALID_PATH_DATA
;
144 data
->cpml
.path
.data
= data
->cpml
.data
;
145 data
->cpml
.path
.num_data
= G_N_ELEMENTS(data
->cpml
.data
);
146 data
->cpml
.path
.data
[0] = move_to
;
147 data
->cpml
.path
.data
[2] = arc_to
;
148 data
->cpml
.path
.data
[5] = move_to
;
149 data
->cpml
.path
.data
[7] = line_to
;
150 data
->cpml
.path
.data
[9] = move_to
;
151 data
->cpml
.path
.data
[11] = line_to
;
154 data
->marker1
= NULL
;
155 data
->marker2
= NULL
;
157 data
->geometry_arranged
= FALSE
;
163 dispose(GObject
*object
)
166 AdgADimPrivate
*data
;
168 adim
= (AdgADim
*) object
;
171 dispose_markers((AdgADim
*) object
);
173 if (data
->org1
!= NULL
) {
174 adg_point_destroy(data
->org1
);
177 if (data
->org2
!= NULL
) {
178 adg_point_destroy(data
->org2
);
182 if (PARENT_OBJECT_CLASS
->dispose
!= NULL
)
183 PARENT_OBJECT_CLASS
->dispose(object
);
187 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
189 AdgADimPrivate
*data
= ((AdgADim
*) object
)->data
;
193 g_value_set_boxed(value
, &data
->org1
);
196 g_value_set_boxed(value
, &data
->org2
);
198 case PROP_HAS_EXTENSION1
:
199 g_value_set_boolean(value
, data
->has_extension1
);
201 case PROP_HAS_EXTENSION2
:
202 g_value_set_boolean(value
, data
->has_extension2
);
205 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
211 set_property(GObject
*object
, guint prop_id
,
212 const GValue
*value
, GParamSpec
*pspec
)
215 AdgADimPrivate
*data
;
217 adim
= (AdgADim
*) object
;
222 if (data
->org1
!= NULL
)
223 adg_point_destroy(data
->org1
);
224 data
->org1
= g_value_dup_boxed(value
);
227 if (data
->org2
!= NULL
)
228 adg_point_destroy(data
->org2
);
229 data
->org2
= g_value_dup_boxed(value
);
231 case PROP_HAS_EXTENSION1
:
232 data
->has_extension1
= g_value_get_boolean(value
);
234 case PROP_HAS_EXTENSION2
:
235 data
->has_extension2
= g_value_get_boolean(value
);
238 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
247 * Creates a new - undefined - angular dimension. You must, at least,
248 * define the reference points with adg_dim_set_ref(), the origins of
249 * the lines ending with the reference points with adg_adim_set_org()
250 * and the reference for positioning the quote with adg_dim_set_pos().
252 * Returns: the newly created angular dimension entity
257 return g_object_new(ADG_TYPE_ADIM
, NULL
);
262 * @ref1: first reference point
263 * @ref2: second reference point
264 * @org1: first origin point
265 * @org2: second origin point
267 * Creates a new angular dimension, specifing all the needed
268 * properties in one shot.
270 * Returns: the newly created angular dimension entity
273 adg_adim_new_full(const AdgPair
*ref1
, const AdgPair
*ref2
,
274 const AdgPair
*org1
, const AdgPair
*org2
,
280 adim
= g_object_new(ADG_TYPE_ADIM
, NULL
);
281 dim
= (AdgDim
*) adim
;
283 adg_dim_set_ref(dim
, ref1
, ref2
);
284 adg_adim_set_org(adim
, org1
, org2
);
285 adg_dim_set_pos(dim
, pos
);
291 * adg_adim_new_full_explicit:
292 * @ref1_x: the x coordinate of the first reference point
293 * @ref1_y: the y coordinate of the first reference point
294 * @ref2_x: the x coordinate of the second reference point
295 * @ref2_y: the y coordinate of the second reference point
296 * @direction: angle where to extend the dimension
297 * @pos_x: the x coordinate of the position reference
298 * @pos_y: the y coordinate of the position reference
300 * Wrappes adg_adim_new_full() with explicit values.
302 * Returns: the newly created linear dimension entity
305 adg_adim_new_full_explicit(gdouble ref1_x
, gdouble ref1_y
,
306 gdouble ref2_x
, gdouble ref2_y
,
307 gdouble org1_x
, gdouble org1_y
,
308 gdouble org2_x
, gdouble org2_y
,
309 gdouble pos_x
, gdouble pos_y
)
311 AdgPair ref1
, ref2
, org1
, org2
, pos
;
324 return adg_adim_new_full(&ref1
, &ref2
, &org1
, &org2
, &pos
);
328 * adg_adim_new_full_from_model:
329 * @model: the model from which the named pairs are taken
330 * @ref1: the end point of the first line
331 * @ref2: the end point of the second line
332 * @org1: the origin of the first line
333 * @org2: the origin of the second line
334 * @pos: the position reference
336 * Creates a new angular dimension, specifing all the needed properties
337 * in one shot and using named pairs from @model.
339 * Returns: the newly created angular dimension entity
342 adg_adim_new_full_from_model(AdgModel
*model
,
343 const gchar
*ref1
, const gchar
*ref2
,
344 const gchar
*org1
, const gchar
*org2
,
350 adim
= g_object_new(ADG_TYPE_ADIM
, NULL
);
351 dim
= (AdgDim
*) adim
;
353 adg_dim_set_ref_from_model(dim
, model
, ref1
, ref2
);
354 adg_dim_set_pos_from_model(dim
, model
, pos
);
355 adg_adim_set_org_from_model(adim
, model
, org1
, org2
);
364 * Gets the first origin of @adim. The returned pair is owned by
365 * @adim and should not be modified or freed.
367 * Returns: a pointer to the internal #AdgPair or %NULL on errors
370 adg_adim_get_org1(AdgADim
*adim
)
372 AdgADimPrivate
*data
;
374 g_return_val_if_fail(ADG_IS_ADIM(adim
), NULL
);
378 return adg_point_pair(data
->org1
);
385 * Gets the second origin of @adim. The returned pair is owned by
386 * @adim and should not be modified or freed.
388 * Returns: a pointer to the internal #AdgPair or %NULL on errors
391 adg_adim_get_org2(AdgADim
*adim
)
393 AdgADimPrivate
*data
;
395 g_return_val_if_fail(ADG_IS_ADIM(adim
), NULL
);
399 return adg_point_pair(data
->org2
);
405 * @org1: the first origin
406 * @org2: the second origin
408 * Sets at once the two origins on @adim. One of @org1 or @org2
409 * (but not both) could be %NULL, in which case only the non-null
413 adg_adim_set_org(AdgADim
*adim
, const AdgPair
*org1
, const AdgPair
*org2
)
416 AdgADimPrivate
*data
;
418 g_return_if_fail(ADG_IS_ADIM(adim
));
419 g_return_if_fail(org1
!= NULL
|| org2
!= NULL
);
421 object
= (GObject
*) adim
;
424 g_object_freeze_notify(object
);
427 if (data
->org1
== NULL
)
428 data
->org1
= adg_point_new();
430 adg_point_set(data
->org1
, org1
);
432 g_object_notify(object
, "org1");
436 if (data
->org2
== NULL
)
437 data
->org2
= adg_point_new();
439 adg_point_set(data
->org2
, org2
);
441 g_object_notify(object
, "org2");
444 g_object_thaw_notify(object
);
448 * adg_adim_set_org_explicit:
450 * @org1_x: x coordinate of org1
451 * @org1_y: y coordinate of org1
452 * @org2_x: x coordinate of org2
453 * @org2_y: y coordinate of org2
455 * Works in the same way as adg_adim_set_org() but using
456 * explicit coordinates instead of #AdgPair args. The
457 * notable difference is that, by using gdouble values,
458 * you can't set only a single origin point.
461 adg_adim_set_org_explicit(AdgADim
*adim
,
462 gdouble org1_x
, gdouble org1_y
,
463 gdouble org2_x
, gdouble org2_y
)
472 adg_adim_set_org(adim
, &org1
, &org2
);
476 * adg_adim_set_org_from_model:
478 * @model: the source #AdgModel
479 * @org1: name of the pair in @model to use as org1
480 * @org2: name of the pair in @model to use as org2
482 * Sets #AdgADim:org1 and #AdgADim:org2 properties by linking
483 * them to the @org1 and @org2 named pairs in @model. @org1
484 * or @org2 could be %NULL (but not both), in which case
485 * only the non-null origin point is changed.
487 * Using this function twice you can also link the origin
488 * points to named pairs taken from different models:
491 * adg_adim_set_org_from_model(adim, model1, org1, NULL);
492 * adg_adim_set_org_from_model(adim, model2, NULL, org2);
496 adg_adim_set_org_from_model(AdgADim
*adim
, AdgModel
*model
,
497 const gchar
*org1
, const gchar
*org2
)
500 AdgADimPrivate
*data
;
502 g_return_if_fail(ADG_IS_ADIM(adim
));
503 g_return_if_fail(ADG_IS_MODEL(model
));
504 g_return_if_fail(org1
!= NULL
|| org2
!= NULL
);
506 object
= (GObject
*) adim
;
509 g_object_freeze_notify(object
);
512 if (data
->org1
== NULL
)
513 data
->org1
= adg_point_new();
515 adg_point_set_from_model(data
->org1
, model
, org1
);
517 g_object_notify(object
, "org1");
521 if (data
->org2
== NULL
)
522 data
->org2
= adg_point_new();
524 adg_point_set_from_model(data
->org2
, model
, org2
);
526 g_object_notify(object
, "org2");
529 g_object_thaw_notify(object
);
534 local_changed(AdgEntity
*entity
)
536 unset_trail((AdgADim
*) entity
);
538 PARENT_ENTITY_CLASS
->local_changed(entity
);
542 invalidate(AdgEntity
*entity
)
545 AdgADimPrivate
*data
;
547 adim
= (AdgADim
*) entity
;
550 dispose_markers(adim
);
551 data
->geometry_arranged
= FALSE
;
554 adg_point_invalidate(data
->org1
);
555 adg_point_invalidate(data
->org2
);
557 if (PARENT_ENTITY_CLASS
->invalidate
!= NULL
)
558 PARENT_ENTITY_CLASS
->invalidate(entity
);
562 arrange(AdgEntity
*entity
)
566 AdgADimPrivate
*data
;
568 const AdgMatrix
*local
;
569 AdgPair ref1
, ref2
, base1
, base12
, base2
;
572 PARENT_ENTITY_CLASS
->arrange(entity
);
574 adim
= (AdgADim
*) entity
;
575 dim
= (AdgDim
*) adim
;
577 quote
= adg_dim_get_quote(dim
);
579 update_geometry(adim
);
580 update_entities(adim
);
582 if (data
->cpml
.path
.status
== CAIRO_STATUS_SUCCESS
) {
583 AdgEntity
*quote_entity
= (AdgEntity
*) quote
;
584 adg_entity_set_global_map(quote_entity
, &data
->quote
.global_map
);
585 adg_entity_set_local_map(quote_entity
, &data
->quote
.local_map
);
589 local
= adg_entity_local_matrix(entity
);
591 /* Apply the local matrix to the relevant points */
592 cpml_pair_transform(cpml_pair_copy(&ref1
, adg_dim_get_ref1(dim
)), local
);
593 cpml_pair_transform(cpml_pair_copy(&ref2
, adg_dim_get_ref2(dim
)), local
);
594 cpml_pair_transform(cpml_pair_copy(&base1
, &data
->point
.base1
), local
);
595 cpml_pair_transform(cpml_pair_copy(&base12
, &data
->point
.base12
), local
);
596 cpml_pair_transform(cpml_pair_copy(&base2
, &data
->point
.base2
), local
);
598 /* Combine points and global shifts to build the path */
599 cpml_pair_add(cpml_pair_copy(&pair
, &ref1
), &data
->shift
.from1
);
600 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[6]);
602 cpml_pair_add(cpml_pair_copy(&pair
, &base1
), &data
->shift
.base1
);
603 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[1]);
605 cpml_pair_add(&pair
, &data
->shift
.to1
);
606 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[8]);
608 cpml_pair_add(cpml_pair_copy(&pair
, &base12
), &data
->shift
.base12
);
609 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[3]);
611 cpml_pair_add(cpml_pair_copy(&pair
, &ref2
), &data
->shift
.from2
);
612 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[10]);
614 cpml_pair_add(cpml_pair_copy(&pair
, &base2
), &data
->shift
.base2
);
615 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[4]);
617 cpml_pair_add(&pair
, &data
->shift
.to2
);
618 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[12]);
620 data
->cpml
.path
.status
= CAIRO_STATUS_SUCCESS
;
623 /* Update global and local map of the quote container */
624 AdgEntity
*quote_entity
;
628 quote_entity
= (AdgEntity
*) quote
;
629 angle
= adg_dim_quote_angle(dim
, (data
->angle1
+ data
->angle2
) / 2 + G_PI_2
);
630 adg_matrix_copy(&matrix
, local
);
631 cairo_matrix_invert(&matrix
);
633 cpml_pair_from_cairo(&pair
, &data
->cpml
.data
[3]);
634 cairo_matrix_transform_point(&matrix
, &pair
.x
, &pair
.y
);
635 cairo_matrix_init_translate(&matrix
, pair
.x
, pair
.y
);
636 adg_entity_set_local_map(quote_entity
, &matrix
);
638 cairo_matrix_init_rotate(&matrix
, angle
);
639 adg_entity_transform_global_map(quote_entity
, &matrix
, ADG_TRANSFORM_BEFORE
);
641 adg_entity_get_global_map(quote_entity
, &data
->quote
.global_map
);
642 adg_entity_get_local_map(quote_entity
, &data
->quote
.local_map
);
645 /* Signal to the markers (if any) that the path has changed */
646 if (data
->marker1
!= NULL
) {
647 adg_marker_set_segment(data
->marker1
, data
->trail
, 1);
648 adg_entity_local_changed((AdgEntity
*) data
->marker1
);
651 if (data
->marker2
!= NULL
) {
652 adg_marker_set_segment(data
->marker2
, data
->trail
, 1);
653 adg_entity_local_changed((AdgEntity
*) data
->marker2
);
656 /* TODO: compute the extents */
660 render(AdgEntity
*entity
, cairo_t
*cr
)
664 AdgADimPrivate
*data
;
665 AdgDimStyle
*dim_style
;
667 const cairo_path_t
*cairo_path
;
669 adim
= (AdgADim
*) entity
;
670 dim
= (AdgDim
*) entity
;
672 dim_style
= GET_DIM_STYLE(dim
);
674 adg_style_apply((AdgStyle
*) dim_style
, entity
, cr
);
676 if (data
->marker1
!= NULL
)
677 adg_entity_render((AdgEntity
*) data
->marker1
, cr
);
679 if (data
->marker2
!= NULL
)
680 adg_entity_render((AdgEntity
*) data
->marker2
, cr
);
682 adg_entity_render((AdgEntity
*) adg_dim_get_quote(dim
), cr
);
684 dress
= adg_dim_style_get_line_dress(dim_style
);
685 adg_entity_apply_dress(entity
, dress
, cr
);
687 cairo_path
= adg_trail_get_cairo_path(data
->trail
);
688 cairo_append_path(cr
, cairo_path
);
693 default_value(AdgDim
*dim
)
696 AdgADimPrivate
*data
;
697 AdgDimStyle
*dim_style
;
701 adim
= (AdgADim
*) dim
;
703 dim_style
= GET_DIM_STYLE(dim
);
704 format
= adg_dim_style_get_number_format(dim_style
);
706 update_geometry(adim
);
707 angle
= (data
->angle2
- data
->angle1
) * 180 / M_PI
;
709 return g_strdup_printf(format
, angle
);
712 /* With "geometry" is considered any data (point, vector or angle)
713 * that can be cached: this is strictly related on how the arrange()
716 update_geometry(AdgADim
*adim
)
718 AdgADimPrivate
*data
;
719 AdgDimStyle
*dim_style
;
720 gdouble from_offset
, to_offset
;
721 gdouble spacing
, level
;
722 CpmlVector vector
[3];
728 if (data
->geometry_arranged
)
731 if (!get_info(adim
, vector
, ¢er
, &distance
)) {
732 /* Parallel lines: hang with an error message */
733 g_warning("%s: trying to set an angular dimension on parallel lines",
738 dim_style
= GET_DIM_STYLE(adim
);
739 from_offset
= adg_dim_style_get_from_offset(dim_style
);
740 to_offset
= adg_dim_style_get_to_offset(dim_style
);
741 spacing
= adg_dim_style_get_baseline_spacing(dim_style
);
742 level
= adg_dim_get_level((AdgDim
*) adim
);
745 cpml_vector_set_length(&vector
[0], from_offset
);
746 cpml_pair_copy(&data
->shift
.from1
, &vector
[0]);
749 cpml_vector_set_length(&vector
[0], level
* spacing
);
750 cpml_pair_copy(&data
->shift
.base1
, &vector
[0]);
753 cpml_vector_set_length(&vector
[0], to_offset
);
754 cpml_pair_copy(&data
->shift
.to1
, &vector
[0]);
757 cpml_vector_set_length(&vector
[2], from_offset
);
758 cpml_pair_copy(&data
->shift
.from2
, &vector
[2]);
761 cpml_vector_set_length(&vector
[2], level
* spacing
);
762 cpml_pair_copy(&data
->shift
.base2
, &vector
[2]);
765 cpml_vector_set_length(&vector
[2], to_offset
);
766 cpml_pair_copy(&data
->shift
.to2
, &vector
[2]);
769 cpml_vector_set_length(&vector
[1], level
* spacing
);
770 cpml_pair_copy(&data
->shift
.base12
, &vector
[1]);
772 /* Distance can be 0, so the following will leave the
773 * vector array in undefined state */
776 cpml_vector_set_length(&vector
[0], distance
);
777 cpml_pair_add(cpml_pair_copy(&data
->point
.base1
, &vector
[0]), ¢er
);
780 cpml_vector_set_length(&vector
[2], distance
);
781 cpml_pair_add(cpml_pair_copy(&data
->point
.base2
, &vector
[2]), ¢er
);
784 cpml_vector_set_length(&vector
[1], distance
);
785 cpml_pair_add(cpml_pair_copy(&data
->point
.base12
, &vector
[1]), ¢er
);
787 data
->geometry_arranged
= TRUE
;
791 update_entities(AdgADim
*adim
)
793 AdgADimPrivate
*data
;
794 AdgDimStyle
*dim_style
;
797 dim_style
= GET_DIM_STYLE(adim
);
799 if (data
->trail
== NULL
)
800 data
->trail
= adg_trail_new(trail_callback
, adim
);
802 if (data
->marker1
== NULL
)
803 data
->marker1
= adg_dim_style_marker1_new(dim_style
);
805 if (data
->marker2
== NULL
)
806 data
->marker2
= adg_dim_style_marker2_new(dim_style
);
810 unset_trail(AdgADim
*adim
)
812 AdgADimPrivate
*data
= adim
->data
;
814 if (data
->trail
!= NULL
)
815 adg_model_clear((AdgModel
*) data
->trail
);
817 data
->cpml
.path
.status
= CAIRO_STATUS_INVALID_PATH_DATA
;
821 dispose_markers(AdgADim
*adim
)
823 AdgADimPrivate
*data
= adim
->data
;
825 if (data
->trail
!= NULL
) {
826 g_object_unref(data
->trail
);
830 if (data
->marker1
!= NULL
) {
831 g_object_unref(data
->marker1
);
832 data
->marker1
= NULL
;
835 if (data
->marker2
!= NULL
) {
836 g_object_unref(data
->marker2
);
837 data
->marker2
= NULL
;
842 get_info(AdgADim
*adim
, CpmlVector vector
[],
843 AdgPair
*center
, gdouble
*distance
)
846 AdgADimPrivate
*data
;
847 const AdgPair
*ref1
, *ref2
;
850 dim
= (AdgDim
*) adim
;
852 ref1
= adg_dim_get_ref1(dim
);
853 ref2
= adg_dim_get_ref2(dim
);
855 cpml_pair_sub(cpml_pair_copy(&vector
[0], ref1
), adg_point_pair(data
->org1
));
856 cpml_pair_sub(cpml_pair_copy(&vector
[2], ref2
), adg_point_pair(data
->org2
));
858 factor
= vector
[0].x
* vector
[2].y
- vector
[0].y
* vector
[2].x
;
862 factor
= ((ref1
->y
- ref2
->y
) * vector
[2].x
-
863 (ref1
->x
- ref2
->x
) * vector
[2].y
) / factor
;
865 center
->x
= ref1
->x
+ vector
[0].x
* factor
;
866 center
->y
= ref1
->y
+ vector
[0].y
* factor
;
867 *distance
= cpml_pair_distance(center
, adg_dim_get_pos(dim
));
868 data
->angle1
= cpml_vector_angle(&vector
[0]);
869 data
->angle2
= cpml_vector_angle(&vector
[2]);
870 while (data
->angle2
< data
->angle1
)
871 data
->angle2
+= M_PI
* 2;
873 cpml_vector_from_angle(&vector
[1], (data
->angle1
+ data
->angle2
) / 2);
879 trail_callback(AdgTrail
*trail
, gpointer user_data
)
882 AdgADimPrivate
*data
;
884 adim
= (AdgADim
*) user_data
;
887 return &data
->cpml
.path
;